Skip to content

Commit

Permalink
add label drawer preference
Browse files Browse the repository at this point in the history
  • Loading branch information
saulhdev committed Jul 28, 2020
1 parent 080cb0b commit 9dbeba5
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Omega/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@
<!-- PREFERENCES DRAWER -->
<string name="title__drawer_sort">Apps Sort</string>
<string name="title__drawer_all_apps">Show "All Apps" label</string>
<string name="title__drawer_mutliline_labels">Multiline app names</string>
<string name="title__drawer_hide_icon_labels">Hide app names</string>

<string name="title__sort_mode">App Sort</string>
<string name="title__sort_alphabetical_az">Alphabetical AZ</string>
<string name="title__sort_alphabetical_za">Alphabetical ZA</string>
<string name="title__sort_last_installed">Last Installed</string>
<string name="title__sort_most_used">Most Used</string>
<string name="title__sort_by_color">By Color</string>

<string name="title_all_apps_search">Drawer search bar</string>
<string name="title_all_apps_google_search">Global search</string>
<string name="summary_all_apps_google_search">Find web results and apps</string>
Expand Down
16 changes: 16 additions & 0 deletions Omega/res/xml/omega_preferences_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
android:title="@string/title__drawer_sort"
app:iconSpaceReserved="false" />

<com.saggitt.omega.preferences.StyledSwitchPreference
android:defaultValue="false"
android:disableDependentsState="true"
android:key="pref_hideAllAppsAppLabels"
android:persistent="true"
android:title="@string/title__drawer_hide_icon_labels"
app:iconSpaceReserved="false" />

<com.saggitt.omega.preferences.StyledSwitchPreference
android:defaultValue="false"
android:dependency="pref_hideAllAppsAppLabels"
android:key="pref_iconLabelsInTwoLines"
android:persistent="true"
android:title="@string/title__drawer_mutliline_labels"
app:iconSpaceReserved="false" />

<!--
<com.saggitt.omega.preferences.StyledSwitchPreference
android:defaultValue="false"
Expand Down
1 change: 1 addition & 0 deletions Omega/src/com/saggitt/omega/OmegaPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class OmegaPreferences(val context: Context) : SharedPreferences.OnSharedPrefere
val drawerPaddingScale by FloatPref("pref_allAppsPaddingScale", 1.0f, recreate)
private val drawerMultilineLabel by BooleanPref("pref_iconLabelsInTwoLines", false, recreate)
val drawerLabelRows get() = if (drawerMultilineLabel) 2 else 1
val hideAllAppsAppLabels by BooleanPref("pref_hideAllAppsAppLabels", false, recreate)

/* --DESKTOP-- */
var autoAddInstalled by BooleanPref("pref_add_icon_to_home", true, doNothing)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {
buildToolsVersion BUILD_TOOLS_VERSION

def name = "0.2.0"
def code = 10
def code = 11

defaultConfig {
minSdkVersion 24
Expand Down
34 changes: 33 additions & 1 deletion src/com/android/launcher3/BubbleTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.util.Property;
Expand Down Expand Up @@ -70,6 +71,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
private static final int DISPLAY_WORKSPACE = 0;
private static final int DISPLAY_ALL_APPS = 1;
private static final int DISPLAY_FOLDER = 2;
private static final int DISPLAY_DRAWER_FOLDER = 5;

private static final int[] STATE_PRESSED = new int[] {android.R.attr.state_pressed};

Expand Down Expand Up @@ -141,6 +143,8 @@ public void set(BubbleTextView bubbleTextView, Float alpha) {

private IconLoadRequest mIconLoadRequest;

private boolean mHideText;

public BubbleTextView(Context context) {
this(context, null, 0);
}
Expand All @@ -160,24 +164,39 @@ public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {

mDisplay = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
final int defaultIconSize;
OmegaPreferences prefs = Utilities.getOmegaPrefs(context);
if (mDisplay == DISPLAY_WORKSPACE) {
DeviceProfile grid = mActivity.getWallpaperDeviceProfile();
setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
defaultIconSize = grid.iconSizePx;
mIgnorePaddingTouch = true;
} else if (mDisplay == DISPLAY_ALL_APPS) {
mHideText = prefs.getHideAllAppsAppLabels();
DeviceProfile grid = mActivity.getDeviceProfile();
setTextSize(TypedValue.COMPLEX_UNIT_PX, isTextHidden() ? 0 : grid.allAppsIconTextSizePx);
setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
defaultIconSize = grid.allAppsIconSizePx;
int lines = prefs.getDrawerLabelRows();
setLineCount(lines);
mIgnorePaddingTouch = true;
} else if (mDisplay == DISPLAY_FOLDER) {
DeviceProfile grid = mActivity.getDeviceProfile();
setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.folderChildTextSizePx);
setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
defaultIconSize = grid.folderChildIconSizePx;
mIgnorePaddingTouch = true;
} else if (mDisplay == DISPLAY_DRAWER_FOLDER) {
mHideText = prefs.getHideAllAppsAppLabels();
DeviceProfile grid = mActivity.getDeviceProfile();
setTextSize(TypedValue.COMPLEX_UNIT_PX,
isTextHidden() ? 0 : grid.allAppsFolderChildTextSizePx);
setCompoundDrawablePadding(grid.allAppsFolderChildDrawablePaddingPx);
defaultIconSize = grid.allAppsFolderChildIconSizePx;
int lines = prefs.getDrawerLabelRows();
setLineCount(lines);
mIgnorePaddingTouch = true;
} else {
// widget_selection or shortcut_popup
defaultIconSize = mActivity.getDeviceProfile().iconSizePx;
Expand All @@ -200,6 +219,14 @@ public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
setTextAlpha(1f);
}

public void setLineCount(int lines) {
setMaxLines(lines);
setSingleLine(lines == 1);
setEllipsize(TextUtils.TruncateAt.END);
// This shouldn't even be needed, what is going on?!
setLines(lines);
}

@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
// Disable marques when not focused to that, so that updating text does not cause relayout.
Expand Down Expand Up @@ -297,7 +324,8 @@ private void applyIconAndLabel(ItemInfoWithIcon info) {
mDotParams.color = IconPalette.getMutedColor(info.iconColor, 0.54f);
}
setIcon(iconDrawable);
setText(info.title);
if (!isTextHidden())
setText(info.title);
if (info.contentDescription != null) {
setContentDescription(info.isDisabled()
? getContext().getString(R.string.disabled_app_label, info.contentDescription)
Expand Down Expand Up @@ -715,4 +743,8 @@ public void verifyHighRes() {
public int getIconSize() {
return mIconSize;
}

protected boolean isTextHidden() {
return mHideText;
}
}
41 changes: 37 additions & 4 deletions src/com/android/launcher3/DeviceProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,19 @@ public class DeviceProfile implements OmegaPreferences.OnPreferenceChangeListene
public int folderCellWidthPx;
public int folderCellHeightPx;

// Drawer folder cell
public int allAppsFolderCellWidthPx;

// Folder child
public int folderChildIconSizePx;
public int folderChildTextSizePx;
public int folderChildDrawablePaddingPx;
public int allAppsFolderCellHeightPx;

// Drawer folder child
public int allAppsFolderChildIconSizePx;
public int allAppsFolderChildTextSizePx;
public int allAppsFolderChildDrawablePaddingPx;

// Hotseat
public int hotseatCellHeightPx;
Expand Down Expand Up @@ -461,12 +470,14 @@ private void adjustToHideWorkspaceLabels() {
iconDrawablePaddingPx = 0;
cellHeightPx = iconSizePx;

int labelRows = prefs.getDrawerLabelRows();

// In normal cases, All Apps cell height should equal the Workspace cell height.
// Since we are removing labels from the Workspace, we need to manually compute the
// All Apps cell height.
int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
+ Utilities.calculateTextHeight(allAppsIconTextSizePx)
+ Utilities.calculateTextHeight(allAppsIconTextSizePx) * labelRows
+ topBottomPadding * 2;
}

Expand Down Expand Up @@ -591,19 +602,22 @@ private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources re
Point totalWorkspacePadding = getTotalWorkspacePadding();

// Check if the icons fit within the available height.
float contentUsedHeight = folderCellHeightPx * inv.numFolderRows;
float contentUsedHeight = allAppsFolderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
- folderMargin;
float scaleY = contentMaxHeight / contentUsedHeight;

// Drawer Folders
updateDrawerFolderCellSize(1f, dm, res);

// Check if the icons fit within the available width.
float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns;
float contentUsedWidth = allAppsFolderCellHeightPx * inv.numFolderColumns;
int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin;
float scaleX = contentMaxWidth / contentUsedWidth;

float scale = Math.min(scaleX, scaleY);
if (scale < 1f) {
updateFolderCellSize(scale, dm, res);
updateDrawerFolderCellSize(scale, dm, res);
}
}

Expand All @@ -622,6 +636,25 @@ private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res)
(folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
}

private void updateDrawerFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
// Drawer folders
int folderLabelRowCount = Utilities.getOmegaPrefs(mContext).getHomeLabelRows();

allAppsFolderChildIconSizePx = (int) (Utilities.pxFromDp(inv.allAppsIconSize, dm) * scale);
allAppsFolderChildTextSizePx =
(int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);

int textHeight =
Utilities.calculateTextHeight(allAppsFolderChildTextSizePx) * folderLabelRowCount;
int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);

allAppsFolderCellWidthPx = allAppsFolderChildIconSizePx + 2 * cellPaddingX;
allAppsFolderCellHeightPx = allAppsFolderChildIconSizePx + 2 * cellPaddingY + textHeight;
allAppsFolderChildDrawablePaddingPx = Math.max(0,
(allAppsFolderCellHeightPx - allAppsFolderChildIconSizePx - textHeight) / 3);
}

public void updateInsets(Rect insets) {
mInsets.set(insets);
updateWorkspacePadding();
Expand Down

0 comments on commit 9dbeba5

Please sign in to comment.