Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.Context; |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 21 | import android.content.res.ColorStateList; |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 22 | import android.content.res.Configuration; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 23 | import android.content.res.Resources; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 24 | import android.graphics.drawable.TransitionDrawable; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 25 | import android.util.AttributeSet; |
| 26 | import android.view.View; |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 27 | import android.view.ViewGroup; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 28 | |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame^] | 29 | import com.android.launcher3.compat.UserHandleCompat; |
| 30 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 31 | public class InfoDropTarget extends ButtonDropTarget { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 32 | |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 33 | private ColorStateList mOriginalTextColor; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 34 | private TransitionDrawable mDrawable; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 35 | |
| 36 | public InfoDropTarget(Context context, AttributeSet attrs) { |
| 37 | this(context, attrs, 0); |
| 38 | } |
| 39 | |
| 40 | public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 41 | super(context, attrs, defStyle); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected void onFinishInflate() { |
| 46 | super.onFinishInflate(); |
| 47 | |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 48 | mOriginalTextColor = getTextColors(); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 49 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 50 | // Get the hover color |
| 51 | Resources r = getResources(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 52 | mHoverColor = r.getColor(R.color.info_target_hover_tint); |
Winson Chung | 947245b | 2012-05-15 16:34:19 -0700 | [diff] [blame] | 53 | mDrawable = (TransitionDrawable) getCurrentDrawable(); |
Adam Cohen | 18bbc6a | 2014-06-03 21:43:24 -0700 | [diff] [blame] | 54 | |
| 55 | if (mDrawable == null) { |
| 56 | // TODO: investigate why this is ever happening. Presently only on one known device. |
Adam Cohen | 1793701 | 2014-06-03 22:23:28 -0700 | [diff] [blame] | 57 | mDrawable = (TransitionDrawable) r.getDrawable(R.drawable.info_target_selector); |
Adam Cohen | 18bbc6a | 2014-06-03 21:43:24 -0700 | [diff] [blame] | 58 | setCompoundDrawablesRelativeWithIntrinsicBounds(mDrawable, null, null, null); |
| 59 | } |
| 60 | |
Fabrice Di Meglio | cc11f74 | 2012-12-18 16:25:49 -0800 | [diff] [blame] | 61 | if (null != mDrawable) { |
| 62 | mDrawable.setCrossFadeEnabled(true); |
| 63 | } |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 64 | |
| 65 | // Remove the text in the Phone UI in landscape |
| 66 | int orientation = getResources().getConfiguration().orientation; |
| 67 | if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 68 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 69 | setText(""); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 74 | @Override |
| 75 | public boolean acceptDrop(DragObject d) { |
| 76 | // acceptDrop is called just before onDrop. We do the work here, rather than |
| 77 | // in onDrop, because it allows us to reject the drop (by returning false) |
| 78 | // so that the object being dragged isn't removed from the drag source. |
| 79 | ComponentName componentName = null; |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 80 | if (d.dragInfo instanceof AppInfo) { |
| 81 | componentName = ((AppInfo) d.dragInfo).componentName; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 82 | } else if (d.dragInfo instanceof ShortcutInfo) { |
| 83 | componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent(); |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 84 | } else if (d.dragInfo instanceof PendingAddItemInfo) { |
| 85 | componentName = ((PendingAddItemInfo) d.dragInfo).componentName; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 86 | } |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame^] | 87 | final UserHandleCompat user; |
| 88 | if (d.dragInfo instanceof ItemInfo) { |
| 89 | user = ((ItemInfo) d.dragInfo).user; |
| 90 | } else { |
| 91 | user = UserHandleCompat.myUserHandle(); |
| 92 | } |
| 93 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 94 | if (componentName != null) { |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame^] | 95 | mLauncher.startApplicationDetailsActivity(componentName, user); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 96 | } |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 97 | |
| 98 | // There is no post-drop animation, so clean up the DragView now |
| 99 | d.deferDragViewCleanupPostAnimation = false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void onDragStart(DragSource source, Object info, int dragAction) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 105 | boolean isVisible = true; |
| 106 | |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 107 | // Hide this button unless we are dragging something from AllApps |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 108 | if (!source.supportsAppInfoDropTarget()) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 109 | isVisible = false; |
| 110 | } |
| 111 | |
| 112 | mActive = isVisible; |
Adam Cohen | e9a5119 | 2014-06-04 01:24:03 +0000 | [diff] [blame] | 113 | mDrawable.resetTransition(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 114 | setTextColor(mOriginalTextColor); |
| 115 | ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void onDragEnd() { |
| 120 | super.onDragEnd(); |
| 121 | mActive = false; |
| 122 | } |
| 123 | |
| 124 | public void onDragEnter(DragObject d) { |
| 125 | super.onDragEnter(d); |
| 126 | |
Adam Cohen | e9a5119 | 2014-06-04 01:24:03 +0000 | [diff] [blame] | 127 | mDrawable.startTransition(mTransitionDuration); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 128 | setTextColor(mHoverColor); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | public void onDragExit(DragObject d) { |
| 132 | super.onDragExit(d); |
| 133 | |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 134 | if (!d.dragComplete) { |
| 135 | mDrawable.resetTransition(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 136 | setTextColor(mOriginalTextColor); |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 137 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 138 | } |
| 139 | } |