summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-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
3 files changed, 73 insertions, 13 deletions
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);