diff options
author | Adam Cohen <adamcohen@google.com> | 2011-11-04 12:12:48 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2011-11-07 17:59:23 -0800 |
commit | 4c96a59b4354c4a593a07a3273c186b51597bcc1 (patch) | |
tree | a4b2876ffafe24670b2edf6e5cf9747e683e89ce | |
parent | 2d9ccdb4abd393375c5ae99445afbb8b0855d25c (diff) | |
download | frameworks_base-4c96a59b4354c4a593a07a3273c186b51597bcc1.zip frameworks_base-4c96a59b4354c4a593a07a3273c186b51597bcc1.tar.gz frameworks_base-4c96a59b4354c4a593a07a3273c186b51597bcc1.tar.bz2 |
Making default widget padding public API
Change-Id: Ibf4f5dc1a36d84be1acc3ccdc4330276f82aa303
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | core/java/android/appwidget/AppWidgetHostView.java | 55 | ||||
-rw-r--r-- | core/res/res/values-sw600dp/dimens.xml | 6 | ||||
-rw-r--r-- | core/res/res/values/public.xml | 1 |
4 files changed, 40 insertions, 23 deletions
diff --git a/api/current.txt b/api/current.txt index cc7f0798..ea97d6d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4145,6 +4145,7 @@ package android.appwidget { ctor public AppWidgetHostView(android.content.Context, int, int); method public int getAppWidgetId(); method public android.appwidget.AppWidgetProviderInfo getAppWidgetInfo(); + method public static android.graphics.Rect getDefaultPaddingForWidget(android.content.Context, android.content.ComponentName, android.graphics.Rect); method protected android.view.View getDefaultView(); method protected android.view.View getErrorView(); method protected void prepareView(android.view.View); diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java index 761c7eb..61a9dce 100644 --- a/core/java/android/appwidget/AppWidgetHostView.java +++ b/core/java/android/appwidget/AppWidgetHostView.java @@ -26,6 +26,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -41,8 +42,8 @@ import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.FrameLayout; import android.widget.RemoteViews; -import android.widget.TextView; import android.widget.RemoteViewsAdapter.RemoteAdapterConnectionCallback; +import android.widget.TextView; /** * Provides the glue to show AppWidget views. This class offers automatic animation @@ -106,7 +107,9 @@ public class AppWidgetHostView extends FrameLayout { } /** - * Set the AppWidget that will be displayed by this view. + * Set the AppWidget that will be displayed by this view. This method also adds default padding + * to widgets, as described in {@link #getDefaultPaddingForWidget(Context, ComponentName, Rect)} + * and can be overridden in order to add custom padding. */ public void setAppWidget(int appWidgetId, AppWidgetProviderInfo info) { mAppWidgetId = appWidgetId; @@ -116,49 +119,57 @@ public class AppWidgetHostView extends FrameLayout { // a widget, eg. for some widgets in safe mode. if (info != null) { // We add padding to the AppWidgetHostView if necessary - Padding padding = getPaddingForWidget(info.provider); + Rect padding = getDefaultPaddingForWidget(mContext, info.provider, null); setPadding(padding.left, padding.top, padding.right, padding.bottom); } } - private static class Padding { - int left = 0; - int right = 0; - int top = 0; - int bottom = 0; - } - /** * As of ICE_CREAM_SANDWICH we are automatically adding padding to widgets targeting * ICE_CREAM_SANDWICH and higher. The new widget design guidelines strongly recommend * that widget developers do not add extra padding to their widgets. This will help * achieve consistency among widgets. + * + * Note: this method is only needed by developers of AppWidgetHosts. The method is provided in + * order for the AppWidgetHost to account for the automatic padding when computing the number + * of cells to allocate to a particular widget. + * + * @param context the current context + * @param component the component name of the widget + * @param padding Rect in which to place the output, if null, a new Rect will be allocated and + * returned + * @return default padding for this widget */ - private Padding getPaddingForWidget(ComponentName component) { - PackageManager packageManager = mContext.getPackageManager(); - Padding p = new Padding(); + public static Rect getDefaultPaddingForWidget(Context context, ComponentName component, + Rect padding) { + PackageManager packageManager = context.getPackageManager(); ApplicationInfo appInfo; + if (padding == null) { + padding = new Rect(0, 0, 0, 0); + } else { + padding.set(0, 0, 0, 0); + } + try { appInfo = packageManager.getApplicationInfo(component.getPackageName(), 0); - } catch (Exception e) { + } catch (NameNotFoundException e) { // if we can't find the package, return 0 padding - return p; + return padding; } if (appInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - Resources r = getResources(); - p.left = r.getDimensionPixelSize(com.android.internal. + Resources r = context.getResources(); + padding.left = r.getDimensionPixelSize(com.android.internal. R.dimen.default_app_widget_padding_left); - p.right = r.getDimensionPixelSize(com.android.internal. + padding.right = r.getDimensionPixelSize(com.android.internal. R.dimen.default_app_widget_padding_right); - p.top = r.getDimensionPixelSize(com.android.internal. + padding.top = r.getDimensionPixelSize(com.android.internal. R.dimen.default_app_widget_padding_top); - p.bottom = r.getDimensionPixelSize(com.android.internal. + padding.bottom = r.getDimensionPixelSize(com.android.internal. R.dimen.default_app_widget_padding_bottom); } - - return p; + return padding; } public int getAppWidgetId() { diff --git a/core/res/res/values-sw600dp/dimens.xml b/core/res/res/values-sw600dp/dimens.xml index 551c1d8..5b488c0 100644 --- a/core/res/res/values-sw600dp/dimens.xml +++ b/core/res/res/values-sw600dp/dimens.xml @@ -60,6 +60,12 @@ <!-- Compensate for double margin : preference_screen_side_margin + 4 (frame background shadow) = -preference_screen_side_margin_negative --> <dimen name="preference_screen_side_margin_negative">-4dp</dimen> + <!-- Default padding to apply to AppWidgetHostViews containing widgets targeting API level 14 and up. --> + <dimen name="default_app_widget_padding_left">12dp</dimen> + <dimen name="default_app_widget_padding_top">12dp</dimen> + <dimen name="default_app_widget_padding_right">4dp</dimen> + <dimen name="default_app_widget_padding_bottom">20dp</dimen> + <!-- Minimum width for an action button in the menu area of an action bar --> <dimen name="action_button_min_width">64dip</dimen> </resources> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 97d5afe..4d97ad2 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1974,5 +1974,4 @@ <public type="color" name="holo_orange_dark" id="0x01060019" /> <public type="color" name="holo_purple" id="0x0106001a" /> <public type="color" name="holo_blue_bright" id="0x0106001b" /> - </resources> |