summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2011-02-25 12:03:37 -0800
committerAdam Cohen <adamcohen@google.com>2011-02-25 15:10:40 -0800
commitd2e20de64b6de8b6391c63e2f5b02ce7698bf4bf (patch)
treef8467e4deac16cdb5a8bc1aca57c97e7b1345e3f
parent0277c171283826dce53cc48e8dd66187051227e4 (diff)
downloadframeworks_base-d2e20de64b6de8b6391c63e2f5b02ce7698bf4bf.zip
frameworks_base-d2e20de64b6de8b6391c63e2f5b02ce7698bf4bf.tar.gz
frameworks_base-d2e20de64b6de8b6391c63e2f5b02ce7698bf4bf.tar.bz2
Adding framework support for resizable widgets
-> Added resizeMode to the widget xml -> Fixed an unexposed bug in AppWidgetHost where minWidth and minHeight were never being converted from complex type to dp Change-Id: Ibbc4fc6542d095623ac2a40694b6a3dbfeb279ad
-rw-r--r--api/current.xml65
-rw-r--r--core/java/android/appwidget/AppWidgetHost.java21
-rw-r--r--core/java/android/appwidget/AppWidgetProviderInfo.java27
-rwxr-xr-xcore/res/res/values/attrs.xml7
-rw-r--r--core/res/res/values/public.xml3
-rw-r--r--services/java/com/android/server/AppWidgetService.java15
6 files changed, 127 insertions, 11 deletions
diff --git a/api/current.xml b/api/current.xml
index 1089604..07d04ca 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -7924,6 +7924,17 @@
visibility="public"
>
</field>
+<field name="resizeMode"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843619"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="resizeable"
type="int"
transient="false"
@@ -39802,6 +39813,50 @@
visibility="public"
>
</field>
+<field name="RESIZE_BOTH"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="3"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="RESIZE_HORIZONTAL"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="1"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="RESIZE_NONE"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="RESIZE_VERTICAL"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="2"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="autoAdvanceViewId"
type="int"
transient="false"
@@ -39892,6 +39947,16 @@
visibility="public"
>
</field>
+<field name="resizableMode"
+ type="int"
+ transient="false"
+ volatile="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="updatePeriodMillis"
type="int"
transient="false"
diff --git a/core/java/android/appwidget/AppWidgetHost.java b/core/java/android/appwidget/AppWidgetHost.java
index 9835484..8204a4f 100644
--- a/core/java/android/appwidget/AppWidgetHost.java
+++ b/core/java/android/appwidget/AppWidgetHost.java
@@ -16,6 +16,9 @@
package android.appwidget;
+import java.util.ArrayList;
+import java.util.HashMap;
+
import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
@@ -23,11 +26,10 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.util.DisplayMetrics;
+import android.util.TypedValue;
import android.widget.RemoteViews;
-import java.util.ArrayList;
-import java.util.HashMap;
-
import com.android.internal.appwidget.IAppWidgetHost;
import com.android.internal.appwidget.IAppWidgetService;
@@ -43,6 +45,7 @@ public class AppWidgetHost {
final static Object sServiceLock = new Object();
static IAppWidgetService sService;
+ private DisplayMetrics mDisplayMetrics;
Context mContext;
String mPackageName;
@@ -103,6 +106,7 @@ public class AppWidgetHost {
mContext = context;
mHostId = hostId;
mHandler = new UpdateHandler(context.getMainLooper());
+ mDisplayMetrics = context.getResources().getDisplayMetrics();
synchronized (sServiceLock) {
if (sService == null) {
IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE);
@@ -243,12 +247,21 @@ public class AppWidgetHost {
AppWidgetProviderInfo appWidget) {
return new AppWidgetHostView(context);
}
-
+
/**
* Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
*/
protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
AppWidgetHostView v;
+
+ // Convert complex to dp -- we are getting the AppWidgetProviderInfo from the
+ // AppWidgetService, which doesn't have our context, hence we need to do the
+ // conversion here.
+ appWidget.minWidth =
+ TypedValue.complexToDimensionPixelSize(appWidget.minWidth, mDisplayMetrics);
+ appWidget.minHeight =
+ TypedValue.complexToDimensionPixelSize(appWidget.minHeight, mDisplayMetrics);
+
synchronized (mViews) {
v = mViews.get(appWidgetId);
}
diff --git a/core/java/android/appwidget/AppWidgetProviderInfo.java b/core/java/android/appwidget/AppWidgetProviderInfo.java
index fe33782..32c2397 100644
--- a/core/java/android/appwidget/AppWidgetProviderInfo.java
+++ b/core/java/android/appwidget/AppWidgetProviderInfo.java
@@ -25,6 +25,24 @@ import android.content.ComponentName;
* correspond to the fields in the <code>&lt;appwidget-provider&gt;</code> xml tag.
*/
public class AppWidgetProviderInfo implements Parcelable {
+
+ /**
+ * Widget is not resizable.
+ */
+ public static final int RESIZE_NONE = 0;
+ /**
+ * Widget is resizable in the horizontal axis only.
+ */
+ public static final int RESIZE_HORIZONTAL = 1;
+ /**
+ * Widget is resizable in the vertical axis only.
+ */
+ public static final int RESIZE_VERTICAL = 2;
+ /**
+ * Widget is resizable in both the horizontal and vertical axes.
+ */
+ public static final int RESIZE_BOTH = RESIZE_HORIZONTAL | RESIZE_VERTICAL;
+
/**
* Identity of this AppWidget component. This component should be a {@link
* android.content.BroadcastReceiver}, and it will be sent the AppWidget intents
@@ -124,6 +142,13 @@ public class AppWidgetProviderInfo implements Parcelable {
*/
public int previewImage;
+ /**
+ * The rules by which a widget can be resized. See {@link #RESIZE_NONE},
+ * {@link #RESIZE_NONE}, {@link #RESIZE_HORIZONTAL},
+ * {@link #RESIZE_VERTICAL}, {@link #RESIZE_BOTH}.
+ */
+ public int resizableMode;
+
public AppWidgetProviderInfo() {
}
@@ -145,6 +170,7 @@ public class AppWidgetProviderInfo implements Parcelable {
this.icon = in.readInt();
this.previewImage = in.readInt();
this.autoAdvanceViewId = in.readInt();
+ this.resizableMode = in.readInt();
}
public void writeToParcel(android.os.Parcel out, int flags) {
@@ -168,6 +194,7 @@ public class AppWidgetProviderInfo implements Parcelable {
out.writeInt(this.icon);
out.writeInt(this.previewImage);
out.writeInt(this.autoAdvanceViewId);
+ out.writeInt(this.resizableMode);
}
public int describeContents() {
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index b48adf1..3b225a4 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -4549,6 +4549,13 @@
<!-- The view id of the AppWidget subview which should be auto-advanced.
by the widget's host. -->
<attr name="autoAdvanceViewId" format="reference" />
+ <!-- Optional parameter which indicates if and how this widget can be
+ resized. -->
+ <attr name="resizeMode" format="integer">
+ <flag name="none" value="0x0" />
+ <flag name="horizontal" value="0x1" />
+ <flag name="vertical" value="0x2" />
+ </attr>
</declare-styleable>
<!-- =============================== -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index c7f082b..f1ec398 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1646,5 +1646,6 @@
Resources added in version 12 of the platform (Honeycomb / 3.1)
=============================================================== -->
<eat-comment />
- <public type="attr" name="textCursorDrawable" id="0x01010362" />
+ <public type="attr" name="textCursorDrawable" id="0x01010362" />
+ <public type="attr" name="resizeMode" />
</resources>
diff --git a/services/java/com/android/server/AppWidgetService.java b/services/java/com/android/server/AppWidgetService.java
index ad25657..550bb3d 100644
--- a/services/java/com/android/server/AppWidgetService.java
+++ b/services/java/com/android/server/AppWidgetService.java
@@ -897,15 +897,15 @@ class AppWidgetService extends IAppWidgetService.Stub
+ "AppWidget provider '" + component + '\'');
return null;
}
-
+
AttributeSet attrs = Xml.asAttributeSet(parser);
-
+
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
// drain whitespace, comments, etc.
}
-
+
String nodeName = parser.getName();
if (!"appwidget-provider".equals(nodeName)) {
Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for"
@@ -925,10 +925,10 @@ class AppWidgetService extends IAppWidgetService.Stub
Resources res = mPackageManager.getResourcesForApplication(
activityInfo.applicationInfo);
-
+
TypedArray sa = res.obtainAttributes(attrs,
com.android.internal.R.styleable.AppWidgetProviderInfo);
-
+
// These dimensions has to be resolved in the application's context.
// We simply send back the raw complex data, which will be
// converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
@@ -937,7 +937,7 @@ class AppWidgetService extends IAppWidgetService.Stub
info.minWidth = value != null ? value.data : 0;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
info.minHeight = value != null ? value.data : 0;
-
+
info.updatePeriodMillis = sa.getInt(
com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
info.initialLayout = sa.getResourceId(
@@ -953,6 +953,9 @@ class AppWidgetService extends IAppWidgetService.Stub
com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
info.autoAdvanceViewId = sa.getResourceId(
com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
+ info.resizableMode = sa.getInt(
+ com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode,
+ AppWidgetProviderInfo.RESIZE_NONE);
sa.recycle();
} catch (Exception e) {