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

Commit 92406ab4 authored by Joey's avatar Joey Committed by Michael Bestas
Browse files

Trebuchet: add toggle for desktop and drawer labels



Squashed with:

Author: razorloves <razorloves@gmail.com>
Date:   Wed Jan 8 23:53:25 2020 -0600

    Trebuchet: Fix missing icon labels in folders

    Fixes regression introduced in 186796eb.

    Change-Id: I1e6054fe84ea54bf2a85bf6d26760196ffe78f69

Change-Id: I98063b7adaf22029c4bfa50d2cac730f3612e121
Signed-off-by: default avatarJoey <joey@lineageos.org>
parent 82d22663
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,4 +19,8 @@

    <!-- Folder titles -->
    <string name="google_folder_title" translatable="false">Google</string>

    <!-- Hide labels -->
    <string name="desktop_show_labels">Show icon labels on desktop</string>
    <string name="drawer_show_labels">Show icon labels in drawer</string>
</resources>
+11 −0
Original line number Diff line number Diff line
@@ -50,4 +50,15 @@
        android:title="Developer Options"
        android:fragment="com.android.launcher3.settings.DeveloperOptionsFragment"/>

    <SwitchPreference
        android:key="pref_desktop_show_labels"
        android:title="@string/desktop_show_labels"
        android:defaultValue="true"
        android:persistent="true" />

    <SwitchPreference
        android:key="pref_drawer_show_labels"
        android:title="@string/drawer_show_labels"
        android:defaultValue="true"
        android:persistent="true" />
</androidx.preference.PreferenceScreen>
+14 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.launcher3;

import static com.android.launcher3.FastBitmapDrawable.newIcon;
import static com.android.launcher3.InvariantDeviceProfile.KEY_SHOW_DESKTOP_LABELS;
import static com.android.launcher3.InvariantDeviceProfile.KEY_SHOW_DRAWER_LABELS;
import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;

@@ -24,6 +26,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -145,6 +148,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
    @ViewDebug.ExportedProperty(category = "launcher")
    private boolean mDisableRelayout = false;

    private boolean mShouldShowLabel;

    private IconLoadRequest mIconLoadRequest;

    public BubbleTextView(Context context) {
@@ -164,23 +169,29 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
        DeviceProfile grid = mActivity.getDeviceProfile();

        SharedPreferences prefs = Utilities.getPrefs(context.getApplicationContext());

        mDisplay = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
        final int defaultIconSize;
        if (mDisplay == DISPLAY_WORKSPACE) {
            setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
            setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
            defaultIconSize = grid.iconSizePx;
            mShouldShowLabel = prefs.getBoolean(KEY_SHOW_DESKTOP_LABELS, true);
        } else if (mDisplay == DISPLAY_ALL_APPS) {
            setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
            setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
            defaultIconSize = grid.allAppsIconSizePx;
            mShouldShowLabel = prefs.getBoolean(KEY_SHOW_DRAWER_LABELS, true);
        } else if (mDisplay == DISPLAY_FOLDER) {
            setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
            setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
            defaultIconSize = grid.folderChildIconSizePx;
            mShouldShowLabel = prefs.getBoolean(KEY_SHOW_DESKTOP_LABELS, true);
        } else {
            // widget_selection or shortcut_popup
            defaultIconSize = grid.iconSizePx;
            mShouldShowLabel = prefs.getBoolean(KEY_SHOW_DESKTOP_LABELS, true);
        }

        mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);
@@ -291,7 +302,9 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        mDotParams.color = IconPalette.getMutedColor(info.bitmap.color, 0.54f);

        setIcon(iconDrawable);
        if (mShouldShowLabel) {
            setText(info.title);
        }
        if (info.contentDescription != null) {
            setContentDescription(info.isDisabled()
                    ? getContext().getString(R.string.disabled_app_label, info.contentDescription)
+19 −2
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -61,7 +63,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class InvariantDeviceProfile {
public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener {

    public static final String TAG = "IDP";
    // We do not need any synchronization for this variable as its only written on UI thread.
@@ -78,6 +80,8 @@ public class InvariantDeviceProfile {
    public static final int CHANGE_FLAG_GRID = 1 << 0;
    public static final int CHANGE_FLAG_ICON_PARAMS = 1 << 1;

    public static final String KEY_SHOW_DESKTOP_LABELS = "pref_desktop_show_labels";
    public static final String KEY_SHOW_DRAWER_LABELS = "pref_drawer_show_labels";
    public static final String KEY_ICON_PATH_REF = "pref_icon_shape_path";

    // Constants that affects the interpolation curve between statically defined device profile
@@ -137,6 +141,8 @@ public class InvariantDeviceProfile {
    private ConfigMonitor mConfigMonitor;
    private OverlayMonitor mOverlayMonitor;

    private Context mContext;

    @VisibleForTesting
    public InvariantDeviceProfile() {}

@@ -163,10 +169,14 @@ public class InvariantDeviceProfile {

    @TargetApi(23)
    private InvariantDeviceProfile(Context context) {
        mContext = context;

        SharedPreferences prefs = Utilities.getPrefs(context);
        prefs.registerOnSharedPreferenceChangeListener(this);
        String gridName = getCurrentGridName(context);
        String newGridName = initGrid(context, gridName);
        if (!newGridName.equals(gridName)) {
            Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
            prefs.edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
        }
        Utilities.getPrefs(context).edit()
                .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numHotseatIcons)
@@ -188,6 +198,13 @@ public class InvariantDeviceProfile {
        }
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
        if (KEY_SHOW_DESKTOP_LABELS.equals(key) || KEY_SHOW_DRAWER_LABELS.equals(key)) {
            apply(mContext, CHANGE_FLAG_ICON_PARAMS);
        }
    }

    /**
     * This constructor should NOT have any monitors by design.
     */