Merge "Fix Sound Amplifier does not have 'Open XXX' button" into sc-dev
This commit is contained in:
@@ -30,34 +30,41 @@ import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Fragment for providing open activity button. */
|
||||
public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeaturePreferenceFragment {
|
||||
private static final String TAG = "LaunchA11yActivity";
|
||||
private static final String EMPTY_STRING = "";
|
||||
protected static final String KEY_LAUNCH_PREFERENCE = "launch_preference";
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
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
|
||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
logAccessibilityServiceEnabled(mComponentName, enabled);
|
||||
launchShortcutTargetActivity(getPrefContext().getDisplayId(), mComponentName);
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,16 +106,6 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
||||
// 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.
|
||||
private AccessibilityShortcutInfo getAccessibilityShortcutInfo() {
|
||||
final List<AccessibilityShortcutInfo> infos = AccessibilityManager.getInstance(
|
||||
@@ -126,6 +123,34 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
||||
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) {
|
||||
final Intent intent = new Intent();
|
||||
final Bundle bundle = ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle();
|
||||
|
Reference in New Issue
Block a user