Merge "Add QuickstepWidgetHolder for widget handling" into tm-qpr-dev am: 04c89fe38e
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/20418248 Change-Id: Ibe09a5d1ab53070bc6a4b797f95e9d853f86fbc0 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
f8ab32a8bc
14 files changed
+384
-72
No files matched your search
@@ -1548,8 +1548,8 @@ public class Launcher extends StatefulActivity<LauncherState>
|
||||
}
|
||||
|
||||
protected LauncherWidgetHolder createAppWidgetHolder() {
|
||||
return new LauncherWidgetHolder(this,
|
||||
appWidgetId -> getWorkspace().removeWidget(appWidgetId));
|
||||
return LauncherWidgetHolder.HolderFactory.newFactory(this).newInstance(
|
||||
this, appWidgetId -> getWorkspace().removeWidget(appWidgetId));
|
||||
}
|
||||
|
||||
public LauncherModel getModel() {
|
||||
|
||||
@@ -1093,7 +1093,7 @@ public class LauncherProvider extends ContentProvider {
|
||||
*/
|
||||
@NonNull
|
||||
public LauncherWidgetHolder newLauncherWidgetHolder() {
|
||||
return new LauncherWidgetHolder(mContext);
|
||||
return LauncherWidgetHolder.newInstance(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -295,7 +295,7 @@ public class AddItemActivity extends BaseActivity
|
||||
mWidgetCell.setRemoteViewsPreview(PinItemDragListener.getPreview(mRequest));
|
||||
|
||||
mAppWidgetManager = new WidgetManagerHelper(this);
|
||||
mAppWidgetHolder = new LauncherWidgetHolder(this);
|
||||
mAppWidgetHolder = LauncherWidgetHolder.newInstance(this);
|
||||
|
||||
PendingAddWidgetInfo pendingInfo =
|
||||
new PendingAddWidgetInfo(widgetInfo, CONTAINER_PIN_WIDGETS);
|
||||
|
||||
@@ -355,7 +355,7 @@ public class RestoreDbTask {
|
||||
private void restoreAppWidgetIdsIfExists(Context context) {
|
||||
SharedPreferences prefs = LauncherPrefs.getPrefs(context);
|
||||
if (prefs.contains(APPWIDGET_OLD_IDS) && prefs.contains(APPWIDGET_IDS)) {
|
||||
LauncherWidgetHolder holder = new LauncherWidgetHolder(context);
|
||||
LauncherWidgetHolder holder = LauncherWidgetHolder.newInstance(context);
|
||||
AppWidgetsRestoredReceiver.restoreAppWidgetIds(context,
|
||||
IntArray.fromConcatString(prefs.getString(APPWIDGET_OLD_IDS, "")).toArray(),
|
||||
IntArray.fromConcatString(prefs.getString(APPWIDGET_IDS, "")).toArray(),
|
||||
|
||||
@@ -19,7 +19,6 @@ import static android.app.Activity.RESULT_CANCELED;
|
||||
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetHost;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
@@ -29,7 +28,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -45,7 +43,7 @@ import com.android.launcher3.model.WidgetsModel;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.testing.TestLogging;
|
||||
import com.android.launcher3.testing.shared.TestProtocol;
|
||||
import com.android.launcher3.uioverrides.ApiWrapper;
|
||||
import com.android.launcher3.util.ResourceBasedOverride;
|
||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
@@ -86,11 +84,7 @@ public class LauncherWidgetHolder {
|
||||
// TODO(b/191735836): Replace with SplashScreen.SPLASH_SCREEN_STYLE_EMPTY when un-hidden
|
||||
private static final int SPLASH_SCREEN_STYLE_EMPTY = 0;
|
||||
|
||||
public LauncherWidgetHolder(@NonNull Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public LauncherWidgetHolder(@NonNull Context context,
|
||||
protected LauncherWidgetHolder(@NonNull Context context,
|
||||
@Nullable IntConsumer appWidgetRemovedCallback) {
|
||||
mContext = context;
|
||||
mWidgetHost = createHost(context, appWidgetRemovedCallback);
|
||||
@@ -320,15 +314,6 @@ public class LauncherWidgetHolder {
|
||||
mFlags &= ~FLAG_LISTENING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the interaction handler for the widget host
|
||||
* @param handler The interaction handler
|
||||
*/
|
||||
public void setInteractionHandler(
|
||||
@Nullable LauncherWidgetInteractionHandler handler) {
|
||||
ApiWrapper.setHostInteractionHandler(mWidgetHost, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the host
|
||||
*/
|
||||
@@ -489,20 +474,35 @@ public class LauncherWidgetHolder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set as a substitution for the hidden interaction handler in RemoteViews
|
||||
* Returns the new LauncherWidgetHolder instance
|
||||
*/
|
||||
public interface LauncherWidgetInteractionHandler {
|
||||
public static LauncherWidgetHolder newInstance(Context context) {
|
||||
return HolderFactory.newFactory(context).newInstance(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory class that generates new instances of {@code LauncherWidgetHolder}
|
||||
*/
|
||||
public static class HolderFactory implements ResourceBasedOverride {
|
||||
|
||||
/**
|
||||
* Invoked when the user performs an interaction on the View.
|
||||
*
|
||||
* @param view the View with which the user interacted
|
||||
* @param pendingIntent the base PendingIntent associated with the view
|
||||
* @param response the response to the interaction, which knows how to fill in the
|
||||
* attached PendingIntent
|
||||
* @param context The context of the caller
|
||||
* @param appWidgetRemovedCallback The callback that is called when widgets are removed
|
||||
* @return A new instance of {@code LauncherWidgetHolder}
|
||||
*/
|
||||
boolean onInteraction(
|
||||
View view,
|
||||
PendingIntent pendingIntent,
|
||||
RemoteViews.RemoteResponse response);
|
||||
public LauncherWidgetHolder newInstance(@NonNull Context context,
|
||||
@Nullable IntConsumer appWidgetRemovedCallback) {
|
||||
return new LauncherWidgetHolder(context, appWidgetRemovedCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context The context of the caller
|
||||
* @return A new instance of factory class for widget holders. If not specified, returning
|
||||
* {@code HolderFactory} by default.
|
||||
*/
|
||||
public static HolderFactory newFactory(Context context) {
|
||||
return Overrides.getObject(
|
||||
HolderFactory.class, context, R.string.widget_holder_factory_class);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user