Support OHM quick settings tooltips when feature on
Bug: 210356011 Test: make RunSettingsRoboTests ROBOTEST_FILTER=AccessibilityShortcutPreferenceFragmentTest Change-Id: I3b35d9bb347b7e516db94a4b801a4484f6f38ca8
This commit is contained in:
@@ -28,6 +28,7 @@ import android.icu.text.CaseMap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -56,6 +57,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
implements ShortcutPreference.OnClickCallback {
|
||||
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
|
||||
protected static final String KEY_SAVED_USER_SHORTCUT_TYPE = "shortcut_type";
|
||||
protected static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
|
||||
protected static final int NOT_SET = -1;
|
||||
// Save user's shortcutType value when savedInstance has value (e.g. device rotated).
|
||||
protected int mSavedCheckBoxValue = NOT_SET;
|
||||
@@ -66,6 +68,8 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
private AccessibilitySettingsContentObserver mSettingsContentObserver;
|
||||
private CheckBox mSoftwareTypeCheckBox;
|
||||
private CheckBox mHardwareTypeCheckBox;
|
||||
private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
|
||||
private boolean mNeedsQSTooltipReshow = false;
|
||||
|
||||
/** Returns the accessibility component name. */
|
||||
protected abstract ComponentName getComponentName();
|
||||
@@ -73,14 +77,25 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
/** Returns the accessibility feature name. */
|
||||
protected abstract CharSequence getLabelName();
|
||||
|
||||
/** Returns the accessibility tile component name. */
|
||||
protected abstract ComponentName getTileComponentName();
|
||||
|
||||
/** Returns the accessibility tile feature name. */
|
||||
protected abstract CharSequence getTileName();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Restore the user shortcut type.
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(
|
||||
KEY_SAVED_USER_SHORTCUT_TYPE)) {
|
||||
mSavedCheckBoxValue = savedInstanceState.getInt(KEY_SAVED_USER_SHORTCUT_TYPE, NOT_SET);
|
||||
// Restore the user shortcut type and tooltip.
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey(KEY_SAVED_USER_SHORTCUT_TYPE)) {
|
||||
mSavedCheckBoxValue = savedInstanceState.getInt(KEY_SAVED_USER_SHORTCUT_TYPE,
|
||||
NOT_SET);
|
||||
}
|
||||
if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_RESHOW)) {
|
||||
mNeedsQSTooltipReshow = savedInstanceState.getBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW);
|
||||
}
|
||||
}
|
||||
|
||||
final int resId = getPreferenceScreenResId();
|
||||
@@ -123,6 +138,16 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// Reshow tooltips when activity recreate, such as rotate device.
|
||||
if (mNeedsQSTooltipReshow) {
|
||||
getView().post(this::showQuickSettingsTooltipIfNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@@ -149,6 +174,9 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
if (value != NOT_SET) {
|
||||
outState.putInt(KEY_SAVED_USER_SHORTCUT_TYPE, value);
|
||||
}
|
||||
if (mTooltipWindow != null) {
|
||||
outState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, mTooltipWindow.isShowing());
|
||||
}
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@@ -423,4 +451,33 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
getComponentName()));
|
||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
protected void showQuickSettingsTooltipIfNeeded() {
|
||||
final ComponentName tileComponentName = getTileComponentName();
|
||||
if (tileComponentName == null) {
|
||||
// Returns if no tile service assigned.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mNeedsQSTooltipReshow && AccessibilityQuickSettingUtils.hasValueInSharedPreferences(
|
||||
getContext(), tileComponentName)) {
|
||||
// Returns if quick settings tooltip only show once.
|
||||
return;
|
||||
}
|
||||
|
||||
final CharSequence tileName = getTileName();
|
||||
if (TextUtils.isEmpty(tileName)) {
|
||||
// Returns if no title of tile service assigned.
|
||||
return;
|
||||
}
|
||||
|
||||
final String title =
|
||||
getString(R.string.accessibility_service_quick_settings_tooltips_content, tileName);
|
||||
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
|
||||
mTooltipWindow.setup(title);
|
||||
mTooltipWindow.showAtTopCenter(getView());
|
||||
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
|
||||
tileComponentName);
|
||||
mNeedsQSTooltipReshow = false;
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ import com.android.settings.accessibility.AccessibilityShortcutPreferenceFragmen
|
||||
import com.android.settings.accessibility.ShortcutPreference;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.widget.IllustrationPreference;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
|
||||
/**
|
||||
* Fragment for One-handed mode settings
|
||||
@@ -40,6 +41,8 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
|
||||
|
||||
private static final String ONE_HANDED_SHORTCUT_KEY = "one_handed_shortcuts_preference";
|
||||
private static final String ONE_HANDED_ILLUSTRATION_KEY = "one_handed_header";
|
||||
protected static final String ONE_HANDED_MAIN_SWITCH_KEY =
|
||||
"gesture_one_handed_mode_enabled_main_switch";
|
||||
private String mFeatureName;
|
||||
private OneHandedSettingsUtils mUtils;
|
||||
|
||||
@@ -48,16 +51,22 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
|
||||
OneHandedSettingsUtils.setUserId(UserHandle.myUserId());
|
||||
super.updatePreferenceStates();
|
||||
|
||||
final IllustrationPreference preference =
|
||||
(IllustrationPreference) getPreferenceScreen().findPreference(
|
||||
ONE_HANDED_ILLUSTRATION_KEY);
|
||||
if (preference != null) {
|
||||
final boolean isSwipeDownNotification =
|
||||
OneHandedSettingsUtils.isSwipeDownNotificationEnabled(getContext());
|
||||
preference.setLottieAnimationResId(
|
||||
isSwipeDownNotification ? R.raw.lottie_swipe_for_notifications
|
||||
: R.raw.lottie_one_hand_mode);
|
||||
}
|
||||
final IllustrationPreference illustrationPreference =
|
||||
getPreferenceScreen().findPreference(ONE_HANDED_ILLUSTRATION_KEY);
|
||||
final boolean isSwipeDownNotification =
|
||||
OneHandedSettingsUtils.isSwipeDownNotificationEnabled(getContext());
|
||||
illustrationPreference.setLottieAnimationResId(
|
||||
isSwipeDownNotification ? R.raw.lottie_swipe_for_notifications
|
||||
: R.raw.lottie_one_hand_mode);
|
||||
|
||||
final MainSwitchPreference mainSwitchPreference =
|
||||
getPreferenceScreen().findPreference(ONE_HANDED_MAIN_SWITCH_KEY);
|
||||
mainSwitchPreference.addOnSwitchChangeListener((switchView, isChecked) -> {
|
||||
switchView.setChecked(isChecked);
|
||||
if (isChecked) {
|
||||
showQuickSettingsTooltipIfNeeded();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,6 +124,16 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
|
||||
return mFeatureName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentName getTileComponentName() {
|
||||
return AccessibilityShortcutController.ONE_HANDED_TILE_COMPONENT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CharSequence getTileName() {
|
||||
return mFeatureName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.one_handed_settings;
|
||||
|
Reference in New Issue
Block a user