ButtonDropTarget.java revision ddec73471eb6cc1f15eb9421a205bb2362509075
161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung/* 261fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * Copyright (C) 2010 The Android Open Source Project 361fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * 461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * Licensed under the Apache License, Version 2.0 (the "License"); 561fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * you may not use this file except in compliance with the License. 661fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * You may obtain a copy of the License at 761fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * 861fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * http://www.apache.org/licenses/LICENSE-2.0 961fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * 1061fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * Unless required by applicable law or agreed to in writing, software 1161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * distributed under the License is distributed on an "AS IS" BASIS, 1261fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1361fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * See the License for the specific language governing permissions and 1461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * limitations under the License. 1561fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung */ 1661fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 17325dc23624160689e59fbac708cf6f222b20d025Daniel Sandlerpackage com.android.launcher3; 1861fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 19fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyalimport android.animation.ObjectAnimator; 20fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyalimport android.annotation.TargetApi; 2161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chungimport android.content.Context; 22fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyalimport android.content.res.ColorStateList; 23fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyalimport android.content.res.Configuration; 24043f2af567178b82b0b41f12d379e7dd12da2936Winson Chungimport android.graphics.PointF; 2561967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chungimport android.graphics.Rect; 26947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chungimport android.graphics.drawable.Drawable; 27fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyalimport android.graphics.drawable.TransitionDrawable; 28fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyalimport android.os.Build; 2961fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chungimport android.util.AttributeSet; 30d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglioimport android.view.View; 311a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyalimport android.view.View.OnClickListener; 32fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyalimport android.view.ViewGroup; 33fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyalimport android.view.animation.DecelerateInterpolator; 34fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyalimport android.view.animation.LinearInterpolator; 35d4d7aa551ffdc80d810ff970fa72a6509960401eAdam Cohenimport android.widget.TextView; 3661fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 37fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyalimport com.android.launcher3.util.Thunk; 3861fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 3961fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung/** 4061fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung * Implements a DropTarget. 4161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung */ 421a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyalpublic abstract class ButtonDropTarget extends TextView 431a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal implements DropTarget, DragController.DragListener, OnClickListener { 44fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 45fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal private static int DRAG_VIEW_DROP_DURATION = 285; 4661fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 4761fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung protected Launcher mLauncher; 48a62e9fd95ae10cff4676f2cc1f4d68334ca27a0bWinson Chung private int mBottomDragPadding; 49d4d7aa551ffdc80d810ff970fa72a6509960401eAdam Cohen protected TextView mText; 50d4d7aa551ffdc80d810ff970fa72a6509960401eAdam Cohen protected SearchDropTargetBar mSearchDropTargetBar; 5161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 5261fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung /** Whether this drop target is active for the current drag */ 5361fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung protected boolean mActive; 5461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 5561fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung /** The paint applied to the drag view on hover */ 5661967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung protected int mHoverColor = 0; 5761fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 58fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal protected ColorStateList mOriginalTextColor; 59fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal protected TransitionDrawable mDrawable; 60fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 61fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal private ObjectAnimator mCurrentColorAnim; 62fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal 6361fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung public ButtonDropTarget(Context context, AttributeSet attrs) { 6461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung this(context, attrs, 0); 6561fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 6661fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 6761fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) { 6861fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung super(context, attrs, defStyle); 69fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mBottomDragPadding = getResources().getDimensionPixelSize(R.dimen.drop_target_drag_padding); 7061fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 7161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 72fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 73fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal protected void onFinishInflate() { 74fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal super.onFinishInflate(); 75fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mOriginalTextColor = getTextColors(); 76fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 77fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal // Remove the text in the Phone UI in landscape 78fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal int orientation = getResources().getConfiguration().orientation; 79fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal if (orientation == Configuration.ORIENTATION_LANDSCAPE) { 80fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal if (!LauncherAppState.getInstance().isScreenLarge()) { 81fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal setText(""); 82fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 83fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 8461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 8561fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 86fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal protected void setDrawable(int resId) { 87fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal // Get the hover color 88fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mDrawable = (TransitionDrawable) getCurrentDrawable(); 89fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 90fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal if (mDrawable == null) { 91fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal // TODO: investigate why this is ever happening. Presently only on one known device. 92fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mDrawable = (TransitionDrawable) getResources().getDrawable(resId); 93fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null); 94fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 95fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 96fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal if (null != mDrawable) { 97fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mDrawable.setCrossFadeEnabled(true); 98fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 99fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 100fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 101fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public void setLauncher(Launcher launcher) { 102fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mLauncher = launcher; 10361fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 10461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 105d4d7aa551ffdc80d810ff970fa72a6509960401eAdam Cohen public void setSearchDropTargetBar(SearchDropTargetBar searchDropTargetBar) { 106d4d7aa551ffdc80d810ff970fa72a6509960401eAdam Cohen mSearchDropTargetBar = searchDropTargetBar; 107d4d7aa551ffdc80d810ff970fa72a6509960401eAdam Cohen } 108d4d7aa551ffdc80d810ff970fa72a6509960401eAdam Cohen 109947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung protected Drawable getCurrentDrawable() { 110d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio Drawable[] drawables = getCompoundDrawablesRelative(); 111947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung for (int i = 0; i < drawables.length; ++i) { 112947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung if (drawables[i] != null) { 113947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung return drawables[i]; 114947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung } 115947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung } 116947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung return null; 117947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung } 118947245ba8ad74aee3dadd02693514765dbb4b5a2Winson Chung 119fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 120ddec73471eb6cc1f15eb9421a205bb2362509075Sunny Goyal public void onFlingToDelete(DragObject d, PointF vec) { } 121fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 122fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 123fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public final void onDragEnter(DragObject d) { 124fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal d.dragView.setColor(mHoverColor); 125fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal if (Utilities.isLmpOrAbove()) { 126fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mDrawable.startTransition(DragView.COLOR_CHANGE_DURATION); 127fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal animateTextColor(mHoverColor); 128fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } else { 129fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mDrawable.startTransition(0); 130fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal setTextColor(mHoverColor); 131fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } 13261fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 13361fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 134fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 135fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public void onDragOver(DragObject d) { 136043f2af567178b82b0b41f12d379e7dd12da2936Winson Chung // Do nothing 137043f2af567178b82b0b41f12d379e7dd12da2936Winson Chung } 138043f2af567178b82b0b41f12d379e7dd12da2936Winson Chung 139fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal protected void resetHoverColor() { 140fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal if (Utilities.isLmpOrAbove()) { 141fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mDrawable.reverseTransition(DragView.COLOR_CHANGE_DURATION); 142fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal animateTextColor(mOriginalTextColor.getDefaultColor()); 143fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } else { 144fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mDrawable.resetTransition(); 145fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal setTextColor(mOriginalTextColor); 146fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } 147fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } 148fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal 149fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal @TargetApi(Build.VERSION_CODES.LOLLIPOP) 150fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal private void animateTextColor(int targetColor) { 151fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal if (mCurrentColorAnim != null) { 152fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mCurrentColorAnim.cancel(); 153fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } 154fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mCurrentColorAnim = ObjectAnimator.ofArgb(this, "textColor", targetColor); 155fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mCurrentColorAnim.setDuration(DragView.COLOR_CHANGE_DURATION); 156fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mCurrentColorAnim.start(); 15761fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 15861fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 159fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 160fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public final void onDragExit(DragObject d) { 161fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal if (!d.dragComplete) { 162fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal d.dragView.setColor(0); 163fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal resetHoverColor(); 164fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } else { 165fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal // Restore the hover color 166fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal d.dragView.setColor(mHoverColor); 167fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 16861fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 16961fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 170fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 171fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public final void onDragStart(DragSource source, Object info, int dragAction) { 172fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mActive = supportsDrop(source, info); 173fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mDrawable.resetTransition(); 174fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal if (mCurrentColorAnim != null) { 175fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mCurrentColorAnim.cancel(); 176fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal mCurrentColorAnim = null; 177fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } 178fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal setTextColor(mOriginalTextColor); 179fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal ((ViewGroup) getParent()).setVisibility(mActive ? View.VISIBLE : View.GONE); 18061fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 18161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 182fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 183fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public final boolean acceptDrop(DragObject dragObject) { 184fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal return supportsDrop(dragObject.dragSource, dragObject.dragInfo); 18561fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 18661fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 187fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal protected abstract boolean supportsDrop(DragSource source, Object info); 188fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 189fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 19061fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung public boolean isDropEnabled() { 19161fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung return mActive; 19261fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 19361fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 194fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 19561fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung public void onDragEnd() { 196fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mActive = false; 19761fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung } 19861fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung 199fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal /** 200fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal * On drop animate the dropView to the icon. 201fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal */ 202fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 203fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public void onDrop(final DragObject d) { 204fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal final DragLayer dragLayer = mLauncher.getDragLayer(); 205fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal final Rect from = new Rect(); 206fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal dragLayer.getViewRectRelativeToSelf(d.dragView, from); 207fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 208fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal int width = mDrawable.getIntrinsicWidth(); 209fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal int height = mDrawable.getIntrinsicHeight(); 210fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal final Rect to = getIconRect(d.dragView.getMeasuredWidth(), d.dragView.getMeasuredHeight(), 211fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal width, height); 212fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal final float scale = (float) to.width() / from.width(); 213fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mSearchDropTargetBar.deferOnDragEnd(); 214fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 215fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal Runnable onAnimationEndRunnable = new Runnable() { 216fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 217fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal public void run() { 218fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal completeDrop(d); 219fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mSearchDropTargetBar.onDragEnd(); 220fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal mLauncher.exitSpringLoadedDragModeDelayed(true, 0, null); 221fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 222fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal }; 223fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, 224fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal DRAG_VIEW_DROP_DURATION, new DecelerateInterpolator(2), 225fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal new LinearInterpolator(), onAnimationEndRunnable, 226fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal DragLayer.ANIMATION_END_DISAPPEAR, null); 227fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal } 228fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 229e9b651eef1b9f3647eba94f833bff3fc52f5956bSunny Goyal @Override 230e9b651eef1b9f3647eba94f833bff3fc52f5956bSunny Goyal public void prepareAccessibilityDrop() { } 231e9b651eef1b9f3647eba94f833bff3fc52f5956bSunny Goyal 232fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Thunk abstract void completeDrop(DragObject d); 233fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal 23461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung @Override 2357d30a37007bac318db1c9af47a9af12d348042a5Adam Cohen public void getHitRectRelativeToDragLayer(android.graphics.Rect outRect) { 236a62e9fd95ae10cff4676f2cc1f4d68334ca27a0bWinson Chung super.getHitRect(outRect); 237a62e9fd95ae10cff4676f2cc1f4d68334ca27a0bWinson Chung outRect.bottom += mBottomDragPadding; 238156ab5b22e45b36a1c5edbe5accccf6aefcb4907Winson Chung 239156ab5b22e45b36a1c5edbe5accccf6aefcb4907Winson Chung int[] coords = new int[2]; 240156ab5b22e45b36a1c5edbe5accccf6aefcb4907Winson Chung mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, coords); 241156ab5b22e45b36a1c5edbe5accccf6aefcb4907Winson Chung outRect.offsetTo(coords[0], coords[1]); 242a62e9fd95ae10cff4676f2cc1f4d68334ca27a0bWinson Chung } 243a62e9fd95ae10cff4676f2cc1f4d68334ca27a0bWinson Chung 244d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio private boolean isRtl() { 245fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); 246d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio } 247d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio 248fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal protected Rect getIconRect(int viewWidth, int viewHeight, int drawableWidth, int drawableHeight) { 24961967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung DragLayer dragLayer = mLauncher.getDragLayer(); 25061967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung 25161967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung // Find the rect to animate to (the view is center aligned) 25261967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung Rect to = new Rect(); 25361967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung dragLayer.getViewRectRelativeToSelf(this, to); 254d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio 255d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int width = drawableWidth; 256d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int height = drawableHeight; 257d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio 258d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int left; 259d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int right; 260d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio 261d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio if (isRtl()) { 262d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio right = to.right - getPaddingRight(); 263d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio left = right - width; 264d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio } else { 265d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio left = to.left + getPaddingLeft(); 266d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio right = left + width; 267d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio } 268d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio 269d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int top = to.top + (getMeasuredHeight() - height) / 2; 270d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int bottom = top + height; 271d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio 272d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio to.set(left, top, right, bottom); 27361967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung 27461967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung // Center the destination rect about the trash icon 275d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int xOffset = (int) -(viewWidth - width) / 2; 276d6a33c6f348d1316e0fdc519eda43468fcdcbfe7Fabrice Di Meglio final int yOffset = (int) -(viewHeight - height) / 2; 27761967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung to.offset(xOffset, yOffset); 27861967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung 27961967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung return to; 28061967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung } 28161967cb17f8fa9ee01f93e9f25a1074559b54cf3Winson Chung 282fa401a10e7e9341daf6f3c5949bf9331902c26d0Sunny Goyal @Override 2838dfcba4af7a7ece09e8c7d96053e54f3a383e905Adam Cohen public void getLocationInDragLayer(int[] loc) { 2848dfcba4af7a7ece09e8c7d96053e54f3a383e905Adam Cohen mLauncher.getDragLayer().getLocationInDragLayer(this, loc); 2858dfcba4af7a7ece09e8c7d96053e54f3a383e905Adam Cohen } 2861a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal 2871a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal public void enableAccessibleDrag(boolean enable) { 2881a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal setOnClickListener(enable ? this : null); 2891a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal } 2901a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal 2911a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal protected String getAccessibilityDropConfirmation() { 2921a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal return null; 2931a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal } 2941a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal 2951a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal @Override 2961a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal public void onClick(View v) { 2971a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal LauncherAppState.getInstance().getAccessibilityDelegate() 2981a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal .handleAccessibleDrop(this, null, getAccessibilityDropConfirmation()); 2991a70cef9884270f2f0a760f079a10fdfb1544c98Sunny Goyal } 300fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal 301fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal public int getTextColor() { 302fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal return getTextColors().getDefaultColor(); 303fe0d1f2458e6a442613b070ae549124a4780e759Sunny Goyal } 30461fa4197c4316bb0f9b05fcefb676f86197a2273Winson Chung} 305