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 | |
| 17 | package com.android.launcher2; |
| 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 | |
| 29 | import com.android.launcher.R; |
| 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(); |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 54 | mDrawable.setCrossFadeEnabled(true); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 55 | |
| 56 | // Remove the text in the Phone UI in landscape |
| 57 | int orientation = getResources().getConfiguration().orientation; |
| 58 | if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 59 | if (!LauncherApplication.isScreenLarge()) { |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 60 | setText(""); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 65 | private boolean isFromAllApps(DragSource source) { |
| 66 | return (source instanceof AppsCustomizePagedView); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean acceptDrop(DragObject d) { |
| 71 | // acceptDrop is called just before onDrop. We do the work here, rather than |
| 72 | // in onDrop, because it allows us to reject the drop (by returning false) |
| 73 | // so that the object being dragged isn't removed from the drag source. |
| 74 | ComponentName componentName = null; |
| 75 | if (d.dragInfo instanceof ApplicationInfo) { |
| 76 | componentName = ((ApplicationInfo) d.dragInfo).componentName; |
| 77 | } else if (d.dragInfo instanceof ShortcutInfo) { |
| 78 | componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent(); |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 79 | } else if (d.dragInfo instanceof PendingAddItemInfo) { |
| 80 | componentName = ((PendingAddItemInfo) d.dragInfo).componentName; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 81 | } |
| 82 | if (componentName != null) { |
| 83 | mLauncher.startApplicationDetailsActivity(componentName); |
| 84 | } |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 85 | |
| 86 | // There is no post-drop animation, so clean up the DragView now |
| 87 | d.deferDragViewCleanupPostAnimation = false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 88 | return false; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void onDragStart(DragSource source, Object info, int dragAction) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 93 | boolean isVisible = true; |
| 94 | |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 95 | // Hide this button unless we are dragging something from AllApps |
| 96 | if (!isFromAllApps(source)) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 97 | isVisible = false; |
| 98 | } |
| 99 | |
| 100 | mActive = isVisible; |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 101 | mDrawable.resetTransition(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 102 | setTextColor(mOriginalTextColor); |
| 103 | ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public void onDragEnd() { |
| 108 | super.onDragEnd(); |
| 109 | mActive = false; |
| 110 | } |
| 111 | |
| 112 | public void onDragEnter(DragObject d) { |
| 113 | super.onDragEnter(d); |
| 114 | |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 115 | mDrawable.startTransition(mTransitionDuration); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 116 | setTextColor(mHoverColor); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | public void onDragExit(DragObject d) { |
| 120 | super.onDragExit(d); |
| 121 | |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 122 | if (!d.dragComplete) { |
| 123 | mDrawable.resetTransition(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 124 | setTextColor(mOriginalTextColor); |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 125 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 126 | } |
| 127 | } |