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