use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.
the class LauncherAppWidgetHostView method onLongClick.
@Override
public boolean onLongClick(View view) {
if (mIsScrollable) {
DragLayer dragLayer = mLauncher.getDragLayer();
dragLayer.requestDisallowInterceptTouchEvent(false);
}
view.performLongClick();
return true;
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.
the class Snackbar method show.
/**
* Show a snackbar with a label and action.
*/
public static <T extends Context & ActivityContext> void show(T activity, int labelStringResId, int actionStringResId, Runnable onDismissed, @Nullable Runnable onActionClicked) {
closeOpenViews(activity, true, TYPE_SNACKBAR);
Snackbar snackbar = new Snackbar(activity, null);
// Set some properties here since inflated xml only contains the children.
snackbar.setOrientation(HORIZONTAL);
snackbar.setGravity(Gravity.CENTER_VERTICAL);
Resources res = activity.getResources();
snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
snackbar.setPadding(padding, padding, padding, padding);
snackbar.setBackgroundResource(R.drawable.round_rect_primary);
snackbar.mIsOpen = true;
BaseDragLayer dragLayer = activity.getDragLayer();
dragLayer.addView(snackbar);
DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
int absoluteMaxWidth = res.getDimensionPixelSize(R.dimen.snackbar_max_width);
Rect insets = activity.getDeviceProfile().getInsets();
int maxWidth = Math.min(dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right, absoluteMaxWidth);
int minWidth = Math.min(dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right, absoluteMaxWidth);
params.width = minWidth;
params.setMargins(0, 0, 0, marginBottom + insets.bottom);
TextView labelView = snackbar.findViewById(R.id.label);
String labelText = res.getString(labelStringResId);
labelView.setText(labelText);
TextView actionView = snackbar.findViewById(R.id.action);
float actionWidth;
if (actionStringResId != NO_ID) {
String actionText = res.getString(actionStringResId);
actionWidth = actionView.getPaint().measureText(actionText) + actionView.getPaddingRight() + actionView.getPaddingLeft();
actionView.setText(actionText);
actionView.setOnClickListener(v -> {
if (onActionClicked != null) {
onActionClicked.run();
}
snackbar.mOnDismissed = null;
snackbar.close(true);
});
} else {
actionWidth = 0;
actionView.setVisibility(GONE);
}
int totalContentWidth = (int) (labelView.getPaint().measureText(labelText) + actionWidth) + labelView.getPaddingRight() + labelView.getPaddingLeft() + padding * 2;
if (totalContentWidth > params.width) {
// The text doesn't fit in our standard width so update width to accommodate.
if (totalContentWidth <= maxWidth) {
params.width = totalContentWidth;
} else {
// One line will be cut off, fallback to 2 lines and smaller font. (This should only
// happen in some languages if system display and font size are set to largest.)
int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
labelView.setLines(2);
labelView.getLayoutParams().height = textHeight * 2;
actionView.getLayoutParams().height = textHeight * 2;
labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
params.height += textHeight;
params.width = maxWidth;
}
}
snackbar.mOnDismissed = onDismissed;
snackbar.setAlpha(0);
snackbar.setScaleX(0.8f);
snackbar.setScaleY(0.8f);
snackbar.animate().alpha(1f).withLayer().scaleX(1).scaleY(1).setDuration(SHOW_DURATION_MS).setInterpolator(Interpolators.ACCEL_DEACCEL).start();
int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity, TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
snackbar.postDelayed(() -> snackbar.close(true), timeout);
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.
the class FolderIcon method onDrop.
private void onDrop(final WorkspaceItemInfo item, DragObject d, Rect finalRect, float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) {
item.cellX = -1;
item.cellY = -1;
DragView animateView = d.dragView;
// will not have a view to animate
if (animateView != null && mActivity instanceof Launcher) {
final Launcher launcher = (Launcher) mActivity;
DragLayer dragLayer = launcher.getDragLayer();
Rect to = finalRect;
if (to == null) {
to = new Rect();
Workspace workspace = launcher.getWorkspace();
// Set cellLayout and this to it's final state to compute final animation locations
workspace.setFinalTransitionTransform();
float scaleX = getScaleX();
float scaleY = getScaleY();
setScaleX(1.0f);
setScaleY(1.0f);
scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
// Finished computing final animation locations, restore current state
setScaleX(scaleX);
setScaleY(scaleY);
workspace.resetTransitionTransform();
}
int numItemsInPreview = Math.min(MAX_NUM_ITEMS_IN_PREVIEW, index + 1);
boolean itemAdded = false;
if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) {
List<WorkspaceItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems);
mInfo.add(item, index, false);
mCurrentPreviewItems.clear();
mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
if (!oldPreviewItems.equals(mCurrentPreviewItems)) {
int newIndex = mCurrentPreviewItems.indexOf(item);
if (newIndex >= 0) {
// If the item dropped is going to be in the preview, we update the
// index here to reflect its position in the preview.
index = newIndex;
}
mPreviewItemManager.hidePreviewItem(index, true);
mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item);
itemAdded = true;
} else {
removeItem(item, false);
}
}
if (!itemAdded) {
mInfo.add(item, index, true);
}
int[] center = new int[2];
float scale = getLocalCenterForIndex(index, numItemsInPreview, center);
center[0] = Math.round(scaleRelativeToDragLayer * center[0]);
center[1] = Math.round(scaleRelativeToDragLayer * center[1]);
to.offset(center[0] - animateView.getMeasuredWidth() / 2, center[1] - animateView.getMeasuredHeight() / 2);
float finalAlpha = index < MAX_NUM_ITEMS_IN_PREVIEW ? 1f : 0f;
float finalScale = scale * scaleRelativeToDragLayer;
// Account for potentially different icon sizes with non-default grid settings
if (d.dragSource instanceof AllAppsContainerView) {
DeviceProfile grid = mActivity.getDeviceProfile();
float containerScale = (1f * grid.iconSizePx / grid.allAppsIconSizePx);
finalScale *= containerScale;
}
final int finalIndex = index;
dragLayer.animateView(animateView, to, finalAlpha, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, Interpolators.DEACCEL_2, () -> {
mPreviewItemManager.hidePreviewItem(finalIndex, false);
mFolder.showItem(item);
}, DragLayer.ANIMATION_END_DISAPPEAR, null);
mFolder.hideItem(item);
if (!itemAdded)
mPreviewItemManager.hidePreviewItem(index, true);
FolderNameInfos nameInfos = new FolderNameInfos();
if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
Executors.MODEL_EXECUTOR.post(() -> {
d.folderNameProvider.getSuggestedFolderName(getContext(), mInfo.contents, nameInfos);
showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
});
} else {
showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
}
} else {
addItem(item);
}
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.
the class DragLayer method animateView.
/**
* This method animates a view at the end of a drag and drop animation.
* @param view The view to be animated. This view is drawn directly into DragLayer, and so
* doesn't need to be a child of DragLayer.
* @param to The final location of the view. Only the left and top parameters are used. This
* location doesn't account for scaling, and so should be centered about the desired
* final location (including scaling).
* @param finalAlpha The final alpha of the view, in case we want it to fade as it animates.
* @param finalScaleX The final scale of the view. The view is scaled about its center.
* @param finalScaleY The final scale of the view. The view is scaled about its center.
* @param duration The duration of the animation.
* @param motionInterpolator The interpolator to use for the location of the view.
* @param onCompleteRunnable Optional runnable to run on animation completion.
* @param animationEndStyle Whether or not to fade out the view once the animation completes.
* {@link #ANIMATION_END_DISAPPEAR} or {@link #ANIMATION_END_REMAIN_VISIBLE}.
* @param anchorView If not null, this represents the view which the animated view stays
*/
public void animateView(final DragView view, final Rect to, final float finalAlpha, final float finalScaleX, final float finalScaleY, int duration, final Interpolator motionInterpolator, final Runnable onCompleteRunnable, final int animationEndStyle, View anchorView) {
view.cancelAnimation();
view.requestLayout();
final int[] from = getViewLocationRelativeToSelf(view);
// Calculate the duration of the animation based on the object's distance
final float dist = (float) Math.hypot(to.left - from[0], to.top - from[1]);
final Resources res = getResources();
final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist);
// If duration < 0, this is a cue to compute the duration based on the distance
if (duration < 0) {
duration = res.getInteger(R.integer.config_dropAnimMaxDuration);
if (dist < maxDist) {
duration *= DEACCEL_1_5.getInterpolation(dist / maxDist);
}
duration = Math.max(duration, res.getInteger(R.integer.config_dropAnimMinDuration));
}
// Fall back to cubic ease out interpolator for the animation if none is specified
TimeInterpolator interpolator = motionInterpolator == null ? DEACCEL_1_5 : motionInterpolator;
// Animate the view
PendingAnimation anim = new PendingAnimation(duration);
anim.add(ofFloat(view, View.SCALE_X, finalScaleX), interpolator, SpringProperty.DEFAULT);
anim.add(ofFloat(view, View.SCALE_Y, finalScaleY), interpolator, SpringProperty.DEFAULT);
anim.setViewAlpha(view, finalAlpha, interpolator);
anim.setFloat(view, VIEW_TRANSLATE_Y, to.top, interpolator);
ObjectAnimator xMotion = ofFloat(view, VIEW_TRANSLATE_X, to.left);
if (anchorView != null) {
final int startScroll = anchorView.getScrollX();
TypeEvaluator<Float> evaluator = (f, s, e) -> mapRange(f, s, e) + (anchorView.getScaleX() * (startScroll - anchorView.getScrollX()));
xMotion.setEvaluator(evaluator);
}
anim.add(xMotion, interpolator, SpringProperty.DEFAULT);
if (onCompleteRunnable != null) {
anim.addListener(forEndCallback(onCompleteRunnable));
}
playDropAnimation(view, anim.buildAnim(), animationEndStyle);
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_404Launcher by P-404.
the class WorkspaceTouchListener method onTouch.
@Override
public boolean onTouch(View view, MotionEvent ev) {
mGestureDetector.onTouchEvent(ev);
int action = ev.getActionMasked();
if (action == ACTION_DOWN) {
// Check if we can handle long press.
boolean handleLongPress = canHandleLongPress();
if (handleLongPress) {
// Check if the event is not near the edges
DeviceProfile dp = mLauncher.getDeviceProfile();
DragLayer dl = mLauncher.getDragLayer();
Rect insets = dp.getInsets();
mTempRect.set(insets.left, insets.top, dl.getWidth() - insets.right, dl.getHeight() - insets.bottom);
mTempRect.inset(dp.edgeMarginPx, dp.edgeMarginPx);
handleLongPress = mTempRect.contains((int) ev.getX(), (int) ev.getY());
}
if (handleLongPress) {
mLongPressState = STATE_REQUESTED;
mTouchDownPoint.set(ev.getX(), ev.getY());
}
mWorkspace.onTouchEvent(ev);
// Return true to keep receiving touch events
return true;
}
if (mLongPressState == STATE_PENDING_PARENT_INFORM) {
// Inform the workspace to cancel touch handling
ev.setAction(ACTION_CANCEL);
mWorkspace.onTouchEvent(ev);
ev.setAction(action);
mLongPressState = STATE_COMPLETED;
}
final boolean result;
if (mLongPressState == STATE_COMPLETED) {
// We have handled the touch, so workspace does not need to know anything anymore.
result = true;
} else if (mLongPressState == STATE_REQUESTED) {
mWorkspace.onTouchEvent(ev);
if (mWorkspace.isHandlingTouch()) {
cancelLongPress();
} else if (action == ACTION_MOVE && PointF.length(mTouchDownPoint.x - ev.getX(), mTouchDownPoint.y - ev.getY()) > mTouchSlop) {
cancelLongPress();
}
result = true;
} else {
// We don't want to handle touch, let workspace handle it as usual.
result = false;
}
if (action == ACTION_UP || action == ACTION_POINTER_UP) {
if (!mWorkspace.isHandlingTouch()) {
final CellLayout currentPage = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
if (currentPage != null) {
mWorkspace.onWallpaperTap(ev);
}
}
}
if (action == ACTION_UP || action == ACTION_CANCEL) {
cancelLongPress();
}
return result;
}
Aggregations