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 | |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 19 | import android.animation.AnimatorSet; |
| 20 | import android.animation.ObjectAnimator; |
| 21 | import android.animation.TimeInterpolator; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Mathew Inwood | cf7f63b | 2011-10-13 11:31:38 +0100 | [diff] [blame] | 23 | import android.graphics.Rect; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
| 25 | import android.view.View; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 26 | import android.view.ViewDebug; |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 27 | import android.view.animation.DecelerateInterpolator; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 28 | |
Vadim Tryshev | fedca43 | 2015-08-19 17:55:02 -0700 | [diff] [blame] | 29 | import com.android.launcher3.dragndrop.DragController; |
Sunny Goyal | d1ea63f | 2015-08-05 12:32:47 -0700 | [diff] [blame] | 30 | import com.android.launcher3.util.Thunk; |
| 31 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 32 | /* |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 33 | * This bar will manage the transition between the QSB search bar and the delete/uninstall drop |
| 34 | * targets so that each of the individual ButtonDropTargets don't have to. |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 35 | */ |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 36 | public class SearchDropTargetBar extends BaseDropTargetBar { |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 37 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 38 | /** The different states that the search bar space can be in. */ |
| 39 | public enum State { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame^] | 40 | INVISIBLE (0f), |
| 41 | DROP_TARGET (1f); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 42 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 43 | private final float mDropTargetBarAlpha; |
| 44 | |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame^] | 45 | State(float dtbAlpha) { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 46 | mDropTargetBarAlpha = dtbAlpha; |
| 47 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 50 | |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 51 | @ViewDebug.ExportedProperty(category = "launcher") |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame^] | 52 | private State mState = State.INVISIBLE; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 53 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 54 | // Drop targets |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 55 | private ButtonDropTarget mDeleteDropTarget; |
| 56 | private ButtonDropTarget mUninstallDropTarget; |
| 57 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 58 | public SearchDropTargetBar(Context context, AttributeSet attrs) { |
| 59 | this(context, attrs, 0); |
| 60 | } |
| 61 | |
| 62 | public SearchDropTargetBar(Context context, AttributeSet attrs, int defStyle) { |
| 63 | super(context, attrs, defStyle); |
| 64 | } |
| 65 | |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 66 | @Override |
| 67 | protected void onFinishInflate() { |
| 68 | super.onFinishInflate(); |
| 69 | |
| 70 | // Get the individual components |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 71 | mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target_text); |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 72 | mUninstallDropTarget = (ButtonDropTarget) mDropTargetBar |
| 73 | .findViewById(R.id.uninstall_target_text); |
Winson Chung | a62e9fd | 2011-07-11 15:20:48 -0700 | [diff] [blame] | 74 | |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 75 | mDeleteDropTarget.setDropTargetBar(this); |
| 76 | mUninstallDropTarget.setDropTargetBar(this); |
| 77 | } |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 78 | |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 79 | @Override |
| 80 | public void setup(Launcher launcher, DragController dragController) { |
| 81 | dragController.addDragListener(this); |
| 82 | dragController.setFlingToDeleteDropTarget(mDeleteDropTarget); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 83 | |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 84 | dragController.addDragListener(mDeleteDropTarget); |
| 85 | dragController.addDragListener(mUninstallDropTarget); |
| 86 | |
| 87 | dragController.addDropTarget(mDeleteDropTarget); |
| 88 | dragController.addDropTarget(mUninstallDropTarget); |
| 89 | |
| 90 | mDeleteDropTarget.setLauncher(launcher); |
| 91 | mUninstallDropTarget.setLauncher(launcher); |
| 92 | } |
| 93 | |
| 94 | @Override |
Tony Wickham | 9aae47f | 2015-10-01 13:04:22 -0700 | [diff] [blame] | 95 | public void showDropTargets() { |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 96 | animateToState(State.DROP_TARGET, DEFAULT_DRAG_FADE_DURATION); |
| 97 | } |
| 98 | |
| 99 | @Override |
Tony Wickham | 9aae47f | 2015-10-01 13:04:22 -0700 | [diff] [blame] | 100 | public void hideDropTargets() { |
Sunny Goyal | da4fe1a | 2016-05-26 16:05:17 -0700 | [diff] [blame^] | 101 | animateToState(State.INVISIBLE, DEFAULT_DRAG_FADE_DURATION); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Animates the current search bar state to a new state. If the {@param duration} is 0, then |
| 106 | * the state is applied immediately. |
| 107 | */ |
| 108 | public void animateToState(State newState, int duration) { |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 109 | animateToState(newState, duration, null); |
| 110 | } |
| 111 | |
| 112 | public void animateToState(State newState, int duration, AnimatorSet animation) { |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 113 | if (mState != newState) { |
| 114 | mState = newState; |
| 115 | |
Sunny Goyal | 7c50b31 | 2016-02-10 12:26:23 -0800 | [diff] [blame] | 116 | resetAnimation(duration); |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 117 | if (duration > 0) { |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 118 | animateAlpha(mDropTargetBar, mState.mDropTargetBarAlpha, DEFAULT_INTERPOLATOR); |
| 119 | } else { |
| 120 | mDropTargetBar.setAlpha(mState.mDropTargetBarAlpha); |
| 121 | AlphaUpdateListener.updateVisibility(mDropTargetBar, mAccessibilityEnabled); |
| 122 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 123 | |
Sunny Goyal | 0ac7ede | 2016-01-29 13:14:14 -0800 | [diff] [blame] | 124 | // Start the final animation |
| 125 | if (duration > 0) { |
| 126 | if (animation != null) { |
| 127 | animation.play(mCurrentAnimation); |
| 128 | } else { |
| 129 | mCurrentAnimation.start(); |
| 130 | } |
| 131 | } |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Tony Wickham | b54c4a3 | 2015-09-11 08:40:20 -0700 | [diff] [blame] | 135 | @Override |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 136 | public void enableAccessibleDrag(boolean enable) { |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 137 | mDeleteDropTarget.enableAccessibleDrag(enable); |
| 138 | mUninstallDropTarget.enableAccessibleDrag(enable); |
| 139 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 140 | } |