Makes all custom caption settings unsearchable when custom captions are not active.
Unifies all custom caption controllers under a base controller, whose searchability is directly determined by CaptionHelper#getCustomCaptionAvailability(). Test: atest CaptionHelperTest Bug: 353757664 Flag: com.android.settings.accessibility.fix_a11y_settings_search Change-Id: If44e6eca4c72aa4413cd0a6e8735dbb22c7abe62
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class BaseCaptioningCustomController extends BasePreferenceController {
|
||||
protected final CaptionHelper mCaptionHelper;
|
||||
|
||||
public BaseCaptioningCustomController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mCaptionHelper.getCustomCaptionAvailability();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@@ -211,4 +213,14 @@ public class CaptionHelper {
|
||||
public Locale getLocale() {
|
||||
return mCaptioningManager.getLocale();
|
||||
}
|
||||
|
||||
/** Returns availability for custom caption preferences, depending on current user style. */
|
||||
public int getCustomCaptionAvailability() {
|
||||
if (com.android.settings.accessibility.Flags.fixA11ySettingsSearch()) {
|
||||
return (getRawUserStyle() == CaptionStyle.PRESET_CUSTOM)
|
||||
? AVAILABLE : AVAILABLE_UNSEARCHABLE;
|
||||
} else {
|
||||
return AVAILABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,23 +25,15 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning background color. */
|
||||
public class CaptioningBackgroundColorController extends BasePreferenceController
|
||||
public class CaptioningBackgroundColorController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED;
|
||||
|
||||
public CaptioningBackgroundColorController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,22 +23,13 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning background opacity. */
|
||||
public class CaptioningBackgroundOpacityController extends BasePreferenceController
|
||||
public class CaptioningBackgroundOpacityController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
|
||||
public CaptioningBackgroundOpacityController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,7 +28,6 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -37,12 +36,11 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/** Preference controller for captioning custom visibility. */
|
||||
public class CaptioningCustomController extends BasePreferenceController
|
||||
public class CaptioningCustomController extends BaseCaptioningCustomController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
@Nullable
|
||||
private Preference mCustom;
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
private final ContentResolver mContentResolver;
|
||||
@VisibleForTesting
|
||||
AccessibilitySettingsContentObserver mSettingsContentObserver;
|
||||
@@ -52,16 +50,15 @@ public class CaptioningCustomController extends BasePreferenceController
|
||||
);
|
||||
|
||||
public CaptioningCustomController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey, new CaptionHelper(context),
|
||||
this(context, preferenceKey,
|
||||
new AccessibilitySettingsContentObserver(new Handler(Looper.getMainLooper())));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
CaptioningCustomController(
|
||||
Context context, String preferenceKey, CaptionHelper captionHelper,
|
||||
Context context, String preferenceKey,
|
||||
AccessibilitySettingsContentObserver contentObserver) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
mContentResolver = context.getContentResolver();
|
||||
mSettingsContentObserver = contentObserver;
|
||||
mSettingsContentObserver.registerKeysToObserverCallback(CAPTIONING_FEATURE_KEYS, key -> {
|
||||
@@ -71,15 +68,6 @@ public class CaptioningCustomController extends BasePreferenceController
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (com.android.settings.accessibility.Flags.fixA11ySettingsSearch()) {
|
||||
return (shouldShowPreference()) ? AVAILABLE : AVAILABLE_UNSEARCHABLE;
|
||||
} else {
|
||||
return AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
@@ -23,22 +23,13 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning edge color. */
|
||||
public class CaptioningEdgeColorController extends BasePreferenceController
|
||||
public class CaptioningEdgeColorController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
|
||||
public CaptioningEdgeColorController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,22 +21,13 @@ import android.content.Context;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning edge type. */
|
||||
public class CaptioningEdgeTypeController extends BasePreferenceController
|
||||
public class CaptioningEdgeTypeController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
|
||||
public CaptioningEdgeTypeController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,23 +24,15 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning foreground color. */
|
||||
public class CaptioningForegroundColorController extends BasePreferenceController
|
||||
public class CaptioningForegroundColorController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED;
|
||||
|
||||
public CaptioningForegroundColorController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,22 +23,13 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning foreground opacity. */
|
||||
public class CaptioningForegroundOpacityController extends BasePreferenceController
|
||||
public class CaptioningForegroundOpacityController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
|
||||
public CaptioningForegroundOpacityController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,22 +23,12 @@ import android.view.accessibility.CaptioningManager.CaptionStyle;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning type face. */
|
||||
public class CaptioningTypefaceController extends BasePreferenceController
|
||||
public class CaptioningTypefaceController extends BaseCaptioningCustomController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
|
||||
public CaptioningTypefaceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = new CaptionHelper(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,43 +19,21 @@ package com.android.settings.accessibility;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.view.accessibility.CaptioningManager;
|
||||
import android.view.accessibility.CaptioningManager.CaptionStyle;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning window color. */
|
||||
public class CaptioningWindowColorController extends BasePreferenceController
|
||||
public class CaptioningWindowColorController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED;
|
||||
|
||||
@VisibleForTesting
|
||||
CaptioningWindowColorController(Context context, String preferenceKey,
|
||||
CaptionHelper captionHelper) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = captionHelper;
|
||||
}
|
||||
|
||||
public CaptioningWindowColorController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey, new CaptionHelper(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (com.android.settings.accessibility.Flags.fixA11ySettingsSearch()) {
|
||||
return (mCaptionHelper.getRawUserStyle()
|
||||
== CaptioningManager.CaptionStyle.PRESET_CUSTOM)
|
||||
? AVAILABLE : AVAILABLE_UNSEARCHABLE;
|
||||
} else {
|
||||
return AVAILABLE;
|
||||
}
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,41 +18,18 @@ package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.accessibility.CaptioningManager;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/** Preference controller for captioning window opacity. */
|
||||
public class CaptioningWindowOpacityController extends BasePreferenceController
|
||||
public class CaptioningWindowOpacityController extends BaseCaptioningCustomController
|
||||
implements OnValueChangedListener {
|
||||
|
||||
private final CaptionHelper mCaptionHelper;
|
||||
|
||||
@VisibleForTesting
|
||||
CaptioningWindowOpacityController(Context context, String preferenceKey,
|
||||
CaptionHelper captionHelper) {
|
||||
super(context, preferenceKey);
|
||||
mCaptionHelper = captionHelper;
|
||||
}
|
||||
|
||||
public CaptioningWindowOpacityController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey, new CaptionHelper(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (com.android.settings.accessibility.Flags.fixA11ySettingsSearch()) {
|
||||
return (mCaptionHelper.getRawUserStyle()
|
||||
== CaptioningManager.CaptionStyle.PRESET_CUSTOM)
|
||||
? AVAILABLE : AVAILABLE_UNSEARCHABLE;
|
||||
} else {
|
||||
return AVAILABLE;
|
||||
}
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user