From ecfa0ff337cf2feae19e651470c1ca05926430f2 Mon Sep 17 00:00:00 2001 From: cretin45 Date: Mon, 30 Nov 2015 16:38:47 -0800 Subject: Trebuchet: Add app drawer settings Change-Id: I040420608de64bedc6e9832268796cdf801f5c21 --- res/values/cm_strings.xml | 11 +++ res/values/preferences_defaults.xml | 2 + src/com/android/launcher3/BaseContainerView.java | 15 +++- src/com/android/launcher3/BubbleTextView.java | 7 +- src/com/android/launcher3/Launcher.java | 22 ++++-- .../android/launcher3/OverviewSettingsPanel.java | 5 +- .../launcher3/allapps/AllAppsContainerView.java | 39 ++++++---- .../launcher3/allapps/AllAppsGridAdapter.java | 8 +- .../list/SettingsPinnedHeaderAdapter.java | 87 +++++++++++++++++++++- .../launcher3/settings/SettingsProvider.java | 4 +- 10 files changed, 165 insertions(+), 35 deletions(-) diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 9072824ce..7a2b84a73 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -60,6 +60,17 @@ Protected apps + + Drawer style + Compact + Sections + Drawer color + Dark + Light + Fast scroller + Horizontal + Vertical + A search activity could not be found! diff --git a/res/values/preferences_defaults.xml b/res/values/preferences_defaults.xml index 9eb5ca58f..494846aed 100644 --- a/res/values/preferences_defaults.xml +++ b/res/values/preferences_defaults.xml @@ -5,5 +5,7 @@ false false false + true false + true diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java index ac2afa944..0f1585a4a 100644 --- a/src/com/android/launcher3/BaseContainerView.java +++ b/src/com/android/launcher3/BaseContainerView.java @@ -17,6 +17,7 @@ package com.android.launcher3; import android.content.Context; +import android.content.res.Resources; import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; @@ -25,6 +26,8 @@ import android.view.ViewStub; import android.widget.LinearLayout; import android.widget.TextView; +import com.android.launcher3.settings.SettingsProvider; + /** * A base container view, which supports resizing. */ @@ -100,9 +103,13 @@ public abstract class BaseContainerView extends LinearLayout implements Insettab }); } - public final void setUseScrubber(boolean use) { - mUseScrubber = use; - if (use) { + public final void setScroller() { + Context context = getContext(); + boolean useHorizontalScroller= SettingsProvider.getBoolean(context, + SettingsProvider.SETTINGS_UI_USE_HORIZONTAL_SCRUBBER, + R.bool.preferences_interface_use_horizontal_scrubber_default); + mUseScrubber = useHorizontalScroller; + if (mUseScrubber) { ViewStub stub = (ViewStub) findViewById(R.id.scrubber_container_stub); mScrubberContainerView = stub.inflate(); if (mScrubberContainerView == null) { @@ -128,7 +135,7 @@ public abstract class BaseContainerView extends LinearLayout implements Insettab } } - public final boolean userScrubber() { + public final boolean useScrubber() { return mUseScrubber; } diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index c15f07de9..32b3a0217 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -133,9 +133,12 @@ public class BubbleTextView extends TextView defaultIconSize = grid.allAppsIconSizePx; } boolean useCompactDrawer = SettingsProvider.getBoolean(context, - SettingsProvider.SETTINGS_UI_DRAWER_COMPACT, + SettingsProvider.SETTINGS_UI_DRAWER_STYLE_USE_COMPACT, R.bool.preferences_interface_drawer_compact_default); - if (!useCompactDrawer) { + boolean useLargeIcons = SettingsProvider.getBoolean(context, + SettingsProvider.SETTINGS_UI_GENERAL_ICONS_LARGE, + R.bool.preferences_interface_general_icons_large_default); + if (!useLargeIcons && !useCompactDrawer) { defaultIconSize = getResources() .getDimensionPixelSize(R.dimen.all_apps_icon_size_ragged); } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 8f3bbf578..fd6ab26e4 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1551,11 +1551,6 @@ public class Launcher extends Activity mAppsView.setSearchBarController(mAppsView.newDefaultAppSearchController()); } - mAppsView.setUseScrubber(mUseScrubber); - mAppsView.setSectionStrategy(AllAppsContainerView.SECTION_STRATEGY_RAGGED); - mAppsView.setGridTheme(AllAppsContainerView.GRID_THEME_DARK); - mWidgetsView.setUseScrubber(false); - // Setup the drag controller (drop targets have to be added in reverse order in priority) dragController.setDragScoller(mWorkspace); dragController.setScrollView(mDragLayer); @@ -1832,6 +1827,23 @@ public class Launcher extends Activity mAppsView.reset(); } + public void reloadAppDrawer() { + List addedApps = mAppsView.getApps(); + mDragLayer.removeView(mAppsView); + mAppsView = (AllAppsContainerView)LayoutInflater + .from(this).inflate(R.layout.all_apps, mDragLayer, false); + mDragLayer.addView(mAppsView, mDragLayer.getChildCount() - 1); + mAppsView.setVisibility(View.INVISIBLE); + if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) { + mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController()); + } else { + mAppsView.setSearchBarController(mAppsView.newDefaultAppSearchController()); + } + mAppsView.addApps(addedApps); + tryAndUpdatePredictedApps(); + mAppsView.reset(); + } + /** * Replaces currently added fragments in the launcher layout with a * {@link DynamicGridSizeFragment}. diff --git a/src/com/android/launcher3/OverviewSettingsPanel.java b/src/com/android/launcher3/OverviewSettingsPanel.java index f608b2609..cac40e6a4 100644 --- a/src/com/android/launcher3/OverviewSettingsPanel.java +++ b/src/com/android/launcher3/OverviewSettingsPanel.java @@ -39,7 +39,10 @@ public class OverviewSettingsPanel { res.getString(R.string.grid_size_text)}; String[] valuesDrawer = new String[] { - res.getString(R.string.icon_labels)}; + res.getString(R.string.icon_labels), + res.getString(R.string.app_drawer_style), + res.getString(R.string.app_drawer_color), + res.getString(R.string.fast_scroller_type)}; String[] valuesApp = new String[] { res.getString(R.string.larger_icons_text)/*, diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 0a94be766..b82cd2d0a 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -48,6 +48,7 @@ import com.android.launcher3.LauncherTransitionable; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; +import com.android.launcher3.settings.SettingsProvider; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.Thunk; @@ -189,12 +190,9 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc Resources res = context.getResources(); mLauncher = (Launcher) context; - mSectionNamesMargin = mSectionStrategy == SECTION_STRATEGY_GRID ? - res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : - res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); mApps = new AlphabeticalAppsList(context); mAdapter = new AllAppsGridAdapter(mLauncher, mApps, this, mLauncher, - this, mSectionStrategy, mGridTheme); + this); mApps.setAdapter(mAdapter); mLayoutManager = mAdapter.getLayoutManager(); mItemDecoration = mAdapter.getItemDecoration(); @@ -254,23 +252,35 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc } private void updateScrubber() { - if (userScrubber()) { + if (useScrubber()) { mScrubber.updateSections(); } } - public void setSectionStrategy(int sectionStrategy) { - Resources res = getResources(); - mSectionStrategy = sectionStrategy; - mSectionNamesMargin = mSectionStrategy == SECTION_STRATEGY_GRID ? + public List getApps() { + return mApps.getApps(); + } + + private void updateSectionStrategy() { + Context context = getContext(); + Resources res = context.getResources(); + boolean useCompactGrid = SettingsProvider.getBoolean(context, + SettingsProvider.SETTINGS_UI_DRAWER_STYLE_USE_COMPACT, + R.bool.preferences_interface_drawer_compact_default); + mSectionStrategy = useCompactGrid ? SECTION_STRATEGY_GRID : SECTION_STRATEGY_RAGGED; + mSectionNamesMargin = useCompactGrid ? res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); mAdapter.setSectionStrategy(mSectionStrategy); mAppsRecyclerView.setSectionStrategy(mSectionStrategy); } - public void setGridTheme(int gridTheme) { - mGridTheme = gridTheme; + private void updateGridTheme() { + Context context = getContext(); + boolean useDarkColor= SettingsProvider.getBoolean(context, + SettingsProvider.SETTINGS_UI_DRAWER_DARK, + R.bool.preferences_interface_drawer_dark_default); + mGridTheme = useDarkColor ? GRID_THEME_DARK : GRID_THEME_LIGHT; mAdapter.setGridTheme(mGridTheme); updateBackgroundAndPaddings(true); } @@ -365,14 +375,15 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc // Load the all apps recycler view mAppsRecyclerView = (AllAppsRecyclerView) findViewById(R.id.apps_list_view); mAppsRecyclerView.setApps(mApps); - mAppsRecyclerView.setSectionStrategy(mSectionStrategy); mAppsRecyclerView.setLayoutManager(mLayoutManager); mAppsRecyclerView.setAdapter(mAdapter); mAppsRecyclerView.setHasFixedSize(true); if (mItemDecoration != null) { mAppsRecyclerView.addItemDecoration(mItemDecoration); } - + setScroller(); + updateGridTheme(); + updateSectionStrategy(); updateBackgroundAndPaddings(); } @@ -442,7 +453,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc // names) int startInset = Math.max(mSectionNamesMargin, mAppsRecyclerView.getMaxScrollbarWidth()); int topBottomPadding = mRecyclerViewTopBottomPadding; - final boolean useScubber = userScrubber(); + final boolean useScubber = useScrubber(); if (isRtl) { mAppsRecyclerView.setPadding(padding.left + mAppsRecyclerView.getMaxScrollbarWidth(), topBottomPadding, padding.right + startInset, useScubber ? diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index 17d106731..a736f7770 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -361,7 +361,7 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter