Loading res/layout/settings_base_layout.xml 0 → 100644 +35 −0 Original line number Diff line number Diff line <!-- 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. --> <!-- The main content view --> <LinearLayout android:id="@+id/content_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Toolbar android:id="@+id/action_bar" style="?android:attr/actionBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="?android:attr/actionBarTheme" android:navigationContentDescription="@*android:string/action_bar_up_description" /> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="fill_parent" android:background="?android:attr/windowBackground" /> </LinearLayout> src/com/android/settings/SettingsActivity.java +4 −3 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import com.android.internal.util.ArrayUtils; import com.android.settings.Settings.WifiSettingsActivity; import com.android.settings.applications.manageapplications.ManageApplications; import com.android.settings.backup.BackupSettingsActivity; import com.android.settings.core.SettingsBaseActivity; import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.gateway.SettingsGateway; import com.android.settings.dashboard.DashboardFeatureProvider; Loading @@ -64,7 +65,6 @@ import com.android.settingslib.core.instrumentation.Instrumentable; import com.android.settingslib.core.instrumentation.SharedPreferencesLogger; import com.android.settingslib.development.DevelopmentSettingsEnabler; import com.android.settingslib.drawer.DashboardCategory; import com.android.settingslib.drawer.SettingsDrawerActivity; import com.android.settingslib.utils.ThreadUtils; import java.util.ArrayList; Loading @@ -76,7 +76,8 @@ import androidx.preference.Preference; import androidx.preference.PreferenceFragment; import androidx.preference.PreferenceManager; public class SettingsActivity extends SettingsDrawerActivity public class SettingsActivity extends SettingsBaseActivity implements PreferenceManager.OnPreferenceTreeClickListener, PreferenceFragment.OnPreferenceStartFragmentCallback, ButtonBarHandler, FragmentManager.OnBackStackChangedListener { Loading Loading @@ -606,7 +607,7 @@ public class SettingsActivity extends SettingsDrawerActivity private void updateTilesList() { // Generally the items that are will be changing from these updates will // not be in the top list of tiles, so run it in the background and the // SettingsDrawerActivity will pick up on the updates automatically. // SettingsBaseActivity will pick up on the updates automatically. AsyncTask.execute(new Runnable() { @Override public void run() { Loading src/com/android/settings/backup/BackupSettingsHelper.java +0 −1 Original line number Diff line number Diff line Loading @@ -152,7 +152,6 @@ public class BackupSettingsHelper { } private Intent getIntentForDefaultBackupSettings() { // Extra needed by {@link SettingsDrawerActivity} to show the back button navigation. return new Intent(mContext, PrivacySettingsActivity.class); } Loading src/com/android/settings/core/SettingsBaseActivity.java 0 → 100644 +211 −0 Original line number Diff line number Diff line /** * 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.android.settings.core; import android.annotation.LayoutRes; import android.annotation.Nullable; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.res.TypedArray; import android.os.AsyncTask; import android.os.Bundle; import android.util.ArraySet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager.LayoutParams; import android.widget.Toolbar; import com.android.settings.R; import com.android.settingslib.drawer.CategoryManager; import com.android.settingslib.drawer.TileUtils; import java.util.ArrayList; import java.util.List; import androidx.fragment.app.FragmentActivity; public class SettingsBaseActivity extends FragmentActivity { protected static final boolean DEBUG_TIMING = false; private static final String TAG = "SettingsBaseActivity"; private static final String DATA_SCHEME_PKG = "package"; // Serves as a temporary list of tiles to ignore until we heard back from the PM that they // are disabled. private static ArraySet<ComponentName> sTileBlacklist = new ArraySet<>(); private final PackageReceiver mPackageReceiver = new PackageReceiver(); private final List<CategoryListener> mCategoryListeners = new ArrayList<>(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final long startTime = System.currentTimeMillis(); final TypedArray theme = getTheme().obtainStyledAttributes(android.R.styleable.Theme); if (!theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) { getWindow().addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); requestWindowFeature(Window.FEATURE_NO_TITLE); } super.setContentView(R.layout.settings_base_layout); final Toolbar toolbar = findViewById(R.id.action_bar); if (theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) { toolbar.setVisibility(View.GONE); return; } setActionBar(toolbar); if (DEBUG_TIMING) { Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms"); } } @Override public boolean onNavigateUp() { if (!super.onNavigateUp()) { finish(); } return true; } @Override protected void onResume() { super.onResume(); final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addAction(Intent.ACTION_PACKAGE_REPLACED); filter.addDataScheme(DATA_SCHEME_PKG); registerReceiver(mPackageReceiver, filter); new CategoriesUpdateTask().execute(); } @Override protected void onPause() { unregisterReceiver(mPackageReceiver); super.onPause(); } public void addCategoryListener(CategoryListener listener) { mCategoryListeners.add(listener); } public void remCategoryListener(CategoryListener listener) { mCategoryListeners.remove(listener); } @Override public void setContentView(@LayoutRes int layoutResID) { final ViewGroup parent = findViewById(R.id.content_frame); if (parent != null) { parent.removeAllViews(); } LayoutInflater.from(this).inflate(layoutResID, parent); } @Override public void setContentView(View view) { ((ViewGroup) findViewById(R.id.content_frame)).addView(view); } @Override public void setContentView(View view, ViewGroup.LayoutParams params) { ((ViewGroup) findViewById(R.id.content_frame)).addView(view, params); } private void onCategoriesChanged() { final int N = mCategoryListeners.size(); for (int i = 0; i < N; i++) { mCategoryListeners.get(i).onCategoriesChanged(); } } /** * @return whether or not the enabled state actually changed. */ public boolean setTileEnabled(ComponentName component, boolean enabled) { final PackageManager pm = getPackageManager(); int state = pm.getComponentEnabledSetting(component); boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; if (isEnabled != enabled || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { if (enabled) { sTileBlacklist.remove(component); } else { sTileBlacklist.add(component); } pm.setComponentEnabledSetting(component, enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); return true; } return false; } /** * Updates dashboard categories. Only necessary to call this after setTileEnabled */ public void updateCategories() { new CategoriesUpdateTask().execute(); } public String getSettingPkg() { return TileUtils.SETTING_PKG; } public interface CategoryListener { void onCategoriesChanged(); } private class CategoriesUpdateTask extends AsyncTask<Void, Void, Void> { private final CategoryManager mCategoryManager; public CategoriesUpdateTask() { mCategoryManager = CategoryManager.get(SettingsBaseActivity.this); } @Override protected Void doInBackground(Void... params) { mCategoryManager.reloadAllCategories(SettingsBaseActivity.this, getSettingPkg()); return null; } @Override protected void onPostExecute(Void result) { mCategoryManager.updateCategoryFromBlacklist(sTileBlacklist); onCategoriesChanged(); } } private class PackageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { new CategoriesUpdateTask().execute(); } } } src/com/android/settings/dashboard/DashboardFragment.java +6 −6 Original line number Diff line number Diff line Loading @@ -27,13 +27,13 @@ import android.util.Log; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.core.BasePreferenceController; import com.android.settings.core.PreferenceControllerListHelper; import com.android.settings.core.SettingsBaseActivity; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.Indexable; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.drawer.DashboardCategory; import com.android.settingslib.drawer.SettingsDrawerActivity; import com.android.settingslib.drawer.Tile; import com.android.settingslib.drawer.TileUtils; Loading @@ -52,7 +52,7 @@ import androidx.preference.PreferenceScreen; * Base fragment for dashboard style UI containing a list of static and dynamic setting items. */ public abstract class DashboardFragment extends SettingsPreferenceFragment implements SettingsDrawerActivity.CategoryListener, Indexable, implements SettingsBaseActivity.CategoryListener, Indexable, SummaryLoader.SummaryConsumer { private static final String TAG = "DashboardFragment"; Loading Loading @@ -145,9 +145,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment mSummaryLoader.setListening(true); } final Activity activity = getActivity(); if (activity instanceof SettingsDrawerActivity) { if (activity instanceof SettingsBaseActivity) { mListeningToCategoryChange = true; ((SettingsDrawerActivity) activity).addCategoryListener(this); ((SettingsBaseActivity) activity).addCategoryListener(this); } } Loading Loading @@ -197,8 +197,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } if (mListeningToCategoryChange) { final Activity activity = getActivity(); if (activity instanceof SettingsDrawerActivity) { ((SettingsDrawerActivity) activity).remCategoryListener(this); if (activity instanceof SettingsBaseActivity) { ((SettingsBaseActivity) activity).remCategoryListener(this); } mListeningToCategoryChange = false; } Loading Loading
res/layout/settings_base_layout.xml 0 → 100644 +35 −0 Original line number Diff line number Diff line <!-- 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. --> <!-- The main content view --> <LinearLayout android:id="@+id/content_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Toolbar android:id="@+id/action_bar" style="?android:attr/actionBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="?android:attr/actionBarTheme" android:navigationContentDescription="@*android:string/action_bar_up_description" /> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="fill_parent" android:background="?android:attr/windowBackground" /> </LinearLayout>
src/com/android/settings/SettingsActivity.java +4 −3 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import com.android.internal.util.ArrayUtils; import com.android.settings.Settings.WifiSettingsActivity; import com.android.settings.applications.manageapplications.ManageApplications; import com.android.settings.backup.BackupSettingsActivity; import com.android.settings.core.SettingsBaseActivity; import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.gateway.SettingsGateway; import com.android.settings.dashboard.DashboardFeatureProvider; Loading @@ -64,7 +65,6 @@ import com.android.settingslib.core.instrumentation.Instrumentable; import com.android.settingslib.core.instrumentation.SharedPreferencesLogger; import com.android.settingslib.development.DevelopmentSettingsEnabler; import com.android.settingslib.drawer.DashboardCategory; import com.android.settingslib.drawer.SettingsDrawerActivity; import com.android.settingslib.utils.ThreadUtils; import java.util.ArrayList; Loading @@ -76,7 +76,8 @@ import androidx.preference.Preference; import androidx.preference.PreferenceFragment; import androidx.preference.PreferenceManager; public class SettingsActivity extends SettingsDrawerActivity public class SettingsActivity extends SettingsBaseActivity implements PreferenceManager.OnPreferenceTreeClickListener, PreferenceFragment.OnPreferenceStartFragmentCallback, ButtonBarHandler, FragmentManager.OnBackStackChangedListener { Loading Loading @@ -606,7 +607,7 @@ public class SettingsActivity extends SettingsDrawerActivity private void updateTilesList() { // Generally the items that are will be changing from these updates will // not be in the top list of tiles, so run it in the background and the // SettingsDrawerActivity will pick up on the updates automatically. // SettingsBaseActivity will pick up on the updates automatically. AsyncTask.execute(new Runnable() { @Override public void run() { Loading
src/com/android/settings/backup/BackupSettingsHelper.java +0 −1 Original line number Diff line number Diff line Loading @@ -152,7 +152,6 @@ public class BackupSettingsHelper { } private Intent getIntentForDefaultBackupSettings() { // Extra needed by {@link SettingsDrawerActivity} to show the back button navigation. return new Intent(mContext, PrivacySettingsActivity.class); } Loading
src/com/android/settings/core/SettingsBaseActivity.java 0 → 100644 +211 −0 Original line number Diff line number Diff line /** * 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.android.settings.core; import android.annotation.LayoutRes; import android.annotation.Nullable; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.res.TypedArray; import android.os.AsyncTask; import android.os.Bundle; import android.util.ArraySet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager.LayoutParams; import android.widget.Toolbar; import com.android.settings.R; import com.android.settingslib.drawer.CategoryManager; import com.android.settingslib.drawer.TileUtils; import java.util.ArrayList; import java.util.List; import androidx.fragment.app.FragmentActivity; public class SettingsBaseActivity extends FragmentActivity { protected static final boolean DEBUG_TIMING = false; private static final String TAG = "SettingsBaseActivity"; private static final String DATA_SCHEME_PKG = "package"; // Serves as a temporary list of tiles to ignore until we heard back from the PM that they // are disabled. private static ArraySet<ComponentName> sTileBlacklist = new ArraySet<>(); private final PackageReceiver mPackageReceiver = new PackageReceiver(); private final List<CategoryListener> mCategoryListeners = new ArrayList<>(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final long startTime = System.currentTimeMillis(); final TypedArray theme = getTheme().obtainStyledAttributes(android.R.styleable.Theme); if (!theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) { getWindow().addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); requestWindowFeature(Window.FEATURE_NO_TITLE); } super.setContentView(R.layout.settings_base_layout); final Toolbar toolbar = findViewById(R.id.action_bar); if (theme.getBoolean(android.R.styleable.Theme_windowNoTitle, false)) { toolbar.setVisibility(View.GONE); return; } setActionBar(toolbar); if (DEBUG_TIMING) { Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms"); } } @Override public boolean onNavigateUp() { if (!super.onNavigateUp()) { finish(); } return true; } @Override protected void onResume() { super.onResume(); final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addAction(Intent.ACTION_PACKAGE_REPLACED); filter.addDataScheme(DATA_SCHEME_PKG); registerReceiver(mPackageReceiver, filter); new CategoriesUpdateTask().execute(); } @Override protected void onPause() { unregisterReceiver(mPackageReceiver); super.onPause(); } public void addCategoryListener(CategoryListener listener) { mCategoryListeners.add(listener); } public void remCategoryListener(CategoryListener listener) { mCategoryListeners.remove(listener); } @Override public void setContentView(@LayoutRes int layoutResID) { final ViewGroup parent = findViewById(R.id.content_frame); if (parent != null) { parent.removeAllViews(); } LayoutInflater.from(this).inflate(layoutResID, parent); } @Override public void setContentView(View view) { ((ViewGroup) findViewById(R.id.content_frame)).addView(view); } @Override public void setContentView(View view, ViewGroup.LayoutParams params) { ((ViewGroup) findViewById(R.id.content_frame)).addView(view, params); } private void onCategoriesChanged() { final int N = mCategoryListeners.size(); for (int i = 0; i < N; i++) { mCategoryListeners.get(i).onCategoriesChanged(); } } /** * @return whether or not the enabled state actually changed. */ public boolean setTileEnabled(ComponentName component, boolean enabled) { final PackageManager pm = getPackageManager(); int state = pm.getComponentEnabledSetting(component); boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; if (isEnabled != enabled || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) { if (enabled) { sTileBlacklist.remove(component); } else { sTileBlacklist.add(component); } pm.setComponentEnabledSetting(component, enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); return true; } return false; } /** * Updates dashboard categories. Only necessary to call this after setTileEnabled */ public void updateCategories() { new CategoriesUpdateTask().execute(); } public String getSettingPkg() { return TileUtils.SETTING_PKG; } public interface CategoryListener { void onCategoriesChanged(); } private class CategoriesUpdateTask extends AsyncTask<Void, Void, Void> { private final CategoryManager mCategoryManager; public CategoriesUpdateTask() { mCategoryManager = CategoryManager.get(SettingsBaseActivity.this); } @Override protected Void doInBackground(Void... params) { mCategoryManager.reloadAllCategories(SettingsBaseActivity.this, getSettingPkg()); return null; } @Override protected void onPostExecute(Void result) { mCategoryManager.updateCategoryFromBlacklist(sTileBlacklist); onCategoriesChanged(); } } private class PackageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { new CategoriesUpdateTask().execute(); } } }
src/com/android/settings/dashboard/DashboardFragment.java +6 −6 Original line number Diff line number Diff line Loading @@ -27,13 +27,13 @@ import android.util.Log; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.core.BasePreferenceController; import com.android.settings.core.PreferenceControllerListHelper; import com.android.settings.core.SettingsBaseActivity; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.Indexable; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.drawer.DashboardCategory; import com.android.settingslib.drawer.SettingsDrawerActivity; import com.android.settingslib.drawer.Tile; import com.android.settingslib.drawer.TileUtils; Loading @@ -52,7 +52,7 @@ import androidx.preference.PreferenceScreen; * Base fragment for dashboard style UI containing a list of static and dynamic setting items. */ public abstract class DashboardFragment extends SettingsPreferenceFragment implements SettingsDrawerActivity.CategoryListener, Indexable, implements SettingsBaseActivity.CategoryListener, Indexable, SummaryLoader.SummaryConsumer { private static final String TAG = "DashboardFragment"; Loading Loading @@ -145,9 +145,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment mSummaryLoader.setListening(true); } final Activity activity = getActivity(); if (activity instanceof SettingsDrawerActivity) { if (activity instanceof SettingsBaseActivity) { mListeningToCategoryChange = true; ((SettingsDrawerActivity) activity).addCategoryListener(this); ((SettingsBaseActivity) activity).addCategoryListener(this); } } Loading Loading @@ -197,8 +197,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } if (mListeningToCategoryChange) { final Activity activity = getActivity(); if (activity instanceof SettingsDrawerActivity) { ((SettingsDrawerActivity) activity).remCategoryListener(this); if (activity instanceof SettingsBaseActivity) { ((SettingsBaseActivity) activity).remCategoryListener(this); } mListeningToCategoryChange = false; } Loading