diff options
author | vadimt <vadimt@google.com> | 2019-05-08 15:29:37 -0700 |
---|---|---|
committer | vadimt <vadimt@google.com> | 2019-05-08 17:20:34 -0700 |
commit | 1b383af65211c57dce66349e13cf7b6123bddbc7 (patch) | |
tree | 9a7428cc4a54fbee6b71361cd231b23989d794c6 /src | |
parent | e627accf264f75bfa70f8df12c10292b23ef0a12 (diff) | |
download | android_packages_apps_Trebuchet-1b383af65211c57dce66349e13cf7b6123bddbc7.tar.gz android_packages_apps_Trebuchet-1b383af65211c57dce66349e13cf7b6123bddbc7.tar.bz2 android_packages_apps_Trebuchet-1b383af65211c57dce66349e13cf7b6123bddbc7.zip |
Not using magic constants for navbar height
Change-Id: I6783b8a2ebb059ce35748d8c3e818cbe732ff40d
Diffstat (limited to 'src')
7 files changed, 58 insertions, 15 deletions
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 3d2d7cf9e..d098b8cd3 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -213,7 +213,7 @@ public class DeviceProfile { // Add a bit of space between nav bar and hotseat in multi-window vertical bar layout. hotseatBarSidePaddingStartPx = isMultiWindowMode && isVerticalBarLayout() ? edgeMarginPx : 0; - hotseatBarSizePx = Utilities.pxFromDp(inv.iconSize, dm) + (isVerticalBarLayout() + hotseatBarSizePx = ResourceUtils.pxFromDp(inv.iconSize, dm) + (isVerticalBarLayout() ? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx) : (res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size) + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx)); @@ -319,7 +319,7 @@ public class DeviceProfile { // Workspace final boolean isVerticalLayout = isVerticalBarLayout(); float invIconSizePx = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize; - iconSizePx = Math.max(1, (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale)); + iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizePx, dm) * scale)); iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale); @@ -399,7 +399,7 @@ public class DeviceProfile { } private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) { - folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); + folderChildIconSizePx = (int) (ResourceUtils.pxFromDp(inv.iconSize, dm) * scale); folderChildTextSizePx = (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale); diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 819a55147..8a8a2fbe5 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -210,7 +210,7 @@ public class InvariantDeviceProfile { iconSize = interpolatedDisplayOption.iconSize; iconShapePath = getIconShapePath(context); landscapeIconSize = interpolatedDisplayOption.landscapeIconSize; - iconBitmapSize = Utilities.pxFromDp(iconSize, dm); + iconBitmapSize = ResourceUtils.pxFromDp(iconSize, dm); iconTextSize = interpolatedDisplayOption.iconTextSize; fillResIconDpi = getLauncherIconDensity(iconBitmapSize); diff --git a/src/com/android/launcher3/ResourceUtils.java b/src/com/android/launcher3/ResourceUtils.java new file mode 100644 index 000000000..8df3290fd --- /dev/null +++ b/src/com/android/launcher3/ResourceUtils.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.content.res.Resources; +import android.util.DisplayMetrics; +import android.util.TypedValue; + +public class ResourceUtils { + public static final String NAVBAR_VERTICAL_SIZE = "navigation_bar_frame_height"; + public static final String NAVBAR_HORIZONTAL_SIZE = "navigation_bar_width"; + + public static int getNavbarSize(String resName, Resources res) { + return getDimenByName(resName, res, 48); + } + + private static int getDimenByName(String resName, Resources res, int defaultValue) { + final int frameSize; + final int frameSizeResID = res.getIdentifier(resName, "dimen", "android"); + if (frameSizeResID != 0) { + frameSize = res.getDimensionPixelSize(frameSizeResID); + } else { + frameSize = pxFromDp(defaultValue, res.getDisplayMetrics()); + } + return frameSize; + } + + public static int pxFromDp(float size, DisplayMetrics metrics) { + return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size, metrics)); + } +} diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 35b967fda..5cfd95cd0 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -477,10 +477,7 @@ public final class Utilities { float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT; return (size / densityRatio); } - public static int pxFromDp(float size, DisplayMetrics metrics) { - return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, - size, metrics)); - } + public static int pxFromSp(float size, DisplayMetrics metrics) { return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, size, metrics)); diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java index 245003989..0e2ddd464 100644 --- a/src/com/android/launcher3/folder/FolderAnimationManager.java +++ b/src/com/android/launcher3/folder/FolderAnimationManager.java @@ -39,6 +39,7 @@ import com.android.launcher3.BubbleTextView; import com.android.launcher3.CellLayout; import com.android.launcher3.Launcher; import com.android.launcher3.R; +import com.android.launcher3.ResourceUtils; import com.android.launcher3.ShortcutAndWidgetContainer; import com.android.launcher3.Utilities; import com.android.launcher3.anim.PropertyResetListener; @@ -165,7 +166,7 @@ public class FolderAnimationManager { Math.round((totalOffsetX + initialSize) / initialScale), Math.round((paddingOffsetY + initialSize) / initialScale)); Rect endRect = new Rect(0, 0, lp.width, lp.height); - float finalRadius = Utilities.pxFromDp(2, mContext.getResources().getDisplayMetrics()); + float finalRadius = ResourceUtils.pxFromDp(2, mContext.getResources().getDisplayMetrics()); // Create the animators. AnimatorSet a = new AnimatorSet(); diff --git a/src/com/android/launcher3/graphics/WorkspaceAndHotseatScrim.java b/src/com/android/launcher3/graphics/WorkspaceAndHotseatScrim.java index 66f9dbfcd..c0aa75f28 100644 --- a/src/com/android/launcher3/graphics/WorkspaceAndHotseatScrim.java +++ b/src/com/android/launcher3/graphics/WorkspaceAndHotseatScrim.java @@ -43,7 +43,7 @@ import android.view.View; import com.android.launcher3.CellLayout; import com.android.launcher3.Launcher; import com.android.launcher3.R; -import com.android.launcher3.Utilities; +import com.android.launcher3.ResourceUtils; import com.android.launcher3.Workspace; import com.android.launcher3.uioverrides.WallpaperColorInfo; import com.android.launcher3.util.Themes; @@ -148,7 +148,7 @@ public class WorkspaceAndHotseatScrim implements mLauncher = Launcher.getLauncher(view.getContext()); mWallpaperColorInfo = WallpaperColorInfo.getInstance(mLauncher); - mMaskHeight = Utilities.pxFromDp(ALPHA_MASK_BITMAP_DP, + mMaskHeight = ResourceUtils.pxFromDp(ALPHA_MASK_BITMAP_DP, view.getResources().getDisplayMetrics()); mTopScrim = Themes.getAttrDrawable(view.getContext(), R.attr.workspaceStatusBarScrim); mBottomMask = mTopScrim == null ? null : createDitheredAlphaMask(); @@ -297,8 +297,8 @@ public class WorkspaceAndHotseatScrim implements public Bitmap createDitheredAlphaMask() { DisplayMetrics dm = mLauncher.getResources().getDisplayMetrics(); - int width = Utilities.pxFromDp(ALPHA_MASK_WIDTH_DP, dm); - int gradientHeight = Utilities.pxFromDp(ALPHA_MASK_HEIGHT_DP, dm); + int width = ResourceUtils.pxFromDp(ALPHA_MASK_WIDTH_DP, dm); + int gradientHeight = ResourceUtils.pxFromDp(ALPHA_MASK_HEIGHT_DP, dm); Bitmap dst = Bitmap.createBitmap(width, mMaskHeight, Bitmap.Config.ALPHA_8); Canvas c = new Canvas(dst); Paint paint = new Paint(Paint.DITHER_FLAG); diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java index 3e2c0aef4..a7078a2f5 100644 --- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java +++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java @@ -36,7 +36,7 @@ import com.android.launcher3.Insettable; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; -import com.android.launcher3.Utilities; +import com.android.launcher3.ResourceUtils; import com.android.launcher3.anim.Interpolators; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.util.PackageUserKey; @@ -126,7 +126,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { // Otherwise, add an empty view to the start as padding (but still scroll edge to edge). View leftPaddingView = LayoutInflater.from(getContext()).inflate( R.layout.widget_list_divider, widgetRow, false); - leftPaddingView.getLayoutParams().width = Utilities.pxFromDp( + leftPaddingView.getLayoutParams().width = ResourceUtils.pxFromDp( 16, getResources().getDisplayMetrics()); widgetCells.addView(leftPaddingView, 0); } |