Updating WidgetSheets so that it can be displayed in any
activity and not just Launcher Bug: 307306823 Test: atest Launcher3Tests Flag: NA Change-Id: I0e33323805c6e895e3a1639ecf5933e698212c65
This commit is contained in:
1 parent
37cf983825
commit
eb29313595
6 files changed
+85
-96
No files matched your search
@@ -21,7 +21,6 @@ import static com.android.launcher3.LauncherPrefs.WIDGETS_EDUCATION_TIP_SEEN;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@@ -35,32 +34,28 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.Px;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
import com.android.launcher3.BaseActivity;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
|
||||
import com.android.launcher3.DragSource;
|
||||
import com.android.launcher3.DropTarget.DragObject;
|
||||
import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.dragndrop.DragOptions;
|
||||
import com.android.launcher3.popup.PopupDataProvider;
|
||||
import com.android.launcher3.testing.TestLogging;
|
||||
import com.android.launcher3.testing.shared.TestProtocol;
|
||||
import com.android.launcher3.touch.ItemLongClickListener;
|
||||
import com.android.launcher3.util.SystemUiController;
|
||||
import com.android.launcher3.util.Themes;
|
||||
import com.android.launcher3.util.window.WindowManagerProxy;
|
||||
import com.android.launcher3.views.AbstractSlideInView;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.views.ArrowTipView;
|
||||
|
||||
/**
|
||||
* Base class for various widgets popup
|
||||
*/
|
||||
public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
|
||||
implements OnClickListener, OnLongClickListener, DragSource,
|
||||
public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
|
||||
implements OnClickListener, OnLongClickListener,
|
||||
PopupDataProvider.PopupDataChangeListener, Insettable, OnDeviceProfileChangeListener {
|
||||
/** The default number of cells that can fit horizontally in a widget sheet. */
|
||||
public static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4;
|
||||
@@ -129,21 +124,25 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
|
||||
} else {
|
||||
mWidgetInstructionToast = showWidgetToast(getContext(), mWidgetInstructionToast);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Widgets.onLongClick");
|
||||
v.cancelLongPress();
|
||||
if (!ItemLongClickListener.canStartDrag(mActivityContext)) return false;
|
||||
|
||||
boolean result = false;
|
||||
if (v instanceof WidgetCell) {
|
||||
return beginDraggingWidget((WidgetCell) v);
|
||||
} else if (v.getParent() instanceof WidgetCell) {
|
||||
return beginDraggingWidget((WidgetCell) v.getParent());
|
||||
result = mActivityContext.getAllAppsItemLongClickListener().onLongClick(v);
|
||||
} else if (v.getParent() instanceof WidgetCell wc) {
|
||||
result = mActivityContext.getAllAppsItemLongClickListener().onLongClick(wc);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
if (result) {
|
||||
close(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,55 +211,12 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
|
||||
MeasureSpec.getSize(heightMeasureSpec));
|
||||
}
|
||||
|
||||
private boolean beginDraggingWidget(WidgetCell v) {
|
||||
// Get the widget preview as the drag representation
|
||||
WidgetImageView image = v.getWidgetView();
|
||||
|
||||
// If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and
|
||||
// we abort the drag.
|
||||
if (image.getDrawable() == null && v.getAppWidgetHostViewPreview() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PendingItemDragHelper dragHelper = new PendingItemDragHelper(v);
|
||||
// RemoteViews are being rendered in AppWidgetHostView in WidgetCell. And thus, the scale of
|
||||
// RemoteViews is equivalent to the AppWidgetHostView scale.
|
||||
dragHelper.setRemoteViewsPreview(v.getRemoteViewsPreview(), v.getAppWidgetHostViewScale());
|
||||
dragHelper.setAppWidgetHostViewPreview(v.getAppWidgetHostViewPreview());
|
||||
|
||||
if (image.getDrawable() != null) {
|
||||
int[] loc = new int[2];
|
||||
getPopupContainer().getLocationInDragLayer(image, loc);
|
||||
|
||||
dragHelper.startDrag(image.getBitmapBounds(), image.getDrawable().getIntrinsicWidth(),
|
||||
image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions());
|
||||
} else {
|
||||
NavigableAppWidgetHostView preview = v.getAppWidgetHostViewPreview();
|
||||
int[] loc = new int[2];
|
||||
getPopupContainer().getLocationInDragLayer(preview, loc);
|
||||
Rect r = new Rect();
|
||||
preview.getWorkspaceVisualDragBounds(r);
|
||||
dragHelper.startDrag(r, preview.getMeasuredWidth(), preview.getMeasuredWidth(),
|
||||
new Point(loc[0], loc[1]), this, new DragOptions());
|
||||
}
|
||||
close(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Interpolator getIdleInterpolator() {
|
||||
return mActivityContext.getDeviceProfile().isTablet
|
||||
? EMPHASIZED : super.getIdleInterpolator();
|
||||
}
|
||||
|
||||
//
|
||||
// Drag related handling methods that implement {@link DragSource} interface.
|
||||
//
|
||||
|
||||
@Override
|
||||
public void onDropCompleted(View target, DragObject d, boolean success) { }
|
||||
|
||||
|
||||
protected void onCloseComplete() {
|
||||
super.onCloseComplete();
|
||||
clearNavBarColor();
|
||||
@@ -344,7 +300,8 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher>
|
||||
@Override
|
||||
protected void setTranslationShift(float translationShift) {
|
||||
super.setTranslationShift(translationShift);
|
||||
Launcher launcher = ActivityContext.lookupContext(getContext());
|
||||
launcher.onWidgetsTransition(1 - translationShift);
|
||||
if (mActivityContext instanceof Launcher ls) {
|
||||
ls.onWidgetsTransition(1 - translationShift);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user