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

Unverified Commit 833ad524 authored by Joey's avatar Joey Committed by Michael Bestas
Browse files

Trebuchet: add toggle for desktop and drawer labels



Co-authored-by: default avatarrazorloves <razorloves@gmail.com>
Co-authored-by: default avatarLuK1337 <priv.luk@gmail.com>
Change-Id: I98063b7adaf22029c4bfa50d2cac730f3612e121
parent 5a4522bf
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -27,4 +27,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>
+12 −0
Original line number Diff line number Diff line
@@ -64,4 +64,16 @@
        android:title="@string/developer_options_title"
        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>
+20 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.launcher3;

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.config.FeatureFlags.ENABLE_ICON_LABEL_AUTO_SCALING;
import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
import static com.android.launcher3.icons.BitmapInfo.FLAG_NO_BADGE;
@@ -26,6 +28,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;
@@ -171,6 +174,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
    @ViewDebug.ExportedProperty(category = "launcher")
    private boolean mDisableRelayout = false;

    private boolean mShouldShowLabel;

    private HandlerRunnable mIconLoadRequest;

    private boolean mEnableIconUpdateAnimation = false;
@@ -194,6 +199,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
                == View.LAYOUT_DIRECTION_RTL);
        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) {
@@ -201,24 +208,30 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
            setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
            defaultIconSize = grid.iconSizePx;
            setCenterVertically(grid.isScalableGrid);
            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 if (mDisplay == DISPLAY_SEARCH_RESULT) {
            defaultIconSize = getResources().getDimensionPixelSize(R.dimen.search_row_icon_size);
            mShouldShowLabel = prefs.getBoolean(KEY_SHOW_DESKTOP_LABELS, true);
        } else if (mDisplay == DISPLAY_SEARCH_RESULT_SMALL) {
            defaultIconSize = getResources().getDimensionPixelSize(
                    R.dimen.search_row_small_icon_size);
            mShouldShowLabel = prefs.getBoolean(KEY_SHOW_DESKTOP_LABELS, true);
        } else if (mDisplay == DISPLAY_TASKBAR) {
            defaultIconSize = grid.iconSizePx;
        } 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);
@@ -383,7 +396,9 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,

    @UiThread
    private void applyLabel(ItemInfoWithIcon info) {
        if (mShouldShowLabel) {
            setText(info.title);
        }
        if (info.contentDescription != null) {
            setContentDescription(info.isDisabled()
                    ? getContext().getString(R.string.disabled_app_label, info.contentDescription)
@@ -657,6 +672,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        }
    }

    public boolean shouldShowLabel() {
        return mShouldShowLabel;
    }

    public boolean shouldTextBeVisible() {
        // Text should be visible everywhere but the hotseat.
        Object tag = getParent() instanceof FolderIcon ? ((View) getParent()).getTag() : getTag();
+19 −2
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import android.annotation.TargetApi;
import android.appwidget.AppWidgetHostView;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -70,7 +72,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;

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.
@@ -88,6 +90,8 @@ public class InvariantDeviceProfile {

    private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;

    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_WORKSPACE_LOCK = "pref_workspace_lock";

    // Constants that affects the interpolation curve between statically defined device profile
@@ -186,6 +190,8 @@ public class InvariantDeviceProfile {
    public Point defaultWallpaperSize;
    public Rect defaultWidgetPadding;

    private Context mContext;

    private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();

    @VisibleForTesting
@@ -193,10 +199,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();
        }
        new DeviceGridState(this).writeToPrefs(context);

@@ -304,6 +314,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)) {
            onConfigChanged(mContext);
        }
    }

    public static String getCurrentGridName(Context context) {
        return Utilities.isGridOptionsEnabled(context)
                ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
+3 −1
Original line number Diff line number Diff line
@@ -197,7 +197,9 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel

        icon.setClipToPadding(false);
        icon.mFolderName = icon.findViewById(R.id.folder_icon_name);
        if (icon.mFolderName.shouldShowLabel()) {
            icon.mFolderName.setText(folderInfo.title);
        }
        icon.mFolderName.setCompoundDrawablePadding(0);
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) icon.mFolderName.getLayoutParams();
        lp.topMargin = grid.iconSizePx + grid.iconDrawablePaddingPx;