summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/Launcher.java
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2011-08-25 18:57:14 -0700
committerAdam Cohen <adamcohen@google.com>2011-08-25 18:57:14 -0700
commit50370f325748c7bddbe91f6a2ea49065f584f14f (patch)
treedea856ef08212207339952a032665a0e1d1af4e8 /src/com/android/launcher2/Launcher.java
parent7ef918374acd7e1564fa1462053b8ac0bfd4ed67 (diff)
downloadpackages_apps_trebuchet-50370f325748c7bddbe91f6a2ea49065f584f14f.zip
packages_apps_trebuchet-50370f325748c7bddbe91f6a2ea49065f584f14f.tar.gz
packages_apps_trebuchet-50370f325748c7bddbe91f6a2ea49065f584f14f.tar.bz2
Automatically padding widgets based on target API level
Change-Id: I062c487df1067a787e9921e85558b38294a10112
Diffstat (limited to 'src/com/android/launcher2/Launcher.java')
-rw-r--r--src/com/android/launcher2/Launcher.java48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 22a34e6..6c446a2 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -52,6 +52,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
@@ -74,8 +75,8 @@ import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
-import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
+import android.view.View.OnLongClickListener;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.InputMethodManager;
@@ -729,8 +730,6 @@ public final class Launcher extends Activity
}
}
-
-
/**
* Creates a view representing a shortcut.
*
@@ -845,6 +844,39 @@ public final class Launcher extends Activity
}
}
+ class Padding {
+ int left = 0;
+ int right = 0;
+ int top = 0;
+ int bottom = 0;
+ }
+
+ Padding getPaddingForWidget(AppWidgetProviderInfo widgetInfo) {
+ PackageManager packageManager = getPackageManager();
+ Padding p = new Padding();
+ android.content.pm.ApplicationInfo appInfo;
+
+ try {
+ appInfo = packageManager.getApplicationInfo(
+ widgetInfo.provider.getPackageName(), 0);
+ } catch (Exception e) {
+ // if we can't find the package, return 0 padding
+ return p;
+ }
+
+ // TODO: This should be ICE_CREAM_SANDWICH, but since the unbundled apps
+ // may not have updated their targetSdkVersion yet, we've bumped it down for now.
+ if (appInfo.targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB_MR2) {
+ Resources r = getResources();
+ p.left = r.getDimensionPixelSize(R.dimen.app_widget_padding_left);
+ p.right = r.getDimensionPixelSize(R.dimen.app_widget_padding_right);
+ p.top = r.getDimensionPixelSize(R.dimen.app_widget_padding_top);
+ p.bottom = r.getDimensionPixelSize(R.dimen.app_widget_padding_bottom);
+ }
+
+ return p;
+ }
+
/**
* Add a widget to the workspace.
*
@@ -857,15 +889,11 @@ public final class Launcher extends Activity
// Calculate the grid spans needed to fit this widget
CellLayout layout = getCellLayout(container, screen);
+ Padding padding = getPaddingForWidget(appWidgetInfo);
// We want to account for the extra amount of padding that we are adding to the widget
// to ensure that it gets the full amount of space that it has requested
- Resources r = getResources();
- int requiredWidth = appWidgetInfo.minWidth +
- r.getDimensionPixelSize(R.dimen.app_widget_padding_left) +
- r.getDimensionPixelSize(R.dimen.app_widget_padding_right);
- int requiredHeight = appWidgetInfo.minHeight +
- r.getDimensionPixelSize(R.dimen.app_widget_padding_top) +
- r.getDimensionPixelSize(R.dimen.app_widget_padding_bottom);
+ int requiredWidth = appWidgetInfo.minWidth + padding.left + padding.right;
+ int requiredHeight = appWidgetInfo.minHeight + padding.top + padding.bottom;
int[] spanXY = layout.rectToCell(requiredWidth, requiredHeight, null);
// Try finding open space on Launcher screen