blob: d00e2103fd70d2501a3ba49380d2f55bca3bd3fa [file] [log] [blame]
Winson Chung4c98d922011-05-31 16:50:48 -07001/*
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.launcher2;
18
19import android.content.Context;
Winson Chung4c98d922011-05-31 16:50:48 -070020import android.util.AttributeSet;
21import android.view.View;
22import android.widget.FrameLayout;
23
24import 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 */
30public class SearchDropTargetBar extends FrameLayout implements DragController.DragListener {
31
32 private static final int sTransitionInDuration = 275;
Winson Chungf0ea4d32011-06-06 14:27:16 -070033 private static final int sTransitionOutDuration = 100;
Winson Chung4c98d922011-05-31 16:50:48 -070034
Winson Chungf0ea4d32011-06-06 14:27:16 -070035 private boolean mIsSearchBarHidden;
Winson Chung4c98d922011-05-31 16:50:48 -070036 private View mQSBSearchBar;
37 private View mDropTargetBar;
Winson Chung61fa4192011-06-12 15:15:29 -070038 private ButtonDropTarget mInfoDropTarget;
39 private ButtonDropTarget mDeleteDropTarget;
Winson Chung4c98d922011-05-31 16:50:48 -070040
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 Chung61fa4192011-06-12 15:15:29 -070057 mDropTargetBar.setBackgroundColor(0x33000000);
Winson Chung4c98d922011-05-31 16:50:48 -070058 }
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 Chung61fa4192011-06-12 15:15:29 -070067 mInfoDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.info_target);
68 mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target);
Winson Chung4c98d922011-05-31 16:50:48 -070069 }
70
71 /*
Winson Chungf0ea4d32011-06-06 14:27:16 -070072 * 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 Chung4c98d922011-05-31 16:50:48 -0700102 * 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 Chung4c98d922011-05-31 16:50:48 -0700107 mDropTargetBar.animate().alpha(1f).setDuration(sTransitionInDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700108 if (!mIsSearchBarHidden) {
109 mQSBSearchBar.animate().alpha(0f).setDuration(sTransitionOutDuration);
110 }
Winson Chung4c98d922011-05-31 16:50:48 -0700111 }
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 Chungf0ea4d32011-06-06 14:27:16 -0700117 if (!mIsSearchBarHidden) {
118 mQSBSearchBar.animate().alpha(1f).setDuration(sTransitionInDuration);
119 }
Winson Chung4c98d922011-05-31 16:50:48 -0700120 }
121}