mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-18 02:08:20 +00:00
Fixing Launcher crash if activity restarts while resixing widget
When activity restarts, the widgetView gets onDetachFromWindow first which inturn removes the AppWidgetResizeFrame from drawLayer while the dispatchAttachToWindow was still in progress in DragLayer Bug: 238416508 Test: Verified no crash after the change Change-Id: I6359840c9fb3ae2719056845818620af19d3c94d
This commit is contained in:
@@ -24,6 +24,7 @@ import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@@ -68,22 +69,6 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
|
||||
private final View[] mDragHandles = new View[HANDLE_COUNT];
|
||||
private final List<Rect> mSystemGestureExclusionRects = new ArrayList<>(HANDLE_COUNT);
|
||||
private final OnAttachStateChangeListener mWidgetViewAttachStateChangeListener =
|
||||
new OnAttachStateChangeListener() {
|
||||
@Override
|
||||
public void onViewAttachedToWindow(View view) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewDetachedFromWindow(View view) {
|
||||
// When the app widget view is detached, we should close the resize frame.
|
||||
// An example is when the dragging starts, the widget view is detached from
|
||||
// CellLayout and then reattached to DragLayout.
|
||||
close(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private LauncherAppWidgetHostView mWidgetView;
|
||||
private CellLayout mCellLayout;
|
||||
@@ -221,11 +206,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout,
|
||||
DragLayer dragLayer) {
|
||||
mCellLayout = cellLayout;
|
||||
if (mWidgetView != null) {
|
||||
mWidgetView.removeOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
|
||||
}
|
||||
mWidgetView = widgetView;
|
||||
mWidgetView.addOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
|
||||
LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo)
|
||||
widgetView.getAppWidgetInfo();
|
||||
mDragLayer = dragLayer;
|
||||
@@ -423,6 +404,10 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
* Based on the current deltas, we determine if and how to resize the widget.
|
||||
*/
|
||||
private void resizeWidgetIfNeeded(boolean onDismiss) {
|
||||
ViewGroup.LayoutParams wlp = mWidgetView.getLayoutParams();
|
||||
if (!(wlp instanceof CellLayout.LayoutParams)) {
|
||||
return;
|
||||
}
|
||||
DeviceProfile dp = mLauncher.getDeviceProfile();
|
||||
float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
|
||||
float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;
|
||||
@@ -435,7 +420,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
mDirectionVector[0] = 0;
|
||||
mDirectionVector[1] = 0;
|
||||
|
||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mWidgetView.getLayoutParams();
|
||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) wlp;
|
||||
|
||||
int spanX = lp.cellHSpan;
|
||||
int spanY = lp.cellVSpan;
|
||||
@@ -687,9 +672,6 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
@Override
|
||||
protected void handleClose(boolean animate) {
|
||||
mDragLayer.removeView(this);
|
||||
if (mWidgetView != null) {
|
||||
mWidgetView.removeOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateInvalidResizeEffect(CellLayout cellLayout, CellLayout pairedCellLayout,
|
||||
|
||||
Reference in New Issue
Block a user