diff options
author | Winson Chung <winsonc@google.com> | 2013-08-20 16:56:15 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2013-08-20 17:12:22 -0700 |
commit | 6670073de833cb56dabecb1eb751b6625a5aed78 (patch) | |
tree | e084ea7df0b300cbe1e6d4a3e83b5092754b7719 /src | |
parent | 81d6f6ecca788e6c300dfbc7d732a3867859fbd8 (diff) | |
download | android_packages_apps_Trebuchet-6670073de833cb56dabecb1eb751b6625a5aed78.tar.gz android_packages_apps_Trebuchet-6670073de833cb56dabecb1eb751b6625a5aed78.tar.bz2 android_packages_apps_Trebuchet-6670073de833cb56dabecb1eb751b6625a5aed78.zip |
Fixing issue with widget sizes being misreported.
- Fixing NPE with getting page indicators in phone landscape
Change-Id: Id369596e38cbe7a161c0d1f62e62e4f4f3cc31b3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/CellLayout.java | 22 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 25 |
3 files changed, 29 insertions, 20 deletions
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index abc057c8d..a516e4e01 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -927,12 +927,12 @@ public class CellLayout extends ViewGroup { return r; } - static void getMetrics(Rect metrics, Resources res, int measureWidth, int measureHeight, - int countX, int countY, int orientation) { + static void getMetrics(Rect metrics, int paddedMeasureWidth, + int paddedMeasureHeight, int countX, int countY) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); - metrics.set(grid.calculateCellWidth(measureWidth, countX), - grid.calculateCellHeight(measureHeight, countY), 0, 0); + metrics.set(grid.calculateCellWidth(paddedMeasureWidth, countX), + grid.calculateCellHeight(paddedMeasureHeight, countY), 0, 0); } public void setFixedSize(int width, int height) { @@ -2961,18 +2961,22 @@ public class CellLayout extends ViewGroup { * @param result An array of length 2 in which to store the result (may be null). */ public int[] rectToCell(int width, int height, int[] result) { - return rectToCell(getResources(), width, height, result); + return rectToCell(width, height, result); } - public static int[] rectToCell(Resources resources, int width, int height, int[] result) { + public static int[] rectToCell(int width, int height, int[] result) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); + Rect padding = grid.getWorkspacePadding(grid.isLandscape ? + CellLayout.LANDSCAPE : CellLayout.PORTRAIT); // Always assume we're working with the smallest span to make sure we // reserve enough space in both orientations. - int actualWidth = grid.cellWidthPx; - int actualHeight = grid.cellHeightPx; - int smallerSize = Math.min(actualWidth, actualHeight); + int parentWidth = grid.calculateCellWidth(grid.widthPx + - padding.left - padding.right, (int) grid.numColumns); + int parentHeight = grid.calculateCellHeight(grid.heightPx + - padding.top - padding.bottom, (int) grid.numRows); + int smallerSize = Math.min(parentWidth, parentHeight); // Always round up to next largest cell int spanX = (int) Math.ceil(width / (float) smallerSize); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 88046e4e0..9ffc572eb 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1267,7 +1267,7 @@ public class Launcher extends Activity // to ensure that it gets the full amount of space that it has requested int requiredWidth = minWidth + padding.left + padding.right; int requiredHeight = minHeight + padding.top + padding.bottom; - return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null); + return CellLayout.rectToCell(requiredWidth, requiredHeight, null); } static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 696b702c8..b2f74330f 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1878,16 +1878,21 @@ public class Workspace extends SmoothPagedView } } } + ObjectAnimator pageIndicatorAlpha = null; + if (getPageIndicator() != null) { + pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", + finalHotseatAndPageIndicatorAlpha); + } ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(mLauncher.getHotseat(), "alpha", finalHotseatAndPageIndicatorAlpha); - ObjectAnimator pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha", - finalHotseatAndPageIndicatorAlpha); ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(mLauncher.getOverviewPanel(), "alpha", finalOverviewPanelAlpha); overviewPanelAlpha.addUpdateListener(new AlphaUpdateListener( mLauncher.getOverviewPanel())); hotseatAlpha.addUpdateListener(new AlphaUpdateListener(mLauncher.getHotseat())); - pageIndicatorAlpha.addUpdateListener(new AlphaUpdateListener(getPageIndicator())); + if (getPageIndicator() != null) { + pageIndicatorAlpha.addUpdateListener(new AlphaUpdateListener(getPageIndicator())); + } anim.play(overviewPanelAlpha); anim.play(hotseatAlpha); anim.play(pageIndicatorAlpha); @@ -1895,7 +1900,9 @@ public class Workspace extends SmoothPagedView } else { mLauncher.getOverviewPanel().setAlpha(finalOverviewPanelAlpha); mLauncher.getHotseat().setAlpha(finalHotseatAndPageIndicatorAlpha); - getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); + if (getPageIndicator() != null) { + getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha); + } } if (stateIsSpringLoaded) { @@ -2634,9 +2641,8 @@ public class Workspace extends SmoothPagedView int width = largestSize.x - padding.left - padding.right; int height = smallestSize.y - padding.top - padding.bottom; mLandscapeCellLayoutMetrics = new Rect(); - CellLayout.getMetrics(mLandscapeCellLayoutMetrics, res, - width, height, LauncherModel.getCellCountX(), LauncherModel.getCellCountY(), - orientation); + CellLayout.getMetrics(mLandscapeCellLayoutMetrics, width, height, + LauncherModel.getCellCountX(), LauncherModel.getCellCountY()); } return mLandscapeCellLayoutMetrics; } else if (orientation == CellLayout.PORTRAIT) { @@ -2645,9 +2651,8 @@ public class Workspace extends SmoothPagedView int width = smallestSize.x - padding.left - padding.right; int height = largestSize.y - padding.top - padding.bottom; mPortraitCellLayoutMetrics = new Rect(); - CellLayout.getMetrics(mPortraitCellLayoutMetrics, res, - width, height, LauncherModel.getCellCountX(), LauncherModel.getCellCountY(), - orientation); + CellLayout.getMetrics(mPortraitCellLayoutMetrics, width, height, + LauncherModel.getCellCountX(), LauncherModel.getCellCountY()); } return mPortraitCellLayoutMetrics; } |