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
This commit is contained in:
Steven Ng 2021-03-01 21:46:25 +00:00
parent f6987b0be1
commit c7537713ca
2 changed files with 29 additions and 4 deletions

View File

@ -50,4 +50,14 @@
android:textSize="14sp"
android:alpha="0.8" />
<TextView
android:id="@+id/widget_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="12sp"
android:maxLines="2"
android:ellipsize="end"
android:fadingEdge="horizontal" />
</merge>

View File

@ -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 {