mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-05 10:26:52 +00:00
Adding support for result callback when starting uninstall-application activity
Change-Id: Ieaca4fbd0ae0156f24c8863ccbef61d4d6d30ba1
This commit is contained in:
@@ -16,12 +16,19 @@
|
||||
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.launcher3.compat.LauncherAppsCompat;
|
||||
|
||||
public class InfoDropTarget extends UninstallDropTarget {
|
||||
|
||||
private static final String TAG = "InfoDropTarget";
|
||||
|
||||
public InfoDropTarget(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
@@ -39,10 +46,19 @@ public class InfoDropTarget extends UninstallDropTarget {
|
||||
setDrawable(R.drawable.ic_info_launcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
void completeDrop(DragObject d) {
|
||||
DropTargetResultCallback callback = d.dragSource instanceof DropTargetResultCallback
|
||||
? (DropTargetResultCallback) d.dragSource : null;
|
||||
startDetailsActivityForInfo(d.dragInfo, mLauncher, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the activity was started.
|
||||
*/
|
||||
public static boolean startDetailsActivityForInfo(ItemInfo info, Launcher launcher) {
|
||||
public static boolean startDetailsActivityForInfo(
|
||||
ItemInfo info, Launcher launcher, DropTargetResultCallback callback) {
|
||||
boolean result = false;
|
||||
ComponentName componentName = null;
|
||||
if (info instanceof AppInfo) {
|
||||
componentName = ((AppInfo) info).componentName;
|
||||
@@ -54,23 +70,28 @@ public class InfoDropTarget extends UninstallDropTarget {
|
||||
componentName = ((LauncherAppWidgetInfo) info).providerName;
|
||||
}
|
||||
if (componentName != null) {
|
||||
launcher.startApplicationDetailsActivity(componentName, info.user);
|
||||
return true;
|
||||
try {
|
||||
LauncherAppsCompat.getInstance(launcher)
|
||||
.showAppDetailsForProfile(componentName, info.user);
|
||||
result = true;
|
||||
} catch (SecurityException | ActivityNotFoundException e) {
|
||||
Toast.makeText(launcher, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
|
||||
Log.e(TAG, "Unable to launch settings", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean startActivityWithUninstallAffordance(DragObject d) {
|
||||
return startDetailsActivityForInfo(d.dragInfo, mLauncher);
|
||||
if (callback != null) {
|
||||
sendUninstallResult(launcher, result, componentName, info.user, callback);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsDrop(DragSource source, ItemInfo info) {
|
||||
return source.supportsAppInfoDropTarget() && supportsDrop(getContext(), info);
|
||||
return source.supportsAppInfoDropTarget() && supportsDrop(info);
|
||||
}
|
||||
|
||||
public static boolean supportsDrop(Context context, ItemInfo info) {
|
||||
public static boolean supportsDrop(ItemInfo info) {
|
||||
return info instanceof AppInfo || info instanceof ShortcutInfo
|
||||
|| info instanceof PendingAddItemInfo || info instanceof LauncherAppWidgetInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user