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; |
| 24 | import android.graphics.PorterDuff; |
| 25 | import android.graphics.PorterDuffColorFilter; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 26 | import android.graphics.drawable.TransitionDrawable; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
| 28 | import android.view.View; |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 29 | import android.view.ViewGroup; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 30 | |
| 31 | import com.android.launcher.R; |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame^] | 32 | import com.android.launcher2.DropTarget.DragObject; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 33 | |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame] | 34 | public class InfoDropTarget extends ButtonDropTarget { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 35 | |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 36 | private ColorStateList mOriginalTextColor; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 37 | private TransitionDrawable mDrawable; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 38 | private int mHoverColor = 0xFF0000FF; |
| 39 | |
| 40 | public InfoDropTarget(Context context, AttributeSet attrs) { |
| 41 | this(context, attrs, 0); |
| 42 | } |
| 43 | |
| 44 | public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) { |
| 45 | super(context, attrs, defStyle); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected void onFinishInflate() { |
| 50 | super.onFinishInflate(); |
| 51 | |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 52 | mOriginalTextColor = getTextColors(); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 53 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 54 | // Get the hover color |
| 55 | Resources r = getResources(); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 56 | mHoverColor = r.getColor(R.color.info_target_hover_tint); |
| 57 | mHoverPaint.setColorFilter(new PorterDuffColorFilter( |
| 58 | mHoverColor, PorterDuff.Mode.SRC_ATOP)); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 59 | mDrawable = (TransitionDrawable) getCompoundDrawables()[0]; |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 60 | mDrawable.setCrossFadeEnabled(true); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 61 | |
| 62 | // Remove the text in the Phone UI in landscape |
| 63 | int orientation = getResources().getConfiguration().orientation; |
| 64 | if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 65 | if (!LauncherApplication.isScreenLarge()) { |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 66 | setText(""); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 71 | private boolean isAllAppsApplication(DragSource source, Object info) { |
| 72 | return (source instanceof AppsCustomizePagedView) && (info instanceof ApplicationInfo); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean acceptDrop(DragObject d) { |
| 77 | // acceptDrop is called just before onDrop. We do the work here, rather than |
| 78 | // in onDrop, because it allows us to reject the drop (by returning false) |
| 79 | // so that the object being dragged isn't removed from the drag source. |
| 80 | ComponentName componentName = null; |
| 81 | if (d.dragInfo instanceof ApplicationInfo) { |
| 82 | componentName = ((ApplicationInfo) d.dragInfo).componentName; |
| 83 | } else if (d.dragInfo instanceof ShortcutInfo) { |
| 84 | componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent(); |
| 85 | } |
| 86 | if (componentName != null) { |
| 87 | mLauncher.startApplicationDetailsActivity(componentName); |
| 88 | } |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame^] | 89 | |
| 90 | // There is no post-drop animation, so clean up the DragView now |
| 91 | d.deferDragViewCleanupPostAnimation = false; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 92 | return false; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public void onDragStart(DragSource source, Object info, int dragAction) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 97 | boolean isVisible = true; |
| 98 | |
| 99 | // If we are dragging a widget or shortcut, hide the info target |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 100 | if (!isAllAppsApplication(source, info)) { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 101 | isVisible = false; |
| 102 | } |
| 103 | |
| 104 | mActive = isVisible; |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 105 | mDrawable.resetTransition(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 106 | setTextColor(mOriginalTextColor); |
| 107 | ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void onDragEnd() { |
| 112 | super.onDragEnd(); |
| 113 | mActive = false; |
| 114 | } |
| 115 | |
| 116 | public void onDragEnter(DragObject d) { |
| 117 | super.onDragEnter(d); |
| 118 | |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 119 | mDrawable.startTransition(mTransitionDuration); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 120 | setTextColor(mHoverColor); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | public void onDragExit(DragObject d) { |
| 124 | super.onDragExit(d); |
| 125 | |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 126 | if (!d.dragComplete) { |
| 127 | mDrawable.resetTransition(); |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 128 | setTextColor(mOriginalTextColor); |
Winson Chung | aaa530a | 2011-07-11 21:06:30 -0700 | [diff] [blame] | 129 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 130 | } |
| 131 | } |