Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b383af6 authored by vadimt's avatar vadimt
Browse files

Not using magic constants for navbar height

Change-Id: I6783b8a2ebb059ce35748d8c3e818cbe732ff40d
parent e627accf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ android_library {
    srcs: [
        "tests/tapl/**/*.java",
        "src/com/android/launcher3/util/SecureSettingsObserver.java",
        "src/com/android/launcher3/ResourceUtils.java",
        "src/com/android/launcher3/TestProtocol.java",
    ],
    manifest: "tests/tapl/AndroidManifest.xml",
+7 −17
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.Region;
@@ -58,6 +57,7 @@ import android.view.WindowManager;

import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.ResourceUtils;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.logging.EventLogArray;
@@ -90,9 +90,6 @@ public class TouchInteractionService extends Service implements
    public static final LooperExecutor BACKGROUND_EXECUTOR =
            new LooperExecutor(UiThreadHelper.getBackgroundLooper());

    private static final String NAVBAR_VERTICAL_SIZE = "navigation_bar_frame_height";
    private static final String NAVBAR_HORIZONTAL_SIZE = "navigation_bar_width";

    public static final EventLogArray TOUCH_INTERACTION_LOG =
            new EventLogArray("touch_interaction_log", 40);

@@ -291,15 +288,7 @@ public class TouchInteractionService extends Service implements
    }

    private int getNavbarSize(String resName) {
        int frameSize;
        Resources res = getResources();
        int frameSizeResID = res.getIdentifier(resName, "dimen", "android");
        if (frameSizeResID != 0) {
            frameSize = res.getDimensionPixelSize(frameSizeResID);
        } else {
            frameSize = Utilities.pxFromDp(48, res.getDisplayMetrics());
        }
        return frameSize;
        return ResourceUtils.getNavbarSize(resName, getResources());
    }

    private void initTouchBounds() {
@@ -312,20 +301,21 @@ public class TouchInteractionService extends Service implements
        defaultDisplay.getRealSize(realSize);
        mSwipeTouchRegion.set(0, 0, realSize.x, realSize.y);
        if (mMode == Mode.NO_BUTTON) {
            mSwipeTouchRegion.top = mSwipeTouchRegion.bottom - getNavbarSize(NAVBAR_VERTICAL_SIZE);
            mSwipeTouchRegion.top = mSwipeTouchRegion.bottom - getNavbarSize(
                    ResourceUtils.NAVBAR_VERTICAL_SIZE);
        } else {
            switch (defaultDisplay.getRotation()) {
                case Surface.ROTATION_90:
                    mSwipeTouchRegion.left = mSwipeTouchRegion.right
                            - getNavbarSize(NAVBAR_HORIZONTAL_SIZE);
                            - getNavbarSize(ResourceUtils.NAVBAR_HORIZONTAL_SIZE);
                    break;
                case Surface.ROTATION_270:
                    mSwipeTouchRegion.right = mSwipeTouchRegion.left
                            + getNavbarSize(NAVBAR_HORIZONTAL_SIZE);
                            + getNavbarSize(ResourceUtils.NAVBAR_HORIZONTAL_SIZE);
                    break;
                default:
                    mSwipeTouchRegion.top = mSwipeTouchRegion.bottom
                            - getNavbarSize(NAVBAR_VERTICAL_SIZE);
                            - getNavbarSize(ResourceUtils.NAVBAR_VERTICAL_SIZE);
            }
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -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);

+1 −1
Original line number Diff line number Diff line
@@ -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);

+45 −0
Original line number Diff line number Diff line
/*
 * 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));
    }
}
Loading