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;
|
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;
|
2015-08-03 14:40:11 -07:00
|
|
|
import android.view.accessibility.AccessibilityManager;
|
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;
|
|
|
|
|
|
2015-08-05 12:32:47 -07:00
|
|
|
import com.android.launcher3.util.Thunk;
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
/*
|
|
|
|
|
* 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 {
|
|
|
|
|
|
2015-08-03 14:40:11 -07:00
|
|
|
/** The different states that the search bar space can be in. */
|
|
|
|
|
public enum State {
|
|
|
|
|
INVISIBLE (0f, 0f),
|
|
|
|
|
SEARCH_BAR (1f, 0f),
|
|
|
|
|
DROP_TARGET (0f, 1f);
|
2011-05-31 16:50:48 -07:00
|
|
|
|
2015-08-03 14:40:11 -07:00
|
|
|
private final float mSearchBarAlpha;
|
|
|
|
|
private final float mDropTargetBarAlpha;
|
|
|
|
|
|
|
|
|
|
State(float sbAlpha, float dtbAlpha) {
|
|
|
|
|
mSearchBarAlpha = sbAlpha;
|
|
|
|
|
mDropTargetBarAlpha = dtbAlpha;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getSearchBarAlpha() {
|
|
|
|
|
return mSearchBarAlpha;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float getDropTargetBarAlpha() {
|
|
|
|
|
return mDropTargetBarAlpha;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int DEFAULT_DRAG_FADE_DURATION = 175;
|
|
|
|
|
|
|
|
|
|
private LauncherViewPropertyAnimator mDropTargetBarAnimator;
|
|
|
|
|
private LauncherViewPropertyAnimator mQSBSearchBarAnimator;
|
2012-05-25 14:25:44 -07:00
|
|
|
private static final AccelerateInterpolator sAccelerateInterpolator =
|
|
|
|
|
new AccelerateInterpolator();
|
2011-06-20 15:41:53 -07:00
|
|
|
|
2015-08-03 14:40:11 -07:00
|
|
|
private State mState = State.SEARCH_BAR;
|
2015-08-05 12:32:47 -07:00
|
|
|
@Thunk View mQSB;
|
|
|
|
|
@Thunk View mDropTargetBar;
|
2011-07-19 21:47:37 -07:00
|
|
|
private boolean mDeferOnDragEnd = false;
|
2015-08-05 12:32:47 -07:00
|
|
|
@Thunk boolean mAccessibilityEnabled = false;
|
2011-05-31 16:50:48 -07:00
|
|
|
|
2015-04-10 13:45:42 -07:00
|
|
|
// Drop targets
|
|
|
|
|
private ButtonDropTarget mInfoDropTarget;
|
|
|
|
|
private ButtonDropTarget mDeleteDropTarget;
|
|
|
|
|
private ButtonDropTarget mUninstallDropTarget;
|
|
|
|
|
|
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);
|
2015-04-10 13:45:42 -07:00
|
|
|
dragController.setFlingToDeleteDropTarget(mDeleteDropTarget);
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
dragController.addDragListener(mInfoDropTarget);
|
|
|
|
|
dragController.addDragListener(mDeleteDropTarget);
|
2015-04-10 13:45:42 -07:00
|
|
|
dragController.addDragListener(mUninstallDropTarget);
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
dragController.addDropTarget(mInfoDropTarget);
|
|
|
|
|
dragController.addDropTarget(mDeleteDropTarget);
|
2015-04-10 13:45:42 -07:00
|
|
|
dragController.addDropTarget(mUninstallDropTarget);
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
mInfoDropTarget.setLauncher(launcher);
|
|
|
|
|
mDeleteDropTarget.setLauncher(launcher);
|
2015-04-10 13:45:42 -07:00
|
|
|
mUninstallDropTarget.setLauncher(launcher);
|
2014-11-06 10:12:54 -08: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);
|
2015-04-10 13:45:42 -07:00
|
|
|
mUninstallDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.uninstall_target_text);
|
2011-07-11 15:20:48 -07:00
|
|
|
|
2011-07-19 21:47:37 -07:00
|
|
|
mInfoDropTarget.setSearchDropTargetBar(this);
|
|
|
|
|
mDeleteDropTarget.setSearchDropTargetBar(this);
|
2015-04-10 13:45:42 -07:00
|
|
|
mUninstallDropTarget.setSearchDropTargetBar(this);
|
2011-07-19 21:47:37 -07:00
|
|
|
|
2011-06-20 15:41:53 -07:00
|
|
|
// Create the various fade animations
|
2015-04-20 18:26:57 -07:00
|
|
|
mDropTargetBar.setAlpha(0f);
|
2015-08-03 14:40:11 -07:00
|
|
|
mDropTargetBarAnimator = new LauncherViewPropertyAnimator(mDropTargetBar);
|
|
|
|
|
mDropTargetBarAnimator.setInterpolator(sAccelerateInterpolator);
|
|
|
|
|
mDropTargetBarAnimator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
// Ensure that the view is visible for the animation
|
|
|
|
|
mDropTargetBar.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
|
2015-08-03 14:40:11 -07:00
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (mDropTargetBar != null) {
|
|
|
|
|
AlphaUpdateListener.updateVisibility(mDropTargetBar, mAccessibilityEnabled);
|
|
|
|
|
}
|
2012-05-14 20:41:52 -07:00
|
|
|
}
|
2015-08-03 14:40:11 -07:00
|
|
|
});
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
2015-04-20 18:26:57 -07:00
|
|
|
|
2015-08-03 14:40:11 -07:00
|
|
|
public void setQsbSearchBar(View qsb) {
|
|
|
|
|
mQSB = qsb;
|
|
|
|
|
if (mQSB != null) {
|
|
|
|
|
// Update the search ber animation
|
|
|
|
|
mQSBSearchBarAnimator = new LauncherViewPropertyAnimator(mQSB);
|
|
|
|
|
mQSBSearchBarAnimator.setInterpolator(sAccelerateInterpolator);
|
|
|
|
|
mQSBSearchBarAnimator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
// Ensure that the view is visible for the animation
|
|
|
|
|
if (mQSB != null) {
|
|
|
|
|
mQSB.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (mQSB != null) {
|
|
|
|
|
AlphaUpdateListener.updateVisibility(mQSB, mAccessibilityEnabled);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-06-06 14:27:16 -07:00
|
|
|
} else {
|
2015-08-03 14:40:11 -07:00
|
|
|
mQSBSearchBarAnimator = null;
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 18:26:57 -07:00
|
|
|
/**
|
2015-08-03 14:40:11 -07:00
|
|
|
* Animates the current search bar state to a new state. If the {@param duration} is 0, then
|
|
|
|
|
* the state is applied immediately.
|
2011-06-06 14:27:16 -07:00
|
|
|
*/
|
2015-08-03 14:40:11 -07:00
|
|
|
public void animateToState(State newState, int duration) {
|
|
|
|
|
if (mState != newState) {
|
|
|
|
|
mState = newState;
|
|
|
|
|
|
|
|
|
|
// Update the accessibility state
|
|
|
|
|
AccessibilityManager am = (AccessibilityManager)
|
|
|
|
|
getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
|
|
|
|
|
mAccessibilityEnabled = am.isEnabled();
|
|
|
|
|
|
|
|
|
|
animateViewAlpha(mQSBSearchBarAnimator, mQSB, newState.getSearchBarAlpha(),
|
|
|
|
|
duration);
|
|
|
|
|
animateViewAlpha(mDropTargetBarAnimator, mDropTargetBar, newState.getDropTargetBarAlpha(),
|
|
|
|
|
duration);
|
|
|
|
|
}
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
2015-04-20 18:26:57 -07:00
|
|
|
|
|
|
|
|
/**
|
2015-08-03 14:40:11 -07:00
|
|
|
* Convenience method to animate the alpha of a view using hardware layers.
|
2015-04-20 18:26:57 -07:00
|
|
|
*/
|
2015-08-03 14:40:11 -07:00
|
|
|
private void animateViewAlpha(LauncherViewPropertyAnimator animator, View v, float alpha,
|
|
|
|
|
int duration) {
|
2015-08-20 15:22:18 -07:00
|
|
|
if (v == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
animator.cancel();
|
|
|
|
|
if (Float.compare(v.getAlpha(), alpha) != 0) {
|
2015-08-03 14:40:11 -07:00
|
|
|
if (duration > 0) {
|
|
|
|
|
animator.alpha(alpha).withLayer().setDuration(duration).start();
|
|
|
|
|
} else {
|
|
|
|
|
v.setAlpha(alpha);
|
|
|
|
|
AlphaUpdateListener.updateVisibility(v, mAccessibilityEnabled);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-06 14:27:16 -07:00
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
/*
|
|
|
|
|
* DragController.DragListener implementation
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragStart(DragSource source, Object info, int dragAction) {
|
2015-08-03 14:40:11 -07:00
|
|
|
animateToState(State.DROP_TARGET, DEFAULT_DRAG_FADE_DURATION);
|
2015-01-23 16:11:55 -08:00
|
|
|
}
|
|
|
|
|
|
2015-08-03 14:40:11 -07:00
|
|
|
/**
|
|
|
|
|
* This is called to defer hiding the delete drop target until the drop animation has completed,
|
|
|
|
|
* instead of hiding immediately when the drag has ended.
|
|
|
|
|
*/
|
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-08-03 14:40:11 -07:00
|
|
|
animateToState(State.SEARCH_BAR, DEFAULT_DRAG_FADE_DURATION);
|
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
|
|
|
|
2015-08-03 14:40:11 -07:00
|
|
|
/**
|
|
|
|
|
* @return the bounds of the QSB search bar.
|
|
|
|
|
*/
|
2011-10-13 11:31:38 +01:00
|
|
|
public Rect getSearchBarBounds() {
|
2015-08-03 14:40:11 -07:00
|
|
|
if (mQSB != null) {
|
2011-10-13 11:31:38 +01:00
|
|
|
final int[] pos = new int[2];
|
2015-08-03 14:40:11 -07:00
|
|
|
mQSB.getLocationOnScreen(pos);
|
2011-10-13 11:31:38 +01:00
|
|
|
|
|
|
|
|
final Rect rect = new Rect();
|
2012-06-14 16:18:21 -07:00
|
|
|
rect.left = pos[0];
|
|
|
|
|
rect.top = pos[1];
|
2015-08-03 14:40:11 -07:00
|
|
|
rect.right = pos[0] + mQSB.getWidth();
|
|
|
|
|
rect.bottom = pos[1] + mQSB.getHeight();
|
2011-10-13 11:31:38 +01:00
|
|
|
return rect;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-22 11:29:51 -07:00
|
|
|
|
|
|
|
|
public void enableAccessibleDrag(boolean enable) {
|
2015-08-03 14:40:11 -07:00
|
|
|
if (mQSB != null) {
|
|
|
|
|
mQSB.setVisibility(enable ? View.GONE : View.VISIBLE);
|
2015-04-22 11:29:51 -07:00
|
|
|
}
|
|
|
|
|
mInfoDropTarget.enableAccessibleDrag(enable);
|
|
|
|
|
mDeleteDropTarget.enableAccessibleDrag(enable);
|
|
|
|
|
mUninstallDropTarget.enableAccessibleDrag(enable);
|
|
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|