From 60820d796f5789ac0d1d478f1d3c8e403fd0a56f Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 9 May 2017 12:40:11 -0700 Subject: [PATCH] Adding listener support for color extraction changes Changing the apps-search layout to use theme attribute instead of hard coded layout id Bug: 37616877 Change-Id: Iae601758303f83a2774635f0d88f74d99fc643c3 --- res/layout/all_apps.xml | 6 ++++-- res/layout/all_apps_search_container.xml | 6 +++--- res/values-sw720dp/styles.xml | 1 + res/values/styles.xml | 1 + src/com/android/launcher3/Launcher.java | 13 ++++-------- .../android/launcher3/LauncherCallbacks.java | 2 -- .../allapps/AllAppsTransitionController.java | 4 +++- .../allapps/AlphabeticalAppsList.java | 12 +++++++++-- .../launcher3/dynamicui/ExtractedColors.java | 20 +++++++++++++++++++ .../launcher3/testing/LauncherExtension.java | 3 --- 10 files changed, 46 insertions(+), 22 deletions(-) diff --git a/res/layout/all_apps.xml b/res/layout/all_apps.xml index 7d97f2564d..f3539dcfa0 100644 --- a/res/layout/all_apps.xml +++ b/res/layout/all_apps.xml @@ -59,13 +59,15 @@ + diff --git a/res/layout/all_apps_search_container.xml b/res/layout/all_apps_search_container.xml index 6addee1e22..c79360f667 100644 --- a/res/layout/all_apps_search_container.xml +++ b/res/layout/all_apps_search_container.xml @@ -15,28 +15,28 @@ --> \ No newline at end of file diff --git a/res/values-sw720dp/styles.xml b/res/values-sw720dp/styles.xml index de809b105e..bc65a0e9aa 100644 --- a/res/values-sw720dp/styles.xml +++ b/res/values-sw720dp/styles.xml @@ -26,6 +26,7 @@ true true ?android:attr/textColorSecondary + @layout/all_apps_search_container diff --git a/res/values/styles.xml b/res/values/styles.xml index c3d11e446f..e2d9ff486b 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -25,6 +25,7 @@ true true #FF757575 + @layout/all_apps_search_container diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index c96c2a7b9a..25995dd1a3 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -212,6 +212,8 @@ public class Launcher extends BaseActivity private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5; @Thunk static int NEW_APPS_ANIMATION_DELAY = 500; + private final ExtractedColors mExtractedColors = new ExtractedColors(); + @Thunk Workspace mWorkspace; private View mLauncherView; @Thunk DragLayer mDragLayer; @@ -260,7 +262,6 @@ public class Launcher extends BaseActivity private LauncherModel mModel; private ModelWriter mModelWriter; private IconCache mIconCache; - private ExtractedColors mExtractedColors; private LauncherAccessibilityDelegate mAccessibilityDelegate; private Handler mHandler = new Handler(); private boolean mIsResumeFromActionScreenOff; @@ -392,11 +393,10 @@ public class Launcher extends BaseActivity // LauncherModel load. mPaused = false; - mLauncherView = getLayoutInflater().inflate(R.layout.launcher, null); + mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null); setupViews(); mDeviceProfile.layout(this, false /* notifyListeners */); - mExtractedColors = new ExtractedColors(); loadExtractedColorsAndColorItems(); mPopupDataProvider = new PopupDataProvider(this); @@ -465,12 +465,7 @@ public class Launcher extends BaseActivity @Override public void onExtractedColorsChanged() { loadExtractedColorsAndColorItems(); - if (mAllAppsController != null) { - mAllAppsController.onExtractedColorsChanged(); - } - if (mLauncherCallbacks != null) { - mLauncherCallbacks.onExtractedColorsChanged(); - } + mExtractedColors.notifyChange(); } public ExtractedColors getExtractedColors() { diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java index ea4aeb9297..d66b14c7dc 100644 --- a/src/com/android/launcher3/LauncherCallbacks.java +++ b/src/com/android/launcher3/LauncherCallbacks.java @@ -97,6 +97,4 @@ public interface LauncherCallbacks { int getSearchBarHeight(); boolean shouldShowDiscoveryBounce(); - - void onExtractedColorsChanged(); } diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index 121ce4ce12..9c1854a367 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -42,7 +42,7 @@ import com.android.launcher3.util.TouchController; * closer to top or closer to the page indicator. */ public class AllAppsTransitionController implements TouchController, VerticalPullDetector.Listener, - View.OnLayoutChangeListener { + View.OnLayoutChangeListener, ExtractedColors.OnChangeListener { private static final String TAG = "AllAppsTrans"; private static final boolean DBG = false; @@ -107,6 +107,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul mEvaluator = new ArgbEvaluator(); mAllAppsBackgroundColor = Themes.getAttrColor(l, android.R.attr.colorPrimary); + mLauncher.getExtractedColors().addOnChangeListener(this); } @Override @@ -288,6 +289,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul mScrimView.setProgress(progress); } + @Override public void onExtractedColorsChanged() { if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) { if (mGradientView != null) { diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java index f291a80eee..047441985b 100644 --- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java +++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java @@ -195,6 +195,8 @@ public class AlphabeticalAppsList { private int mNumPredictedAppsPerRow; private int mNumAppRowsInAdapter; + private boolean mHasSearchDivider = true; + public AlphabeticalAppsList(Context context) { mLauncher = Launcher.getLauncher(context); mIndexer = new AlphabeticIndexCompat(context); @@ -343,6 +345,10 @@ public class AlphabeticalAppsList { onAppsUpdated(); } + public void disableSearchDivider() { + mHasSearchDivider = false; + } + /** * Updates internals when the set of apps are updated. */ @@ -429,8 +435,10 @@ public class AlphabeticalAppsList { } } - // Add the search divider - mAdapterItems.add(AdapterItem.asSearchDivider(position++)); + if (mHasSearchDivider) { + // Add the search divider + mAdapterItems.add(AdapterItem.asSearchDivider(position++)); + } // Process the predicted app components mPredictedApps.clear(); diff --git a/src/com/android/launcher3/dynamicui/ExtractedColors.java b/src/com/android/launcher3/dynamicui/ExtractedColors.java index 3c4aba130d..108a21f400 100644 --- a/src/com/android/launcher3/dynamicui/ExtractedColors.java +++ b/src/com/android/launcher3/dynamicui/ExtractedColors.java @@ -26,6 +26,7 @@ import android.util.Log; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; +import java.util.ArrayList; import java.util.Arrays; /** @@ -80,6 +81,7 @@ public class ExtractedColors { private static final String COLOR_SEPARATOR = ","; + private final ArrayList mListeners = new ArrayList<>(); private final int[] mColors; public ExtractedColors() { @@ -171,4 +173,22 @@ public class ExtractedColors { setColorAtIndex(idx, wallpaperPalette == null ? DEFAULT_VALUES[idx] : wallpaperPalette.getVibrantColor(DEFAULT_VALUES[idx])); } + + public void addOnChangeListener(OnChangeListener listener) { + mListeners.add(listener); + } + + public void notifyChange() { + for (OnChangeListener listener : mListeners) { + listener.onExtractedColorsChanged(); + } + } + + /** + * Interface for listening for extracted color changes + */ + public interface OnChangeListener { + + void onExtractedColorsChanged(); + } } diff --git a/src/com/android/launcher3/testing/LauncherExtension.java b/src/com/android/launcher3/testing/LauncherExtension.java index 36df22cd58..8d4351884a 100644 --- a/src/com/android/launcher3/testing/LauncherExtension.java +++ b/src/com/android/launcher3/testing/LauncherExtension.java @@ -219,8 +219,5 @@ public class LauncherExtension extends Launcher { public boolean shouldShowDiscoveryBounce() { return false; } - - @Override - public void onExtractedColorsChanged() { } } }