背景描述
桌面默认配置Google时钟插件,Android 12上Google时钟插件新增插件样式功能。
可以设置为白色底和透明两种样式。设置为白色底时,调整setting中显示大小为最大,时钟显示被截断。
问题分析
尝试在Android11上升级最新的Google时钟,发现还是没有样式功能。
在Android12上抓取样式界面包类名
com.google.android.deskclock/com.android.deskclock.DigitalAppWidgetConfigActivity
此界面设置了enable属性
<activity android:theme="@style/Theme.DeskClock.AppWidgetConfig"
android:name="com.android.deskclock.DigitalAppWidgetConfigActivity"
android:enabled="@bool/enable_digital_widgets_configs"
android:exported="false"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
enable_digital_widgets_configs默认配置false
只有v31配置为true
所以只有Android12有此问题。
问题修复
packages\apps\Launcher3\src\com\android\launcher3\widget\util\WidgetSizes.java
public static ArrayList<SizeF> getWidgetPaddedSizes(Context context, ComponentName provider,
int spanX, int spanY) {
Rect padding = getDefaultPaddingForWidget(context, provider, /* padding= */ null);
ArrayList<SizeF> sizes = new ArrayList<>(2);
//这里改为获取系统的density值,打log可以发现launcher内部的density值更新不及时,显示的是上次的显示大小对应的值
//final float density = context.getResources().getDisplayMetrics().density;
final float density = Resources.getSystem().getDisplayMetrics().density;
final Point cellSize = new Point();
for (DeviceProfile profile : LauncherAppState.getIDP(context).supportedProfiles) {
Size widgetSizePx = getWidgetSizePx(profile, spanX, spanY, cellSize);
if (!profile.shouldInsetWidgets()) {
widgetSizePx = new Size(widgetSizePx.getWidth() - padding.left - padding.right,
widgetSizePx.getHeight() - padding.top - padding.bottom);
}
sizes.add(new SizeF(widgetSizePx.getWidth() / density,
widgetSizePx.getHeight() / density));
}
return sizes;
}