Merge "Add drag handle to shortcuts." into ub-launcher3-calgary
This commit is contained in:
@@ -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>
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user