summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2016-07-20 15:21:04 -0700
committerTony Wickham <twickham@google.com>2016-07-20 17:28:34 -0700
commit377ed3f63ec517ed1ec1957dc1122f96f616fe65 (patch)
tree2af2069e1660868fcfcae7ee1835e13a252eb358
parent2eeae10e984993af563b4d207deac855ca7d8620 (diff)
downloadandroid_packages_apps_Trebuchet-377ed3f63ec517ed1ec1957dc1122f96f616fe65.tar.gz
android_packages_apps_Trebuchet-377ed3f63ec517ed1ec1957dc1122f96f616fe65.tar.bz2
android_packages_apps_Trebuchet-377ed3f63ec517ed1ec1957dc1122f96f616fe65.zip
Add drag handle to shortcuts.
Also use short text if long text is ellipsized. Bug: 30212144 Bug: 28980830 Change-Id: I213766bca0561d284d1da883ca37b0a42d886129
-rw-r--r--res/drawable/deep_shortcuts_drag_handle.xml26
-rw-r--r--res/layout/deep_shortcut.xml2
-rw-r--r--res/values/styles.xml3
-rw-r--r--src/com/android/launcher3/BubbleTextView.java12
-rw-r--r--src/com/android/launcher3/shortcuts/DeepShortcutTextView.java50
-rw-r--r--src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java24
6 files changed, 102 insertions, 15 deletions
diff --git a/res/drawable/deep_shortcuts_drag_handle.xml b/res/drawable/deep_shortcuts_drag_handle.xml
new file mode 100644
index 000000000..d5fca2ecf
--- /dev/null
+++ b/res/drawable/deep_shortcuts_drag_handle.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+
+ <path
+ android:pathData="M20 9H4v2h16V9zM4 15h16v-2H4v2z"
+ android:fillColor="#757575"/>
+</vector> \ No newline at end of file
diff --git a/res/layout/deep_shortcut.xml b/res/layout/deep_shortcut.xml
index 089546033..4fcbbd206 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">
- <com.android.launcher3.BubbleTextView
+ <com.android.launcher3.shortcuts.DeepShortcutTextView
android:id="@+id/deep_shortcut"
style="@style/Icon.DeepShortcut"
android:focusable="true"/>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 532b701d0..627c433e5 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -81,7 +81,8 @@
<item name="android:gravity">start|center_vertical</item>
<item name="android:elevation">@dimen/deep_shortcuts_elevation</item>
<item name="android:paddingLeft">7dp</item>
- <item name="android:drawablePadding">12dp</item>
+ <item name="android:paddingRight">12dp</item>
+ <item name="android:drawablePadding">9dp</item>
<item name="android:textColor">@color/quantum_panel_text_color</item>
<item name="android:shadowRadius">0</item>
<item name="customShadows">false</item>
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 00ec4c2ff..c0c6673ee 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 000000000..c48d16008
--- /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 912f00622..f91665f86 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);