fix:
update:更换为酷信
This commit is contained in:
tt committed 2023-10-11 19:19:52 +08:00
1 parent 625a121cbb
commit 8799e85443
723 files changed
+4158 -4041

No files matched your search

@@ -0,0 +1,287 @@
/*
* Copyright (C) 2018 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.uiuipad.os.settings;
import static com.uiuipad.os.uioverrides.plugins.PluginManagerWrapper.PLUGIN_CHANGED;
import static com.uiuipad.os.uioverrides.plugins.PluginManagerWrapper.pluginEnabledKey;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import com.uiuipad.os.R;
import com.uiuipad.os.config.FeatureFlags;
import com.uiuipad.os.config.FlagTogglerPrefUi;
import com.uiuipad.os.uioverrides.plugins.PluginManagerWrapper;
import java.util.List;
import java.util.Set;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceDataStore;
import androidx.preference.PreferenceFragment;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.SwitchPreference;
/**
* Dev-build only UI allowing developers to toggle flag settings and plugins.
* See {@link FeatureFlags}.
*/
@TargetApi(Build.VERSION_CODES.O)
public class DeveloperOptionsFragment extends PreferenceFragment {
private static final String ACTION_PLUGIN_SETTINGS = "com.android.systemui.action.PLUGIN_SETTINGS";
private static final String PLUGIN_PERMISSION = "com.android.systemui.permission.PLUGIN";
private final BroadcastReceiver mPluginReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
loadPluginPrefs();
}
};
private PreferenceScreen mPreferenceScreen;
private PreferenceCategory mPluginsCategory;
private FlagTogglerPrefUi mFlagTogglerPrefUi;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
getContext().registerReceiver(mPluginReceiver, filter);
getContext().registerReceiver(mPluginReceiver,
new IntentFilter(Intent.ACTION_USER_UNLOCKED));
mPreferenceScreen = getPreferenceManager().createPreferenceScreen(getContext());
setPreferenceScreen(mPreferenceScreen);
initFlags();
loadPluginPrefs();
}
@Override
public void onDestroy() {
super.onDestroy();
getContext().unregisterReceiver(mPluginReceiver);
}
private PreferenceCategory newCategory(String title) {
PreferenceCategory category = new PreferenceCategory(getContext());
category.setOrder(Preference.DEFAULT_ORDER);
category.setTitle(title);
mPreferenceScreen.addPreference(category);
return category;
}
private void initFlags() {
if (!FeatureFlags.showFlagTogglerUi(getContext())) {
return;
}
mFlagTogglerPrefUi = new FlagTogglerPrefUi(this);
mFlagTogglerPrefUi.applyTo(newCategory("Feature flags"));
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (mFlagTogglerPrefUi != null) {
mFlagTogglerPrefUi.onCreateOptionsMenu(menu);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mFlagTogglerPrefUi != null) {
mFlagTogglerPrefUi.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}
@Override
public void onStop() {
if (mFlagTogglerPrefUi != null) {
mFlagTogglerPrefUi.onStop();
}
super.onStop();
}
private void loadPluginPrefs() {
if (mPluginsCategory != null) {
mPreferenceScreen.removePreference(mPluginsCategory);
}
if (!PluginManagerWrapper.hasPlugins(getActivity())) {
mPluginsCategory = null;
return;
}
mPluginsCategory = newCategory("Plugins");
PluginManagerWrapper manager = PluginManagerWrapper.INSTANCE.get(getContext());
Context prefContext = getContext();
PackageManager pm = getContext().getPackageManager();
Set<String> pluginActions = manager.getPluginActions();
ArrayMap<String, ArraySet<String>> plugins = new ArrayMap<>();
for (String action : pluginActions) {
String name = toName(action);
List<ResolveInfo> result = pm.queryIntentServices(
new Intent(action), PackageManager.MATCH_DISABLED_COMPONENTS);
for (ResolveInfo info : result) {
String packageName = info.serviceInfo.packageName;
if (!plugins.containsKey(packageName)) {
plugins.put(packageName, new ArraySet<>());
}
plugins.get(packageName).add(name);
}
}
List<PackageInfo> apps = pm.getPackagesHoldingPermissions(new String[]{PLUGIN_PERMISSION},
PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.GET_SERVICES);
PreferenceDataStore enabled = manager.getPluginEnabler();
apps.forEach(app -> {
if (!plugins.containsKey(app.packageName)) return;
SwitchPreference pref = new PluginPreference(prefContext, app, enabled);
pref.setSummary("Plugins: " + toString(plugins.get(app.packageName)));
mPluginsCategory.addPreference(pref);
});
}
private String toString(ArraySet<String> plugins) {
StringBuilder b = new StringBuilder();
for (String string : plugins) {
if (b.length() != 0) {
b.append(", ");
}
b.append(string);
}
return b.toString();
}
private String toName(String action) {
String str = action.replace("com.android.systemui.action.PLUGIN_", "");
StringBuilder b = new StringBuilder();
for (String s : str.split("_")) {
if (b.length() != 0) {
b.append(' ');
}
b.append(s.substring(0, 1));
b.append(s.substring(1).toLowerCase());
}
return b.toString();
}
private static class PluginPreference extends SwitchPreference {
private final boolean mHasSettings;
private final PackageInfo mInfo;
private final PreferenceDataStore mPluginEnabler;
public PluginPreference(Context prefContext, PackageInfo info,
PreferenceDataStore pluginEnabler) {
super(prefContext);
PackageManager pm = prefContext.getPackageManager();
mHasSettings = pm.resolveActivity(new Intent(ACTION_PLUGIN_SETTINGS)
.setPackage(info.packageName), 0) != null;
mInfo = info;
mPluginEnabler = pluginEnabler;
setTitle(info.applicationInfo.loadLabel(pm));
setChecked(isPluginEnabled());
setWidgetLayoutResource(R.layout.switch_preference_with_settings);
}
private boolean isEnabled(ComponentName cn) {
return mPluginEnabler.getBoolean(pluginEnabledKey(cn), true);
}
private boolean isPluginEnabled() {
for (int i = 0; i < mInfo.services.length; i++) {
ComponentName componentName = new ComponentName(mInfo.packageName,
mInfo.services[i].name);
if (!isEnabled(componentName)) {
return false;
}
}
return true;
}
@Override
protected boolean persistBoolean(boolean isEnabled) {
boolean shouldSendBroadcast = false;
for (int i = 0; i < mInfo.services.length; i++) {
ComponentName componentName = new ComponentName(mInfo.packageName,
mInfo.services[i].name);
if (isEnabled(componentName) != isEnabled) {
mPluginEnabler.putBoolean(pluginEnabledKey(componentName), isEnabled);
shouldSendBroadcast = true;
}
}
if (shouldSendBroadcast) {
final String pkg = mInfo.packageName;
final Intent intent = new Intent(PLUGIN_CHANGED,
pkg != null ? Uri.fromParts("package", pkg, null) : null);
getContext().sendBroadcast(intent);
}
setChecked(isEnabled);
return true;
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.findViewById(R.id.settings).setVisibility(mHasSettings ? View.VISIBLE
: View.GONE);
holder.findViewById(R.id.divider).setVisibility(mHasSettings ? View.VISIBLE
: View.GONE);
holder.findViewById(R.id.settings).setOnClickListener(v -> {
ResolveInfo result = v.getContext().getPackageManager().resolveActivity(
new Intent(ACTION_PLUGIN_SETTINGS).setPackage(
mInfo.packageName), 0);
if (result != null) {
v.getContext().startActivity(new Intent().setComponent(
new ComponentName(result.activityInfo.packageName,
result.activityInfo.name)));
}
});
holder.itemView.setOnLongClickListener(v -> {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", mInfo.packageName, null));
getContext().startActivity(intent);
return true;
});
}
}
}
@@ -0,0 +1,137 @@
/*
* Copyright (C) 2017 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.uiuipad.os.settings;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;
import com.uiuipad.os.R;
import com.uiuipad.os.notification.NotificationListener;
import com.uiuipad.os.util.SecureSettingsObserver;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
/**
* A {@link Preference} for indicating notification dots status.
* Also has utility methods for updating UI based on dots status changes.
*/
public class NotificationDotsPreference extends Preference
implements SecureSettingsObserver.OnChangeListener {
private boolean mWidgetFrameVisible = false;
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";
public NotificationDotsPreference(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public NotificationDotsPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public NotificationDotsPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NotificationDotsPreference(Context context) {
super(context);
}
private void setWidgetFrameVisible(boolean isVisible) {
if (mWidgetFrameVisible != isVisible) {
mWidgetFrameVisible = isVisible;
notifyChanged();
}
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View widgetFrame = holder.findViewById(android.R.id.widget_frame);
if (widgetFrame != null) {
widgetFrame.setVisibility(mWidgetFrameVisible ? View.VISIBLE : View.GONE);
}
}
@Override
public void onSettingsChanged(boolean enabled) {
int summary = enabled
? R.string.notification_dots_desc_on
: R.string.notification_dots_desc_off;
boolean serviceEnabled = true;
if (enabled) {
// Check if the listener is enabled or not.
String enabledListeners = Settings.Secure.getString(
getContext().getContentResolver(), NOTIFICATION_ENABLED_LISTENERS);
ComponentName myListener =
new ComponentName(getContext(), NotificationListener.class);
serviceEnabled = enabledListeners != null &&
(enabledListeners.contains(myListener.flattenToString()) ||
enabledListeners.contains(myListener.flattenToShortString()));
if (!serviceEnabled) {
summary = R.string.title_missing_notification_access;
}
}
setWidgetFrameVisible(!serviceEnabled);
setFragment(serviceEnabled ? null : NotificationAccessConfirmation.class.getName());
setSummary(summary);
}
public static class NotificationAccessConfirmation
extends DialogFragment implements DialogInterface.OnClickListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
String msg = context.getString(R.string.msg_missing_notification_access,
context.getString(R.string.derived_app_name));
return new AlertDialog.Builder(context)
.setTitle(R.string.title_missing_notification_access)
.setMessage(msg)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.title_change_settings, this)
.create();
}
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ComponentName cn = new ComponentName(getActivity(), NotificationListener.class);
Bundle showFragmentArgs = new Bundle();
showFragmentArgs.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString());
Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString())
.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs);
getActivity().startActivity(intent);
}
}
}
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2018 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.uiuipad.os.settings;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Property;
import android.view.View;
import com.uiuipad.os.util.Themes;
import com.uiuipad.os.icons.GraphicsUtils;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
import androidx.recyclerview.widget.RecyclerView.State;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
/**
* Utility class for highlighting a preference
*/
public class PreferenceHighlighter extends ItemDecoration implements Runnable {
private static final Property<PreferenceHighlighter, Integer> HIGHLIGHT_COLOR =
new Property<PreferenceHighlighter, Integer>(Integer.TYPE, "highlightColor") {
@Override
public Integer get(PreferenceHighlighter highlighter) {
return highlighter.mHighlightColor;
}
@Override
public void set(PreferenceHighlighter highlighter, Integer value) {
highlighter.mHighlightColor = value;
highlighter.mRv.invalidateItemDecorations();
}
};
private static final long HIGHLIGHT_DURATION = 15000L;
private static final long HIGHLIGHT_FADE_OUT_DURATION = 500L;
private static final long HIGHLIGHT_FADE_IN_DURATION = 200L;
private static final int END_COLOR = GraphicsUtils.setColorAlphaBound(Color.WHITE, 0);
private final Paint mPaint = new Paint();
private final RecyclerView mRv;
private final int mIndex;
private boolean mHighLightStarted = false;
private int mHighlightColor = END_COLOR;
public PreferenceHighlighter(RecyclerView rv, int index) {
mRv = rv;
mIndex = index;
}
@Override
public void run() {
mRv.addItemDecoration(this);
mRv.smoothScrollToPosition(mIndex);
}
@Override
public void onDraw(Canvas c, RecyclerView parent, State state) {
ViewHolder holder = parent.findViewHolderForAdapterPosition(mIndex);
if (holder == null) {
return;
}
if (!mHighLightStarted && state.getRemainingScrollVertical() != 0) {
// Wait until scrolling stopped
return;
}
if (!mHighLightStarted) {
// Start highlight
int colorTo = GraphicsUtils.setColorAlphaBound(Themes.getColorAccent(mRv.getContext()), 66);
ObjectAnimator anim = ObjectAnimator.ofArgb(this, HIGHLIGHT_COLOR, END_COLOR, colorTo);
anim.setDuration(HIGHLIGHT_FADE_IN_DURATION);
anim.setRepeatMode(ValueAnimator.REVERSE);
anim.setRepeatCount(4);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
removeHighlight();
}
});
anim.start();
mHighLightStarted = true;
}
View view = holder.itemView;
mPaint.setColor(mHighlightColor);
c.drawRect(0, view.getY(), parent.getWidth(), view.getY() + view.getHeight(), mPaint);
}
private void removeHighlight() {
ObjectAnimator anim = ObjectAnimator.ofArgb(
this, HIGHLIGHT_COLOR, mHighlightColor, END_COLOR);
anim.setDuration(HIGHLIGHT_FADE_OUT_DURATION);
anim.setStartDelay(HIGHLIGHT_DURATION);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mRv.removeItemDecoration(PreferenceHighlighter.this);
}
});
anim.start();
}
}
@@ -0,0 +1,280 @@
/*
* Copyright (C) 2015 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.uiuipad.os.settings;
import static com.uiuipad.os.SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY;
import static com.uiuipad.os.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
import static com.uiuipad.os.states.RotationHelper.getAllowRotationDefaultValue;
import static com.uiuipad.os.util.SecureSettingsObserver.newNotificationSettingsObserver;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import com.uiuipad.os.LauncherFiles;
import com.uiuipad.os.R;
import com.uiuipad.os.Utilities;
import com.uiuipad.os.config.FeatureFlags;
import com.uiuipad.os.graphics.GridOptionsProvider;
import com.uiuipad.os.uioverrides.plugins.PluginManagerWrapper;
import com.uiuipad.os.util.SecureSettingsObserver;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragment;
import androidx.preference.PreferenceFragment.OnPreferenceStartFragmentCallback;
import androidx.preference.PreferenceFragment.OnPreferenceStartScreenCallback;
import androidx.preference.PreferenceGroup.PreferencePositionCallback;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
/**
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
*/
public class SettingsActivity extends Activity
implements OnPreferenceStartFragmentCallback, OnPreferenceStartScreenCallback,
SharedPreferences.OnSharedPreferenceChangeListener{
private static final String DEVELOPER_OPTIONS_KEY = "pref_developer_options";
private static final String FLAGS_PREFERENCE_KEY = "flag_toggler";
private static final String NOTIFICATION_DOTS_PREFERENCE_KEY = "pref_icon_badging";
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";
public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
public static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args";
private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600;
public static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
public static final String GRID_OPTIONS_PREFERENCE_KEY = "pref_grid_options";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
Bundle args = new Bundle();
String prefKey = getIntent().getStringExtra(EXTRA_FRAGMENT_ARG_KEY);
if (!TextUtils.isEmpty(prefKey)) {
args.putString(EXTRA_FRAGMENT_ARG_KEY, prefKey);
}
Fragment f = Fragment.instantiate(
this, getString(R.string.settings_fragment_name), args);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, f)
.commit();
}
Utilities.getPrefs(getApplicationContext()).registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (GRID_OPTIONS_PREFERENCE_KEY.equals(key)) {
final ComponentName cn = new ComponentName(getApplicationContext(),
GridOptionsProvider.class);
Context c = getApplicationContext();
int oldValue = c.getPackageManager().getComponentEnabledSetting(cn);
int newValue;
if (Utilities.getPrefs(c).getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)) {
newValue = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
} else {
newValue = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}
if (oldValue != newValue) {
c.getPackageManager().setComponentEnabledSetting(cn, newValue,
PackageManager.DONT_KILL_APP);
}
}
}
private boolean startFragment(String fragment, Bundle args, String key) {
if (Utilities.ATLEAST_P && getFragmentManager().isStateSaved()) {
// Sometimes onClick can come after onPause because of being posted on the handler.
// Skip starting new fragments in that case.
return false;
}
Fragment f = Fragment.instantiate(this, fragment, args);
if (f instanceof DialogFragment) {
((DialogFragment) f).show(getFragmentManager(), key);
} else {
getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, f)
.addToBackStack(key)
.commit();
}
return true;
}
@Override
public boolean onPreferenceStartFragment(
PreferenceFragment preferenceFragment, Preference pref) {
return startFragment(pref.getFragment(), pref.getExtras(), pref.getKey());
}
@Override
public boolean onPreferenceStartScreen(PreferenceFragment caller, PreferenceScreen pref) {
Bundle args = new Bundle();
args.putString(PreferenceFragment.ARG_PREFERENCE_ROOT, pref.getKey());
return startFragment(getString(R.string.settings_fragment_name), args, pref.getKey());
}
/**
* This fragment shows the launcher preferences.
*/
public static class LauncherSettingsFragment extends PreferenceFragment {
private SecureSettingsObserver mNotificationDotsObserver;
private String mHighLightKey;
private boolean mPreferenceHighlighted = false;
@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);
}
if (savedInstanceState != null) {
mPreferenceHighlighted = savedInstanceState.getBoolean(SAVE_HIGHLIGHTED_KEY);
}
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
setPreferencesFromResource(R.xml.launcher_preferences, rootKey);
PreferenceScreen screen = getPreferenceScreen();
for (int i = screen.getPreferenceCount() - 1; i >= 0; i--) {
Preference preference = screen.getPreference(i);
if (!initPreference(preference)) {
screen.removePreference(preference);
}
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
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
* will remove that preference from the list.
*/
protected boolean initPreference(Preference preference) {
switch (preference.getKey()) {
case NOTIFICATION_DOTS_PREFERENCE_KEY:
if (!Utilities.ATLEAST_OREO ||
!getResources().getBoolean(R.bool.notification_dots_enabled)) {
return false;
}
// Listen to system notification dot settings while this UI is active.
mNotificationDotsObserver = newNotificationSettingsObserver(
getActivity(), (NotificationDotsPreference) preference);
mNotificationDotsObserver.register();
// Also listen if notification permission changes
mNotificationDotsObserver.getResolver().registerContentObserver(
Settings.Secure.getUriFor(NOTIFICATION_ENABLED_LISTENERS), false,
mNotificationDotsObserver);
mNotificationDotsObserver.dispatchOnChange();
return true;
case ADD_ICON_PREFERENCE_KEY:
return Utilities.ATLEAST_OREO;
case ALLOW_ROTATION_PREFERENCE_KEY:
if (getResources().getBoolean(R.bool.allow_rotation)) {
// Launcher supports rotation by default. No need to show this setting.
return false;
}
// Initialize the UI once
preference.setDefaultValue(getAllowRotationDefaultValue());
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:
// Show if plugins are enabled or flag UI is enabled.
return FeatureFlags.showFlagTogglerUi(getContext()) ||
PluginManagerWrapper.hasPlugins(getContext());
case GRID_OPTIONS_PREFERENCE_KEY:
return Utilities.isDevelopersOptionsEnabled(getContext()) &&
Utilities.IS_DEBUG_DEVICE &&
Utilities.existsStyleWallpapers(getContext());
}
return true;
}
@Override
public void onResume() {
super.onResume();
if (isAdded() && !mPreferenceHighlighted) {
PreferenceHighlighter highlighter = createHighlighter();
if (highlighter != null) {
getView().postDelayed(highlighter, DELAY_HIGHLIGHT_DURATION_MILLIS);
mPreferenceHighlighted = true;
}
}
}
private PreferenceHighlighter createHighlighter() {
if (TextUtils.isEmpty(mHighLightKey)) {
return null;
}
PreferenceScreen screen = getPreferenceScreen();
if (screen == null) {
return null;
}
RecyclerView list = getListView();
PreferencePositionCallback callback = (PreferencePositionCallback) list.getAdapter();
int position = callback.getPreferenceAdapterPosition(mHighLightKey);
return position >= 0 ? new PreferenceHighlighter(list, position) : null;
}
@Override
public void onDestroy() {
if (mNotificationDotsObserver != null) {
mNotificationDotsObserver.unregister();
mNotificationDotsObserver = null;
}
super.onDestroy();
}
}
}