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.Context; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 20 | import android.util.AttributeSet; |
| 21 | import android.view.View; |
| 22 | import android.widget.FrameLayout; |
| 23 | |
| 24 | import com.android.launcher.R; |
| 25 | |
| 26 | /* |
| 27 | * Ths bar will manage the transition between the QSB search bar and the delete drop |
| 28 | * targets so that each of the individual IconDropTargets don't have to. |
| 29 | */ |
| 30 | public class SearchDropTargetBar extends FrameLayout implements DragController.DragListener { |
| 31 | |
| 32 | private static final int sTransitionInDuration = 275; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 33 | private static final int sTransitionOutDuration = 100; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 34 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 35 | private boolean mIsSearchBarHidden; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 36 | private View mQSBSearchBar; |
| 37 | private View mDropTargetBar; |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame^] | 38 | private ButtonDropTarget mInfoDropTarget; |
| 39 | private ButtonDropTarget mDeleteDropTarget; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 40 | |
| 41 | public SearchDropTargetBar(Context context, AttributeSet attrs) { |
| 42 | this(context, attrs, 0); |
| 43 | } |
| 44 | |
| 45 | public SearchDropTargetBar(Context context, AttributeSet attrs, int defStyle) { |
| 46 | super(context, attrs, defStyle); |
| 47 | } |
| 48 | |
| 49 | public void setup(Launcher launcher, DragController dragController) { |
| 50 | dragController.addDragListener(this); |
| 51 | dragController.addDragListener(mInfoDropTarget); |
| 52 | dragController.addDragListener(mDeleteDropTarget); |
| 53 | dragController.addDropTarget(mInfoDropTarget); |
| 54 | dragController.addDropTarget(mDeleteDropTarget); |
| 55 | mInfoDropTarget.setLauncher(launcher); |
| 56 | mDeleteDropTarget.setLauncher(launcher); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame^] | 57 | mDropTargetBar.setBackgroundColor(0x33000000); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected void onFinishInflate() { |
| 62 | super.onFinishInflate(); |
| 63 | |
| 64 | // Get the individual components |
| 65 | mQSBSearchBar = findViewById(R.id.qsb_search_bar); |
| 66 | mDropTargetBar = findViewById(R.id.drag_target_bar); |
Winson Chung | 61fa419 | 2011-06-12 15:15:29 -0700 | [diff] [blame^] | 67 | mInfoDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.info_target); |
| 68 | mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target); |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /* |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 72 | * Shows and hides the search bar. |
| 73 | */ |
| 74 | public void showSearchBar(boolean animated) { |
| 75 | if (animated) { |
| 76 | mQSBSearchBar.animate().alpha(1f).setDuration(sTransitionInDuration); |
| 77 | } else { |
| 78 | mQSBSearchBar.setAlpha(1f); |
| 79 | } |
| 80 | mIsSearchBarHidden = false; |
| 81 | } |
| 82 | public void hideSearchBar(boolean animated) { |
| 83 | if (animated) { |
| 84 | mQSBSearchBar.animate().alpha(0f).setDuration(sTransitionOutDuration); |
| 85 | } else { |
| 86 | mQSBSearchBar.setAlpha(0f); |
| 87 | } |
| 88 | mIsSearchBarHidden = true; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * Gets various transition durations. |
| 93 | */ |
| 94 | public int getTransitionInDuration() { |
| 95 | return sTransitionInDuration; |
| 96 | } |
| 97 | public int getTransitionOutDuration() { |
| 98 | return sTransitionOutDuration; |
| 99 | } |
| 100 | |
| 101 | /* |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 102 | * DragController.DragListener implementation |
| 103 | */ |
| 104 | @Override |
| 105 | public void onDragStart(DragSource source, Object info, int dragAction) { |
| 106 | // Animate out the QSB search bar, and animate in the drop target bar |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 107 | mDropTargetBar.animate().alpha(1f).setDuration(sTransitionInDuration); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 108 | if (!mIsSearchBarHidden) { |
| 109 | mQSBSearchBar.animate().alpha(0f).setDuration(sTransitionOutDuration); |
| 110 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void onDragEnd() { |
| 115 | // Restore the QSB search bar, and animate out the drop target bar |
| 116 | mDropTargetBar.animate().alpha(0f).setDuration(sTransitionOutDuration); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 117 | if (!mIsSearchBarHidden) { |
| 118 | mQSBSearchBar.animate().alpha(1f).setDuration(sTransitionInDuration); |
| 119 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 120 | } |
| 121 | } |