From 377ed3f63ec517ed1ec1957dc1122f96f616fe65 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Wed, 20 Jul 2016 15:21:04 -0700 Subject: [PATCH] Add drag handle to shortcuts. Also use short text if long text is ellipsized. Bug: 30212144 Bug: 28980830 Change-Id: I213766bca0561d284d1da883ca37b0a42d886129 --- res/drawable/deep_shortcuts_drag_handle.xml | 26 ++++++++++ res/layout/deep_shortcut.xml | 2 +- res/values/styles.xml | 3 +- src/com/android/launcher3/BubbleTextView.java | 12 +++-- .../shortcuts/DeepShortcutTextView.java | 50 +++++++++++++++++++ .../shortcuts/DeepShortcutsContainer.java | 24 +++++---- 6 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 res/drawable/deep_shortcuts_drag_handle.xml create mode 100644 src/com/android/launcher3/shortcuts/DeepShortcutTextView.java diff --git a/res/drawable/deep_shortcuts_drag_handle.xml b/res/drawable/deep_shortcuts_drag_handle.xml new file mode 100644 index 0000000000..d5fca2ecfc --- /dev/null +++ b/res/drawable/deep_shortcuts_drag_handle.xml @@ -0,0 +1,26 @@ + + + + + + + \ No newline at end of file diff --git a/res/layout/deep_shortcut.xml b/res/layout/deep_shortcut.xml index 089546033e..4fcbbd2066 100644 --- a/res/layout/deep_shortcut.xml +++ b/res/layout/deep_shortcut.xml @@ -21,7 +21,7 @@ android:elevation="@dimen/deep_shortcuts_elevation" android:background="@drawable/bg_white_pill"> - diff --git a/res/values/styles.xml b/res/values/styles.xml index 532b701d00..627c433e55 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -81,7 +81,8 @@ start|center_vertical @dimen/deep_shortcuts_elevation 7dp - 12dp + 12dp + 9dp @color/quantum_panel_text_color 0 false diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 00ec4c2ffc..c0c6673eef 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -526,19 +526,23 @@ public class BubbleTextView extends TextView * Sets the icon for this view based on the layout direction. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) - public void setIcon(Drawable icon) { + private void setIcon(Drawable icon) { mIcon = icon; if (mIconSize != -1) { mIcon.setBounds(0, 0, mIconSize, mIconSize); } + applyCompoundDrawables(mIcon); + } + + protected void applyCompoundDrawables(Drawable icon) { if (mLayoutHorizontal) { if (Utilities.ATLEAST_JB_MR1) { - setCompoundDrawablesRelative(mIcon, null, null, null); + setCompoundDrawablesRelative(icon, null, null, null); } else { - setCompoundDrawables(mIcon, null, null, null); + setCompoundDrawables(icon, null, null, null); } } else { - setCompoundDrawables(null, mIcon, null, null); + setCompoundDrawables(null, icon, null, null); } } diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java new file mode 100644 index 0000000000..c48d160089 --- /dev/null +++ b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 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.shortcuts; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.util.AttributeSet; + +import com.android.launcher3.BubbleTextView; +import com.android.launcher3.R; + +/** + * A {@link BubbleTextView} that has the shortcut icon on the left and drag handle on the right. + */ +public class DeepShortcutTextView extends BubbleTextView { + + public DeepShortcutTextView(Context context) { + this(context, null, 0); + } + + public DeepShortcutTextView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public DeepShortcutTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + /** Use the BubbleTextView icon for the start and the drag handle for the end. */ + protected void applyCompoundDrawables(Drawable icon) { + Drawable dragHandle = getResources().getDrawable(R.drawable.deep_shortcuts_drag_handle); + dragHandle.setBounds(0, 0, dragHandle.getIntrinsicWidth(), dragHandle.getIntrinsicHeight()); + setCompoundDrawablesRelative(icon, null, dragHandle, null); + } +} diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java index 912f00622b..f91665f865 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java @@ -160,11 +160,10 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC final ShortcutInfoCompat shortcut = shortcuts.get(i); final ShortcutInfo launcherShortcutInfo = ShortcutInfo .fromDeepShortcutInfo(shortcut, mLauncher); - CharSequence label = shortcut.getLongLabel(); - if (TextUtils.isEmpty(label)) { - label = shortcut.getShortLabel(); - } - uiHandler.post(new UpdateShortcutChild(i, launcherShortcutInfo, label)); + CharSequence shortLabel = shortcut.getShortLabel(); + CharSequence longLabel = shortcut.getLongLabel(); + uiHandler.post(new UpdateShortcutChild(i, launcherShortcutInfo, + shortLabel, longLabel)); } } }); @@ -174,13 +173,15 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC private class UpdateShortcutChild implements Runnable { private int mShortcutChildIndex; private ShortcutInfo mShortcutChildInfo; - private CharSequence mLabel; + private CharSequence mShortLabel; + private CharSequence mLongLabel; public UpdateShortcutChild(int shortcutChildIndex, ShortcutInfo shortcutChildInfo, - CharSequence label) { + CharSequence shortLabel, CharSequence longLabel) { mShortcutChildIndex = shortcutChildIndex; mShortcutChildInfo = shortcutChildInfo; - mLabel = label; + mShortLabel = shortLabel; + mLongLabel = longLabel; } @Override @@ -188,7 +189,12 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC BubbleTextView shortcutView = getShortcutAt(mShortcutChildIndex).getBubbleText(); shortcutView.applyFromShortcutInfo(mShortcutChildInfo, LauncherAppState.getInstance().getIconCache()); - shortcutView.setText(mLabel); + // Use the long label as long as it exists and fits. + int availableWidth = shortcutView.getWidth() - shortcutView.getTotalPaddingLeft() + - shortcutView.getTotalPaddingRight(); + boolean usingLongLabel = !TextUtils.isEmpty(mLongLabel) + && shortcutView.getPaint().measureText(mLongLabel.toString()) <= availableWidth; + shortcutView.setText(usingLongLabel ? mLongLabel : mShortLabel); shortcutView.setOnClickListener(mLauncher); shortcutView.setOnLongClickListener(DeepShortcutsContainer.this); shortcutView.setOnTouchListener(DeepShortcutsContainer.this);