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 17package com.android.launcher3; 18 19import android.content.ComponentName; 20import android.content.Context; 21import android.content.res.ColorStateList; 22import android.content.res.Configuration; 23import android.content.res.Resources; 24import android.graphics.drawable.TransitionDrawable; 25import android.util.AttributeSet; 26import android.view.View; 27import android.view.ViewGroup; 28 29public class InfoDropTarget extends ButtonDropTarget { 30 31 private ColorStateList mOriginalTextColor; 32 private TransitionDrawable mDrawable; 33 34 public InfoDropTarget(Context context, AttributeSet attrs) { 35 this(context, attrs, 0); 36 } 37 38 public InfoDropTarget(Context context, AttributeSet attrs, int defStyle) { 39 super(context, attrs, defStyle); 40 } 41 42 @Override 43 protected void onFinishInflate() { 44 super.onFinishInflate(); 45 46 mOriginalTextColor = getTextColors(); 47 48 // Get the hover color 49 Resources r = getResources(); 50 mHoverColor = r.getColor(R.color.info_target_hover_tint); 51 mDrawable = (TransitionDrawable) getCurrentDrawable(); 52 if (null != mDrawable) { 53 mDrawable.setCrossFadeEnabled(true); 54 } 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 (!LauncherAppState.getInstance().isScreenLarge()) { 60 setText(""); 61 } 62 } 63 } 64 65 private boolean isFromAllApps(DragSource source) { 66 return (source instanceof AppsCustomizePagedView); 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 AppInfo) { 76 componentName = ((AppInfo) d.dragInfo).componentName; 77 } else if (d.dragInfo instanceof ShortcutInfo) { 78 componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent(); 79 } else if (d.dragInfo instanceof PendingAddItemInfo) { 80 componentName = ((PendingAddItemInfo) d.dragInfo).componentName; 81 } 82 if (componentName != null) { 83 mLauncher.startApplicationDetailsActivity(componentName); 84 } 85 86 // There is no post-drop animation, so clean up the DragView now 87 d.deferDragViewCleanupPostAnimation = false; 88 return false; 89 } 90 91 @Override 92 public void onDragStart(DragSource source, Object info, int dragAction) { 93 boolean isVisible = true; 94 95 // Hide this button unless we are dragging something from AllApps 96 if (!isFromAllApps(source)) { 97 isVisible = false; 98 } 99 100 mActive = isVisible; 101 mDrawable.resetTransition(); 102 setTextColor(mOriginalTextColor); 103 ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); 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 115 mDrawable.startTransition(mTransitionDuration); 116 setTextColor(mHoverColor); 117 } 118 119 public void onDragExit(DragObject d) { 120 super.onDragExit(d); 121 122 if (!d.dragComplete) { 123 mDrawable.resetTransition(); 124 setTextColor(mOriginalTextColor); 125 } 126 } 127} 128