Merge "Fixing issue where last workspace page was offset when rotated. (Bug 6413570)" into jb-dev
diff --git a/res/values-ms/strings.xml b/res/values-ms/strings.xml
index 2c13cf1..29b8f7d 100644
--- a/res/values-ms/strings.xml
+++ b/res/values-ms/strings.xml
@@ -40,8 +40,7 @@
<string name="group_shortcuts" msgid="9133529424900391877">"Pintasan"</string>
<string name="group_widgets" msgid="6704978494073105844">"Widget"</string>
<string name="group_wallpapers" msgid="1568191644272224858">"Kertas dinding"</string>
- <!-- no translation found for completely_out_of_space (1759078539443491182) -->
- <skip />
+ <string name="completely_out_of_space" msgid="1759078539443491182">"Tiada lagi ruang pada skrin Utama anda."</string>
<string name="out_of_space" msgid="8365249326091984698">"Tiada lagi ruang pada skrin Utama ini"</string>
<string name="hotseat_out_of_space" msgid="6304886797358479361">"Tiada lagi ruang pada kerusi panas."</string>
<string name="invalid_hotseat_item" msgid="6545340627805449250">"Widget ini terlalu besar untuk kerusi panas."</string>
diff --git a/res/values-pl/strings.xml b/res/values-pl/strings.xml
index 7a15e41..2e434bd 100644
--- a/res/values-pl/strings.xml
+++ b/res/values-pl/strings.xml
@@ -40,8 +40,7 @@
<string name="group_shortcuts" msgid="9133529424900391877">"Skróty"</string>
<string name="group_widgets" msgid="6704978494073105844">"Widżety"</string>
<string name="group_wallpapers" msgid="1568191644272224858">"Tapety"</string>
- <!-- no translation found for completely_out_of_space (1759078539443491182) -->
- <skip />
+ <string name="completely_out_of_space" msgid="1759078539443491182">"Brak miejsca na Twoich ekranach głównych."</string>
<string name="out_of_space" msgid="8365249326091984698">"Brak miejsca na tej stronie głównej"</string>
<string name="hotseat_out_of_space" msgid="6304886797358479361">"Brak miejsca w kieszonce."</string>
<string name="invalid_hotseat_item" msgid="6545340627805449250">"Ten widżet jest za duży, aby umieścić go w kieszonce."</string>
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index a79c704..e430420 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -40,8 +40,7 @@
<string name="group_shortcuts" msgid="9133529424900391877">"快捷方式"</string>
<string name="group_widgets" msgid="6704978494073105844">"窗口小部件"</string>
<string name="group_wallpapers" msgid="1568191644272224858">"壁纸"</string>
- <!-- no translation found for completely_out_of_space (1759078539443491182) -->
- <skip />
+ <string name="completely_out_of_space" msgid="1759078539443491182">"您的主屏幕上没有空间了。"</string>
<string name="out_of_space" msgid="8365249326091984698">"此主屏幕上已没有空间。"</string>
<string name="hotseat_out_of_space" msgid="6304886797358479361">"底部区域已无空间。"</string>
<string name="invalid_hotseat_item" msgid="6545340627805449250">"该窗口小部件太大,超出基座区域可用空间。"</string>
diff --git a/src/com/android/launcher2/AppWidgetResizeFrame.java b/src/com/android/launcher2/AppWidgetResizeFrame.java
index 9df6f32..7281a6f 100644
--- a/src/com/android/launcher2/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher2/AppWidgetResizeFrame.java
@@ -307,11 +307,38 @@
lp.cellVSpan = spanY;
mRunningVInc += vSpanDelta;
mRunningHInc += hSpanDelta;
+ if (!onDismiss) {
+ updateWidgetSizeRanges(mWidgetView, mLauncher, spanX, spanY);
+ }
}
-
mWidgetView.requestLayout();
}
+ static void updateWidgetSizeRanges(AppWidgetHostView widgetView, Launcher launcher,
+ int spanX, int spanY) {
+ Rect landMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.LANDSCAPE);
+ Rect portMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.PORTRAIT);
+ final float density = launcher.getResources().getDisplayMetrics().density;
+
+ // Compute landscape size
+ int cellWidth = landMetrics.left;
+ int cellHeight = landMetrics.top;
+ int widthGap = landMetrics.right;
+ int heightGap = landMetrics.bottom;
+ int landWidth = (int) ((spanX * cellWidth + (spanX - 1) * widthGap) / density);
+ int landHeight = (int) ((spanY * cellHeight + (spanY - 1) * heightGap) / density);
+
+ // Compute portrait size
+ cellWidth = portMetrics.left;
+ cellHeight = portMetrics.top;
+ widthGap = portMetrics.right;
+ heightGap = portMetrics.bottom;
+ int portWidth = (int) ((spanX * cellWidth + (spanX - 1) * widthGap) / density);
+ int portHeight = (int) ((spanY * cellHeight + (spanY - 1) * heightGap) / density);
+
+ widgetView.updateAppWidgetSize(null, portWidth, landHeight, landWidth, portHeight);
+ }
+
/**
* This is the final step of the resize. Here we save the new widget size and position
* to LauncherModel and animate the resize frame.
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 24e4047..2772d5c 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -146,6 +146,9 @@
private static final boolean DESTRUCTIVE_REORDER = false;
private static final boolean DEBUG_VISUALIZE_OCCUPIED = false;
+ static final int LANDSCAPE = 0;
+ static final int PORTRAIT = 1;
+
private static final float REORDER_HINT_MAGNITUDE = 0.27f;
private static final int REORDER_ANIMATION_DURATION = 150;
private float mReorderHintAnimationMagnitude;
@@ -910,11 +913,10 @@
return r;
}
- final int LANDSCAPE = 0;
- final int PORTRAIT = 1;
- void getCellLayoutMetrics(int measureWidth, int measureHeight, int orientation, Rect metrics) {
- int numWidthGaps = mCountX - 1;
- int numHeightGaps = mCountY - 1;
+ static void getMetrics(Rect metrics, Resources res, int measureWidth, int measureHeight,
+ int countX, int countY, int orientation) {
+ int numWidthGaps = countX - 1;
+ int numHeightGaps = countY - 1;
int widthGap;
int heightGap;
@@ -925,7 +927,7 @@
int paddingTop;
int paddingBottom;
- Resources res = getContext().getResources();
+ int maxGap = res.getDimensionPixelSize(R.dimen.workspace_max_gap);
if (orientation == LANDSCAPE) {
cellWidth = res.getDimensionPixelSize(R.dimen.workspace_cell_width_land);
cellHeight = res.getDimensionPixelSize(R.dimen.workspace_cell_height_land);
@@ -950,18 +952,16 @@
if (widthGap < 0 || heightGap < 0) {
int hSpace = measureWidth - paddingLeft - paddingRight;
int vSpace = measureHeight - paddingTop - paddingBottom;
- int hFreeSpace = hSpace - (mCountX * cellWidth);
- int vFreeSpace = vSpace - (mCountY * cellHeight);
- widthGap = Math.min(mMaxGap, numWidthGaps > 0 ? (hFreeSpace / numWidthGaps) : 0);
- heightGap = Math.min(mMaxGap, numHeightGaps > 0 ? (vFreeSpace / numHeightGaps) : 0);
+ int hFreeSpace = hSpace - (countX * cellWidth);
+ int vFreeSpace = vSpace - (countY * cellHeight);
+ widthGap = Math.min(maxGap, numWidthGaps > 0 ? (hFreeSpace / numWidthGaps) : 0);
+ heightGap = Math.min(maxGap, numHeightGaps > 0 ? (vFreeSpace / numHeightGaps) : 0);
}
metrics.set(cellWidth, cellHeight, widthGap, heightGap);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- // TODO: currently ignoring padding
-
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 028a451..dbc3f2d 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -1102,6 +1102,8 @@
launcherInfo.hostView.setTag(launcherInfo);
launcherInfo.hostView.setVisibility(View.VISIBLE);
+ AppWidgetResizeFrame.updateWidgetSizeRanges(launcherInfo.hostView,
+ this, launcherInfo.spanX, launcherInfo.spanY);
mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 84787a2..404efc2 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -122,6 +122,9 @@
private int mDragOverX = -1;
private int mDragOverY = -1;
+ static Rect mLandscapeCellLayoutMetrics = null;
+ static Rect mPortraitCellLayoutMetrics = null;
+
/**
* The CellLayout that is currently being dragged over
*/
@@ -2389,6 +2392,44 @@
}
}
+ static Rect getCellLayoutMetrics(Launcher launcher, int orientation) {
+ Resources res = launcher.getResources();
+ Display display = launcher.getWindowManager().getDefaultDisplay();
+ Point smallestSize = new Point();
+ Point largestSize = new Point();
+ display.getCurrentSizeRange(smallestSize, largestSize);
+ if (orientation == CellLayout.LANDSCAPE) {
+ if (mLandscapeCellLayoutMetrics == null) {
+ int paddingLeft = res.getDimensionPixelSize(R.dimen.workspace_left_padding_land);
+ int paddingRight = res.getDimensionPixelSize(R.dimen.workspace_right_padding_land);
+ int paddingTop = res.getDimensionPixelSize(R.dimen.workspace_top_padding_land);
+ int paddingBottom = res.getDimensionPixelSize(R.dimen.workspace_bottom_padding_land);
+ int width = largestSize.x - paddingLeft - paddingRight;
+ int height = smallestSize.y - paddingTop - paddingBottom;
+ mLandscapeCellLayoutMetrics = new Rect();
+ CellLayout.getMetrics(mLandscapeCellLayoutMetrics, res,
+ width, height, LauncherModel.getCellCountX(), LauncherModel.getCellCountY(),
+ orientation);
+ }
+ return mLandscapeCellLayoutMetrics;
+ } else if (orientation == CellLayout.PORTRAIT) {
+ if (mPortraitCellLayoutMetrics == null) {
+ int paddingLeft = res.getDimensionPixelSize(R.dimen.workspace_left_padding_land);
+ int paddingRight = res.getDimensionPixelSize(R.dimen.workspace_right_padding_land);
+ int paddingTop = res.getDimensionPixelSize(R.dimen.workspace_top_padding_land);
+ int paddingBottom = res.getDimensionPixelSize(R.dimen.workspace_bottom_padding_land);
+ int width = smallestSize.x - paddingLeft - paddingRight;
+ int height = largestSize.y - paddingTop - paddingBottom;
+ mPortraitCellLayoutMetrics = new Rect();
+ CellLayout.getMetrics(mPortraitCellLayoutMetrics, res,
+ width, height, LauncherModel.getCellCountX(), LauncherModel.getCellCountY(),
+ orientation);
+ }
+ return mPortraitCellLayoutMetrics;
+ }
+ return null;
+ }
+
public void onDragExit(DragObject d) {
mDragEnforcer.onDragExit();