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; |
Adam Cohen | ed11c14 | 2014-06-03 18:03:29 -0700 | [diff] [blame^] | 24 | import android.graphics.drawable.Drawable; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 25 | import android.graphics.drawable.TransitionDrawable; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 26 | import android.util.AttributeSet; |
| 27 | import android.view.View; |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 28 | import android.view.ViewGroup; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 29 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 30 | public class InfoDropTarget extends ButtonDropTarget { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 31 | |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 32 | private ColorStateList mOriginalTextColor; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 33 | private TransitionDrawable mDrawable; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 34 | |
| 35 | public InfoDropTarget(Context context, AttributeSet attrs) { |
| 36 | this(context, attrs, 0); |
| 37 | } |
| 38 | |
| 39 | public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 40 | super(context, attrs, defStyle); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | protected void onFinishInflate() { |
| 45 | super.onFinishInflate(); |
| 46 | |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 47 | mOriginalTextColor = getTextColors(); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 48 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 49 | // Get the hover color |
| 50 | Resources r = getResources(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 51 | mHoverColor = r.getColor(R.color.info_target_hover_tint); |
Winson Chung | 947245b | 2012-05-15 16:34:19 -0700 | [diff] [blame] | 52 | mDrawable = (TransitionDrawable) getCurrentDrawable(); |
Adam Cohen | ed11c14 | 2014-06-03 18:03:29 -0700 | [diff] [blame^] | 53 | |
| 54 | if (mDrawable == null) { |
| 55 | System.out.println("onFinishInflate -- drawable null"); |
| 56 | } |
| 57 | |
| 58 | // DEBUG CODE: |
| 59 | Drawable normal = r.getDrawable(R.drawable.ic_launcher_info_normal_holo); |
| 60 | Drawable active = r.getDrawable(R.drawable.ic_launcher_info_active_holo); |
| 61 | Drawable selector = r.getDrawable(R.drawable.info_target_selector); |
| 62 | System.out.println("Normal: " + normal); |
| 63 | System.out.println("Active: " + active); |
| 64 | System.out.println("Selector: " + selector); |
| 65 | |
Fabrice Di Meglio | cc11f74 | 2012-12-18 16:25:49 -0800 | [diff] [blame] | 66 | if (null != mDrawable) { |
| 67 | mDrawable.setCrossFadeEnabled(true); |
| 68 | } |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 69 | |
| 70 | // Remove the text in the Phone UI in landscape |
| 71 | int orientation = getResources().getConfiguration().orientation; |
| 72 | if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 73 | if (!LauncherAppState.getInstance().isScreenLarge()) { |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 74 | setText(""); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 79 | @Override |
| 80 | public boolean acceptDrop(DragObject d) { |
| 81 | // acceptDrop is called just before onDrop. We do the work here, rather than |
| 82 | // in onDrop, because it allows us to reject the drop (by returning false) |
| 83 | // so that the object being dragged isn't removed from the drag source. |
| 84 | ComponentName componentName = null; |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 85 | if (d.dragInfo instanceof AppInfo) { |
| 86 | componentName = ((AppInfo) d.dragInfo).componentName; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 87 | } else if (d.dragInfo instanceof ShortcutInfo) { |
| 88 | componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent(); |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 89 | } else if (d.dragInfo instanceof PendingAddItemInfo) { |
| 90 | componentName = ((PendingAddItemInfo) d.dragInfo).componentName; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 91 | } |
| 92 | if (componentName != null) { |
| 93 | mLauncher.startApplicationDetailsActivity(componentName); |
| 94 | } |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 95 | |
| 96 | // There is no post-drop animation, so clean up the DragView now |
| 97 | d.deferDragViewCleanupPostAnimation = false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 98 | return false; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void onDragStart(DragSource source, Object info, int dragAction) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 103 | boolean isVisible = true; |
| 104 | |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 105 | // Hide this button unless we are dragging something from AllApps |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 106 | if (!source.supportsAppInfoDropTarget()) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 107 | isVisible = false; |
| 108 | } |
| 109 | |
Adam Cohen | ed11c14 | 2014-06-03 18:03:29 -0700 | [diff] [blame^] | 110 | if (mDrawable == null) { |
| 111 | System.out.println("onDragStart -- drawable null"); |
| 112 | } |
| 113 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 114 | mActive = isVisible; |
Adam Cohen | ed11c14 | 2014-06-03 18:03:29 -0700 | [diff] [blame^] | 115 | if (mDrawable != null) { |
| 116 | mDrawable.resetTransition(); |
| 117 | } |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 118 | setTextColor(mOriginalTextColor); |
| 119 | ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void onDragEnd() { |
| 124 | super.onDragEnd(); |
| 125 | mActive = false; |
| 126 | } |
| 127 | |
| 128 | public void onDragEnter(DragObject d) { |
| 129 | super.onDragEnter(d); |
| 130 | |
Adam Cohen | ed11c14 | 2014-06-03 18:03:29 -0700 | [diff] [blame^] | 131 | if (mDrawable != null) { |
| 132 | mDrawable.startTransition(mTransitionDuration); |
| 133 | } |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 134 | setTextColor(mHoverColor); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | public void onDragExit(DragObject d) { |
| 138 | super.onDragExit(d); |
| 139 | |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 140 | if (!d.dragComplete) { |
| 141 | mDrawable.resetTransition(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 142 | setTextColor(mOriginalTextColor); |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 143 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 144 | } |
| 145 | } |