Loading res/layout/widget_cell_content.xml +3 −2 Original line number Diff line number Diff line Loading @@ -48,14 +48,15 @@ <!-- The name of the widget. --> <TextView android:id="@+id/widget_name" android:layout_width="match_parent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:fadingEdge="horizontal" android:gravity="center_horizontal" android:gravity="center_horizontal|center_vertical" android:singleLine="true" android:maxLines="1" android:textColor="?android:attr/textColorPrimary" android:drawablePadding="@dimen/widget_cell_app_icon_padding" android:textSize="@dimen/widget_cell_font_size" /> <!-- The original dimensions of the widget --> Loading res/values/dimens.xml +2 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,8 @@ <dimen name="widget_cell_vertical_padding">8dp</dimen> <dimen name="widget_cell_horizontal_padding">16dp</dimen> <dimen name="widget_cell_font_size">14sp</dimen> <dimen name="widget_cell_app_icon_size">24dp</dimen> <dimen name="widget_cell_app_icon_padding">8dp</dimen> <dimen name="widget_tabs_button_horizontal_padding">4dp</dimen> <dimen name="widget_tabs_horizontal_padding">16dp</dimen> Loading src/com/android/launcher3/model/WidgetItem.java +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import androidx.core.os.BuildCompat; import com.android.launcher3.Flags; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Utilities; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.IconCache; import com.android.launcher3.pm.ShortcutConfigActivityInfo; import com.android.launcher3.util.ComponentKey; Loading @@ -35,6 +36,7 @@ public class WidgetItem extends ComponentKey { public final LauncherAppWidgetProviderInfo widgetInfo; public final ShortcutConfigActivityInfo activityInfo; public BitmapInfo bitmap = BitmapInfo.LOW_RES_INFO; public final String label; public final CharSequence description; public final int spanX, spanY; Loading src/com/android/launcher3/widget/WidgetCell.java +65 −0 Original line number Diff line number Diff line Loading @@ -48,10 +48,13 @@ import androidx.annotation.Nullable; import com.android.launcher3.CheckLongPressHelper; import com.android.launcher3.Flags; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.icons.FastBitmapDrawable; import com.android.launcher3.icons.RoundDrawableWrapper; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.util.CancellableTask; import com.android.launcher3.views.ActivityContext; Loading Loading @@ -102,6 +105,8 @@ public class WidgetCell extends LinearLayout { private float mAppWidgetHostViewScale = 1f; private int mSourceContainer = CONTAINER_WIDGETS_TRAY; private CancellableTask mIconLoadRequest; public WidgetCell(Context context) { this(context, null); } Loading Loading @@ -185,6 +190,7 @@ public class WidgetCell extends LinearLayout { mPreviewContainerScale = 1f; mItem = null; mWidgetSize = new Size(0, 0); showAppIconInWidgetTitle(false); } public void setSourceContainer(int sourceContainer) { Loading Loading @@ -377,6 +383,31 @@ public class WidgetCell extends LinearLayout { mWidgetDescription.setVisibility(show ? VISIBLE : GONE); } /** * Set whether the app icon, for the app that provides the widget, should be shown next to the * title text of the widget. * * @param show true if the app icon should be shown in the title text of the cell, false hides * it. */ public void showAppIconInWidgetTitle(boolean show) { if (show) { if (mItem.widgetInfo != null) { loadHighResPackageIcon(); Drawable icon = mItem.bitmap.newIcon(getContext()); int size = getResources().getDimensionPixelSize(R.dimen.widget_cell_app_icon_size); icon.setBounds(0, 0, size, size); mWidgetName.setCompoundDrawablesRelative( icon, null, null, null); } } else { cancelIconLoadRequest(); mWidgetName.setCompoundDrawables(null, null, null, null); } } @Override public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Loading Loading @@ -430,4 +461,38 @@ public class WidgetCell extends LinearLayout { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } /** * Loads a high resolution package icon to show next to the widget title. */ public void loadHighResPackageIcon() { cancelIconLoadRequest(); if (mItem.bitmap.isLowRes()) { // We use the package icon instead of the receiver one so that the overall package that // the widget came from can be identified in the recommended widgets. This matches with // the package icon headings in the all widgets list. PackageItemInfo tmpPackageItem = new PackageItemInfo( mItem.componentName.getPackageName(), mItem.user); mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache() .updateIconInBackground(this::reapplyIconInfo, tmpPackageItem); } } /** Can be called to update the package icon shown in the label of recommended widgets. */ private void reapplyIconInfo(ItemInfoWithIcon info) { if (mItem == null || info.bitmap.isNullOrLowRes()) { showAppIconInWidgetTitle(false); return; } mItem.bitmap = info.bitmap; showAppIconInWidgetTitle(true); } private void cancelIconLoadRequest() { if (mIconLoadRequest != null) { mIconLoadRequest.cancel(); mIconLoadRequest = null; } } } src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java +1 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ public final class WidgetsRecommendationTableLayout extends TableLayout { for (WidgetItem widgetItem : widgetItems) { WidgetCell widgetCell = addItemCell(tableRow); widgetCell.applyFromCellItem(widgetItem, data.mPreviewScale); widgetCell.showAppIconInWidgetTitle(true); widgetCell.showBadge(); if (enableCategorizedWidgetSuggestions()) { widgetCell.showDescription(false); Loading Loading
res/layout/widget_cell_content.xml +3 −2 Original line number Diff line number Diff line Loading @@ -48,14 +48,15 @@ <!-- The name of the widget. --> <TextView android:id="@+id/widget_name" android:layout_width="match_parent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:fadingEdge="horizontal" android:gravity="center_horizontal" android:gravity="center_horizontal|center_vertical" android:singleLine="true" android:maxLines="1" android:textColor="?android:attr/textColorPrimary" android:drawablePadding="@dimen/widget_cell_app_icon_padding" android:textSize="@dimen/widget_cell_font_size" /> <!-- The original dimensions of the widget --> Loading
res/values/dimens.xml +2 −0 Original line number Diff line number Diff line Loading @@ -178,6 +178,8 @@ <dimen name="widget_cell_vertical_padding">8dp</dimen> <dimen name="widget_cell_horizontal_padding">16dp</dimen> <dimen name="widget_cell_font_size">14sp</dimen> <dimen name="widget_cell_app_icon_size">24dp</dimen> <dimen name="widget_cell_app_icon_padding">8dp</dimen> <dimen name="widget_tabs_button_horizontal_padding">4dp</dimen> <dimen name="widget_tabs_horizontal_padding">16dp</dimen> Loading
src/com/android/launcher3/model/WidgetItem.java +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import androidx.core.os.BuildCompat; import com.android.launcher3.Flags; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Utilities; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.IconCache; import com.android.launcher3.pm.ShortcutConfigActivityInfo; import com.android.launcher3.util.ComponentKey; Loading @@ -35,6 +36,7 @@ public class WidgetItem extends ComponentKey { public final LauncherAppWidgetProviderInfo widgetInfo; public final ShortcutConfigActivityInfo activityInfo; public BitmapInfo bitmap = BitmapInfo.LOW_RES_INFO; public final String label; public final CharSequence description; public final int spanX, spanY; Loading
src/com/android/launcher3/widget/WidgetCell.java +65 −0 Original line number Diff line number Diff line Loading @@ -48,10 +48,13 @@ import androidx.annotation.Nullable; import com.android.launcher3.CheckLongPressHelper; import com.android.launcher3.Flags; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.icons.FastBitmapDrawable; import com.android.launcher3.icons.RoundDrawableWrapper; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.util.CancellableTask; import com.android.launcher3.views.ActivityContext; Loading Loading @@ -102,6 +105,8 @@ public class WidgetCell extends LinearLayout { private float mAppWidgetHostViewScale = 1f; private int mSourceContainer = CONTAINER_WIDGETS_TRAY; private CancellableTask mIconLoadRequest; public WidgetCell(Context context) { this(context, null); } Loading Loading @@ -185,6 +190,7 @@ public class WidgetCell extends LinearLayout { mPreviewContainerScale = 1f; mItem = null; mWidgetSize = new Size(0, 0); showAppIconInWidgetTitle(false); } public void setSourceContainer(int sourceContainer) { Loading Loading @@ -377,6 +383,31 @@ public class WidgetCell extends LinearLayout { mWidgetDescription.setVisibility(show ? VISIBLE : GONE); } /** * Set whether the app icon, for the app that provides the widget, should be shown next to the * title text of the widget. * * @param show true if the app icon should be shown in the title text of the cell, false hides * it. */ public void showAppIconInWidgetTitle(boolean show) { if (show) { if (mItem.widgetInfo != null) { loadHighResPackageIcon(); Drawable icon = mItem.bitmap.newIcon(getContext()); int size = getResources().getDimensionPixelSize(R.dimen.widget_cell_app_icon_size); icon.setBounds(0, 0, size, size); mWidgetName.setCompoundDrawablesRelative( icon, null, null, null); } } else { cancelIconLoadRequest(); mWidgetName.setCompoundDrawables(null, null, null, null); } } @Override public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Loading Loading @@ -430,4 +461,38 @@ public class WidgetCell extends LinearLayout { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } /** * Loads a high resolution package icon to show next to the widget title. */ public void loadHighResPackageIcon() { cancelIconLoadRequest(); if (mItem.bitmap.isLowRes()) { // We use the package icon instead of the receiver one so that the overall package that // the widget came from can be identified in the recommended widgets. This matches with // the package icon headings in the all widgets list. PackageItemInfo tmpPackageItem = new PackageItemInfo( mItem.componentName.getPackageName(), mItem.user); mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache() .updateIconInBackground(this::reapplyIconInfo, tmpPackageItem); } } /** Can be called to update the package icon shown in the label of recommended widgets. */ private void reapplyIconInfo(ItemInfoWithIcon info) { if (mItem == null || info.bitmap.isNullOrLowRes()) { showAppIconInWidgetTitle(false); return; } mItem.bitmap = info.bitmap; showAppIconInWidgetTitle(true); } private void cancelIconLoadRequest() { if (mIconLoadRequest != null) { mIconLoadRequest.cancel(); mIconLoadRequest = null; } } }
src/com/android/launcher3/widget/picker/WidgetsRecommendationTableLayout.java +1 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ public final class WidgetsRecommendationTableLayout extends TableLayout { for (WidgetItem widgetItem : widgetItems) { WidgetCell widgetCell = addItemCell(tableRow); widgetCell.applyFromCellItem(widgetItem, data.mPreviewScale); widgetCell.showAppIconInWidgetTitle(true); widgetCell.showBadge(); if (enableCategorizedWidgetSuggestions()) { widgetCell.showDescription(false); Loading