Merge "Add new attributes for widget sizing controls." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cdb4ebd90d
@@ -960,6 +960,8 @@ package android {
|
||||
field public static final int maxLines = 16843091; // 0x1010153
|
||||
field public static final int maxLongVersionCode = 16844163; // 0x1010583
|
||||
field public static final int maxRecents = 16843846; // 0x1010446
|
||||
field public static final int maxResizeHeight = 16844339; // 0x1010633
|
||||
field public static final int maxResizeWidth = 16844338; // 0x1010632
|
||||
field public static final int maxRows = 16843059; // 0x1010133
|
||||
field public static final int maxSdkVersion = 16843377; // 0x1010271
|
||||
field public static final int maxWidth = 16843039; // 0x101011f
|
||||
@@ -1394,6 +1396,8 @@ package android {
|
||||
field public static final int tabWidgetStyle = 16842883; // 0x1010083
|
||||
field public static final int tag = 16842961; // 0x10100d1
|
||||
field public static final int targetActivity = 16843266; // 0x1010202
|
||||
field public static final int targetCellHeight = 16844341; // 0x1010635
|
||||
field public static final int targetCellWidth = 16844340; // 0x1010634
|
||||
field public static final int targetClass = 16842799; // 0x101002f
|
||||
field @Deprecated public static final int targetDescriptions = 16843680; // 0x10103a0
|
||||
field public static final int targetId = 16843740; // 0x10103dc
|
||||
@@ -8428,6 +8432,8 @@ package android.appwidget {
|
||||
field public int initialKeyguardLayout;
|
||||
field public int initialLayout;
|
||||
field @Deprecated public String label;
|
||||
field public int maxResizeHeight;
|
||||
field public int maxResizeWidth;
|
||||
field public int minHeight;
|
||||
field public int minResizeHeight;
|
||||
field public int minResizeWidth;
|
||||
@@ -8436,6 +8442,8 @@ package android.appwidget {
|
||||
field @IdRes public int previewLayout;
|
||||
field public android.content.ComponentName provider;
|
||||
field public int resizeMode;
|
||||
field public int targetCellHeight;
|
||||
field public int targetCellWidth;
|
||||
field public int updatePeriodMillis;
|
||||
field public int widgetCategory;
|
||||
field public int widgetFeatures;
|
||||
|
||||
@@ -178,6 +178,44 @@ public class AppWidgetProviderInfo implements Parcelable {
|
||||
*/
|
||||
public int minResizeHeight;
|
||||
|
||||
/**
|
||||
* Maximum width (in dp) which the widget can be resized to. This field has no effect if it is
|
||||
* smaller than minWidth or if horizontal resizing isn't enabled (see {@link #resizeMode}).
|
||||
*
|
||||
* <p>This field corresponds to the <code>android:maxResizeWidth</code> attribute in the
|
||||
* AppWidget meta-data file.
|
||||
*/
|
||||
@SuppressLint("MutableBareField")
|
||||
public int maxResizeWidth;
|
||||
|
||||
/**
|
||||
* Maximum height (in dp) which the widget can be resized to. This field has no effect if it is
|
||||
* smaller than minHeight or if vertical resizing isn't enabled (see {@link #resizeMode}).
|
||||
*
|
||||
* <p>This field corresponds to the <code>android:maxResizeHeight</code> attribute in the
|
||||
* AppWidget meta-data file.
|
||||
*/
|
||||
@SuppressLint("MutableBareField")
|
||||
public int maxResizeHeight;
|
||||
|
||||
/**
|
||||
* The default width of a widget when added to a host, in units of launcher grid cells.
|
||||
*
|
||||
* <p>This field corresponds to the <code>android:targetCellWidth</code> attribute in the
|
||||
* AppWidget meta-data file.
|
||||
*/
|
||||
@SuppressLint("MutableBareField")
|
||||
public int targetCellWidth;
|
||||
|
||||
/**
|
||||
* The default height of a widget when added to a host, in units of launcher grid cells.
|
||||
*
|
||||
* <p>This field corresponds to the <code>android:targetCellHeight</code> attribute in the
|
||||
* AppWidget meta-data file.
|
||||
*/
|
||||
@SuppressLint("MutableBareField")
|
||||
public int targetCellHeight;
|
||||
|
||||
/**
|
||||
* How often, in milliseconds, that this AppWidget wants to be updated.
|
||||
* The AppWidget manager may place a limit on how often a AppWidget is updated.
|
||||
@@ -330,6 +368,10 @@ public class AppWidgetProviderInfo implements Parcelable {
|
||||
this.minHeight = in.readInt();
|
||||
this.minResizeWidth = in.readInt();
|
||||
this.minResizeHeight = in.readInt();
|
||||
this.maxResizeWidth = in.readInt();
|
||||
this.maxResizeHeight = in.readInt();
|
||||
this.targetCellWidth = in.readInt();
|
||||
this.targetCellHeight = in.readInt();
|
||||
this.updatePeriodMillis = in.readInt();
|
||||
this.initialLayout = in.readInt();
|
||||
this.initialKeyguardLayout = in.readInt();
|
||||
@@ -440,6 +482,10 @@ public class AppWidgetProviderInfo implements Parcelable {
|
||||
out.writeInt(this.minHeight);
|
||||
out.writeInt(this.minResizeWidth);
|
||||
out.writeInt(this.minResizeHeight);
|
||||
out.writeInt(this.maxResizeWidth);
|
||||
out.writeInt(this.maxResizeHeight);
|
||||
out.writeInt(this.targetCellWidth);
|
||||
out.writeInt(this.targetCellHeight);
|
||||
out.writeInt(this.updatePeriodMillis);
|
||||
out.writeInt(this.initialLayout);
|
||||
out.writeInt(this.initialKeyguardLayout);
|
||||
@@ -463,8 +509,12 @@ public class AppWidgetProviderInfo implements Parcelable {
|
||||
that.provider = this.provider == null ? null : this.provider.clone();
|
||||
that.minWidth = this.minWidth;
|
||||
that.minHeight = this.minHeight;
|
||||
that.minResizeWidth = this.minResizeHeight;
|
||||
that.minResizeWidth = this.minResizeWidth;
|
||||
that.minResizeHeight = this.minResizeHeight;
|
||||
that.maxResizeWidth = this.maxResizeWidth;
|
||||
that.maxResizeHeight = this.maxResizeHeight;
|
||||
that.targetCellWidth = this.targetCellWidth;
|
||||
that.targetCellHeight = this.targetCellHeight;
|
||||
that.updatePeriodMillis = this.updatePeriodMillis;
|
||||
that.initialLayout = this.initialLayout;
|
||||
that.initialKeyguardLayout = this.initialKeyguardLayout;
|
||||
@@ -512,6 +562,8 @@ public class AppWidgetProviderInfo implements Parcelable {
|
||||
minHeight = TypedValue.complexToDimensionPixelSize(minHeight, displayMetrics);
|
||||
minResizeWidth = TypedValue.complexToDimensionPixelSize(minResizeWidth, displayMetrics);
|
||||
minResizeHeight = TypedValue.complexToDimensionPixelSize(minResizeHeight, displayMetrics);
|
||||
maxResizeWidth = TypedValue.complexToDimensionPixelSize(maxResizeWidth, displayMetrics);
|
||||
maxResizeHeight = TypedValue.complexToDimensionPixelSize(maxResizeHeight, displayMetrics);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8010,6 +8010,14 @@
|
||||
<attr name="minResizeWidth" format="dimension"/>
|
||||
<!-- Minimum height that the AppWidget can be resized to. -->
|
||||
<attr name="minResizeHeight" format="dimension"/>
|
||||
<!-- Maximum width that the AppWidget can be resized to. -->
|
||||
<attr name="maxResizeWidth" format="dimension"/>
|
||||
<!-- Maximum height that the AppWidget can be resized to. -->
|
||||
<attr name="maxResizeHeight" format="dimension"/>
|
||||
<!-- Default width of the AppWidget in units of launcher grid cells. -->
|
||||
<attr name="targetCellWidth" format="integer"/>
|
||||
<!-- Default height of the AppWidget in units of launcher grid cells. -->
|
||||
<attr name="targetCellHeight" format="integer"/>
|
||||
<!-- Update period in milliseconds, or 0 if the AppWidget will update itself. -->
|
||||
<attr name="updatePeriodMillis" format="integer" />
|
||||
<!-- A resource id of a layout. -->
|
||||
|
||||
@@ -3072,6 +3072,10 @@
|
||||
<public name="windowSplashScreenBrandingImage"/>
|
||||
<public name="splashScreenTheme" />
|
||||
<public name="rippleStyle" />
|
||||
<public name="maxResizeWidth" />
|
||||
<public name="maxResizeHeight" />
|
||||
<public name="targetCellWidth" />
|
||||
<public name="targetCellHeight" />
|
||||
</public-group>
|
||||
|
||||
<public-group type="drawable" first-id="0x010800b5">
|
||||
|
||||
@@ -2624,12 +2624,26 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
|
||||
info.minWidth = value != null ? value.data : 0;
|
||||
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
|
||||
info.minHeight = value != null ? value.data : 0;
|
||||
|
||||
value = sa.peekValue(
|
||||
com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
|
||||
info.minResizeWidth = value != null ? value.data : info.minWidth;
|
||||
value = sa.peekValue(
|
||||
com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
|
||||
info.minResizeHeight = value != null ? value.data : info.minHeight;
|
||||
|
||||
value = sa.peekValue(
|
||||
com.android.internal.R.styleable.AppWidgetProviderInfo_maxResizeWidth);
|
||||
info.maxResizeWidth = value != null ? value.data : 0;
|
||||
value = sa.peekValue(
|
||||
com.android.internal.R.styleable.AppWidgetProviderInfo_maxResizeHeight);
|
||||
info.maxResizeHeight = value != null ? value.data : 0;
|
||||
|
||||
info.targetCellWidth = sa.getInt(
|
||||
com.android.internal.R.styleable.AppWidgetProviderInfo_targetCellWidth, 0);
|
||||
info.targetCellHeight = sa.getInt(
|
||||
com.android.internal.R.styleable.AppWidgetProviderInfo_targetCellHeight, 0);
|
||||
|
||||
info.updatePeriodMillis = sa.getInt(
|
||||
com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
|
||||
info.initialLayout = sa.getResourceId(
|
||||
|
||||
@@ -36,4 +36,12 @@
|
||||
<string name="module_2_name" translatable="false">module_2_name</string>
|
||||
|
||||
<string name="widget_description">widget description string</string>
|
||||
<dimen name="widget_min_width">80dp</dimen>
|
||||
<dimen name="widget_min_height">40dp</dimen>
|
||||
<dimen name="widget_min_resize_width">40dp</dimen>
|
||||
<dimen name="widget_min_resize_height">20dp</dimen>
|
||||
<dimen name="widget_max_resize_width">160dp</dimen>
|
||||
<dimen name="widget_max_resize_height">80dp</dimen>
|
||||
<integer name="widget_target_cell_width">2</integer>
|
||||
<integer name="widget_target_cell_height">1</integer>
|
||||
</resources>
|
||||
@@ -16,12 +16,18 @@
|
||||
-->
|
||||
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="40dp"
|
||||
android:minHeight="40dp"
|
||||
android:minWidth="@dimen/widget_min_width"
|
||||
android:minHeight="@dimen/widget_min_height"
|
||||
android:minResizeWidth="@dimen/widget_min_resize_width"
|
||||
android:minResizeHeight="@dimen/widget_min_resize_height"
|
||||
android:maxResizeWidth="@dimen/widget_max_resize_width"
|
||||
android:maxResizeHeight="@dimen/widget_max_resize_height"
|
||||
android:targetCellWidth="@integer/widget_target_cell_width"
|
||||
android:targetCellHeight="@integer/widget_target_cell_height"
|
||||
android:updatePeriodMillis="86400000"
|
||||
android:previewImage="@drawable/icon1"
|
||||
android:previewLayout="@layout/widget_preview"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:description="@string/widget_description"
|
||||
android:widgetCategory="home_screen">
|
||||
</appwidget-provider>
|
||||
</appwidget-provider>
|
||||
|
||||
@@ -103,6 +103,26 @@ public class AppWidgetServiceImplTest extends InstrumentationTestCase {
|
||||
assertEquals(info.loadDescription(mTestContext), "widget description string");
|
||||
}
|
||||
|
||||
public void testParseSizeConfiguration() {
|
||||
AppWidgetProviderInfo info =
|
||||
mManager.getInstalledProvidersForPackage(mPkgName, null).get(0);
|
||||
|
||||
assertThat(info.minWidth).isEqualTo(getDimensionResource(R.dimen.widget_min_width));
|
||||
assertThat(info.minHeight).isEqualTo(getDimensionResource(R.dimen.widget_min_height));
|
||||
assertThat(info.minResizeWidth)
|
||||
.isEqualTo(getDimensionResource(R.dimen.widget_min_resize_width));
|
||||
assertThat(info.minResizeHeight)
|
||||
.isEqualTo(getDimensionResource(R.dimen.widget_min_resize_height));
|
||||
assertThat(info.maxResizeWidth)
|
||||
.isEqualTo(getDimensionResource(R.dimen.widget_max_resize_width));
|
||||
assertThat(info.maxResizeHeight)
|
||||
.isEqualTo(getDimensionResource(R.dimen.widget_max_resize_height));
|
||||
assertThat(info.targetCellWidth)
|
||||
.isEqualTo(getIntegerResource(R.integer.widget_target_cell_width));
|
||||
assertThat(info.targetCellHeight)
|
||||
.isEqualTo(getIntegerResource(R.integer.widget_target_cell_height));
|
||||
}
|
||||
|
||||
public void testRequestPinAppWidget_otherProvider() {
|
||||
ComponentName otherProvider = null;
|
||||
for (AppWidgetProviderInfo provider : mManager.getInstalledProviders()) {
|
||||
@@ -325,6 +345,14 @@ public class AppWidgetServiceImplTest extends InstrumentationTestCase {
|
||||
latch.await();
|
||||
}
|
||||
|
||||
private int getDimensionResource(int resId) {
|
||||
return mTestContext.getResources().getDimensionPixelSize(resId);
|
||||
}
|
||||
|
||||
private int getIntegerResource(int resId) {
|
||||
return mTestContext.getResources().getInteger(resId);
|
||||
}
|
||||
|
||||
private class TestContext extends ContextWrapper {
|
||||
|
||||
public TestContext() {
|
||||
|
||||
Reference in New Issue
Block a user