Loading res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,9 @@ <!-- Accessibility label for the icon button shown in the widget picker that opens a overflow menu with widgets viewing options. [CHAR_LIMIT=25] --> <string name="widget_picker_widget_options_button_description">More options</string> <!-- Label for the checkbox shown in the widget picker toggles whether to show all widgets or the default set. [CHAR_LIMIT=25] --> <string name="widget_picker_show_all_widgets_menu_item_title">Show all widgets</string> <!-- The format string for the dimensions of a widget in the drawer --> <!-- There is a special version of this format string for Farsi --> <string name="widget_dims_format">%1$d \u00d7 %2$d</string> Loading src/com/android/launcher3/popup/PopupDataProvider.java +4 −2 Original line number Diff line number Diff line Loading @@ -284,8 +284,10 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } /** Gets the WidgetsListContentEntry for the currently selected header. */ public WidgetsListContentEntry getSelectedAppWidgets(PackageUserKey packageUserKey) { return (WidgetsListContentEntry) mAllWidgets.stream() public WidgetsListContentEntry getSelectedAppWidgets(PackageUserKey packageUserKey, boolean useDefault) { List<WidgetsListBaseEntry> widgets = useDefault ? mDefaultWidgets : mAllWidgets; return (WidgetsListContentEntry) widgets.stream() .filter(row -> row instanceof WidgetsListContentEntry && PackageUserKey.fromPackageItemInfo(row.mPkgItem).equals(packageUserKey)) .findAny() Loading src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +11 −5 Original line number Diff line number Diff line Loading @@ -135,7 +135,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet private WidgetsRecyclerView mCurrentTouchEventRecyclerView; @Nullable PersonalWorkPagedView mViewPager; private boolean mIsInSearchMode; protected boolean mIsInSearchMode; private boolean mIsNoWidgetsViewNeeded; @Px protected int mMaxSpanPerRow; Loading Loading @@ -462,22 +462,28 @@ public class WidgetsFullSheet extends BaseWidgetSheet setTranslationShift(mTranslationShift); } /** * Returns all displayable widgets. */ protected List<WidgetsListBaseEntry> getWidgetsToDisplay() { return mActivityContext.getPopupDataProvider().getAllWidgets(); } @Override public void onWidgetsBound() { if (mIsInSearchMode) { return; } List<WidgetsListBaseEntry> allWidgets = mActivityContext.getPopupDataProvider().getAllWidgets(); List<WidgetsListBaseEntry> widgets = getWidgetsToDisplay(); AdapterHolder primaryUserAdapterHolder = mAdapters.get(AdapterHolder.PRIMARY); primaryUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets); primaryUserAdapterHolder.mWidgetsListAdapter.setWidgets(widgets); if (mHasWorkProfile) { mViewPager.setVisibility(VISIBLE); mTabBar.setVisibility(VISIBLE); AdapterHolder workUserAdapterHolder = mAdapters.get(AdapterHolder.WORK); workUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets); workUserAdapterHolder.mWidgetsListAdapter.setWidgets(widgets); onActivePageChanged(mViewPager.getCurrentPage()); } else { onActivePageChanged(0); Loading src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java +90 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,9 @@ import android.content.Context; import android.graphics.Rect; import android.os.Process; import android.util.AttributeSet; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; Loading @@ -35,6 +37,7 @@ import android.view.ViewParent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.PopupMenu; import android.widget.ScrollView; import android.widget.TextView; Loading Loading @@ -83,6 +86,17 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { private PackageUserKey mSelectedHeader; private TextView mHeaderDescription; /** * A menu displayed for options (e.g. "show all widgets" filter) around widget lists in the * picker. */ protected View mWidgetOptionsMenu; /** * State of the options in the menu (if displayed to the user). */ @Nullable protected WidgetOptionsMenuState mWidgetOptionsMenuState = null; public WidgetsTwoPaneSheet(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } Loading Loading @@ -130,6 +144,9 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { mHeaderTitle = mContent.findViewById(R.id.title); mHeaderDescription = mContent.findViewById(R.id.widget_picker_description); mWidgetOptionsMenu = mContent.findViewById(R.id.widget_picker_widget_options_menu); setupWidgetOptionsMenu(); mRightPane = mContent.findViewById(R.id.right_pane); mRightPaneScrollView = mContent.findViewById(R.id.right_pane_scroll_view); mRightPaneScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER); Loading @@ -155,6 +172,40 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { } } protected void setupWidgetOptionsMenu() { mWidgetOptionsMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mWidgetOptionsMenuState != null) { PopupMenu popupMenu = new PopupMenu(mActivityContext, /*anchor=*/ v, Gravity.END); MenuItem menuItem = popupMenu.getMenu().add( R.string.widget_picker_show_all_widgets_menu_item_title); menuItem.setCheckable(true); menuItem.setChecked(mWidgetOptionsMenuState.showAllWidgets); menuItem.setOnMenuItemClickListener( item -> onShowAllWidgetsMenuItemClick(item)); popupMenu.show(); } } }); } private boolean onShowAllWidgetsMenuItemClick(MenuItem menuItem) { mWidgetOptionsMenuState.showAllWidgets = !mWidgetOptionsMenuState.showAllWidgets; menuItem.setChecked(mWidgetOptionsMenuState.showAllWidgets); // Refresh widgets onWidgetsBound(); if (mIsInSearchMode) { mSearchBar.reset(); } else if (!mSuggestedWidgetsPackageUserKey.equals(mSelectedHeader)) { mAdapters.get(mActivePage).mWidgetsListAdapter.selectFirstHeaderEntry(); mAdapters.get(mActivePage).mWidgetsRecyclerView.scrollToTop(); } return true; } @Override protected int getTabletHorizontalMargin(DeviceProfile deviceProfile) { if (enableCategorizedWidgetSuggestions()) { Loading Loading @@ -233,6 +284,29 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { } } @Override protected List<WidgetsListBaseEntry> getWidgetsToDisplay() { List<WidgetsListBaseEntry> allWidgets = mActivityContext.getPopupDataProvider().getAllWidgets(); List<WidgetsListBaseEntry> defaultWidgets = mActivityContext.getPopupDataProvider().getDefaultWidgets(); if (allWidgets.isEmpty() || defaultWidgets.isEmpty()) { // no menu if there are no default widgets to show mWidgetOptionsMenuState = null; mWidgetOptionsMenu.setVisibility(GONE); } else { if (mWidgetOptionsMenuState == null) { mWidgetOptionsMenuState = new WidgetOptionsMenuState(); } mWidgetOptionsMenu.setVisibility(VISIBLE); return mWidgetOptionsMenuState.showAllWidgets ? allWidgets : defaultWidgets; } return allWidgets; } @Override public void onWidgetsBound() { super.onWidgetsBound(); Loading Loading @@ -435,8 +509,11 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { final boolean isUserClick = mSelectedHeader != null && !getAccessibilityInitialFocusView().isAccessibilityFocused(); mSelectedHeader = selectedHeader; WidgetsListContentEntry contentEntry = mActivityContext.getPopupDataProvider() .getSelectedAppWidgets(selectedHeader); WidgetsListContentEntry contentEntry = mActivityContext.getPopupDataProvider().getSelectedAppWidgets( selectedHeader, /*useDefault=*/ (mWidgetOptionsMenuState != null && !mWidgetOptionsMenuState.showAllWidgets)); if (contentEntry == null || mRightPane == null) { return; Loading Loading @@ -570,4 +647,15 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { */ void onHeaderChanged(@NonNull PackageUserKey selectedHeader); } /** * Holds the selection state of the options menu (if presented to the user). */ protected static class WidgetOptionsMenuState { /** * UI state indicating whether to show default or all widgets. * <p>If true, shows all widgets; else shows the default widgets.</p> */ public boolean showAllWidgets = false; } } Loading
res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,9 @@ <!-- Accessibility label for the icon button shown in the widget picker that opens a overflow menu with widgets viewing options. [CHAR_LIMIT=25] --> <string name="widget_picker_widget_options_button_description">More options</string> <!-- Label for the checkbox shown in the widget picker toggles whether to show all widgets or the default set. [CHAR_LIMIT=25] --> <string name="widget_picker_show_all_widgets_menu_item_title">Show all widgets</string> <!-- The format string for the dimensions of a widget in the drawer --> <!-- There is a special version of this format string for Farsi --> <string name="widget_dims_format">%1$d \u00d7 %2$d</string> Loading
src/com/android/launcher3/popup/PopupDataProvider.java +4 −2 Original line number Diff line number Diff line Loading @@ -284,8 +284,10 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } /** Gets the WidgetsListContentEntry for the currently selected header. */ public WidgetsListContentEntry getSelectedAppWidgets(PackageUserKey packageUserKey) { return (WidgetsListContentEntry) mAllWidgets.stream() public WidgetsListContentEntry getSelectedAppWidgets(PackageUserKey packageUserKey, boolean useDefault) { List<WidgetsListBaseEntry> widgets = useDefault ? mDefaultWidgets : mAllWidgets; return (WidgetsListContentEntry) widgets.stream() .filter(row -> row instanceof WidgetsListContentEntry && PackageUserKey.fromPackageItemInfo(row.mPkgItem).equals(packageUserKey)) .findAny() Loading
src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +11 −5 Original line number Diff line number Diff line Loading @@ -135,7 +135,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet private WidgetsRecyclerView mCurrentTouchEventRecyclerView; @Nullable PersonalWorkPagedView mViewPager; private boolean mIsInSearchMode; protected boolean mIsInSearchMode; private boolean mIsNoWidgetsViewNeeded; @Px protected int mMaxSpanPerRow; Loading Loading @@ -462,22 +462,28 @@ public class WidgetsFullSheet extends BaseWidgetSheet setTranslationShift(mTranslationShift); } /** * Returns all displayable widgets. */ protected List<WidgetsListBaseEntry> getWidgetsToDisplay() { return mActivityContext.getPopupDataProvider().getAllWidgets(); } @Override public void onWidgetsBound() { if (mIsInSearchMode) { return; } List<WidgetsListBaseEntry> allWidgets = mActivityContext.getPopupDataProvider().getAllWidgets(); List<WidgetsListBaseEntry> widgets = getWidgetsToDisplay(); AdapterHolder primaryUserAdapterHolder = mAdapters.get(AdapterHolder.PRIMARY); primaryUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets); primaryUserAdapterHolder.mWidgetsListAdapter.setWidgets(widgets); if (mHasWorkProfile) { mViewPager.setVisibility(VISIBLE); mTabBar.setVisibility(VISIBLE); AdapterHolder workUserAdapterHolder = mAdapters.get(AdapterHolder.WORK); workUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets); workUserAdapterHolder.mWidgetsListAdapter.setWidgets(widgets); onActivePageChanged(mViewPager.getCurrentPage()); } else { onActivePageChanged(0); Loading
src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java +90 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,9 @@ import android.content.Context; import android.graphics.Rect; import android.os.Process; import android.util.AttributeSet; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; Loading @@ -35,6 +37,7 @@ import android.view.ViewParent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.PopupMenu; import android.widget.ScrollView; import android.widget.TextView; Loading Loading @@ -83,6 +86,17 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { private PackageUserKey mSelectedHeader; private TextView mHeaderDescription; /** * A menu displayed for options (e.g. "show all widgets" filter) around widget lists in the * picker. */ protected View mWidgetOptionsMenu; /** * State of the options in the menu (if displayed to the user). */ @Nullable protected WidgetOptionsMenuState mWidgetOptionsMenuState = null; public WidgetsTwoPaneSheet(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } Loading Loading @@ -130,6 +144,9 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { mHeaderTitle = mContent.findViewById(R.id.title); mHeaderDescription = mContent.findViewById(R.id.widget_picker_description); mWidgetOptionsMenu = mContent.findViewById(R.id.widget_picker_widget_options_menu); setupWidgetOptionsMenu(); mRightPane = mContent.findViewById(R.id.right_pane); mRightPaneScrollView = mContent.findViewById(R.id.right_pane_scroll_view); mRightPaneScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER); Loading @@ -155,6 +172,40 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { } } protected void setupWidgetOptionsMenu() { mWidgetOptionsMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mWidgetOptionsMenuState != null) { PopupMenu popupMenu = new PopupMenu(mActivityContext, /*anchor=*/ v, Gravity.END); MenuItem menuItem = popupMenu.getMenu().add( R.string.widget_picker_show_all_widgets_menu_item_title); menuItem.setCheckable(true); menuItem.setChecked(mWidgetOptionsMenuState.showAllWidgets); menuItem.setOnMenuItemClickListener( item -> onShowAllWidgetsMenuItemClick(item)); popupMenu.show(); } } }); } private boolean onShowAllWidgetsMenuItemClick(MenuItem menuItem) { mWidgetOptionsMenuState.showAllWidgets = !mWidgetOptionsMenuState.showAllWidgets; menuItem.setChecked(mWidgetOptionsMenuState.showAllWidgets); // Refresh widgets onWidgetsBound(); if (mIsInSearchMode) { mSearchBar.reset(); } else if (!mSuggestedWidgetsPackageUserKey.equals(mSelectedHeader)) { mAdapters.get(mActivePage).mWidgetsListAdapter.selectFirstHeaderEntry(); mAdapters.get(mActivePage).mWidgetsRecyclerView.scrollToTop(); } return true; } @Override protected int getTabletHorizontalMargin(DeviceProfile deviceProfile) { if (enableCategorizedWidgetSuggestions()) { Loading Loading @@ -233,6 +284,29 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { } } @Override protected List<WidgetsListBaseEntry> getWidgetsToDisplay() { List<WidgetsListBaseEntry> allWidgets = mActivityContext.getPopupDataProvider().getAllWidgets(); List<WidgetsListBaseEntry> defaultWidgets = mActivityContext.getPopupDataProvider().getDefaultWidgets(); if (allWidgets.isEmpty() || defaultWidgets.isEmpty()) { // no menu if there are no default widgets to show mWidgetOptionsMenuState = null; mWidgetOptionsMenu.setVisibility(GONE); } else { if (mWidgetOptionsMenuState == null) { mWidgetOptionsMenuState = new WidgetOptionsMenuState(); } mWidgetOptionsMenu.setVisibility(VISIBLE); return mWidgetOptionsMenuState.showAllWidgets ? allWidgets : defaultWidgets; } return allWidgets; } @Override public void onWidgetsBound() { super.onWidgetsBound(); Loading Loading @@ -435,8 +509,11 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { final boolean isUserClick = mSelectedHeader != null && !getAccessibilityInitialFocusView().isAccessibilityFocused(); mSelectedHeader = selectedHeader; WidgetsListContentEntry contentEntry = mActivityContext.getPopupDataProvider() .getSelectedAppWidgets(selectedHeader); WidgetsListContentEntry contentEntry = mActivityContext.getPopupDataProvider().getSelectedAppWidgets( selectedHeader, /*useDefault=*/ (mWidgetOptionsMenuState != null && !mWidgetOptionsMenuState.showAllWidgets)); if (contentEntry == null || mRightPane == null) { return; Loading Loading @@ -570,4 +647,15 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { */ void onHeaderChanged(@NonNull PackageUserKey selectedHeader); } /** * Holds the selection state of the options menu (if presented to the user). */ protected static class WidgetOptionsMenuState { /** * UI state indicating whether to show default or all widgets. * <p>If true, shows all widgets; else shows the default widgets.</p> */ public boolean showAllWidgets = false; } }