summaryrefslogtreecommitdiff
path: root/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/widget/picker/WidgetsFullSheet.java')
-rw-r--r--src/com/android/launcher3/widget/picker/WidgetsFullSheet.java129
1 files changed, 64 insertions, 65 deletions
diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
index a4b605cccd..e9a590b814 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java
@@ -17,14 +17,14 @@ package com.android.launcher3.widget.picker;
import static android.view.View.MeasureSpec.makeMeasureSpec;
+import static com.android.launcher3.Flags.enableUnfoldedTwoPanePicker;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
-import static com.android.launcher3.config.FeatureFlags.LARGE_SCREEN_WIDGET_PICKER;
+import static com.android.launcher3.LauncherPrefs.WIDGETS_EDUCATION_DIALOG_SEEN;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGETSTRAY_SEARCHED;
import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL;
import android.animation.Animator;
import android.content.Context;
-import android.content.pm.LauncherApps;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
@@ -40,6 +40,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
+import android.view.WindowInsetsController;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.Button;
@@ -54,8 +55,10 @@ import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;
+import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
-import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.PendingAnimation;
@@ -69,7 +72,6 @@ import com.android.launcher3.views.SpringRelativeLayout;
import com.android.launcher3.views.StickyHeaderLayout;
import com.android.launcher3.views.WidgetsEduView;
import com.android.launcher3.widget.BaseWidgetSheet;
-import com.android.launcher3.widget.LauncherWidgetHolder.ProviderChangedListener;
import com.android.launcher3.widget.model.WidgetsListBaseEntry;
import com.android.launcher3.widget.picker.search.SearchModeListener;
import com.android.launcher3.widget.picker.search.WidgetsSearchBar;
@@ -86,27 +88,24 @@ import java.util.stream.IntStream;
* Popup for showing the full list of available widgets
*/
public class WidgetsFullSheet extends BaseWidgetSheet
- implements ProviderChangedListener, OnActivePageChangedListener,
+ implements OnActivePageChangedListener,
WidgetsRecyclerView.HeaderViewDimensionsProvider, SearchModeListener {
private static final long FADE_IN_DURATION = 150;
private static final long EDUCATION_TIP_DELAY_MS = 200;
private static final long EDUCATION_DIALOG_DELAY_MS = 500;
- private static final float VERTICAL_START_POSITION = 0.3f;
+
// The widget recommendation table can easily take over the entire screen on devices with small
// resolution or landscape on phone. This ratio defines the max percentage of content area that
// the table can display.
private static final float RECOMMENDATION_TABLE_HEIGHT_RATIO = 0.75f;
- private static final String KEY_WIDGETS_EDUCATION_DIALOG_SEEN =
- "launcher.widgets_education_dialog_seen";
+ private final UserCache mUserCache;
private final UserManagerState mUserManagerState = new UserManagerState();
private final UserHandle mCurrentUser = Process.myUserHandle();
private final Predicate<WidgetsListBaseEntry> mPrimaryWidgetsFilter =
entry -> mCurrentUser.equals(entry.mPkgItem.user);
- private final Predicate<WidgetsListBaseEntry> mWorkWidgetsFilter =
- entry -> !mCurrentUser.equals(entry.mPkgItem.user)
- && !mUserManagerState.isUserQuiet(entry.mPkgItem.user);
+ private final Predicate<WidgetsListBaseEntry> mWorkWidgetsFilter;
protected final boolean mHasWorkProfile;
protected boolean mHasRecommendedWidgets;
protected final SparseArray<AdapterHolder> mAdapters = new SparseArray();
@@ -164,9 +163,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
private boolean mIsInSearchMode;
private boolean mIsNoWidgetsViewNeeded;
@Px private int mMaxSpanPerRow;
- private DeviceProfile mDeviceProfile;
-
- private int mOrientation;
+ protected DeviceProfile mDeviceProfile;
protected TextView mNoWidgetsView;
protected StickyHeaderLayout mSearchScrollView;
@@ -179,20 +176,23 @@ public class WidgetsFullSheet extends BaseWidgetSheet
public WidgetsFullSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- mDeviceProfile = Launcher.getLauncher(context).getDeviceProfile();
- mHasWorkProfile = context.getSystemService(LauncherApps.class).getProfiles().size() > 1;
- mOrientation = context.getResources().getConfiguration().orientation;
+ mDeviceProfile = mActivityContext.getDeviceProfile();
+ mUserCache = UserCache.INSTANCE.get(context);
+ mHasWorkProfile = mUserCache.getUserProfiles()
+ .stream()
+ .anyMatch(user -> mUserCache.getUserInfo(user).isWork());
+ mWorkWidgetsFilter = entry -> mHasWorkProfile
+ && mUserCache.getUserInfo(entry.mPkgItem.user).isWork();
mAdapters.put(AdapterHolder.PRIMARY, new AdapterHolder(AdapterHolder.PRIMARY));
mAdapters.put(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK));
mAdapters.put(AdapterHolder.SEARCH, new AdapterHolder(AdapterHolder.SEARCH));
Resources resources = getResources();
+ mUserManagerState.init(UserCache.INSTANCE.get(context),
+ context.getSystemService(UserManager.class));
mTabsHeight = mHasWorkProfile
? resources.getDimensionPixelSize(R.dimen.all_apps_header_pill_height)
: 0;
-
- mUserManagerState.init(UserCache.INSTANCE.get(context),
- context.getSystemService(UserManager.class));
}
public WidgetsFullSheet(Context context, AttributeSet attrs) {
@@ -310,7 +310,9 @@ public class WidgetsFullSheet extends BaseWidgetSheet
if (adapterHolder.mAdapterType == AdapterHolder.SEARCH) {
mNoWidgetsView.setText(R.string.no_search_results);
} else if (adapterHolder.mAdapterType == AdapterHolder.WORK
- && mUserManagerState.isAnyProfileQuietModeEnabled()
+ && mUserCache.getUserProfiles().stream()
+ .filter(userHandle -> mUserCache.getUserInfo(userHandle).isWork())
+ .anyMatch(mUserManagerState::isUserQuiet)
&& mActivityContext.getStringCache() != null) {
mNoWidgetsView.setText(mActivityContext.getStringCache().workProfilePausedTitle);
} else {
@@ -348,15 +350,14 @@ public class WidgetsFullSheet extends BaseWidgetSheet
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- mActivityContext.getAppWidgetHolder().addProviderChangeListener(this);
- notifyWidgetProvidersChanged();
+ LauncherAppState.getInstance(mActivityContext).getModel()
+ .refreshAndBindWidgetsAndShortcuts(null);
onRecommendedWidgetsBound();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- mActivityContext.getAppWidgetHolder().removeProviderChangeListener(this);
mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView
.removeOnAttachStateChangeListener(mBindScrollbarInSearchMode);
if (mHasWorkProfile) {
@@ -477,11 +478,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
}
@Override
- public void notifyWidgetProvidersChanged() {
- mActivityContext.refreshAndBindWidgetsForPackageUser(null);
- }
-
- @Override
public void onWidgetsBound() {
if (mIsInSearchMode) {
return;
@@ -623,7 +619,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet
if (animate) {
if (getPopupContainer().getInsets().bottom > 0) {
mContent.setAlpha(0);
- setTranslationShift(VERTICAL_START_POSITION);
}
setUpOpenAnimation(mActivityContext.getDeviceProfile().bottomSheetOpenDuration);
Animator animator = mOpenCloseAnimation.getAnimationPlayer();
@@ -677,31 +672,27 @@ public class WidgetsFullSheet extends BaseWidgetSheet
}
/** Shows the {@link WidgetsFullSheet} on the launcher. */
- public static WidgetsFullSheet show(Launcher launcher, boolean animate) {
- boolean isTwoPane = LARGE_SCREEN_WIDGET_PICKER.get()
- && launcher.getDeviceProfile().isTablet
- && launcher.getDeviceProfile().isLandscape
- && !launcher.getDeviceProfile().isTwoPanels;
-
- WidgetsFullSheet sheet;
- if (isTwoPane) {
- sheet = (WidgetsTwoPaneSheet) launcher.getLayoutInflater().inflate(
- R.layout.widgets_two_pane_sheet,
- launcher.getDragLayer(),
- false);
- } else {
- sheet = (WidgetsFullSheet) launcher.getLayoutInflater().inflate(
- R.layout.widgets_full_sheet,
- launcher.getDragLayer(),
- false);
- }
-
+ public static WidgetsFullSheet show(BaseActivity activity, boolean animate) {
+ WidgetsFullSheet sheet = (WidgetsFullSheet) activity.getLayoutInflater().inflate(
+ getWidgetSheetId(activity),
+ activity.getDragLayer(),
+ false);
sheet.attachToContainer();
sheet.mIsOpen = true;
sheet.open(animate);
return sheet;
}
+ private static int getWidgetSheetId(BaseActivity activity) {
+ boolean isTwoPane = (activity.getDeviceProfile().isTablet
+ && activity.getDeviceProfile().isLandscape
+ && !activity.getDeviceProfile().isTwoPanels)
+ // Enables two pane picker for unfolded foldables if the flag is on.
+ || (activity.getDeviceProfile().isTwoPanels && enableUnfoldedTwoPanePicker());
+
+ return isTwoPane ? R.layout.widgets_two_pane_sheet : R.layout.widgets_full_sheet;
+ }
+
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return isTouchOnScrollbar(ev) || super.onInterceptTouchEvent(ev);
@@ -749,7 +740,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
/** Gets the {@link WidgetsRecyclerView} which shows all widgets in {@link WidgetsFullSheet}. */
@VisibleForTesting
- public static WidgetsRecyclerView getWidgetsView(Launcher launcher) {
+ public static WidgetsRecyclerView getWidgetsView(BaseActivity launcher) {
return launcher.findViewById(R.id.primary_widgets_list_view);
}
@@ -792,18 +783,25 @@ public class WidgetsFullSheet extends BaseWidgetSheet
if (mIsInSearchMode) {
mSearchBar.reset();
}
+ }
- // Checks the orientation of the screen
- if (mOrientation != newConfig.orientation) {
- mOrientation = newConfig.orientation;
- if (LARGE_SCREEN_WIDGET_PICKER.get()
- && mDeviceProfile.isTablet && !mDeviceProfile.isTwoPanels) {
- handleClose(false);
- show(Launcher.getLauncher(getContext()), false);
- } else {
- reset();
- }
+ @Override
+ public void onDeviceProfileChanged(DeviceProfile dp) {
+ if (mDeviceProfile.isLandscape != dp.isLandscape && dp.isTablet && !dp.isTwoPanels) {
+ handleClose(false);
+ show(BaseActivity.fromContext(getContext()), false);
+ } else {
+ reset();
+ }
+
+ // When folding/unfolding the foldables, we need to switch between the regular widget picker
+ // and the two pane picker, so we rebuild the picker with the correct layout.
+ if (mDeviceProfile.isTwoPanels != dp.isTwoPanels && enableUnfoldedTwoPanePicker()) {
+ handleClose(false);
+ show(BaseActivity.fromContext(getContext()), false);
}
+
+ mDeviceProfile = dp;
}
@Override
@@ -819,7 +817,10 @@ public class WidgetsFullSheet extends BaseWidgetSheet
@Override
public void onDragStart(boolean start, float startDisplacement) {
super.onDragStart(start, startDisplacement);
- getWindowInsetsController().hide(WindowInsets.Type.ime());
+ WindowInsetsController insetsController = getWindowInsetsController();
+ if (insetsController != null) {
+ insetsController.hide(WindowInsets.Type.ime());
+ }
}
@Nullable private View getViewToShowEducationTip() {
@@ -850,15 +851,13 @@ public class WidgetsFullSheet extends BaseWidgetSheet
/** Shows education dialog for widgets. */
private WidgetsEduView showEducationDialog() {
- mActivityContext.getSharedPrefs().edit()
- .putBoolean(KEY_WIDGETS_EDUCATION_DIALOG_SEEN, true).apply();
+ LauncherPrefs.get(getContext()).put(WIDGETS_EDUCATION_DIALOG_SEEN, true);
return WidgetsEduView.showEducationDialog(mActivityContext);
}
/** Returns {@code true} if education dialog has previously been shown. */
protected boolean hasSeenEducationDialog() {
- return mActivityContext.getSharedPrefs()
- .getBoolean(KEY_WIDGETS_EDUCATION_DIALOG_SEEN, false)
+ return LauncherPrefs.get(getContext()).get(WIDGETS_EDUCATION_DIALOG_SEEN)
|| Utilities.isRunningInTestHarness();
}