Update the title and description provided by intent params.

Bug: 347288851
Flag: EXEMPT flagged in sys ui
Test: Manual (automated covered in b/339716822)
Change-Id: I71f21bc48fd03dbbe2b3804b7fcade5940606917
This commit is contained in:
Shamali P
2024-07-02 22:22:48 +00:00
parent 10923a2985
commit 96ebf67b9f
9 changed files with 80 additions and 17 deletions
@@ -44,7 +44,6 @@ import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.widget.BaseWidgetSheet;
import com.android.launcher3.widget.WidgetCell;
import com.android.launcher3.widget.model.WidgetsListBaseEntry;
import com.android.launcher3.widget.model.WidgetsListContentEntry;
@@ -80,6 +79,15 @@ public class WidgetPickerActivity extends BaseActivity {
* <p>This allows widget picker to exclude existing widgets from suggestions.</p>
*/
private static final String EXTRA_ADDED_APP_WIDGETS = "added_app_widgets";
/**
* Intent extra for the string representing the title displayed within the picker header.
*/
private static final String EXTRA_PICKER_TITLE = "picker_title";
/**
* Intent extra for the string representing the description displayed within the picker header.
*/
private static final String EXTRA_PICKER_DESCRIPTION = "picker_description";
/**
* A unique identifier of the surface hosting the widgets;
* <p>"widgets" is reserved for home screen surface.</p>
@@ -108,6 +116,10 @@ public class WidgetPickerActivity extends BaseActivity {
// Widgets existing on the host surface.
@NonNull
private List<AppWidgetProviderInfo> mAddedWidgets = new ArrayList<>();
@Nullable
private String mTitle;
@Nullable
private String mDescription;
/** A set of user ids that should be filtered out from the selected widgets. */
@NonNull
@@ -137,6 +149,9 @@ public class WidgetPickerActivity extends BaseActivity {
}
private void parseIntentExtras() {
mTitle = getIntent().getStringExtra(EXTRA_PICKER_TITLE);
mDescription = getIntent().getStringExtra(EXTRA_PICKER_DESCRIPTION);
// A value of 0 for either size means that no filtering will occur in that dimension. If
// both values are 0, then no size filtering will occur.
mDesiredWidgetWidth =
@@ -241,7 +256,7 @@ public class WidgetPickerActivity extends BaseActivity {
/** Updates the model with widgets, applies filters and launches the widgets sheet once
* widgets are available */
private void refreshAndBindWidgets() {
MODEL_EXECUTOR.getHandler().postDelayed(() -> {
MODEL_EXECUTOR.execute(() -> {
LauncherAppState app = LauncherAppState.getInstance(this);
mModel.update(app, null);
final List<WidgetsListBaseEntry> allWidgets =
@@ -271,7 +286,7 @@ public class WidgetPickerActivity extends BaseActivity {
mUiSurface, allWidgetItems);
mWidgetPredictionsRequester.request(mAddedWidgets, this::bindRecommendedWidgets);
}
}, mDeviceProfile.bottomSheetOpenDuration);
});
}
private void bindWidgets(List<WidgetsListBaseEntry> widgets) {
@@ -280,7 +295,8 @@ public class WidgetPickerActivity extends BaseActivity {
private void openWidgetsSheet() {
MAIN_EXECUTOR.execute(() -> {
BaseWidgetSheet widgetSheet = WidgetsFullSheet.show(this, true);
WidgetsFullSheet widgetSheet = WidgetsFullSheet.show(this, true);
widgetSheet.mayUpdateTitleAndDescription(mTitle, mDescription);
widgetSheet.disableNavBarScrim(true);
widgetSheet.addOnCloseListener(this::finish);
});
+20 -7
View File
@@ -48,20 +48,23 @@
android:textSize="24sp" />
<TextView
android:id="@+id/no_widgets_text"
style="@style/PrimaryHeadline"
android:id="@+id/widget_picker_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="18sp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="@id/title"
android:maxLines="1"
android:paddingHorizontal="@dimen/widget_list_horizontal_margin_two_pane"
android:textColor="?attr/widgetPickerDescriptionColor"
android:visibility="gone"
tools:text="@string/no_widgets_available" />
android:lineHeight="20sp"
android:textSize="14sp" />
<LinearLayout
android:id="@+id/linear_layout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/title">
android:layout_below="@id/widget_picker_description">
<FrameLayout
android:id="@+id/recycler_view_container"
@@ -124,6 +127,16 @@
android:background="@drawable/widgets_surface_background"
android:importantForAccessibility="yes"
android:id="@+id/right_pane">
<TextView
android:id="@+id/no_widgets_text"
style="@style/PrimaryHeadline"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="18sp"
android:visibility="gone"
tools:text="@string/no_widgets_available" />
<!-- Shown when there are recommendations to display -->
<LinearLayout
android:id="@+id/widget_recommendations_container"
+2
View File
@@ -26,6 +26,8 @@
<color name="home_settings_track_off_color">@android:color/system_neutral1_700</color>
<color name="widget_picker_title_color_dark">@android:color/system_neutral1_100</color>
<color name="widget_picker_description_color_dark">
@android:color/system_neutral2_200</color>
<color name="widget_picker_header_app_title_color_dark">
@android:color/system_neutral1_100</color>
<color name="widget_picker_header_app_subtitle_color_dark">
+2
View File
@@ -75,6 +75,8 @@
<color name="widget_picker_title_color_light">
@android:color/system_neutral1_900</color>
<color name="widget_picker_description_color_light">
@android:color/system_neutral2_700</color>
<color name="widget_picker_header_app_title_color_light">
@android:color/system_neutral1_900</color>
<color name="widget_picker_header_app_subtitle_color_light">
+1
View File
@@ -61,6 +61,7 @@
<attr name="preloadIconAccentColor" format="color" />
<attr name="preloadIconBackgroundColor" format="color" />
<attr name="widgetPickerTitleColor" format="color"/>
<attr name="widgetPickerDescriptionColor" format="color"/>
<attr name="widgetPickerPrimarySurfaceColor" format="color"/>
<attr name="widgetPickerSecondarySurfaceColor" format="color"/>
<attr name="widgetPickerHeaderAppTitleColor" format="color"/>
+2
View File
@@ -104,6 +104,7 @@
<color name="widget_picker_primary_surface_color_light">#EFEDED</color>
<color name="widget_picker_secondary_surface_color_light">#FAF9F8</color>
<color name="widget_picker_title_color_light">#1F1F1F</color>
<color name="widget_picker_description_color_light">#4C4D50</color>
<color name="widget_picker_header_app_title_color_light">#1F1F1F</color>
<color name="widget_picker_header_app_subtitle_color_light">#444746</color>
<color name="widget_picker_header_background_color_light">#C2E7FF</color>
@@ -123,6 +124,7 @@
<color name="widget_picker_primary_surface_color_dark">#1F2020</color>
<color name="widget_picker_secondary_surface_color_dark">#393939</color>
<color name="widget_picker_title_color_dark">#E3E3E3</color>
<color name="widget_picker_description_color_dark">#CCCDCF</color>
<color name="widget_picker_header_app_title_color_dark">#E3E3E3</color>
<color name="widget_picker_header_app_subtitle_color_dark">#C4C7C5</color>
<color name="widget_picker_header_background_color_dark">#004A77</color>
+2
View File
@@ -243,6 +243,7 @@
<item name="widgetPickerSecondarySurfaceColor">
@color/widget_picker_secondary_surface_color_light</item>
<item name="widgetPickerTitleColor">@color/widget_picker_title_color_light</item>
<item name="widgetPickerDescriptionColor">@color/widget_picker_description_color_light</item>
<item name="widgetPickerHeaderAppTitleColor">
@color/widget_picker_header_app_title_color_light</item>
<item name="widgetPickerHeaderAppSubtitleColor">
@@ -282,6 +283,7 @@
@color/widget_picker_secondary_surface_color_dark</item>
<item name="widgetPickerTitleColor">
@color/widget_picker_title_color_dark</item>
<item name="widgetPickerDescriptionColor">@color/widget_picker_description_color_dark</item>
<item name="widgetPickerHeaderAppTitleColor">
@color/widget_picker_header_app_title_color_dark</item>
<item name="widgetPickerHeaderAppSubtitleColor">
@@ -679,6 +679,18 @@ public class WidgetsFullSheet extends BaseWidgetSheet
return sheet;
}
/**
* Updates the widget picker's title and description in the header to the provided values (if
* present).
*/
public void mayUpdateTitleAndDescription(@Nullable String title,
@Nullable String descriptionRes) {
if (title != null) {
mHeaderTitle.setText(title);
}
// Full sheet doesn't support a description.
}
@Override
public void saveHierarchyState(SparseArray<Parcelable> sparseArray) {
Bundle bundle = new Bundle();
@@ -36,6 +36,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -60,9 +61,6 @@ import java.util.List;
* Popup for showing the full list of available widgets with a two-pane layout.
*/
public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
private static final int PERSONAL_TAB = 0;
private static final int WORK_TAB = 1;
private static final int MINIMUM_WIDTH_LEFT_PANE_FOLDABLE_DP = 268;
private static final int MAXIMUM_WIDTH_LEFT_PANE_FOLDABLE_DP = 395;
private static final String SUGGESTIONS_PACKAGE_NAME = "widgets_list_suggestions_entry";
@@ -83,6 +81,7 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
private int mActivePage = -1;
@Nullable
private PackageUserKey mSelectedHeader;
private TextView mHeaderDescription;
public WidgetsTwoPaneSheet(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
@@ -126,6 +125,8 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
newPage -> mRecommendationsCurrentPage = newPage);
mHeaderTitle = mContent.findViewById(R.id.title);
mHeaderDescription = mContent.findViewById(R.id.widget_picker_description);
mRightPane = mContent.findViewById(R.id.right_pane);
mRightPaneScrollView = mContent.findViewById(R.id.right_pane_scroll_view);
mRightPaneScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
@@ -140,6 +141,17 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
mFastScroller.setVisibility(GONE);
}
@Override
public void mayUpdateTitleAndDescription(@Nullable String title, @Nullable String description) {
if (title != null) {
mHeaderTitle.setText(title);
}
if (description != null) {
mHeaderDescription.setText(description);
mHeaderDescription.setVisibility(VISIBLE);
}
}
@Override
protected int getTabletHorizontalMargin(DeviceProfile deviceProfile) {
if (enableCategorizedWidgetSuggestions()) {
@@ -371,9 +383,10 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
protected void updateRecyclerViewVisibility(AdapterHolder adapterHolder) {
// The first item is always an empty space entry. Look for any more items.
boolean isWidgetAvailable = adapterHolder.mWidgetsListAdapter.hasVisibleEntries();
mRightPane.setVisibility(isWidgetAvailable ? VISIBLE : GONE);
if (!isWidgetAvailable) {
mRightPane.removeAllViews();
mRightPane.addView(mNoWidgetsView);
}
super.updateRecyclerViewVisibility(adapterHolder);
}