blob: 7a208b7610b1202402e9b24368b76670123b4c77 [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;
36 private static final int sTransitionOutDuration = 200;
37
38 private View mQSBSearchBar;
39 private View mDropTargetBar;
40 private IconDropTarget mInfoDropTarget;
41 private IconDropTarget mDeleteDropTarget;
42
43 public SearchDropTargetBar(Context context, AttributeSet attrs) {
44 this(context, attrs, 0);
45 }
46
47 public SearchDropTargetBar(Context context, AttributeSet attrs, int defStyle) {
48 super(context, attrs, defStyle);
49 }
50
51 public void setup(Launcher launcher, DragController dragController) {
52 dragController.addDragListener(this);
53 dragController.addDragListener(mInfoDropTarget);
54 dragController.addDragListener(mDeleteDropTarget);
55 dragController.addDropTarget(mInfoDropTarget);
56 dragController.addDropTarget(mDeleteDropTarget);
57 mInfoDropTarget.setLauncher(launcher);
58 mDeleteDropTarget.setLauncher(launcher);
59 }
60
61 @Override
62 protected void onFinishInflate() {
63 super.onFinishInflate();
64
65 // Get the individual components
66 mQSBSearchBar = findViewById(R.id.qsb_search_bar);
67 mDropTargetBar = findViewById(R.id.drag_target_bar);
68 mInfoDropTarget = (IconDropTarget) mDropTargetBar.findViewById(R.id.info_target);
69 mDeleteDropTarget = (IconDropTarget) mDropTargetBar.findViewById(R.id.delete_target);
70 }
71
72 /*
73 * DragController.DragListener implementation
74 */
75 @Override
76 public void onDragStart(DragSource source, Object info, int dragAction) {
77 // Animate out the QSB search bar, and animate in the drop target bar
78 mQSBSearchBar.animate().alpha(0f).setDuration(sTransitionOutDuration);
79 mDropTargetBar.animate().alpha(1f).setDuration(sTransitionInDuration);
80 }
81
82 @Override
83 public void onDragEnd() {
84 // Restore the QSB search bar, and animate out the drop target bar
85 mDropTargetBar.animate().alpha(0f).setDuration(sTransitionOutDuration);
86 mQSBSearchBar.animate().alpha(1f).setDuration(sTransitionInDuration);
87 }
88}