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; |
| 20 | import android.content.res.Resources; |
| 21 | import android.graphics.PorterDuff; |
| 22 | import android.graphics.PorterDuffColorFilter; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.view.View; |
| 25 | import android.widget.FrameLayout; |
| 26 | |
| 27 | import 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 | */ |
| 33 | public class SearchDropTargetBar extends FrameLayout implements DragController.DragListener { |
| 34 | |
| 35 | private static final int sTransitionInDuration = 275; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame^] | 36 | private static final int sTransitionOutDuration = 100; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 37 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame^] | 38 | private boolean mIsSearchBarHidden; |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 39 | 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 Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame^] | 74 | * 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 104 | * 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 Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 109 | mDropTargetBar.animate().alpha(1f).setDuration(sTransitionInDuration); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame^] | 110 | if (!mIsSearchBarHidden) { |
| 111 | mQSBSearchBar.animate().alpha(0f).setDuration(sTransitionOutDuration); |
| 112 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 113 | } |
| 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 Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame^] | 119 | if (!mIsSearchBarHidden) { |
| 120 | mQSBSearchBar.animate().alpha(1f).setDuration(sTransitionInDuration); |
| 121 | } |
Winson Chung | 4c98d92 | 2011-05-31 16:50:48 -0700 | [diff] [blame] | 122 | } |
| 123 | } |