Fix Sound Amplifier does not have 'Open XXX' button
SettingsMainSwitchPreference does not allow hide switch bar. For support this launch preference, we hide the SettingsMainSwitchPreference and add new preference into the list. Bug: 184711985 Test: Manual testing Change-Id: I293800e83aafb387e0bb0a4988af774b56f508e6
This commit is contained in:
@@ -30,34 +30,41 @@ import android.os.Bundle;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Fragment for providing open activity button. */
|
/** Fragment for providing open activity button. */
|
||||||
public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeaturePreferenceFragment {
|
public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeaturePreferenceFragment {
|
||||||
private static final String TAG = "LaunchA11yActivity";
|
private static final String TAG = "LaunchA11yActivity";
|
||||||
private static final String EMPTY_STRING = "";
|
private static final String EMPTY_STRING = "";
|
||||||
|
protected static final String KEY_LAUNCH_PREFERENCE = "launch_preference";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
super.onViewCreated(view, savedInstanceState);
|
Bundle savedInstanceState) {
|
||||||
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
|
||||||
mToggleServiceSwitchPreference.hide();
|
// Init new preference to replace the switch preference instead.
|
||||||
}
|
initLaunchPreference();
|
||||||
|
removePreference(KEY_USE_SERVICE_PREFERENCE);
|
||||||
|
return view;
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||||
logAccessibilityServiceEnabled(mComponentName, enabled);
|
// Do nothing.
|
||||||
launchShortcutTargetActivity(getPrefContext().getDisplayId(), mComponentName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,16 +106,6 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
|||||||
// accessibility service from this page.
|
// accessibility service from this page.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
|
|
||||||
final AccessibilityShortcutInfo info = getAccessibilityShortcutInfo();
|
|
||||||
final String switchBarText = (info == null) ? EMPTY_STRING : getString(
|
|
||||||
R.string.accessibility_service_primary_open_title,
|
|
||||||
info.getActivityInfo().loadLabel(getPackageManager()));
|
|
||||||
|
|
||||||
switchPreference.setTitle(switchBarText);
|
|
||||||
}
|
|
||||||
|
|
||||||
// IMPORTANT: Refresh the info since there are dynamically changing capabilities.
|
// IMPORTANT: Refresh the info since there are dynamically changing capabilities.
|
||||||
private AccessibilityShortcutInfo getAccessibilityShortcutInfo() {
|
private AccessibilityShortcutInfo getAccessibilityShortcutInfo() {
|
||||||
final List<AccessibilityShortcutInfo> infos = AccessibilityManager.getInstance(
|
final List<AccessibilityShortcutInfo> infos = AccessibilityManager.getInstance(
|
||||||
@@ -126,6 +123,34 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Customizes the order by preference key. */
|
||||||
|
protected List<String> getPreferenceOrderList() {
|
||||||
|
final List<String> lists = new ArrayList<>();
|
||||||
|
lists.add(KEY_ANIMATED_IMAGE);
|
||||||
|
lists.add(KEY_LAUNCH_PREFERENCE);
|
||||||
|
lists.add(KEY_GENERAL_CATEGORY);
|
||||||
|
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
|
||||||
|
return lists;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initLaunchPreference() {
|
||||||
|
final Preference launchPreference = new Preference(getPrefContext());
|
||||||
|
launchPreference.setKey(KEY_LAUNCH_PREFERENCE);
|
||||||
|
|
||||||
|
final AccessibilityShortcutInfo info = getAccessibilityShortcutInfo();
|
||||||
|
final String switchBarText = (info == null) ? EMPTY_STRING : getString(
|
||||||
|
R.string.accessibility_service_primary_open_title,
|
||||||
|
info.getActivityInfo().loadLabel(getPackageManager()));
|
||||||
|
launchPreference.setTitle(switchBarText);
|
||||||
|
|
||||||
|
launchPreference.setOnPreferenceClickListener(preference -> {
|
||||||
|
logAccessibilityServiceEnabled(mComponentName, /* enabled= */ true);
|
||||||
|
launchShortcutTargetActivity(getPrefContext().getDisplayId(), mComponentName);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
getPreferenceScreen().addPreference(launchPreference);
|
||||||
|
}
|
||||||
|
|
||||||
private void launchShortcutTargetActivity(int displayId, ComponentName name) {
|
private void launchShortcutTargetActivity(int displayId, ComponentName name) {
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
final Bundle bundle = ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle();
|
final Bundle bundle = ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle();
|
||||||
|
Reference in New Issue
Block a user