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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2011-05-31 16:50:48 -07:00
|
|
|
|
2011-06-20 15:41:53 -07:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
2014-10-16 09:49:24 -07:00
|
|
|
import android.animation.ValueAnimator;
|
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-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;
|
2011-05-31 16:50:48 -07:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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-25 14:25:44 -07:00
|
|
|
private ObjectAnimator mDropTargetBarAnim;
|
2014-10-16 09:49:24 -07:00
|
|
|
private ValueAnimator mQSBSearchBarAnim;
|
2012-05-25 14:25:44 -07:00
|
|
|
private static final AccelerateInterpolator sAccelerateInterpolator =
|
|
|
|
|
new AccelerateInterpolator();
|
2011-06-20 15:41:53 -07:00
|
|
|
|
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
|
|
|
|
2012-05-14 20:41:52 -07:00
|
|
|
private boolean mEnableDropDownDropTargets;
|
2011-10-05 11:44:49 -07:00
|
|
|
|
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);
|
2014-11-06 10:12:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setQsbSearchBar(View qsb) {
|
|
|
|
|
mQSBSearchBar = qsb;
|
2014-10-16 09:49:24 -07:00
|
|
|
if (mQSBSearchBar != null) {
|
|
|
|
|
if (mEnableDropDownDropTargets) {
|
|
|
|
|
mQSBSearchBarAnim = LauncherAnimUtils.ofFloat(mQSBSearchBar, "translationY", 0,
|
|
|
|
|
-mBarHeight);
|
|
|
|
|
} else {
|
|
|
|
|
mQSBSearchBarAnim = LauncherAnimUtils.ofFloat(mQSBSearchBar, "alpha", 1f, 0f);
|
|
|
|
|
}
|
|
|
|
|
setupAnimation(mQSBSearchBarAnim, mQSBSearchBar);
|
2013-08-07 17:20:14 +01:00
|
|
|
} else {
|
2014-10-16 09:49:24 -07:00
|
|
|
// Create a no-op animation of the search bar is null
|
|
|
|
|
mQSBSearchBarAnim = ValueAnimator.ofFloat(0, 0);
|
|
|
|
|
mQSBSearchBarAnim.setDuration(sTransitionInDuration);
|
2013-08-07 17:20:14 +01:00
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
2012-05-16 17:02:20 -07:00
|
|
|
private void prepareStartAnimation(View v) {
|
2012-05-25 14:25:44 -07:00
|
|
|
// Enable the hw layers before the animation starts (will be disabled in the onAnimationEnd
|
|
|
|
|
// callback below)
|
2014-10-16 09:49:24 -07:00
|
|
|
if (v != null) {
|
|
|
|
|
v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
|
}
|
2012-05-16 17:02:20 -07:00
|
|
|
}
|
|
|
|
|
|
2014-10-16 09:49:24 -07:00
|
|
|
private void setupAnimation(ValueAnimator anim, final View v) {
|
2012-05-25 14:25:44 -07:00
|
|
|
anim.setInterpolator(sAccelerateInterpolator);
|
|
|
|
|
anim.setDuration(sTransitionInDuration);
|
|
|
|
|
anim.addListener(new AnimatorListenerAdapter() {
|
2012-05-11 10:51:32 -07:00
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
2014-10-16 09:49:24 -07:00
|
|
|
if (v != null) {
|
|
|
|
|
v.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
|
}
|
2012-05-11 10:51:32 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
|
|
|
|
|
// Get the individual components
|
|
|
|
|
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
|
|
|
|
2011-07-19 21:47:37 -07:00
|
|
|
mInfoDropTarget.setSearchDropTargetBar(this);
|
|
|
|
|
mDeleteDropTarget.setSearchDropTargetBar(this);
|
|
|
|
|
|
2012-05-14 20:41:52 -07:00
|
|
|
mEnableDropDownDropTargets =
|
2011-07-11 15:20:48 -07:00
|
|
|
getResources().getBoolean(R.bool.config_useDropTargetDownTransition);
|
2011-06-20 15:41:53 -07:00
|
|
|
|
|
|
|
|
// Create the various fade animations
|
2012-05-14 20:41:52 -07:00
|
|
|
if (mEnableDropDownDropTargets) {
|
2013-08-12 16:19:28 -07:00
|
|
|
LauncherAppState app = LauncherAppState.getInstance();
|
|
|
|
|
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
|
|
|
|
|
mBarHeight = grid.searchBarSpaceHeightPx;
|
2011-07-11 15:20:48 -07:00
|
|
|
mDropTargetBar.setTranslationY(-mBarHeight);
|
2013-11-06 16:37:34 +01:00
|
|
|
mDropTargetBarAnim = LauncherAnimUtils.ofFloat(mDropTargetBar, "translationY",
|
2012-05-25 14:25:44 -07:00
|
|
|
-mBarHeight, 0f);
|
2013-08-07 17:20:14 +01:00
|
|
|
|
2012-05-11 10:51:32 -07:00
|
|
|
} else {
|
|
|
|
|
mDropTargetBar.setAlpha(0f);
|
2013-11-06 16:37:34 +01:00
|
|
|
mDropTargetBarAnim = LauncherAnimUtils.ofFloat(mDropTargetBar, "alpha", 0f, 1f);
|
2011-07-11 15:20:48 -07:00
|
|
|
}
|
2012-05-25 14:25:44 -07:00
|
|
|
setupAnimation(mDropTargetBarAnim, mDropTargetBar);
|
2011-06-20 15:41:53 -07:00
|
|
|
}
|
|
|
|
|
|
2012-03-01 16:09:54 -08:00
|
|
|
public void finishAnimations() {
|
2012-05-25 14:25:44 -07:00
|
|
|
prepareStartAnimation(mDropTargetBar);
|
|
|
|
|
mDropTargetBarAnim.reverse();
|
|
|
|
|
prepareStartAnimation(mQSBSearchBar);
|
|
|
|
|
mQSBSearchBarAnim.reverse();
|
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) {
|
2013-10-16 13:46:04 +01:00
|
|
|
boolean needToCancelOngoingAnimation = mQSBSearchBarAnim.isRunning() && !animated;
|
|
|
|
|
if (!mIsSearchBarHidden && !needToCancelOngoingAnimation) return;
|
2011-06-06 14:27:16 -07:00
|
|
|
if (animated) {
|
2012-05-16 17:02:20 -07:00
|
|
|
prepareStartAnimation(mQSBSearchBar);
|
2012-05-25 14:25:44 -07:00
|
|
|
mQSBSearchBarAnim.reverse();
|
2011-06-06 14:27:16 -07:00
|
|
|
} else {
|
2012-05-25 14:25:44 -07:00
|
|
|
mQSBSearchBarAnim.cancel();
|
2014-10-16 09:49:24 -07:00
|
|
|
if (mQSBSearchBar != null && mEnableDropDownDropTargets) {
|
2012-05-14 20:41:52 -07:00
|
|
|
mQSBSearchBar.setTranslationY(0);
|
2014-10-16 09:49:24 -07:00
|
|
|
} else if (mQSBSearchBar != null) {
|
2012-06-18 14:31:28 -07:00
|
|
|
mQSBSearchBar.setAlpha(1f);
|
2012-05-14 20:41:52 -07:00
|
|
|
}
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
|
|
|
|
mIsSearchBarHidden = false;
|
|
|
|
|
}
|
|
|
|
|
public void hideSearchBar(boolean animated) {
|
2013-10-16 13:46:04 +01:00
|
|
|
boolean needToCancelOngoingAnimation = mQSBSearchBarAnim.isRunning() && !animated;
|
|
|
|
|
if (mIsSearchBarHidden && !needToCancelOngoingAnimation) return;
|
2011-06-06 14:27:16 -07:00
|
|
|
if (animated) {
|
2012-05-16 17:02:20 -07:00
|
|
|
prepareStartAnimation(mQSBSearchBar);
|
2012-05-25 14:25:44 -07:00
|
|
|
mQSBSearchBarAnim.start();
|
2011-06-06 14:27:16 -07:00
|
|
|
} else {
|
2012-05-25 14:25:44 -07:00
|
|
|
mQSBSearchBarAnim.cancel();
|
2014-10-16 09:49:24 -07:00
|
|
|
if (mQSBSearchBar != null && mEnableDropDownDropTargets) {
|
2012-05-25 14:25:44 -07:00
|
|
|
mQSBSearchBar.setTranslationY(-mBarHeight);
|
2014-10-16 09:49:24 -07:00
|
|
|
} else if (mQSBSearchBar != null) {
|
2012-06-18 14:31:28 -07:00
|
|
|
mQSBSearchBar.setAlpha(0f);
|
2012-05-14 20:41:52 -07:00
|
|
|
}
|
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) {
|
2015-01-23 16:11:55 -08:00
|
|
|
showDeleteTarget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void showDeleteTarget() {
|
2011-05-31 16:50:48 -07:00
|
|
|
// Animate out the QSB search bar, and animate in the drop target bar
|
2012-05-16 17:02:20 -07:00
|
|
|
prepareStartAnimation(mDropTargetBar);
|
2012-05-25 14:25:44 -07:00
|
|
|
mDropTargetBarAnim.start();
|
2011-06-06 14:27:16 -07:00
|
|
|
if (!mIsSearchBarHidden) {
|
2012-05-16 17:02:20 -07:00
|
|
|
prepareStartAnimation(mQSBSearchBar);
|
2012-05-25 14:25:44 -07:00
|
|
|
mQSBSearchBarAnim.start();
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 16:11:55 -08:00
|
|
|
public void hideDeleteTarget() {
|
|
|
|
|
// Restore the QSB search bar, and animate out the drop target bar
|
|
|
|
|
prepareStartAnimation(mDropTargetBar);
|
|
|
|
|
mDropTargetBarAnim.reverse();
|
|
|
|
|
if (!mIsSearchBarHidden) {
|
|
|
|
|
prepareStartAnimation(mQSBSearchBar);
|
|
|
|
|
mQSBSearchBarAnim.reverse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2015-01-23 16:11:55 -08:00
|
|
|
hideDeleteTarget();
|
2011-07-19 21:47:37 -07:00
|
|
|
} 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
|
|
|
|
2011-10-13 11:31:38 +01:00
|
|
|
public Rect getSearchBarBounds() {
|
|
|
|
|
if (mQSBSearchBar != null) {
|
|
|
|
|
final int[] pos = new int[2];
|
|
|
|
|
mQSBSearchBar.getLocationOnScreen(pos);
|
|
|
|
|
|
|
|
|
|
final Rect rect = new Rect();
|
2012-06-14 16:18:21 -07:00
|
|
|
rect.left = pos[0];
|
|
|
|
|
rect.top = pos[1];
|
|
|
|
|
rect.right = pos[0] + mQSBSearchBar.getWidth();
|
|
|
|
|
rect.bottom = pos[1] + mQSBSearchBar.getHeight();
|
2011-10-13 11:31:38 +01:00
|
|
|
return rect;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|