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
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.android.launcher3.appprediction;
|
||||
|
||||
import static com.android.launcher3.LauncherState.ALL_APPS;
|
||||
import static com.android.launcher3.util.OnboardingPrefs.ALL_APPS_VISITED_COUNT;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
@@ -34,23 +34,17 @@ import androidx.annotation.ColorInt;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherState;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.allapps.FloatingHeaderRow;
|
||||
import com.android.launcher3.allapps.FloatingHeaderView;
|
||||
import com.android.launcher3.statemanager.StateManager.StateListener;
|
||||
import com.android.launcher3.util.Themes;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
|
||||
/**
|
||||
* A view which shows a horizontal divider
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
public class AppsDividerView extends View implements StateListener<LauncherState>,
|
||||
FloatingHeaderRow {
|
||||
|
||||
private static final String ALL_APPS_VISITED_COUNT = "launcher.all_apps_visited_count";
|
||||
private static final int SHOW_ALL_APPS_LABEL_ON_ALL_APPS_VISITED_COUNT = 20;
|
||||
public class AppsDividerView extends View implements FloatingHeaderRow {
|
||||
|
||||
public enum DividerType {
|
||||
NONE,
|
||||
@@ -58,7 +52,6 @@ public class AppsDividerView extends View implements StateListener<LauncherState
|
||||
ALL_APPS_LABEL
|
||||
}
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final TextPaint mPaint = new TextPaint();
|
||||
private DividerType mDividerType = DividerType.NONE;
|
||||
|
||||
@@ -86,7 +79,6 @@ public class AppsDividerView extends View implements StateListener<LauncherState
|
||||
|
||||
public AppsDividerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mLauncher = Launcher.getLauncher(context);
|
||||
|
||||
boolean isMainColorDark = Themes.getAttrBoolean(context, R.attr.isMainColorDark);
|
||||
mDividerSize = new int[]{
|
||||
@@ -101,6 +93,9 @@ public class AppsDividerView extends View implements StateListener<LauncherState
|
||||
mAllAppsLabelTextColor = ContextCompat.getColor(context, isMainColorDark
|
||||
? R.color.all_apps_label_text_dark
|
||||
: R.color.all_apps_label_text);
|
||||
|
||||
mShowAllAppsLabel = !ActivityContext.lookupContext(
|
||||
getContext()).getOnboardingPrefs().hasReachedMaxCount(ALL_APPS_VISITED_COUNT);
|
||||
}
|
||||
|
||||
public void setup(FloatingHeaderView parent, FloatingHeaderRow[] rows, boolean tabsHidden) {
|
||||
@@ -110,6 +105,14 @@ public class AppsDividerView extends View implements StateListener<LauncherState
|
||||
updateDividerType();
|
||||
}
|
||||
|
||||
/** {@code true} if all apps label should be shown in place of divider. */
|
||||
public void setShowAllAppsLabel(boolean showAllAppsLabel) {
|
||||
if (showAllAppsLabel != mShowAllAppsLabel) {
|
||||
mShowAllAppsLabel = showAllAppsLabel;
|
||||
updateDividerType();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExpectedHeight() {
|
||||
return getPaddingTop() + getPaddingBottom();
|
||||
@@ -235,51 +238,6 @@ public class AppsDividerView extends View implements StateListener<LauncherState
|
||||
getPaddingBottom() + getPaddingTop());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
if (shouldShowAllAppsLabel()) {
|
||||
mShowAllAppsLabel = true;
|
||||
mLauncher.getStateManager().addStateListener(this);
|
||||
updateDividerType();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mLauncher.getStateManager().removeStateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateTransitionComplete(LauncherState finalState) {
|
||||
if (finalState == ALL_APPS) {
|
||||
setAllAppsVisitedCount(getAllAppsVisitedCount() + 1);
|
||||
} else {
|
||||
if (mShowAllAppsLabel != shouldShowAllAppsLabel()) {
|
||||
mShowAllAppsLabel = !mShowAllAppsLabel;
|
||||
updateDividerType();
|
||||
}
|
||||
|
||||
if (!mShowAllAppsLabel) {
|
||||
mLauncher.getStateManager().removeStateListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setAllAppsVisitedCount(int count) {
|
||||
mLauncher.getSharedPrefs().edit().putInt(ALL_APPS_VISITED_COUNT, count).apply();
|
||||
}
|
||||
|
||||
private int getAllAppsVisitedCount() {
|
||||
return mLauncher.getSharedPrefs().getInt(ALL_APPS_VISITED_COUNT, 0);
|
||||
}
|
||||
|
||||
private boolean shouldShowAllAppsLabel() {
|
||||
return getAllAppsVisitedCount() < SHOW_ALL_APPS_LABEL_ON_ALL_APPS_VISITED_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInsets(Rect insets, DeviceProfile grid) {
|
||||
int leftRightPadding = grid.allAppsLeftRightPadding;
|
||||
|
||||
Reference in New Issue
Block a user