summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/ShortcutAndWidgetContainer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/ShortcutAndWidgetContainer.java')
-rw-r--r--src/com/android/launcher3/ShortcutAndWidgetContainer.java30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
index 9568d5792..6c7376230 100644
--- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java
+++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java
@@ -18,6 +18,7 @@ package com.android.launcher3;
import android.app.WallpaperManager;
import android.content.Context;
+import android.graphics.PointF;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
@@ -100,20 +101,20 @@ public class ShortcutAndWidgetContainer extends ViewGroup {
}
public void measureChild(View child) {
- final DeviceProfile grid = mLauncher.getDeviceProfile();
- final int cellWidth = mCellWidth;
- final int cellHeight = mCellHeight;
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
if (!lp.isFullscreen) {
- lp.setup(cellWidth, cellHeight, invertLayoutHorizontally(), mCountX);
+ final DeviceProfile profile = mLauncher.getDeviceProfile();
if (child instanceof LauncherAppWidgetHostView) {
- // Widgets have their own padding, so skip
+ lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX,
+ profile.appWidgetScale.x, profile.appWidgetScale.y);
+ // Widgets have their own padding
} else {
- // Otherwise, center the icon/folder
+ lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX);
+ // Center the icon/folder
int cHeight = getCellContentHeight();
int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f));
- int cellPaddingX = (int) (grid.edgeMarginPx / 2f);
+ int cellPaddingX = (int) (profile.edgeMarginPx / 2f);
child.setPadding(cellPaddingX, cellPaddingY, cellPaddingX, 0);
}
} else {
@@ -138,6 +139,21 @@ public class ShortcutAndWidgetContainer extends ViewGroup {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+
+ if (child instanceof LauncherAppWidgetHostView) {
+ // Scale and center the widget to fit within its cells.
+ DeviceProfile profile = mLauncher.getDeviceProfile();
+ float scaleX = profile.appWidgetScale.x;
+ float scaleY = profile.appWidgetScale.y;
+
+ float scale = Math.min(scaleX, scaleY);
+ child.setScaleX(scale);
+ child.setScaleY(scale);
+
+ child.setTranslationX(-(lp.width - (lp.width * scaleX)) / 2.0f);
+ child.setTranslationY(-(lp.height - (lp.height * scaleY)) / 2.0f);
+ }
+
int childLeft = lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);