Add predictions row to taskbar all apps.
- We need to listen to DeviceProfile changes in case the number of
columns changes in the grid. I made an interface/mixin separate from
ActivityContext to avoid polutting the latter with too many things. I
also applied this change to existing taskbar A-Z grid.
- Added all apps visited count to onboarding preferences for only
showing "All Apps" label in place of divider 20 times. Label is also
tracked on taskbar side and should be kept in sync.
Test: Manual
Fix: 216843395
Bug: 174174514
Change-Id: I97aa91397c334123626caf18251f19e17c7104fb
diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java
index ec96c6d..42f7053 100644
--- a/src/com/android/launcher3/BaseActivity.java
+++ b/src/com/android/launcher3/BaseActivity.java
@@ -34,6 +34,7 @@
import androidx.annotation.IntDef;
+import com.android.launcher3.DeviceProfile.DeviceProfileListenable;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.util.SystemUiController;
@@ -44,11 +45,13 @@
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.util.ArrayList;
+import java.util.List;
/**
* Launcher BaseActivity
*/
-public abstract class BaseActivity extends Activity implements ActivityContext {
+public abstract class BaseActivity extends Activity implements ActivityContext,
+ DeviceProfileListenable {
private static final String TAG = "BaseActivity";
@@ -142,6 +145,11 @@
return mDeviceProfile;
}
+ @Override
+ public List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners() {
+ return mDPChangeListeners;
+ }
+
/**
* Returns {@link StatsLogManager} for user event logging.
*/
@@ -261,20 +269,6 @@
protected void onActivityFlagsChanged(int changeBits) { }
- public void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
- mDPChangeListeners.add(listener);
- }
-
- public void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
- mDPChangeListeners.remove(listener);
- }
-
- protected void dispatchDeviceProfileChanged() {
- for (int i = mDPChangeListeners.size() - 1; i >= 0; i--) {
- mDPChangeListeners.get(i).onDeviceProfileChanged(mDeviceProfile);
- }
- }
-
public void addMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) {
mMultiWindowModeChangedListeners.add(listener);
}
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index c456a4d..62703ad 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -44,6 +44,7 @@
import com.android.launcher3.util.WindowBounds;
import java.io.PrintWriter;
+import java.util.List;
@SuppressLint("NewApi")
public class DeviceProfile {
@@ -1223,6 +1224,35 @@
void onDeviceProfileChanged(DeviceProfile dp);
}
+ /** Allows registering listeners for {@link DeviceProfile} changes. */
+ public interface DeviceProfileListenable {
+
+ /** The current device profile. */
+ DeviceProfile getDeviceProfile();
+
+ /** Registered {@link OnDeviceProfileChangeListener} instances. */
+ List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
+
+ /** Notifies listeners of a {@link DeviceProfile} change. */
+ default void dispatchDeviceProfileChanged() {
+ DeviceProfile deviceProfile = getDeviceProfile();
+ List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
+ for (int i = listeners.size() - 1; i >= 0; i--) {
+ listeners.get(i).onDeviceProfileChanged(deviceProfile);
+ }
+ }
+
+ /** Register listener for {@link DeviceProfile} changes. */
+ default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
+ getOnDeviceProfileChangeListeners().add(listener);
+ }
+
+ /** Unregister listener for {@link DeviceProfile} changes. */
+ default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
+ getOnDeviceProfileChangeListeners().remove(listener);
+ }
+ }
+
public static class Builder {
private Context mContext;
private InvariantDeviceProfile mInv;
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index ebc0c75..fcd147f 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -351,7 +351,7 @@
// We only want to get the SharedPreferences once since it does an FS stat each time we get
// it from the context.
private SharedPreferences mSharedPrefs;
- private OnboardingPrefs mOnboardingPrefs;
+ private OnboardingPrefs<? extends Launcher> mOnboardingPrefs;
// Activity result which needs to be processed after workspace has loaded.
private ActivityResultInfo mPendingActivityResult;
@@ -557,11 +557,12 @@
return new LauncherOverlayManager() { };
}
- protected OnboardingPrefs createOnboardingPrefs(SharedPreferences sharedPrefs) {
+ protected OnboardingPrefs<? extends Launcher> createOnboardingPrefs(
+ SharedPreferences sharedPrefs) {
return new OnboardingPrefs<>(this, sharedPrefs);
}
- public OnboardingPrefs getOnboardingPrefs() {
+ public OnboardingPrefs<? extends Launcher> getOnboardingPrefs() {
return mOnboardingPrefs;
}
@@ -588,7 +589,7 @@
}
@Override
- protected void dispatchDeviceProfileChanged() {
+ public void dispatchDeviceProfileChanged() {
super.dispatchDeviceProfileChanged();
mOverlayManager.onDeviceProvideChanged();
}
@@ -1782,6 +1783,11 @@
return mWorkspaceLoading;
}
+ @Override
+ public boolean isBindingItems() {
+ return mWorkspaceLoading;
+ }
+
private void setWorkspaceLoading(boolean value) {
mWorkspaceLoading = value;
}
diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
index fb87f88..114f813 100644
--- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
@@ -62,7 +62,6 @@
public ActivityAllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- mActivityContext.addOnDeviceProfileChangeListener(this);
}
public SearchUiManager getSearchUiManager() {
diff --git a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java
index a66ae78..59e21c0 100644
--- a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java
@@ -48,6 +48,7 @@
import androidx.recyclerview.widget.RecyclerView;
import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.DeviceProfile.DeviceProfileListenable;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget.DragObject;
@@ -75,9 +76,10 @@
*
* @param <T> Type of context inflating all apps.
*/
-public abstract class BaseAllAppsContainerView<T extends Context & ActivityContext> extends
- SpringRelativeLayout implements DragSource, Insettable, OnDeviceProfileChangeListener,
- OnActivePageChangedListener, ScrimView.ScrimDrawingController {
+public abstract class BaseAllAppsContainerView<T extends Context & ActivityContext
+ & DeviceProfileListenable> extends SpringRelativeLayout implements DragSource, Insettable,
+ OnDeviceProfileChangeListener, OnActivePageChangedListener,
+ ScrimView.ScrimDrawingController {
private static final String BUNDLE_KEY_CURRENT_PAGE = "launcher.allapps.current_page";
@@ -148,6 +150,7 @@
mNavBarScrimPaint.setColor(Themes.getAttrColor(context, R.attr.allAppsNavBarScrimColor));
mAllAppsStore.addUpdateListener(this::onAppsUpdated);
+ mActivityContext.addOnDeviceProfileChangeListener(this);
}
/** Creates the adapter provider for the main section. */
@@ -580,7 +583,10 @@
void setupHeader() {
mHeader.setVisibility(View.VISIBLE);
- mHeader.setup(mAH, mAH.get(AdapterHolder.WORK).mRecyclerView == null);
+ mHeader.setup(
+ mAH.get(AdapterHolder.MAIN).mRecyclerView,
+ mAH.get(AdapterHolder.WORK).mRecyclerView,
+ mAH.get(AdapterHolder.WORK).mRecyclerView == null);
int padding = mHeader.getMaxTranslation();
for (int i = 0; i < mAH.size(); i++) {
diff --git a/src/com/android/launcher3/allapps/FloatingHeaderView.java b/src/com/android/launcher3/allapps/FloatingHeaderView.java
index 059d4b8..ed8761e 100644
--- a/src/com/android/launcher3/allapps/FloatingHeaderView.java
+++ b/src/com/android/launcher3/allapps/FloatingHeaderView.java
@@ -41,7 +41,6 @@
import com.android.systemui.plugins.PluginListener;
import java.util.ArrayList;
-import java.util.List;
import java.util.Map;
public class FloatingHeaderView extends LinearLayout implements
@@ -226,8 +225,7 @@
return super.getFocusedChild();
}
- <T extends Context & ActivityContext> void setup(
- List<BaseAllAppsContainerView<T>.AdapterHolder> mAH, boolean tabsHidden) {
+ void setup(AllAppsRecyclerView mainRV, AllAppsRecyclerView workRV, boolean tabsHidden) {
for (FloatingHeaderRow row : mAllRows) {
row.setup(this, mAllRows, tabsHidden);
}
@@ -235,10 +233,8 @@
mTabsHidden = tabsHidden;
mTabLayout.setVisibility(tabsHidden ? View.GONE : View.VISIBLE);
- mMainRV = setupRV(mMainRV,
- mAH.get(BaseAllAppsContainerView.AdapterHolder.MAIN).mRecyclerView);
- mWorkRV = setupRV(mWorkRV,
- mAH.get(BaseAllAppsContainerView.AdapterHolder.WORK).mRecyclerView);
+ mMainRV = setupRV(mMainRV, mainRV);
+ mWorkRV = setupRV(mWorkRV, workRV);
mParent = (ViewGroup) mMainRV.getParent();
setMainActive(mMainRVActive || mWorkRV == null);
reset(false);
diff --git a/src/com/android/launcher3/util/OnboardingPrefs.java b/src/com/android/launcher3/util/OnboardingPrefs.java
index 5ba0d30..39d7cfe 100644
--- a/src/com/android/launcher3/util/OnboardingPrefs.java
+++ b/src/com/android/launcher3/util/OnboardingPrefs.java
@@ -20,7 +20,7 @@
import androidx.annotation.StringDef;
-import com.android.launcher3.Launcher;
+import com.android.launcher3.views.ActivityContext;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -29,8 +29,10 @@
/**
* Stores and retrieves onboarding-related data via SharedPreferences.
+ *
+ * @param <T> Context which owns these preferences.
*/
-public class OnboardingPrefs<T extends Launcher> {
+public class OnboardingPrefs<T extends ActivityContext> {
public static final String HOME_BOUNCE_SEEN = "launcher.apps_view_shown";
public static final String HOME_BOUNCE_COUNT = "launcher.home_bounce_count";
@@ -39,13 +41,15 @@
public static final String SEARCH_EDU_SEEN = "launcher.search_edu_seen";
public static final String SEARCH_SNACKBAR_COUNT = "launcher.keyboard_snackbar_count";
public static final String TASKBAR_EDU_SEEN = "launcher.taskbar_edu_seen";
+ public static final String ALL_APPS_VISITED_COUNT = "launcher.all_apps_visited_count";
// When adding a new key, add it here as well, to be able to reset it from Developer Options.
public static final Map<String, String[]> ALL_PREF_KEYS = Map.of(
"All Apps Bounce", new String[] { HOME_BOUNCE_SEEN, HOME_BOUNCE_COUNT },
"Hybrid Hotseat Education", new String[] { HOTSEAT_DISCOVERY_TIP_COUNT,
HOTSEAT_LONGPRESS_TIP_SEEN },
"Search Education", new String[] { SEARCH_EDU_SEEN, SEARCH_SNACKBAR_COUNT },
- "Taskbar Education", new String[] { TASKBAR_EDU_SEEN }
+ "Taskbar Education", new String[] { TASKBAR_EDU_SEEN },
+ "All Apps Visited Count", new String[] {ALL_APPS_VISITED_COUNT}
);
/**
@@ -67,7 +71,8 @@
@StringDef(value = {
HOME_BOUNCE_COUNT,
HOTSEAT_DISCOVERY_TIP_COUNT,
- SEARCH_SNACKBAR_COUNT
+ SEARCH_SNACKBAR_COUNT,
+ ALL_APPS_VISITED_COUNT
})
@Retention(RetentionPolicy.SOURCE)
public @interface EventCountKey {
@@ -80,6 +85,7 @@
maxCounts.put(HOME_BOUNCE_COUNT, 3);
maxCounts.put(HOTSEAT_DISCOVERY_TIP_COUNT, 5);
maxCounts.put(SEARCH_SNACKBAR_COUNT, 3);
+ maxCounts.put(ALL_APPS_VISITED_COUNT, 20);
MAX_COUNTS = Collections.unmodifiableMap(maxCounts);
}
diff --git a/src/com/android/launcher3/views/ActivityContext.java b/src/com/android/launcher3/views/ActivityContext.java
index a318363..3c90eea 100644
--- a/src/com/android/launcher3/views/ActivityContext.java
+++ b/src/com/android/launcher3/views/ActivityContext.java
@@ -34,6 +34,7 @@
import com.android.launcher3.model.StringCache;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.popup.PopupDataProvider;
+import com.android.launcher3.util.OnboardingPrefs;
import com.android.launcher3.util.ViewCache;
/**
@@ -138,6 +139,16 @@
*/
default void applyOverwritesToLogItem(LauncherAtom.ItemInfo.Builder itemInfoBuilder) { }
+ /** Onboarding preferences for any onboarding data within this context. */
+ default OnboardingPrefs<?> getOnboardingPrefs() {
+ return null;
+ }
+
+ /** Returns {@code true} if items are currently being bound within this context. */
+ default boolean isBindingItems() {
+ return false;
+ }
+
/**
* Returns the ActivityContext associated with the given Context, or throws an exception if
* the Context is not associated with any ActivityContext.