Commit d1f5ebce authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Handle backpress when animation is running

parent 516866fb
Pipeline #129258 passed with stage
in 6 minutes and 46 seconds
......@@ -724,18 +724,26 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
* @param screenId The screen in which to add the child.
* @param x The X position of the child in the screen's grid.
* @param y The Y position of the child in the screen's grid.
* @param animate If the view should start to animate after drag and drop.
*/
private void addInScreen(View child, long container, long screenId, int x, int y) {
Log.d(
TAG,
"addInScreen() called with: child = [" + child + "], container = [" + container + "], screenId = [" + screenId + "], x = [" + x + "], y = [" + y + "]"
);
private void addInScreen(View child, long container, long screenId, int x, int y, boolean animate) {
int index = y * mLauncher.getDeviceProfile().getInv().getNumColumns() + x;
addInScreen(
child,
container,
screenId,
y * mLauncher.getDeviceProfile().getInv().getNumColumns() + x
index
);
post(() -> {
if(animate) {
if(index % 2 == 0) {
child.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble));
} else {
child.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.wobble_reverse));
}
}
});
}
/**
......@@ -1406,8 +1414,6 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
Log.d(TAG, "Found cell " + foundCell + " " + mTargetCell[0] + " " + mTargetCell[0]);
if (foundCell) {
if (getScreenIdForPageIndex(mCurrentPage) != screenId && !hasMovedIntoHotseat) {
snapScreen = getPageIndexForScreenId(screenId);
......@@ -1419,12 +1425,13 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
// Reparent the view
CellLayout parentCell = getParentCellLayoutForView(cell);
if (parentCell != null) {
cell.clearAnimation();
parentCell.removeView(cell);
} else if (BuildConfig.DEBUG) {
throw new NullPointerException("mDragInfo.cell has null parent");
}
addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1]);
addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1], true);
}
// update the item's position after drop
......@@ -1456,7 +1463,7 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
// spring-loaded mode so the page meets the icon where it was picked up.
mLauncher.getDragController().animateDragViewToOriginalPosition(
onCompleteRunnable, cell, SPRING_LOADED_TRANSITION_MS);
//mLauncher.getStateManager().goToState(NORMAL);
mLauncher.getStateManager().goToState(NORMAL);
parent.onDropChild(cell);
return;
}
......@@ -1907,7 +1914,18 @@ public class LauncherPagedView extends PagedView<PageIndicatorDots> implements V
mSpringLoadedDragController.cancel();
// Reset the grid state by stopping the animation and removing uninstall icon after 25 seconds
wobbleExpireAlarm.setAlarm(WOBBLE_EXPIRATION_TIMEOUT);
setWobbleExpirationAlarm(WOBBLE_EXPIRATION_TIMEOUT);
}
/**
* @param timeoutInMillis Expire wobble animation after the given timeout
* @return true if there was any pending alarm otherwise false.
*/
public boolean setWobbleExpirationAlarm(long timeoutInMillis) {
boolean alarmPending = wobbleExpireAlarm.alarmPending();
wobbleExpireAlarm.cancelAlarm();
wobbleExpireAlarm.setAlarm(timeoutInMillis);
return alarmPending;
}
@Override
......
......@@ -16,6 +16,7 @@ import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.view.animation.AnimationUtils
import android.widget.GridLayout
import androidx.annotation.IntDef
import foundation.e.blisslauncher.R
......@@ -785,7 +786,7 @@ open class CellLayout @JvmOverloads constructor(
minSpanY: Int,
spanX: Int,
spanY: Int,
dragView: View?,
dragView: View,
result: IntArray?,
resultSpan: IntArray?,
mode: Int
......@@ -812,7 +813,7 @@ open class CellLayout @JvmOverloads constructor(
// committing anything or animating anything as we just want to determine if a solution
// exists
if (mode == MODE_DRAG_OVER || mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL) {
val parent = (dragView?.parent as ViewGroup?)
val parent = (dragView.parent as ViewGroup?)
parent?.removeView(dragView)
if (childCount == mCountX * mCountY) {
......@@ -835,10 +836,10 @@ open class CellLayout @JvmOverloads constructor(
iconLayoutParams.height = if (mContainerType == HOTSEAT)
dp.hotseatCellHeightPx else dp.cellHeightPx
iconLayoutParams.width = dp.cellWidthPx
dragView?.also {
dragView.also {
if (it is IconTextView) it.setTextVisibility(mContainerType != HOTSEAT)
}
dragView?.setLayoutParams(iconLayoutParams)
dragView.layoutParams = iconLayoutParams
addView(dragView, index)
/*copySolutionToTempState(finalSolution, dragView)
......@@ -856,13 +857,16 @@ open class CellLayout @JvmOverloads constructor(
ReorderPreviewAnimation.MODE_PREVIEW
)
}*/
}
// May consider this later.
/*if ((mode == MODE_ON_DROP || !foundSolution)) {
setUseTempCoords(false)
}*/
// requestLayout()
if ((mode == MODE_ON_DROP)) {
if (index % 2 == 0) {
dragView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.wobble))
} else {
dragView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.wobble_reverse))
}
}
}
requestLayout()
return result
}
......
......@@ -1228,11 +1228,16 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
return
}
if (dragController.isDragging()) {
if (dragController.isDragging) {
dragController.cancelDrag()
return
}
// We expire wobble animation as soon a back press is done and return if the animation was running.
if(getLauncherPagedView().setWobbleExpirationAlarm(0)) {
return
}
// Note: There should be at most one log per method call. This is enforced implicitly
// by using if-else statements.
val topView = AbstractFloatingView.getTopOpenView(this)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment