Loading res/layout/expand_preference.xml 0 → 100644 +32 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2016 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. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/selectable_card_grey" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="vertical" android:paddingEnd="?android:attr/scrollbarSize"> <TextView android:id="@android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> </LinearLayout> No newline at end of file src/com/android/settings/core/PreferenceController.java +7 −7 Original line number Diff line number Diff line Loading @@ -50,7 +50,8 @@ public abstract class PreferenceController { /** * Updates the current status of preference (summary, switch state, etc) */ public void updateState(PreferenceScreen screen) { public void updateState(Preference preference) { } /** Loading @@ -72,6 +73,11 @@ public abstract class PreferenceController { */ public abstract boolean handlePreferenceTreeClick(Preference preference); /** * Returns the key for this preference. */ public abstract String getPreferenceKey(); /** * Removes preference from screen. */ Loading @@ -86,10 +92,4 @@ public abstract class PreferenceController { * Returns true if preference is available (should be displayed) */ protected abstract boolean isAvailable(); /** * Returns the key for this preference. */ protected abstract String getPreferenceKey(); } src/com/android/settings/core/lifecycle/ObservablePreferenceFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ public abstract class ObservablePreferenceFragment extends PreferenceFragment { @CallSuper @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLifecycle.onCreate(savedInstanceState); super.onCreate(savedInstanceState); } @CallSuper Loading src/com/android/settings/dashboard/DashboardFragment.java +48 −6 Original line number Diff line number Diff line Loading @@ -52,12 +52,14 @@ import java.util.Set; public abstract class DashboardFragment extends SettingsPreferenceFragment implements SettingsDrawerActivity.CategoryListener, Indexable, SummaryLoader.SummaryConsumer { private static final String TAG = "DashboardFragment"; private final Map<Class, PreferenceController> mPreferenceControllers = new ArrayMap<>(); private final Set<String> mDashboardTilePrefKeys = new ArraySet<>(); private DashboardDividerDecoration mDividerDecoration; protected ProgressiveDisclosureMixin mProgressiveDisclosureMixin; protected DashboardFeatureProvider mDashboardFeatureProvider; private boolean mListeningToCategoryChange; private SummaryLoader mSummaryLoader; Loading @@ -67,6 +69,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment super.onAttach(context); mDashboardFeatureProvider = FeatureFactory.getFactory(context).getDashboardFeatureProvider(context); mProgressiveDisclosureMixin = new ProgressiveDisclosureMixin(context, this); getLifecycle().addObserver(mProgressiveDisclosureMixin); final List<PreferenceController> controllers = getPreferenceControllers(context); if (controllers == null) { Loading Loading @@ -160,6 +164,18 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } } @Override public Preference findPreference(CharSequence key) { Preference preference = super.findPreference(key); if (preference == null && mProgressiveDisclosureMixin != null) { preference = mProgressiveDisclosureMixin.findPreference(key); } if (preference == null) { Log.d(TAG, "Cannot find preference with key " + key); } return preference; } protected <T extends PreferenceController> T getPreferenceController(Class<T> clazz) { PreferenceController controller = mPreferenceControllers.get(clazz); return (T) controller; Loading Loading @@ -259,9 +275,21 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment // (larger value has higher priority). However pref order defines smaller value has // higher priority. pref.setOrder(-tile.priority); // Either add to screen, or to collapsed list. if (mProgressiveDisclosureMixin.isCollapsed()) { // Already collapsed, add to collapsed list. mProgressiveDisclosureMixin.addToCollapsedList(pref); } else if (mProgressiveDisclosureMixin.shouldCollapse(screen)) { // About to have too many tiles on scree, collapse and add pref to collapsed list. mProgressiveDisclosureMixin.collapse(screen); mProgressiveDisclosureMixin.addToCollapsedList(pref); } else { // No need to collapse, add to screen directly. screen.addPreference(pref); } } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Loading @@ -278,9 +306,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment */ private void updatePreferenceStates() { Collection<PreferenceController> controllers = mPreferenceControllers.values(); final PreferenceScreen screen = getPreferenceScreen(); for (PreferenceController controller : controllers) { controller.updateState(screen); final String key = controller.getPreferenceKey(); final Preference preference = findPreference(key); if (preference == null) { Log.d(TAG, "Cannot find preference with key " + key); continue; } controller.updateState(preference); } } Loading @@ -302,15 +336,20 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment */ private void refreshAllPreferences(final String TAG) { // First remove old preferences. final PreferenceScreen screen = getPreferenceScreen(); if (screen != null) { screen.removeAll(); if (getPreferenceScreen() != null) { // Intentionally do not cache PreferenceScreen because it will be recreated later. getPreferenceScreen().removeAll(); } // Add resource based tiles. displayResourceTiles(); refreshDashboardTiles(TAG); if (!mProgressiveDisclosureMixin.isCollapsed() && mProgressiveDisclosureMixin.shouldCollapse(getPreferenceScreen())) { mProgressiveDisclosureMixin.collapse(getPreferenceScreen()); } } /** Loading @@ -319,10 +358,13 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment private void refreshDashboardTiles(final String TAG) { final PreferenceScreen screen = getPreferenceScreen(); for (String key : mDashboardTilePrefKeys) { // Remove tiles from screen final Preference pref = screen.findPreference(key); if (pref != null) { screen.removePreference(pref); } // Also remove tile from collapsed set mProgressiveDisclosureMixin.removePreference(screen, key); } mDashboardTilePrefKeys.clear(); displayDashboardTiles(TAG, getPreferenceScreen()); Loading src/com/android/settings/dashboard/ExpandPreference.java 0 → 100644 +53 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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.dashboard; import android.content.Context; import android.support.v7.preference.Preference; import android.util.AttributeSet; import com.android.settings.R; public class ExpandPreference extends Preference { public ExpandPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(); } public ExpandPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } public ExpandPreference(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ExpandPreference(Context context) { super(context); init(); } private void init() { setLayoutResource(R.layout.expand_preference); setTitle(R.string.wifi_more); setOrder(999); } } Loading
res/layout/expand_preference.xml 0 → 100644 +32 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2016 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. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/selectable_card_grey" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="vertical" android:paddingEnd="?android:attr/scrollbarSize"> <TextView android:id="@android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"/> </LinearLayout> No newline at end of file
src/com/android/settings/core/PreferenceController.java +7 −7 Original line number Diff line number Diff line Loading @@ -50,7 +50,8 @@ public abstract class PreferenceController { /** * Updates the current status of preference (summary, switch state, etc) */ public void updateState(PreferenceScreen screen) { public void updateState(Preference preference) { } /** Loading @@ -72,6 +73,11 @@ public abstract class PreferenceController { */ public abstract boolean handlePreferenceTreeClick(Preference preference); /** * Returns the key for this preference. */ public abstract String getPreferenceKey(); /** * Removes preference from screen. */ Loading @@ -86,10 +92,4 @@ public abstract class PreferenceController { * Returns true if preference is available (should be displayed) */ protected abstract boolean isAvailable(); /** * Returns the key for this preference. */ protected abstract String getPreferenceKey(); }
src/com/android/settings/core/lifecycle/ObservablePreferenceFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -42,8 +42,8 @@ public abstract class ObservablePreferenceFragment extends PreferenceFragment { @CallSuper @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLifecycle.onCreate(savedInstanceState); super.onCreate(savedInstanceState); } @CallSuper Loading
src/com/android/settings/dashboard/DashboardFragment.java +48 −6 Original line number Diff line number Diff line Loading @@ -52,12 +52,14 @@ import java.util.Set; public abstract class DashboardFragment extends SettingsPreferenceFragment implements SettingsDrawerActivity.CategoryListener, Indexable, SummaryLoader.SummaryConsumer { private static final String TAG = "DashboardFragment"; private final Map<Class, PreferenceController> mPreferenceControllers = new ArrayMap<>(); private final Set<String> mDashboardTilePrefKeys = new ArraySet<>(); private DashboardDividerDecoration mDividerDecoration; protected ProgressiveDisclosureMixin mProgressiveDisclosureMixin; protected DashboardFeatureProvider mDashboardFeatureProvider; private boolean mListeningToCategoryChange; private SummaryLoader mSummaryLoader; Loading @@ -67,6 +69,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment super.onAttach(context); mDashboardFeatureProvider = FeatureFactory.getFactory(context).getDashboardFeatureProvider(context); mProgressiveDisclosureMixin = new ProgressiveDisclosureMixin(context, this); getLifecycle().addObserver(mProgressiveDisclosureMixin); final List<PreferenceController> controllers = getPreferenceControllers(context); if (controllers == null) { Loading Loading @@ -160,6 +164,18 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } } @Override public Preference findPreference(CharSequence key) { Preference preference = super.findPreference(key); if (preference == null && mProgressiveDisclosureMixin != null) { preference = mProgressiveDisclosureMixin.findPreference(key); } if (preference == null) { Log.d(TAG, "Cannot find preference with key " + key); } return preference; } protected <T extends PreferenceController> T getPreferenceController(Class<T> clazz) { PreferenceController controller = mPreferenceControllers.get(clazz); return (T) controller; Loading Loading @@ -259,9 +275,21 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment // (larger value has higher priority). However pref order defines smaller value has // higher priority. pref.setOrder(-tile.priority); // Either add to screen, or to collapsed list. if (mProgressiveDisclosureMixin.isCollapsed()) { // Already collapsed, add to collapsed list. mProgressiveDisclosureMixin.addToCollapsedList(pref); } else if (mProgressiveDisclosureMixin.shouldCollapse(screen)) { // About to have too many tiles on scree, collapse and add pref to collapsed list. mProgressiveDisclosureMixin.collapse(screen); mProgressiveDisclosureMixin.addToCollapsedList(pref); } else { // No need to collapse, add to screen directly. screen.addPreference(pref); } } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Loading @@ -278,9 +306,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment */ private void updatePreferenceStates() { Collection<PreferenceController> controllers = mPreferenceControllers.values(); final PreferenceScreen screen = getPreferenceScreen(); for (PreferenceController controller : controllers) { controller.updateState(screen); final String key = controller.getPreferenceKey(); final Preference preference = findPreference(key); if (preference == null) { Log.d(TAG, "Cannot find preference with key " + key); continue; } controller.updateState(preference); } } Loading @@ -302,15 +336,20 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment */ private void refreshAllPreferences(final String TAG) { // First remove old preferences. final PreferenceScreen screen = getPreferenceScreen(); if (screen != null) { screen.removeAll(); if (getPreferenceScreen() != null) { // Intentionally do not cache PreferenceScreen because it will be recreated later. getPreferenceScreen().removeAll(); } // Add resource based tiles. displayResourceTiles(); refreshDashboardTiles(TAG); if (!mProgressiveDisclosureMixin.isCollapsed() && mProgressiveDisclosureMixin.shouldCollapse(getPreferenceScreen())) { mProgressiveDisclosureMixin.collapse(getPreferenceScreen()); } } /** Loading @@ -319,10 +358,13 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment private void refreshDashboardTiles(final String TAG) { final PreferenceScreen screen = getPreferenceScreen(); for (String key : mDashboardTilePrefKeys) { // Remove tiles from screen final Preference pref = screen.findPreference(key); if (pref != null) { screen.removePreference(pref); } // Also remove tile from collapsed set mProgressiveDisclosureMixin.removePreference(screen, key); } mDashboardTilePrefKeys.clear(); displayDashboardTiles(TAG, getPreferenceScreen()); Loading
src/com/android/settings/dashboard/ExpandPreference.java 0 → 100644 +53 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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.dashboard; import android.content.Context; import android.support.v7.preference.Preference; import android.util.AttributeSet; import com.android.settings.R; public class ExpandPreference extends Preference { public ExpandPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(); } public ExpandPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } public ExpandPreference(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ExpandPreference(Context context) { super(context); init(); } private void init() { setLayoutResource(R.layout.expand_preference); setTitle(R.string.wifi_more); setOrder(999); } }