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