mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-17 09:38:19 +00:00
Merge "Remove launcher widget onAppWidgetRemoved" into ub-launcher3-qt-future-dev
This commit is contained in:
@@ -332,8 +332,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
|
||||
UiFactory.onCreate(this);
|
||||
|
||||
mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
|
||||
|
||||
mAppWidgetHost = new LauncherAppWidgetHost(this);
|
||||
mAppWidgetHost = new LauncherAppWidgetHost(this,
|
||||
appWidgetId -> getWorkspace().removeWidget(appWidgetId));
|
||||
mAppWidgetHost.startListening();
|
||||
|
||||
mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null);
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.android.launcher3.widget.DeferredAppWidgetHostView;
|
||||
import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
|
||||
/**
|
||||
@@ -56,9 +57,17 @@ public class LauncherAppWidgetHost extends AppWidgetHost {
|
||||
private final Context mContext;
|
||||
private int mFlags = FLAG_RESUMED;
|
||||
|
||||
private IntConsumer mAppWidgetRemovedCallback = null;
|
||||
|
||||
public LauncherAppWidgetHost(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public LauncherAppWidgetHost(Context context,
|
||||
IntConsumer appWidgetRemovedCallback) {
|
||||
super(context, APPWIDGET_HOST_ID);
|
||||
mContext = context;
|
||||
mAppWidgetRemovedCallback = appWidgetRemovedCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,7 +220,7 @@ public class LauncherAppWidgetHost extends AppWidgetHost {
|
||||
}
|
||||
view.setAppWidget(appWidgetId, appWidget);
|
||||
view.switchToErrorView();
|
||||
return view;
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,6 +238,15 @@ public class LauncherAppWidgetHost extends AppWidgetHost {
|
||||
info.initSpans(mContext);
|
||||
}
|
||||
|
||||
//TODO: make this override when SDK is updated
|
||||
//@Override
|
||||
protected void onAppWidgetRemoved(int appWidgetId) {
|
||||
if (mAppWidgetRemovedCallback == null) {
|
||||
return;
|
||||
}
|
||||
mAppWidgetRemovedCallback.accept(appWidgetId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAppWidgetId(int appWidgetId) {
|
||||
super.deleteAppWidgetId(appWidgetId);
|
||||
|
||||
@@ -2801,6 +2801,23 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed widget from workspace by appWidgetId
|
||||
* @param appWidgetId
|
||||
*/
|
||||
public void removeWidget(int appWidgetId) {
|
||||
mapOverItems((info, view) -> {
|
||||
if (info instanceof LauncherAppWidgetInfo) {
|
||||
LauncherAppWidgetInfo appWidgetInfo = (LauncherAppWidgetInfo) info;
|
||||
if (appWidgetInfo.appWidgetId == appWidgetId) {
|
||||
mLauncher.removeItem(view, appWidgetInfo, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all folder listeners
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user