2015-03-10 16:28:47 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 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.
|
|
|
|
|
*/
|
2015-05-22 11:12:27 -07:00
|
|
|
package com.android.launcher3.allapps;
|
2015-03-02 11:51:23 -08:00
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-10-10 15:21:15 -07:00
|
|
|
import android.graphics.Bitmap;
|
2015-03-02 11:51:23 -08:00
|
|
|
import android.graphics.Rect;
|
2017-04-20 12:07:38 -07:00
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
2015-06-04 17:18:17 -07:00
|
|
|
import android.text.Selection;
|
|
|
|
|
import android.text.SpannableStringBuilder;
|
2015-03-02 11:51:23 -08:00
|
|
|
import android.util.AttributeSet;
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.view.KeyEvent;
|
2015-03-02 11:51:23 -08:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
2016-07-06 15:10:14 -07:00
|
|
|
import android.view.ViewGroup;
|
2017-10-10 15:21:15 -07:00
|
|
|
import android.widget.RelativeLayout;
|
2016-01-29 13:14:14 -08:00
|
|
|
|
2015-05-22 11:12:27 -07:00
|
|
|
import com.android.launcher3.AppInfo;
|
2017-03-20 11:30:27 -07:00
|
|
|
import com.android.launcher3.BubbleTextView;
|
2017-10-10 15:21:15 -07:00
|
|
|
import com.android.launcher3.ClickShadowView;
|
2015-05-22 11:12:27 -07:00
|
|
|
import com.android.launcher3.DeleteDropTarget;
|
|
|
|
|
import com.android.launcher3.DeviceProfile;
|
|
|
|
|
import com.android.launcher3.DragSource;
|
|
|
|
|
import com.android.launcher3.DropTarget;
|
2016-09-26 14:01:56 -07:00
|
|
|
import com.android.launcher3.Insettable;
|
2015-05-22 11:12:27 -07:00
|
|
|
import com.android.launcher3.ItemInfo;
|
|
|
|
|
import com.android.launcher3.Launcher;
|
2017-03-20 11:30:27 -07:00
|
|
|
import com.android.launcher3.PromiseAppInfo;
|
2015-05-22 11:12:27 -07:00
|
|
|
import com.android.launcher3.R;
|
2017-04-20 12:07:38 -07:00
|
|
|
import com.android.launcher3.anim.SpringAnimationHandler;
|
2016-04-28 17:39:03 -07:00
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2016-09-28 12:49:25 -07:00
|
|
|
import com.android.launcher3.dragndrop.DragController;
|
2016-08-16 15:36:48 -07:00
|
|
|
import com.android.launcher3.dragndrop.DragOptions;
|
2016-04-28 17:39:03 -07:00
|
|
|
import com.android.launcher3.folder.Folder;
|
2016-05-09 20:43:21 -07:00
|
|
|
import com.android.launcher3.keyboard.FocusedItemDecorator;
|
2016-09-01 12:47:12 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
2017-01-20 08:15:28 -08:00
|
|
|
import com.android.launcher3.util.PackageUserKey;
|
2017-10-10 15:21:15 -07:00
|
|
|
import com.android.launcher3.util.TransformingTouchDelegate;
|
2015-03-18 14:16:05 -07:00
|
|
|
|
2015-03-02 11:51:23 -08:00
|
|
|
import java.util.List;
|
2017-01-20 08:15:28 -08:00
|
|
|
import java.util.Set;
|
2015-03-02 11:51:23 -08:00
|
|
|
|
|
|
|
|
/**
|
2015-05-08 13:06:44 -07:00
|
|
|
* The all apps view container.
|
2015-03-02 11:51:23 -08:00
|
|
|
*/
|
2017-10-10 15:21:15 -07:00
|
|
|
public class AllAppsContainerView extends RelativeLayout implements DragSource,
|
|
|
|
|
View.OnLongClickListener, Insettable, DeviceProfile.LauncherLayoutChangeListener,
|
|
|
|
|
BubbleTextView.BubbleTextShadowHandler {
|
|
|
|
|
|
|
|
|
|
protected final Rect mBasePadding = new Rect();
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2016-01-29 13:14:14 -08:00
|
|
|
private final Launcher mLauncher;
|
|
|
|
|
private final AlphabeticalAppsList mApps;
|
|
|
|
|
private final AllAppsGridAdapter mAdapter;
|
2017-04-20 12:07:38 -07:00
|
|
|
private final LinearLayoutManager mLayoutManager;
|
2017-10-10 15:21:15 -07:00
|
|
|
private final ClickShadowView mTouchFeedbackView;
|
2016-01-29 13:14:14 -08:00
|
|
|
|
|
|
|
|
private AllAppsRecyclerView mAppsRecyclerView;
|
2017-05-07 11:56:00 -07:00
|
|
|
private SearchUiManager mSearchUiManager;
|
2016-01-29 13:14:14 -08:00
|
|
|
private View mSearchContainer;
|
|
|
|
|
|
2015-07-10 12:38:30 -07:00
|
|
|
private SpannableStringBuilder mSearchQueryBuilder = null;
|
2015-05-13 17:40:42 -07:00
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
private int mNumAppsPerRow;
|
2015-05-12 19:05:30 -07:00
|
|
|
private int mNumPredictedAppsPerRow;
|
2016-09-22 16:50:17 -07:00
|
|
|
|
2017-04-20 12:07:38 -07:00
|
|
|
private SpringAnimationHandler mSpringAnimationHandler;
|
|
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
private TransformingTouchDelegate mTouchDelegate;
|
|
|
|
|
|
2015-05-22 11:12:27 -07:00
|
|
|
public AllAppsContainerView(Context context) {
|
2015-03-02 11:51:23 -08:00
|
|
|
this(context, null);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 11:12:27 -07:00
|
|
|
public AllAppsContainerView(Context context, AttributeSet attrs) {
|
2015-03-02 11:51:23 -08:00
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 11:12:27 -07:00
|
|
|
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
2015-03-24 16:28:44 -07:00
|
|
|
super(context, attrs, defStyleAttr);
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2016-06-19 12:49:00 -07:00
|
|
|
mLauncher = Launcher.getLauncher(context);
|
2015-06-04 17:18:17 -07:00
|
|
|
mApps = new AlphabeticalAppsList(context);
|
2017-06-06 15:41:21 -07:00
|
|
|
mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
|
|
|
|
|
mSpringAnimationHandler = mAdapter.getSpringAnimationHandler();
|
2015-06-04 17:18:17 -07:00
|
|
|
mApps.setAdapter(mAdapter);
|
2015-05-05 17:21:58 -07:00
|
|
|
mLayoutManager = mAdapter.getLayoutManager();
|
2015-06-04 17:18:17 -07:00
|
|
|
mSearchQueryBuilder = new SpannableStringBuilder();
|
2016-11-11 14:35:20 -08:00
|
|
|
|
2015-06-04 17:18:17 -07:00
|
|
|
Selection.setSelection(mSearchQueryBuilder, 0);
|
2017-10-10 15:21:15 -07:00
|
|
|
|
|
|
|
|
mTouchFeedbackView = new ClickShadowView(context);
|
|
|
|
|
// Make the feedback view large enough to hold the blur bitmap.
|
|
|
|
|
int size = mLauncher.getDeviceProfile().allAppsIconSizePx
|
|
|
|
|
+ mTouchFeedbackView.getExtraSize();
|
|
|
|
|
addView(mTouchFeedbackView, size, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
|
|
|
|
|
|
DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile();
|
|
|
|
|
grid.addLauncherLayoutChangedListener(this);
|
|
|
|
|
|
|
|
|
|
mTouchDelegate = new TransformingTouchDelegate(mAppsRecyclerView);
|
|
|
|
|
setTouchDelegate(mTouchDelegate);
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
2016-11-01 13:42:23 -07:00
|
|
|
@Override
|
2017-10-10 15:21:15 -07:00
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
|
|
|
|
|
|
DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile();
|
|
|
|
|
grid.removeLauncherLayoutChangedListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate the background padding as it can change due to insets/content padding change.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onLauncherLayoutChanged() {
|
|
|
|
|
DeviceProfile grid = mLauncher.getDeviceProfile();
|
|
|
|
|
if (!grid.isVerticalBarLayout()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int[] padding = grid.getContainerPadding();
|
|
|
|
|
int paddingLeft = padding[0];
|
|
|
|
|
int paddingRight = padding[1];
|
|
|
|
|
mBasePadding.set(paddingLeft, 0, paddingRight, 0);
|
|
|
|
|
setPadding(paddingLeft, 0, paddingRight, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
|
mTouchDelegate.setBounds(
|
|
|
|
|
mAppsRecyclerView.getLeft() - mBasePadding.left,
|
|
|
|
|
mAppsRecyclerView.getTop() - mBasePadding.top,
|
|
|
|
|
mAppsRecyclerView.getRight() + mBasePadding.right,
|
|
|
|
|
mAppsRecyclerView.getBottom() + mBasePadding.bottom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setPressedIcon(BubbleTextView icon, Bitmap background) {
|
|
|
|
|
if (icon == null || background == null) {
|
|
|
|
|
mTouchFeedbackView.setBitmap(null);
|
|
|
|
|
mTouchFeedbackView.animate().cancel();
|
|
|
|
|
} else if (mTouchFeedbackView.setBitmap(background)) {
|
|
|
|
|
View rv = findViewById(R.id.apps_list_view);
|
|
|
|
|
mTouchFeedbackView.alignWithIconView(icon, (ViewGroup) icon.getParent(), rv);
|
|
|
|
|
mTouchFeedbackView.animateShadow();
|
2016-11-01 13:42:23 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 11:51:23 -08:00
|
|
|
/**
|
|
|
|
|
* Sets the current set of apps.
|
|
|
|
|
*/
|
|
|
|
|
public void setApps(List<AppInfo> apps) {
|
|
|
|
|
mApps.setApps(apps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-17 07:45:25 -07:00
|
|
|
* Adds or updates existing apps in the list
|
2015-03-02 11:51:23 -08:00
|
|
|
*/
|
2017-08-17 07:45:25 -07:00
|
|
|
public void addOrUpdateApps(List<AppInfo> apps) {
|
|
|
|
|
mApps.addOrUpdateApps(apps);
|
2017-05-07 11:56:00 -07:00
|
|
|
mSearchUiManager.refreshSearchResult();
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
2017-03-20 11:30:27 -07:00
|
|
|
public void updatePromiseAppProgress(PromiseAppInfo app) {
|
|
|
|
|
int childCount = mAppsRecyclerView.getChildCount();
|
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
|
View child = mAppsRecyclerView.getChildAt(i);
|
|
|
|
|
if (child instanceof BubbleTextView && child.getTag() == app) {
|
|
|
|
|
BubbleTextView bubbleTextView = (BubbleTextView) child;
|
|
|
|
|
bubbleTextView.applyProgressLevel(app.level);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 11:51:23 -08:00
|
|
|
/**
|
|
|
|
|
* Removes some apps from the list.
|
|
|
|
|
*/
|
|
|
|
|
public void removeApps(List<AppInfo> apps) {
|
|
|
|
|
mApps.removeApps(apps);
|
2017-05-07 11:56:00 -07:00
|
|
|
mSearchUiManager.refreshSearchResult();
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
2016-06-10 12:00:02 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether the view itself will handle the touch event or not.
|
|
|
|
|
*/
|
2016-08-05 13:57:21 -07:00
|
|
|
public boolean shouldContainerScroll(MotionEvent ev) {
|
|
|
|
|
// IF the MotionEvent is inside the search box, and the container keeps on receiving
|
|
|
|
|
// touch input, container should move down.
|
|
|
|
|
if (mLauncher.getDragLayer().isEventOverView(mSearchContainer, ev)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-10-10 15:21:15 -07:00
|
|
|
return mAppsRecyclerView.shouldContainerScroll(ev, mLauncher.getDragLayer());
|
2016-06-06 14:19:02 -07:00
|
|
|
}
|
2016-06-30 13:52:36 -07:00
|
|
|
|
2015-09-03 11:36:19 -07:00
|
|
|
/**
|
|
|
|
|
* Resets the state of AllApps.
|
|
|
|
|
*/
|
|
|
|
|
public void reset() {
|
|
|
|
|
// Reset the search bar and base recycler view after transitioning home
|
2017-05-07 11:56:00 -07:00
|
|
|
mAppsRecyclerView.scrollToTop();
|
|
|
|
|
mSearchUiManager.reset();
|
2015-09-03 11:36:19 -07:00
|
|
|
}
|
|
|
|
|
|
2015-03-02 11:51:23 -08:00
|
|
|
@Override
|
|
|
|
|
protected void onFinishInflate() {
|
2015-06-04 17:18:17 -07:00
|
|
|
super.onFinishInflate();
|
2015-04-10 10:19:58 -07:00
|
|
|
|
2015-06-04 17:18:17 -07:00
|
|
|
// This is a focus listener that proxies focus from a view into the list view. This is to
|
|
|
|
|
// work around the search box from getting first focus and showing the cursor.
|
2017-10-10 15:21:15 -07:00
|
|
|
setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
2015-04-10 10:19:58 -07:00
|
|
|
@Override
|
|
|
|
|
public void onFocusChange(View v, boolean hasFocus) {
|
2015-06-04 17:18:17 -07:00
|
|
|
if (hasFocus) {
|
2015-07-06 17:14:51 -07:00
|
|
|
mAppsRecyclerView.requestFocus();
|
2015-04-10 10:19:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-29 13:14:14 -08:00
|
|
|
});
|
|
|
|
|
|
2015-06-04 17:18:17 -07:00
|
|
|
// Load the all apps recycler view
|
2017-06-07 17:01:35 -07:00
|
|
|
mAppsRecyclerView = findViewById(R.id.apps_list_view);
|
2015-04-10 10:19:58 -07:00
|
|
|
mAppsRecyclerView.setApps(mApps);
|
|
|
|
|
mAppsRecyclerView.setLayoutManager(mLayoutManager);
|
|
|
|
|
mAppsRecyclerView.setAdapter(mAdapter);
|
|
|
|
|
mAppsRecyclerView.setHasFixedSize(true);
|
2017-08-15 10:31:17 -07:00
|
|
|
// No animations will occur when changes occur to the items in this RecyclerView.
|
|
|
|
|
mAppsRecyclerView.setItemAnimator(null);
|
2017-04-20 12:07:38 -07:00
|
|
|
if (FeatureFlags.LAUNCHER3_PHYSICS) {
|
|
|
|
|
mAppsRecyclerView.setSpringAnimationHandler(mSpringAnimationHandler);
|
|
|
|
|
}
|
2017-05-07 11:56:00 -07:00
|
|
|
|
2017-06-27 11:11:03 -07:00
|
|
|
mSearchContainer = findViewById(R.id.search_container_all_apps);
|
2017-05-07 11:56:00 -07:00
|
|
|
mSearchUiManager = (SearchUiManager) mSearchContainer;
|
|
|
|
|
mSearchUiManager.initialize(mApps, mAppsRecyclerView);
|
|
|
|
|
|
2016-01-29 13:14:14 -08:00
|
|
|
|
2016-05-09 20:43:21 -07:00
|
|
|
FocusedItemDecorator focusedItemDecorator = new FocusedItemDecorator(mAppsRecyclerView);
|
|
|
|
|
mAppsRecyclerView.addItemDecoration(focusedItemDecorator);
|
2016-07-11 18:59:18 -07:00
|
|
|
mAppsRecyclerView.preMeasureViews(mAdapter);
|
2016-05-09 20:43:21 -07:00
|
|
|
mAdapter.setIconFocusListener(focusedItemDecorator.getFocusListener());
|
|
|
|
|
|
2017-10-10 15:21:15 -07:00
|
|
|
onLauncherLayoutChanged();
|
2015-06-04 17:18:17 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 08:17:35 -07:00
|
|
|
public SearchUiManager getSearchUiManager() {
|
|
|
|
|
return mSearchUiManager;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-02 11:51:23 -08:00
|
|
|
@Override
|
2015-06-04 17:18:17 -07:00
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2016-06-06 14:19:02 -07:00
|
|
|
DeviceProfile grid = mLauncher.getDeviceProfile();
|
2017-05-07 11:56:00 -07:00
|
|
|
// Update the number of items in the grid before we measure the view
|
2016-07-18 17:18:02 -07:00
|
|
|
grid.updateAppsViewNumCols();
|
2017-05-07 11:56:00 -07:00
|
|
|
|
2017-08-17 22:26:35 -07:00
|
|
|
if (mNumAppsPerRow != grid.inv.numColumns ||
|
|
|
|
|
mNumPredictedAppsPerRow != grid.inv.numColumns) {
|
|
|
|
|
mNumAppsPerRow = grid.inv.numColumns;
|
|
|
|
|
mNumPredictedAppsPerRow = grid.inv.numColumns;
|
2015-06-12 14:18:55 -07:00
|
|
|
|
2015-06-25 16:46:47 -07:00
|
|
|
mAppsRecyclerView.setNumAppsPerRow(grid, mNumAppsPerRow);
|
2015-05-08 13:06:44 -07:00
|
|
|
mAdapter.setNumAppsPerRow(mNumAppsPerRow);
|
2016-10-13 09:31:24 -07:00
|
|
|
mApps.setNumAppsPerRow(mNumAppsPerRow, mNumPredictedAppsPerRow);
|
2015-05-08 13:06:44 -07:00
|
|
|
}
|
2015-06-04 17:18:17 -07:00
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
2015-04-08 10:27:49 -07:00
|
|
|
}
|
|
|
|
|
|
2015-05-15 12:03:37 -07:00
|
|
|
@Override
|
2015-06-04 17:18:17 -07:00
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
2017-05-07 11:56:00 -07:00
|
|
|
mSearchUiManager.preDispatchKeyEvent(event);
|
2015-06-04 17:18:17 -07:00
|
|
|
return super.dispatchKeyEvent(event);
|
2015-05-15 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-03-02 11:51:23 -08:00
|
|
|
@Override
|
2016-09-28 12:49:25 -07:00
|
|
|
public boolean onLongClick(final View v) {
|
2015-03-02 11:51:23 -08:00
|
|
|
// When we have exited all apps or are in transition, disregard long clicks
|
|
|
|
|
if (!mLauncher.isAppsViewVisible() ||
|
|
|
|
|
mLauncher.getWorkspace().isSwitchingState()) return false;
|
Refactor shortcuts drag and drop.
- Instead of creating our own drag view within the container, and
handling logic to determine when to start a real drag, we start
the drag immediately and just defer onDragStart().
- To determine when the deferred drag should start, we add a
DeferDragCondition to DragOptions. The default DeferDragCondition
never defers a drag, but is overridden for apps with shortcuts
to defer until the icon is dragged a given distance.
- Because the drag is handled in DragController, including checking
when to start the deferred drag, DeepShortcutsContainer no longer
needs to handle touch events and ShortcutsContainerListener has
been removed.
This change has several immediate benefits:
- The code is much cleaner, because it allows touch handling to be
done by the DragController through the normal drag flow, without
recreating logic in ShortcutsContainerListener/DeepShortcutContainer.
- The janky second haptic feedback has been removed (now it vibrates
when you long press, like everywhere else, but not again when the
shortcuts close after dragging a distance).
- Drops are animated, instead of just popping the icon back into place.
Bug: 30769920
Bug: 30465972
Bug: 31533078
Change-Id: I679b412b72fbf6c3895d76963311eb5010c8e8db
2016-09-19 14:06:31 -07:00
|
|
|
// Return if global dragging is not enabled or we are already dragging
|
2015-03-02 11:51:23 -08:00
|
|
|
if (!mLauncher.isDraggingEnabled()) return false;
|
Refactor shortcuts drag and drop.
- Instead of creating our own drag view within the container, and
handling logic to determine when to start a real drag, we start
the drag immediately and just defer onDragStart().
- To determine when the deferred drag should start, we add a
DeferDragCondition to DragOptions. The default DeferDragCondition
never defers a drag, but is overridden for apps with shortcuts
to defer until the icon is dragged a given distance.
- Because the drag is handled in DragController, including checking
when to start the deferred drag, DeepShortcutsContainer no longer
needs to handle touch events and ShortcutsContainerListener has
been removed.
This change has several immediate benefits:
- The code is much cleaner, because it allows touch handling to be
done by the DragController through the normal drag flow, without
recreating logic in ShortcutsContainerListener/DeepShortcutContainer.
- The janky second haptic feedback has been removed (now it vibrates
when you long press, like everywhere else, but not again when the
shortcuts close after dragging a distance).
- Drops are animated, instead of just popping the icon back into place.
Bug: 30769920
Bug: 30465972
Bug: 31533078
Change-Id: I679b412b72fbf6c3895d76963311eb5010c8e8db
2016-09-19 14:06:31 -07:00
|
|
|
if (mLauncher.getDragController().isDragging()) return false;
|
2015-03-02 11:51:23 -08:00
|
|
|
|
|
|
|
|
// Start the drag
|
2016-09-28 12:49:25 -07:00
|
|
|
final DragController dragController = mLauncher.getDragController();
|
|
|
|
|
dragController.addDragListener(new DragController.DragListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
|
|
|
|
|
v.setVisibility(INVISIBLE);
|
Refactor shortcuts drag and drop.
- Instead of creating our own drag view within the container, and
handling logic to determine when to start a real drag, we start
the drag immediately and just defer onDragStart().
- To determine when the deferred drag should start, we add a
DeferDragCondition to DragOptions. The default DeferDragCondition
never defers a drag, but is overridden for apps with shortcuts
to defer until the icon is dragged a given distance.
- Because the drag is handled in DragController, including checking
when to start the deferred drag, DeepShortcutsContainer no longer
needs to handle touch events and ShortcutsContainerListener has
been removed.
This change has several immediate benefits:
- The code is much cleaner, because it allows touch handling to be
done by the DragController through the normal drag flow, without
recreating logic in ShortcutsContainerListener/DeepShortcutContainer.
- The janky second haptic feedback has been removed (now it vibrates
when you long press, like everywhere else, but not again when the
shortcuts close after dragging a distance).
- Drops are animated, instead of just popping the icon back into place.
Bug: 30769920
Bug: 30465972
Bug: 31533078
Change-Id: I679b412b72fbf6c3895d76963311eb5010c8e8db
2016-09-19 14:06:31 -07:00
|
|
|
}
|
2016-09-28 12:49:25 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDragEnd() {
|
|
|
|
|
v.setVisibility(VISIBLE);
|
|
|
|
|
dragController.removeDragListener(this);
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-03-02 11:51:23 -08:00
|
|
|
|
2015-05-06 11:42:25 -07:00
|
|
|
DeviceProfile grid = mLauncher.getDeviceProfile();
|
2017-10-03 16:17:32 -07:00
|
|
|
DragOptions options = new DragOptions();
|
|
|
|
|
options.intrinsicIconScaleFactor = (float) grid.allAppsIconSizePx / grid.iconSizePx;
|
|
|
|
|
mLauncher.getWorkspace().beginDragShared(v, this, options);
|
|
|
|
|
return false;
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-03-10 16:28:47 -07:00
|
|
|
public void onDropCompleted(View target, DropTarget.DragObject d, boolean isFlingToDelete,
|
|
|
|
|
boolean success) {
|
2015-03-02 11:51:23 -08:00
|
|
|
if (isFlingToDelete || !success || (target != mLauncher.getWorkspace() &&
|
|
|
|
|
!(target instanceof DeleteDropTarget) && !(target instanceof Folder))) {
|
|
|
|
|
// Exit spring loaded mode if we have not successfully dropped or have not handled the
|
|
|
|
|
// drop in Workspace
|
|
|
|
|
mLauncher.exitSpringLoadedDragModeDelayed(true,
|
|
|
|
|
Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
|
|
|
|
|
}
|
|
|
|
|
mLauncher.unlockScreenOrientation(false);
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
d.deferDragViewCleanupPostAnimation = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-10 16:28:47 -07:00
|
|
|
|
2016-09-01 12:47:12 -07:00
|
|
|
@Override
|
2016-10-06 17:52:22 -07:00
|
|
|
public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) {
|
2017-07-18 04:25:55 -07:00
|
|
|
// This is filled in {@link AllAppsRecyclerView}
|
2016-09-01 12:47:12 -07:00
|
|
|
}
|
2016-09-09 15:02:20 -07:00
|
|
|
|
2016-09-26 14:01:56 -07:00
|
|
|
@Override
|
|
|
|
|
public void setInsets(Rect insets) {
|
|
|
|
|
DeviceProfile grid = mLauncher.getDeviceProfile();
|
2017-05-12 08:17:35 -07:00
|
|
|
mAppsRecyclerView.setPadding(
|
|
|
|
|
mAppsRecyclerView.getPaddingLeft(), mAppsRecyclerView.getPaddingTop(),
|
|
|
|
|
mAppsRecyclerView.getPaddingRight(), insets.bottom);
|
|
|
|
|
|
2016-09-26 14:01:56 -07:00
|
|
|
if (grid.isVerticalBarLayout()) {
|
|
|
|
|
ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
|
|
|
|
|
mlp.leftMargin = insets.left;
|
|
|
|
|
mlp.topMargin = insets.top;
|
|
|
|
|
mlp.rightMargin = insets.right;
|
|
|
|
|
setLayoutParams(mlp);
|
|
|
|
|
} else {
|
|
|
|
|
View navBarBg = findViewById(R.id.nav_bar_bg);
|
|
|
|
|
ViewGroup.LayoutParams navBarBgLp = navBarBg.getLayoutParams();
|
|
|
|
|
navBarBgLp.height = insets.bottom;
|
|
|
|
|
navBarBg.setLayoutParams(navBarBgLp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-20 08:15:28 -08:00
|
|
|
|
|
|
|
|
public void updateIconBadges(Set<PackageUserKey> updatedBadges) {
|
|
|
|
|
final PackageUserKey packageUserKey = new PackageUserKey(null, null);
|
2017-04-25 14:13:20 -07:00
|
|
|
final int n = mAppsRecyclerView.getChildCount();
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
View child = mAppsRecyclerView.getChildAt(i);
|
|
|
|
|
if (!(child instanceof BubbleTextView) || !(child.getTag() instanceof ItemInfo)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ItemInfo info = (ItemInfo) child.getTag();
|
|
|
|
|
if (packageUserKey.updateFromItemInfo(info) && updatedBadges.contains(packageUserKey)) {
|
|
|
|
|
((BubbleTextView) child).applyBadgeState(info, true /* animate */);
|
2017-01-20 08:15:28 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-20 12:07:38 -07:00
|
|
|
|
|
|
|
|
public SpringAnimationHandler getSpringAnimationHandler() {
|
|
|
|
|
return mSpringAnimationHandler;
|
|
|
|
|
}
|
2015-03-02 11:51:23 -08:00
|
|
|
}
|