2011-05-31 16:50:48 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher2;
|
|
|
|
|
|
2011-06-20 15:41:53 -07:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2011-07-11 15:20:48 -07:00
|
|
|
import android.animation.AnimatorSet;
|
2011-06-20 15:41:53 -07:00
|
|
|
import android.animation.ObjectAnimator;
|
2011-05-31 16:50:48 -07:00
|
|
|
import android.content.Context;
|
2011-10-13 11:31:38 +01:00
|
|
|
import android.graphics.Rect;
|
2011-10-05 11:44:49 -07:00
|
|
|
import android.graphics.drawable.Drawable;
|
2011-05-31 16:50:48 -07:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
import android.view.View;
|
2011-07-11 15:20:48 -07:00
|
|
|
import android.view.animation.AccelerateInterpolator;
|
|
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2011-05-31 16:50:48 -07:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher.R;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ths bar will manage the transition between the QSB search bar and the delete drop
|
|
|
|
|
* targets so that each of the individual IconDropTargets don't have to.
|
|
|
|
|
*/
|
|
|
|
|
public class SearchDropTargetBar extends FrameLayout implements DragController.DragListener {
|
|
|
|
|
|
2011-07-11 15:20:48 -07:00
|
|
|
private static final int sTransitionInDuration = 200;
|
|
|
|
|
private static final int sTransitionOutDuration = 175;
|
2011-05-31 16:50:48 -07:00
|
|
|
|
2012-05-11 10:51:32 -07:00
|
|
|
private ObjectAnimator mDropTargetBarFadeInAnim;
|
|
|
|
|
private ObjectAnimator mDropTargetBarFadeOutAnim;
|
2011-06-20 15:41:53 -07:00
|
|
|
private ObjectAnimator mQSBSearchBarFadeInAnim;
|
|
|
|
|
private ObjectAnimator mQSBSearchBarFadeOutAnim;
|
|
|
|
|
|
2011-06-06 14:27:16 -07:00
|
|
|
private boolean mIsSearchBarHidden;
|
2011-05-31 16:50:48 -07:00
|
|
|
private View mQSBSearchBar;
|
|
|
|
|
private View mDropTargetBar;
|
2011-06-12 15:15:29 -07:00
|
|
|
private ButtonDropTarget mInfoDropTarget;
|
|
|
|
|
private ButtonDropTarget mDeleteDropTarget;
|
2011-07-11 15:20:48 -07:00
|
|
|
private int mBarHeight;
|
2011-07-19 21:47:37 -07:00
|
|
|
private boolean mDeferOnDragEnd = false;
|
2011-05-31 16:50:48 -07:00
|
|
|
|
2011-10-05 11:44:49 -07:00
|
|
|
private Drawable mPreviousBackground;
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
public SearchDropTargetBar(Context context, AttributeSet attrs) {
|
|
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SearchDropTargetBar(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setup(Launcher launcher, DragController dragController) {
|
|
|
|
|
dragController.addDragListener(this);
|
|
|
|
|
dragController.addDragListener(mInfoDropTarget);
|
|
|
|
|
dragController.addDragListener(mDeleteDropTarget);
|
|
|
|
|
dragController.addDropTarget(mInfoDropTarget);
|
|
|
|
|
dragController.addDropTarget(mDeleteDropTarget);
|
2012-03-01 16:09:54 -08:00
|
|
|
dragController.setFlingToDeleteDropTarget(mDeleteDropTarget);
|
2011-05-31 16:50:48 -07:00
|
|
|
mInfoDropTarget.setLauncher(launcher);
|
|
|
|
|
mDeleteDropTarget.setLauncher(launcher);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-11 10:51:32 -07:00
|
|
|
private void prepareAnimation(ObjectAnimator in, ObjectAnimator out, final View v) {
|
|
|
|
|
in.setInterpolator(new AccelerateInterpolator());
|
|
|
|
|
in.setDuration(sTransitionInDuration);
|
|
|
|
|
in.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
v.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
out.setInterpolator(new DecelerateInterpolator());
|
|
|
|
|
out.setDuration(sTransitionOutDuration);
|
|
|
|
|
out.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
v.setVisibility(View.INVISIBLE);
|
|
|
|
|
v.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
|
|
|
|
|
// Get the individual components
|
|
|
|
|
mQSBSearchBar = findViewById(R.id.qsb_search_bar);
|
|
|
|
|
mDropTargetBar = findViewById(R.id.drag_target_bar);
|
2011-07-27 10:53:39 -07:00
|
|
|
mInfoDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.info_target_text);
|
|
|
|
|
mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target_text);
|
2011-07-11 15:20:48 -07:00
|
|
|
mBarHeight = getResources().getDimensionPixelSize(R.dimen.qsb_bar_height);
|
|
|
|
|
|
2011-07-19 21:47:37 -07:00
|
|
|
mInfoDropTarget.setSearchDropTargetBar(this);
|
|
|
|
|
mDeleteDropTarget.setSearchDropTargetBar(this);
|
|
|
|
|
|
2011-07-11 15:20:48 -07:00
|
|
|
boolean enableDropDownDropTargets =
|
|
|
|
|
getResources().getBoolean(R.bool.config_useDropTargetDownTransition);
|
2011-06-20 15:41:53 -07:00
|
|
|
|
|
|
|
|
// Create the various fade animations
|
2011-07-11 15:20:48 -07:00
|
|
|
if (enableDropDownDropTargets) {
|
|
|
|
|
mDropTargetBar.setTranslationY(-mBarHeight);
|
2012-05-11 10:51:32 -07:00
|
|
|
mDropTargetBarFadeInAnim = ObjectAnimator.ofFloat(mDropTargetBar, "translationY", 0f);
|
|
|
|
|
mDropTargetBarFadeOutAnim = ObjectAnimator.ofFloat(mDropTargetBar, "translationY",
|
|
|
|
|
-mBarHeight);
|
|
|
|
|
mQSBSearchBarFadeInAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "translationY", 0);
|
|
|
|
|
mQSBSearchBarFadeOutAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "translationY",
|
|
|
|
|
-mBarHeight);
|
|
|
|
|
} else {
|
|
|
|
|
mDropTargetBar.setAlpha(0f);
|
|
|
|
|
mDropTargetBarFadeInAnim = ObjectAnimator.ofFloat(mDropTargetBar, "alpha", 1f);
|
|
|
|
|
mDropTargetBarFadeOutAnim = ObjectAnimator.ofFloat(mDropTargetBar, "alpha", 0f);
|
|
|
|
|
mQSBSearchBarFadeInAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "alpha", 1f);
|
|
|
|
|
mQSBSearchBarFadeOutAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "alpha", 0f);
|
2011-07-11 15:20:48 -07:00
|
|
|
}
|
2012-05-11 10:51:32 -07:00
|
|
|
prepareAnimation(mDropTargetBarFadeInAnim, mDropTargetBarFadeOutAnim, mDropTargetBar);
|
|
|
|
|
prepareAnimation(mQSBSearchBarFadeInAnim, mQSBSearchBarFadeOutAnim, mQSBSearchBar);
|
2011-06-20 15:41:53 -07:00
|
|
|
}
|
|
|
|
|
|
2012-03-01 16:09:54 -08:00
|
|
|
public void finishAnimations() {
|
|
|
|
|
mDropTargetBarFadeInAnim.end();
|
|
|
|
|
mDropTargetBarFadeOutAnim.end();
|
|
|
|
|
mQSBSearchBarFadeInAnim.end();
|
|
|
|
|
mQSBSearchBarFadeOutAnim.end();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 15:41:53 -07:00
|
|
|
private void cancelAnimations() {
|
|
|
|
|
mDropTargetBarFadeInAnim.cancel();
|
|
|
|
|
mDropTargetBarFadeOutAnim.cancel();
|
|
|
|
|
mQSBSearchBarFadeInAnim.cancel();
|
|
|
|
|
mQSBSearchBarFadeOutAnim.cancel();
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
2011-06-06 14:27:16 -07:00
|
|
|
/*
|
|
|
|
|
* Shows and hides the search bar.
|
|
|
|
|
*/
|
|
|
|
|
public void showSearchBar(boolean animated) {
|
2011-06-20 15:41:53 -07:00
|
|
|
cancelAnimations();
|
2011-06-06 14:27:16 -07:00
|
|
|
if (animated) {
|
2011-06-20 15:41:53 -07:00
|
|
|
mQSBSearchBarFadeInAnim.start();
|
2011-06-06 14:27:16 -07:00
|
|
|
} else {
|
2011-06-20 15:41:53 -07:00
|
|
|
mQSBSearchBar.setVisibility(View.VISIBLE);
|
2011-06-06 14:27:16 -07:00
|
|
|
mQSBSearchBar.setAlpha(1f);
|
2012-05-14 11:03:49 -07:00
|
|
|
mQSBSearchBar.setTranslationY(0);
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
|
|
|
|
mIsSearchBarHidden = false;
|
|
|
|
|
}
|
|
|
|
|
public void hideSearchBar(boolean animated) {
|
2011-06-20 15:41:53 -07:00
|
|
|
cancelAnimations();
|
2011-06-06 14:27:16 -07:00
|
|
|
if (animated) {
|
2011-06-20 15:41:53 -07:00
|
|
|
mQSBSearchBarFadeOutAnim.start();
|
2011-06-06 14:27:16 -07:00
|
|
|
} else {
|
2011-11-03 13:50:45 -07:00
|
|
|
mQSBSearchBar.setVisibility(View.INVISIBLE);
|
2011-06-06 14:27:16 -07:00
|
|
|
mQSBSearchBar.setAlpha(0f);
|
2012-05-14 11:03:49 -07:00
|
|
|
mQSBSearchBar.setTranslationY(0);
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
|
|
|
|
mIsSearchBarHidden = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Gets various transition durations.
|
|
|
|
|
*/
|
|
|
|
|
public int getTransitionInDuration() {
|
|
|
|
|
return sTransitionInDuration;
|
|
|
|
|
}
|
|
|
|
|
public int getTransitionOutDuration() {
|
|
|
|
|
return sTransitionOutDuration;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
/*
|
|
|
|
|
* DragController.DragListener implementation
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragStart(DragSource source, Object info, int dragAction) {
|
|
|
|
|
// Animate out the QSB search bar, and animate in the drop target bar
|
2011-07-11 15:20:48 -07:00
|
|
|
mDropTargetBar.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
|
mDropTargetBar.buildLayer();
|
|
|
|
|
mDropTargetBarFadeOutAnim.cancel();
|
2011-06-20 15:41:53 -07:00
|
|
|
mDropTargetBarFadeInAnim.start();
|
2011-06-06 14:27:16 -07:00
|
|
|
if (!mIsSearchBarHidden) {
|
2011-07-11 15:20:48 -07:00
|
|
|
mQSBSearchBarFadeInAnim.cancel();
|
2011-06-20 15:41:53 -07:00
|
|
|
mQSBSearchBarFadeOutAnim.start();
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
2011-07-19 21:47:37 -07:00
|
|
|
public void deferOnDragEnd() {
|
|
|
|
|
mDeferOnDragEnd = true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
@Override
|
|
|
|
|
public void onDragEnd() {
|
2011-07-19 21:47:37 -07:00
|
|
|
if (!mDeferOnDragEnd) {
|
|
|
|
|
// Restore the QSB search bar, and animate out the drop target bar
|
|
|
|
|
mDropTargetBarFadeInAnim.cancel();
|
|
|
|
|
mDropTargetBarFadeOutAnim.start();
|
|
|
|
|
if (!mIsSearchBarHidden) {
|
|
|
|
|
mQSBSearchBarFadeOutAnim.cancel();
|
|
|
|
|
mQSBSearchBarFadeInAnim.start();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mDeferOnDragEnd = false;
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
2011-10-05 11:44:49 -07:00
|
|
|
|
|
|
|
|
public void onSearchPackagesChanged(boolean searchVisible, boolean voiceVisible) {
|
|
|
|
|
if (mQSBSearchBar != null) {
|
|
|
|
|
Drawable bg = mQSBSearchBar.getBackground();
|
|
|
|
|
if (bg != null && (!searchVisible && !voiceVisible)) {
|
|
|
|
|
// Save the background and disable it
|
|
|
|
|
mPreviousBackground = bg;
|
|
|
|
|
mQSBSearchBar.setBackgroundResource(0);
|
|
|
|
|
} else if (mPreviousBackground != null && (searchVisible || voiceVisible)) {
|
|
|
|
|
// Restore the background
|
2012-04-13 14:44:29 -07:00
|
|
|
mQSBSearchBar.setBackground(mPreviousBackground);
|
2011-10-05 11:44:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-13 11:31:38 +01:00
|
|
|
|
|
|
|
|
public Rect getSearchBarBounds() {
|
|
|
|
|
if (mQSBSearchBar != null) {
|
|
|
|
|
final float appScale = mQSBSearchBar.getContext().getResources()
|
|
|
|
|
.getCompatibilityInfo().applicationScale;
|
|
|
|
|
final int[] pos = new int[2];
|
|
|
|
|
mQSBSearchBar.getLocationOnScreen(pos);
|
|
|
|
|
|
|
|
|
|
final Rect rect = new Rect();
|
|
|
|
|
rect.left = (int) (pos[0] * appScale + 0.5f);
|
|
|
|
|
rect.top = (int) (pos[1] * appScale + 0.5f);
|
|
|
|
|
rect.right = (int) ((pos[0] + mQSBSearchBar.getWidth()) * appScale + 0.5f);
|
|
|
|
|
rect.bottom = (int) ((pos[1] + mQSBSearchBar.getHeight()) * appScale + 0.5f);
|
|
|
|
|
return rect;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|