From c7537713ca553728316286e048af304af7cf4989 Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Mon, 1 Mar 2021 21:46:25 +0000 Subject: [PATCH] Add widget description to WidgetCell Full picker: https://screenshot.googleplex.com/8Dij79K8Pq2KWdm.png Bottom picker: https://screenshot.googleplex.com/5f9TLra49dYJjLB.png Test: Manually launch full and bottom widget pickers and observe description is only shown for widgets but not shortcut. Bug: 179797520 Change-Id: I5bfde056906a4a0f4fff9bc9a488f808365173b3 --- res/layout/widget_cell_content.xml | 10 ++++++++ .../android/launcher3/widget/WidgetCell.java | 23 +++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/res/layout/widget_cell_content.xml b/res/layout/widget_cell_content.xml index c3e37e9176..65a49ab627 100644 --- a/res/layout/widget_cell_content.xml +++ b/res/layout/widget_cell_content.xml @@ -50,4 +50,14 @@ android:textSize="14sp" android:alpha="0.8" /> + + \ No newline at end of file diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index c6593f869e..8c315fd604 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -16,6 +16,8 @@ package com.android.launcher3.widget; +import static com.android.launcher3.Utilities.ATLEAST_S; + import android.content.Context; import android.graphics.Bitmap; import android.os.CancellationSignal; @@ -67,6 +69,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { private WidgetImageView mWidgetImage; private TextView mWidgetName; private TextView mWidgetDims; + private TextView mWidgetDescription; protected WidgetItem mItem; @@ -114,9 +117,10 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { protected void onFinishInflate() { super.onFinishInflate(); - mWidgetImage = (WidgetImageView) findViewById(R.id.widget_preview); - mWidgetName = ((TextView) findViewById(R.id.widget_name)); - mWidgetDims = ((TextView) findViewById(R.id.widget_dims)); + mWidgetImage = findViewById(R.id.widget_preview); + mWidgetName = findViewById(R.id.widget_name); + mWidgetDims = findViewById(R.id.widget_dims); + mWidgetDescription = findViewById(R.id.widget_description); } /** @@ -130,6 +134,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { mWidgetImage.setBitmap(null, null); mWidgetName.setText(null); mWidgetDims.setText(null); + mWidgetDescription.setText(null); + mWidgetDescription.setVisibility(GONE); mPreviewWidth = mPreviewHeight = mPresetPreviewSize; if (mActiveRequest != null) { @@ -145,8 +151,17 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { mItem.spanX, mItem.spanY)); mWidgetDims.setContentDescription(getContext().getString( R.string.widget_accessible_dims_format, mItem.spanX, mItem.spanY)); - mWidgetPreviewLoader = loader; + if (ATLEAST_S && mItem.widgetInfo != null) { + CharSequence description = mItem.widgetInfo.loadDescription(getContext()); + if (description != null && description.length() > 0) { + mWidgetDescription.setText(description); + mWidgetDescription.setVisibility(VISIBLE); + } else { + mWidgetDescription.setVisibility(GONE); + } + } + mWidgetPreviewLoader = loader; if (item.activityInfo != null) { setTag(new PendingAddShortcutInfo(item.activityInfo)); } else {