Merge "Add a layout attribute in widget metadata for widget preview" into sc-dev
This commit is contained in:
@@ -1100,6 +1100,7 @@ package android {
|
|||||||
field public static final int presentationTheme = 16843712; // 0x10103c0
|
field public static final int presentationTheme = 16843712; // 0x10103c0
|
||||||
field public static final int preserveLegacyExternalStorage = 16844308; // 0x1010614
|
field public static final int preserveLegacyExternalStorage = 16844308; // 0x1010614
|
||||||
field public static final int previewImage = 16843482; // 0x10102da
|
field public static final int previewImage = 16843482; // 0x10102da
|
||||||
|
field public static final int previewLayout = 16844327; // 0x1010627
|
||||||
field public static final int primaryContentAlpha = 16844114; // 0x1010552
|
field public static final int primaryContentAlpha = 16844114; // 0x1010552
|
||||||
field public static final int priority = 16842780; // 0x101001c
|
field public static final int priority = 16842780; // 0x101001c
|
||||||
field public static final int privateImeOptions = 16843299; // 0x1010223
|
field public static final int privateImeOptions = 16843299; // 0x1010223
|
||||||
@@ -8386,6 +8387,7 @@ package android.appwidget {
|
|||||||
field public int minResizeWidth;
|
field public int minResizeWidth;
|
||||||
field public int minWidth;
|
field public int minWidth;
|
||||||
field public int previewImage;
|
field public int previewImage;
|
||||||
|
field @IdRes public int previewLayout;
|
||||||
field public android.content.ComponentName provider;
|
field public android.content.ComponentName provider;
|
||||||
field public int resizeMode;
|
field public int resizeMode;
|
||||||
field public int updatePeriodMillis;
|
field public int updatePeriodMillis;
|
||||||
|
|||||||
@@ -247,11 +247,28 @@ public class AppWidgetProviderInfo implements Parcelable {
|
|||||||
* A preview of what the AppWidget will look like after it's configured.
|
* A preview of what the AppWidget will look like after it's configured.
|
||||||
* If not supplied, the AppWidget's icon will be used.
|
* If not supplied, the AppWidget's icon will be used.
|
||||||
*
|
*
|
||||||
* <p>This field corresponds to the <code>android:previewImage</code> attribute in
|
* <p>This field corresponds to the <code>android:previewImage</code> attribute in the AppWidget
|
||||||
* the <code><receiver></code> element in the AndroidManifest.xml file.
|
* meta-data file.
|
||||||
*/
|
*/
|
||||||
public int previewImage;
|
public int previewImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The layout resource id of a preview of what the AppWidget will look like after it's
|
||||||
|
* configured.
|
||||||
|
*
|
||||||
|
* <p>Unlike previewImage, previewLayout can better showcase AppWidget in different locales,
|
||||||
|
* system themes, display sizes & density etc.
|
||||||
|
*
|
||||||
|
* <p>If supplied, this will take precedence over the previewImage on supported widget hosts.
|
||||||
|
* Otherwise, previewImage will be used.
|
||||||
|
*
|
||||||
|
* <p>This field corresponds to the <code>android:previewLayout</code> attribute in the
|
||||||
|
* AppWidget meta-data file.
|
||||||
|
*/
|
||||||
|
@SuppressLint("MutableBareField")
|
||||||
|
@IdRes
|
||||||
|
public int previewLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rules by which a widget can be resized. See {@link #RESIZE_NONE},
|
* The rules by which a widget can be resized. See {@link #RESIZE_NONE},
|
||||||
* {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL},
|
* {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL},
|
||||||
@@ -320,6 +337,7 @@ public class AppWidgetProviderInfo implements Parcelable {
|
|||||||
this.label = in.readString();
|
this.label = in.readString();
|
||||||
this.icon = in.readInt();
|
this.icon = in.readInt();
|
||||||
this.previewImage = in.readInt();
|
this.previewImage = in.readInt();
|
||||||
|
this.previewLayout = in.readInt();
|
||||||
this.autoAdvanceViewId = in.readInt();
|
this.autoAdvanceViewId = in.readInt();
|
||||||
this.resizeMode = in.readInt();
|
this.resizeMode = in.readInt();
|
||||||
this.widgetCategory = in.readInt();
|
this.widgetCategory = in.readInt();
|
||||||
@@ -429,6 +447,7 @@ public class AppWidgetProviderInfo implements Parcelable {
|
|||||||
out.writeString(this.label);
|
out.writeString(this.label);
|
||||||
out.writeInt(this.icon);
|
out.writeInt(this.icon);
|
||||||
out.writeInt(this.previewImage);
|
out.writeInt(this.previewImage);
|
||||||
|
out.writeInt(this.previewLayout);
|
||||||
out.writeInt(this.autoAdvanceViewId);
|
out.writeInt(this.autoAdvanceViewId);
|
||||||
out.writeInt(this.resizeMode);
|
out.writeInt(this.resizeMode);
|
||||||
out.writeInt(this.widgetCategory);
|
out.writeInt(this.widgetCategory);
|
||||||
@@ -453,6 +472,7 @@ public class AppWidgetProviderInfo implements Parcelable {
|
|||||||
that.label = this.label;
|
that.label = this.label;
|
||||||
that.icon = this.icon;
|
that.icon = this.icon;
|
||||||
that.previewImage = this.previewImage;
|
that.previewImage = this.previewImage;
|
||||||
|
that.previewLayout = this.previewLayout;
|
||||||
that.autoAdvanceViewId = this.autoAdvanceViewId;
|
that.autoAdvanceViewId = this.autoAdvanceViewId;
|
||||||
that.resizeMode = this.resizeMode;
|
that.resizeMode = this.resizeMode;
|
||||||
that.widgetCategory = this.widgetCategory;
|
that.widgetCategory = this.widgetCategory;
|
||||||
|
|||||||
@@ -7969,9 +7969,17 @@
|
|||||||
<!-- A class name in the AppWidget's package to be launched to configure.
|
<!-- A class name in the AppWidget's package to be launched to configure.
|
||||||
If not supplied, then no activity will be launched. -->
|
If not supplied, then no activity will be launched. -->
|
||||||
<attr name="configure" format="string" />
|
<attr name="configure" format="string" />
|
||||||
<!-- A preview of what the AppWidget will look like after it's configured.
|
<!-- A preview, in a drawable resource id, of what the AppWidget will look like after it's
|
||||||
If not supplied, the AppWidget's icon will be used. -->
|
configured.
|
||||||
|
If not supplied, the AppWidget's icon will be used. -->
|
||||||
<attr name="previewImage" format="reference" />
|
<attr name="previewImage" format="reference" />
|
||||||
|
<!-- The layout resource id of a preview of what the AppWidget will look like after it's
|
||||||
|
configured.
|
||||||
|
Unlike previewImage, previewLayout can better showcase AppWidget in different locales,
|
||||||
|
system themes, display sizes & density etc.
|
||||||
|
If supplied, this will take precedence over the previewImage on supported widget hosts.
|
||||||
|
Otherwise, previewImage will be used. -->
|
||||||
|
<attr name="previewLayout" format="reference" />
|
||||||
<!-- The view id of the AppWidget subview which should be auto-advanced.
|
<!-- The view id of the AppWidget subview which should be auto-advanced.
|
||||||
by the widget's host. -->
|
by the widget's host. -->
|
||||||
<attr name="autoAdvanceViewId" format="reference" />
|
<attr name="autoAdvanceViewId" format="reference" />
|
||||||
|
|||||||
@@ -3061,6 +3061,7 @@
|
|||||||
<public name="nativeHeapZeroInit" />
|
<public name="nativeHeapZeroInit" />
|
||||||
<!-- @hide @SystemApi -->
|
<!-- @hide @SystemApi -->
|
||||||
<public name="hotwordDetectionService" />
|
<public name="hotwordDetectionService" />
|
||||||
|
<public name="previewLayout" />
|
||||||
</public-group>
|
</public-group>
|
||||||
|
|
||||||
<public-group type="drawable" first-id="0x010800b5">
|
<public-group type="drawable" first-id="0x010800b5">
|
||||||
|
|||||||
@@ -2647,6 +2647,8 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
|
|||||||
info.icon = activityInfo.getIconResource();
|
info.icon = activityInfo.getIconResource();
|
||||||
info.previewImage = sa.getResourceId(
|
info.previewImage = sa.getResourceId(
|
||||||
com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
|
com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
|
||||||
|
info.previewLayout = sa.getResourceId(
|
||||||
|
com.android.internal.R.styleable.AppWidgetProviderInfo_previewLayout, 0);
|
||||||
info.autoAdvanceViewId = sa.getResourceId(
|
info.autoAdvanceViewId = sa.getResourceId(
|
||||||
com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
|
com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
|
||||||
info.resizeMode = sa.getInt(
|
info.resizeMode = sa.getInt(
|
||||||
|
|||||||
21
services/tests/servicestests/res/layout/widget_preview.xml
Normal file
21
services/tests/servicestests/res/layout/widget_preview.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (C) 2021 The Android Open Source Project
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
<TextView android:id="@+id/widget_preview"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="Widget preview" />
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (C) 2017 The Android Open Source Project
|
~ Copyright (C) 2017 The Android Open Source Project
|
||||||
~
|
~
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
android:minHeight="40dp"
|
android:minHeight="40dp"
|
||||||
android:updatePeriodMillis="86400000"
|
android:updatePeriodMillis="86400000"
|
||||||
android:previewImage="@drawable/icon1"
|
android:previewImage="@drawable/icon1"
|
||||||
|
android:previewLayout="@layout/widget_preview"
|
||||||
android:resizeMode="horizontal|vertical"
|
android:resizeMode="horizontal|vertical"
|
||||||
android:description="@string/widget_description"
|
android:description="@string/widget_description"
|
||||||
android:widgetCategory="home_screen">
|
android:widgetCategory="home_screen">
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.server.appwidget;
|
package com.android.server.appwidget;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
@@ -44,6 +46,7 @@ import android.test.InstrumentationTestCase;
|
|||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
|
import com.android.frameworks.servicestests.R;
|
||||||
import com.android.internal.appwidget.IAppWidgetHost;
|
import com.android.internal.appwidget.IAppWidgetHost;
|
||||||
import com.android.server.LocalServices;
|
import com.android.server.LocalServices;
|
||||||
|
|
||||||
@@ -293,6 +296,13 @@ public class AppWidgetServiceImplTest extends InstrumentationTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetPreviewLayout() {
|
||||||
|
AppWidgetProviderInfo info =
|
||||||
|
mManager.getInstalledProvidersForPackage(mPkgName, null).get(0);
|
||||||
|
|
||||||
|
assertThat(info.previewLayout).isEqualTo(R.layout.widget_preview);
|
||||||
|
}
|
||||||
|
|
||||||
private int setupHostAndWidget() {
|
private int setupHostAndWidget() {
|
||||||
List<PendingHostUpdate> updates = mService.startListening(
|
List<PendingHostUpdate> updates = mService.startListening(
|
||||||
mMockHost, mPkgName, HOST_ID, new int[0]).getList();
|
mMockHost, mPkgName, HOST_ID, new int[0]).getList();
|
||||||
|
|||||||
Reference in New Issue
Block a user