Merge branch 'android15-release' into merge-aosp15
This commit is contained in:
commit
eeb7416bfe
1401 files changed
+86072
-39248
No files matched your search
@@ -16,19 +16,24 @@
|
||||
|
||||
package com.android.launcher3.settings;
|
||||
|
||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS;
|
||||
import static android.provider.Settings.Global.DEVELOPMENT_SETTINGS_ENABLED;
|
||||
|
||||
import static com.android.launcher3.config.FeatureFlags.IS_STUDIO_BUILD;
|
||||
import static androidx.preference.PreferenceFragmentCompat.ARG_PREFERENCE_ROOT;
|
||||
|
||||
import static com.android.launcher3.BuildConfig.IS_DEBUG_DEVICE;
|
||||
import static com.android.launcher3.BuildConfig.IS_STUDIO_BUILD;
|
||||
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
@@ -43,58 +48,48 @@ import androidx.preference.PreferenceGroup.PreferencePositionCallback;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.BuildConfig;
|
||||
import com.android.launcher3.LauncherFiles;
|
||||
import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.states.RotationHelper;
|
||||
import com.android.launcher3.uioverrides.flags.DeveloperOptionsFragment;
|
||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||
import com.android.launcher3.util.DisplayController;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import com.android.launcher3.util.SettingsCache;
|
||||
|
||||
/**
|
||||
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
|
||||
* Settings activity for Launcher. Currently implements the following setting:
|
||||
* Allow rotation
|
||||
*/
|
||||
public class SettingsActivity extends FragmentActivity
|
||||
implements OnPreferenceStartFragmentCallback, OnPreferenceStartScreenCallback,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
implements OnPreferenceStartFragmentCallback, OnPreferenceStartScreenCallback {
|
||||
|
||||
/** List of fragments that can be hosted by this activity. */
|
||||
private static final List<String> VALID_PREFERENCE_FRAGMENTS =
|
||||
Collections.singletonList(DeveloperOptionsFragment.class.getName());
|
||||
|
||||
private static final String DEVELOPER_OPTIONS_KEY = "pref_developer_options";
|
||||
private static final String FLAGS_PREFERENCE_KEY = "flag_toggler";
|
||||
@VisibleForTesting
|
||||
static final String DEVELOPER_OPTIONS_KEY = "pref_developer_options";
|
||||
|
||||
private static final String NOTIFICATION_DOTS_PREFERENCE_KEY = "pref_icon_badging";
|
||||
|
||||
public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
|
||||
public static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args";
|
||||
public static final String EXTRA_FRAGMENT_ARGS = ":settings:fragment_args";
|
||||
|
||||
// Intent extra to indicate the pref-key to highlighted when opening the
|
||||
// settings activity
|
||||
public static final String EXTRA_FRAGMENT_HIGHLIGHT_KEY = ":settings:fragment_args_key";
|
||||
// Intent extra to indicate the pref-key of the root screen when opening the
|
||||
// settings activity
|
||||
public static final String EXTRA_FRAGMENT_ROOT_KEY = ARG_PREFERENCE_ROOT;
|
||||
|
||||
private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600;
|
||||
public static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
|
||||
|
||||
@VisibleForTesting
|
||||
static final String EXTRA_FRAGMENT = ":settings:fragment";
|
||||
@VisibleForTesting
|
||||
static final String EXTRA_FRAGMENT_ARGS = ":settings:fragment_args";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.settings_activity);
|
||||
|
||||
setActionBar(findViewById(R.id.action_bar));
|
||||
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent.hasExtra(EXTRA_FRAGMENT) || intent.hasExtra(EXTRA_FRAGMENT_ARGS)
|
||||
|| intent.hasExtra(EXTRA_FRAGMENT_ARG_KEY)) {
|
||||
if (intent.hasExtra(EXTRA_FRAGMENT_ROOT_KEY) || intent.hasExtra(EXTRA_FRAGMENT_ARGS)
|
||||
|| intent.hasExtra(EXTRA_FRAGMENT_HIGHLIGHT_KEY)) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@@ -104,49 +99,28 @@ public class SettingsActivity extends FragmentActivity
|
||||
args = new Bundle();
|
||||
}
|
||||
|
||||
String prefKey = intent.getStringExtra(EXTRA_FRAGMENT_ARG_KEY);
|
||||
if (!TextUtils.isEmpty(prefKey)) {
|
||||
args.putString(EXTRA_FRAGMENT_ARG_KEY, prefKey);
|
||||
String highlight = intent.getStringExtra(EXTRA_FRAGMENT_HIGHLIGHT_KEY);
|
||||
if (!TextUtils.isEmpty(highlight)) {
|
||||
args.putString(EXTRA_FRAGMENT_HIGHLIGHT_KEY, highlight);
|
||||
}
|
||||
String root = intent.getStringExtra(EXTRA_FRAGMENT_ROOT_KEY);
|
||||
if (!TextUtils.isEmpty(root)) {
|
||||
args.putString(EXTRA_FRAGMENT_ROOT_KEY, root);
|
||||
}
|
||||
|
||||
final FragmentManager fm = getSupportFragmentManager();
|
||||
final Fragment f = fm.getFragmentFactory().instantiate(getClassLoader(),
|
||||
getPreferenceFragment());
|
||||
getString(R.string.settings_fragment_name));
|
||||
f.setArguments(args);
|
||||
// Display the fragment as the main content.
|
||||
fm.beginTransaction().replace(R.id.content_frame, f).commit();
|
||||
}
|
||||
LauncherPrefs.getPrefs(getApplicationContext())
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the preference fragment to instantiate in this activity.
|
||||
*
|
||||
* @return the preference fragment class
|
||||
* @throws IllegalArgumentException if the fragment is unknown to this activity
|
||||
*/
|
||||
private String getPreferenceFragment() {
|
||||
String preferenceFragment = getIntent().getStringExtra(EXTRA_FRAGMENT);
|
||||
String defaultFragment = getString(R.string.settings_fragment_name);
|
||||
|
||||
if (TextUtils.isEmpty(preferenceFragment)) {
|
||||
return defaultFragment;
|
||||
} else if (!preferenceFragment.equals(defaultFragment)
|
||||
&& !VALID_PREFERENCE_FRAGMENTS.contains(preferenceFragment)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid fragment for this activity: " + preferenceFragment);
|
||||
} else {
|
||||
return preferenceFragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { }
|
||||
|
||||
private boolean startPreference(String fragment, Bundle args, String key) {
|
||||
if (Utilities.ATLEAST_P && getSupportFragmentManager().isStateSaved()) {
|
||||
// Sometimes onClick can come after onPause because of being posted on the handler.
|
||||
if (getSupportFragmentManager().isStateSaved()) {
|
||||
// Sometimes onClick can come after onPause because of being posted on the
|
||||
// handler.
|
||||
// Skip starting new preferences in that case.
|
||||
return false;
|
||||
}
|
||||
@@ -157,7 +131,6 @@ public class SettingsActivity extends FragmentActivity
|
||||
((DialogFragment) f).show(fm, key);
|
||||
} else {
|
||||
startActivity(new Intent(this, SettingsActivity.class)
|
||||
.putExtra(EXTRA_FRAGMENT, fragment)
|
||||
.putExtra(EXTRA_FRAGMENT_ARGS, args));
|
||||
}
|
||||
return true;
|
||||
@@ -172,7 +145,7 @@ public class SettingsActivity extends FragmentActivity
|
||||
@Override
|
||||
public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen pref) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.getKey());
|
||||
args.putString(ARG_PREFERENCE_ROOT, pref.getKey());
|
||||
return startPreference(getString(R.string.settings_fragment_name), args, pref.getKey());
|
||||
}
|
||||
|
||||
@@ -188,19 +161,31 @@ public class SettingsActivity extends FragmentActivity
|
||||
/**
|
||||
* This fragment shows the launcher preferences.
|
||||
*/
|
||||
public static class LauncherSettingsFragment extends PreferenceFragmentCompat {
|
||||
public static class LauncherSettingsFragment extends PreferenceFragmentCompat implements
|
||||
SettingsCache.OnChangeListener {
|
||||
|
||||
protected boolean mDeveloperOptionsEnabled = false;
|
||||
|
||||
private boolean mRestartOnResume = false;
|
||||
|
||||
private String mHighLightKey;
|
||||
private boolean mPreferenceHighlighted = false;
|
||||
private Preference mDeveloperOptionPref;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
if (BuildConfig.IS_DEBUG_DEVICE) {
|
||||
Uri devUri = Settings.Global.getUriFor(DEVELOPMENT_SETTINGS_ENABLED);
|
||||
SettingsCache settingsCache = SettingsCache.INSTANCE.get(getContext());
|
||||
mDeveloperOptionsEnabled = settingsCache.getValue(devUri);
|
||||
settingsCache.register(devUri, this);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
final Bundle args = getArguments();
|
||||
mHighLightKey = args == null ? null : args.getString(EXTRA_FRAGMENT_ARG_KEY);
|
||||
if (rootKey == null && !TextUtils.isEmpty(mHighLightKey)) {
|
||||
rootKey = getParentKeyForPref(mHighLightKey);
|
||||
}
|
||||
mHighLightKey = args == null ? null : args.getString(EXTRA_FRAGMENT_HIGHLIGHT_KEY);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mPreferenceHighlighted = savedInstanceState.getBoolean(SAVE_HIGHLIGHTED_KEY);
|
||||
@@ -212,25 +197,12 @@ public class SettingsActivity extends FragmentActivity
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
for (int i = screen.getPreferenceCount() - 1; i >= 0; i--) {
|
||||
Preference preference = screen.getPreference(i);
|
||||
if (initPreference(preference)) {
|
||||
if (IS_STUDIO_BUILD && preference == mDeveloperOptionPref) {
|
||||
preference.setOrder(0);
|
||||
}
|
||||
} else {
|
||||
if (!initPreference(preference)) {
|
||||
screen.removePreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
if (getActivity() != null && !TextUtils.isEmpty(getPreferenceScreen().getTitle())) {
|
||||
if (getPreferenceScreen().getTitle().equals(
|
||||
getResources().getString(R.string.search_pref_screen_title))){
|
||||
DeviceProfile mDeviceProfile = InvariantDeviceProfile.INSTANCE.get(
|
||||
getContext()).getDeviceProfile(getContext());
|
||||
getPreferenceScreen().setTitle(mDeviceProfile.isMultiDisplay
|
||||
|| mDeviceProfile.isPhone ?
|
||||
R.string.search_pref_screen_title :
|
||||
R.string.search_pref_screen_title_tablet);
|
||||
}
|
||||
getActivity().setTitle(getPreferenceScreen().getTitle());
|
||||
}
|
||||
}
|
||||
@@ -248,6 +220,7 @@ public class SettingsActivity extends FragmentActivity
|
||||
bottomPadding + insets.getSystemWindowInsetBottom());
|
||||
return insets.consumeSystemWindowInsets();
|
||||
});
|
||||
|
||||
// Overriding Text Direction in the Androidx preference library to support RTL
|
||||
view.setTextDirection(View.TEXT_DIRECTION_LOCALE);
|
||||
}
|
||||
@@ -258,22 +231,18 @@ public class SettingsActivity extends FragmentActivity
|
||||
outState.putBoolean(SAVE_HIGHLIGHTED_KEY, mPreferenceHighlighted);
|
||||
}
|
||||
|
||||
protected String getParentKeyForPref(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a preference. This is called for every preference. Returning false here
|
||||
* Initializes a preference. This is called for every preference. Returning
|
||||
* false here
|
||||
* will remove that preference from the list.
|
||||
*/
|
||||
protected boolean initPreference(Preference preference) {
|
||||
switch (preference.getKey()) {
|
||||
case NOTIFICATION_DOTS_PREFERENCE_KEY:
|
||||
return !WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS;
|
||||
return BuildConfig.NOTIFICATION_DOTS_ENABLED;
|
||||
|
||||
case ALLOW_ROTATION_PREFERENCE_KEY:
|
||||
DisplayController.Info info =
|
||||
DisplayController.INSTANCE.get(getContext()).getInfo();
|
||||
DisplayController.Info info = DisplayController.INSTANCE.get(getContext()).getInfo();
|
||||
if (info.isTablet(info.realBounds)) {
|
||||
// Launcher supports rotation by default. No need to show this setting.
|
||||
return false;
|
||||
@@ -282,51 +251,64 @@ public class SettingsActivity extends FragmentActivity
|
||||
preference.setDefaultValue(RotationHelper.getAllowRotationDefaultValue(info));
|
||||
return true;
|
||||
|
||||
case FLAGS_PREFERENCE_KEY:
|
||||
// Only show flag toggler UI if this build variant implements that.
|
||||
return FeatureFlags.showFlagTogglerUi(getContext());
|
||||
|
||||
case DEVELOPER_OPTIONS_KEY:
|
||||
mDeveloperOptionPref = preference;
|
||||
return updateDeveloperOption();
|
||||
if (IS_STUDIO_BUILD) {
|
||||
preference.setOrder(0);
|
||||
}
|
||||
return mDeveloperOptionsEnabled;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show if plugins are enabled or flag UI is enabled.
|
||||
* @return True if we should show the preference option.
|
||||
*/
|
||||
private boolean updateDeveloperOption() {
|
||||
boolean showPreference = FeatureFlags.showFlagTogglerUi(getContext())
|
||||
|| PluginManagerWrapper.hasPlugins(getContext());
|
||||
if (mDeveloperOptionPref != null) {
|
||||
mDeveloperOptionPref.setEnabled(showPreference);
|
||||
if (showPreference) {
|
||||
getPreferenceScreen().addPreference(mDeveloperOptionPref);
|
||||
} else {
|
||||
getPreferenceScreen().removePreference(mDeveloperOptionPref);
|
||||
}
|
||||
}
|
||||
return showPreference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
updateDeveloperOption();
|
||||
|
||||
if (isAdded() && !mPreferenceHighlighted) {
|
||||
PreferenceHighlighter highlighter = createHighlighter();
|
||||
if (highlighter != null) {
|
||||
getView().postDelayed(highlighter, DELAY_HIGHLIGHT_DURATION_MILLIS);
|
||||
mPreferenceHighlighted = true;
|
||||
} else {
|
||||
requestAccessibilityFocus(getListView());
|
||||
}
|
||||
}
|
||||
|
||||
if (mRestartOnResume) {
|
||||
recreateActivityNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingsChanged(boolean isEnabled) {
|
||||
// Developer options changed, try recreate
|
||||
tryRecreateActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (IS_DEBUG_DEVICE) {
|
||||
SettingsCache.INSTANCE.get(getContext())
|
||||
.unregister(Settings.Global.getUriFor(DEVELOPMENT_SETTINGS_ENABLED), this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to recreate the preference
|
||||
*/
|
||||
protected void tryRecreateActivity() {
|
||||
if (isResumed()) {
|
||||
recreateActivityNow();
|
||||
} else {
|
||||
mRestartOnResume = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void recreateActivityNow() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.recreate();
|
||||
}
|
||||
}
|
||||
|
||||
private PreferenceHighlighter createHighlighter() {
|
||||
@@ -346,14 +328,5 @@ public class SettingsActivity extends FragmentActivity
|
||||
list, position, screen.findPreference(mHighLightKey))
|
||||
: null;
|
||||
}
|
||||
|
||||
private void requestAccessibilityFocus(@NonNull final RecyclerView rv) {
|
||||
rv.post(() -> {
|
||||
if (!rv.hasFocus() && rv.getChildCount() > 0) {
|
||||
rv.getChildAt(0)
|
||||
.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user