use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Launcher3 by AOSPA.
the class ModelUtils method fromLegacyShortcutIntent.
/**
* Creates a workspace item info for the legacy shortcut intent
*/
@SuppressWarnings("deprecation")
public static WorkspaceItemInfo fromLegacyShortcutIntent(Context context, Intent data) {
if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.class)) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {
Log.e(TAG, "Invalid install shortcut intent");
return null;
}
Intent launchIntent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
String label = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
if (launchIntent == null || label == null) {
Log.e(TAG, "Invalid install shortcut intent");
return null;
}
final WorkspaceItemInfo info = new WorkspaceItemInfo();
info.user = Process.myUserHandle();
BitmapInfo iconInfo = null;
try (LauncherIcons li = LauncherIcons.obtain(context)) {
Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
if (bitmap != null) {
iconInfo = li.createIconBitmap(bitmap);
} else {
info.iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (info.iconResource != null) {
iconInfo = li.createIconBitmap(info.iconResource);
}
}
}
if (iconInfo == null) {
Log.e(TAG, "Invalid icon by the app");
return null;
}
info.bitmap = iconInfo;
info.contentDescription = info.title = Utilities.trim(label);
info.intent = launchIntent;
return info;
}
use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Trebuchet by LineageOS.
the class LauncherUIScrollTest method testWidgetsListScroll.
@Test
public void testWidgetsListScroll() throws Exception {
// Install 100 widgets
for (int i = 0; i < 100; i++) {
mModelHelper.installCustomShortcut(TEST_PACKAGE + i, "shortcutProvider");
}
// Bind and open widgets
Launcher launcher = loadLauncher();
WidgetsFullSheet widgets = WidgetsFullSheet.show(launcher, false);
doLayout(launcher);
int currentScroll = widgets.getRecyclerView().getCurrentScrollY();
launcher.dispatchGenericMotionEvent(createScrollEvent(-1));
int newScroll = widgets.getRecyclerView().getCurrentScrollY();
assertNotEquals("Widgets was not scrolled", currentScroll, newScroll);
assertEquals("Workspace was scrolled", 0, launcher.getWorkspace().getNextPage());
}
use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Trebuchet by LineageOS.
the class LauncherUIScrollTest method testAllAppsScroll.
@Test
public void testAllAppsScroll() throws Exception {
// Install 100 apps
for (int i = 0; i < 100; i++) {
mModelHelper.installApp(TEST_PACKAGE + i);
}
// Bind and open all-apps
Launcher launcher = loadLauncher();
launcher.getStateManager().goToState(LauncherState.ALL_APPS, false);
doLayout(launcher);
int currentScroll = launcher.getAppsView().getActiveRecyclerView().getCurrentScrollY();
launcher.dispatchGenericMotionEvent(createScrollEvent(-1));
int newScroll = launcher.getAppsView().getActiveRecyclerView().getCurrentScrollY();
assertNotEquals("All Apps was not scrolled", currentScroll, newScroll);
assertEquals("Workspace was scrolled", 0, launcher.getWorkspace().getNextPage());
}
use of com.android.launcher3.popup.SystemShortcut.INSTALL in project android_packages_apps_Trebuchet by LineageOS.
the class PackageInstallStateChangedTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
if (mInstallInfo.state == PackageInstallInfo.STATUS_INSTALLED) {
try {
// For instant apps we do not get package-add. Use setting events to update
// any pinned icons.
ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
}
} catch (PackageManager.NameNotFoundException e) {
// Ignore
}
// Ignore install success events as they are handled by Package add events.
return;
}
synchronized (apps) {
PromiseAppInfo updated = apps.updatePromiseInstallInfo(mInstallInfo);
if (updated != null) {
scheduleCallbackTask(c -> c.bindPromiseAppProgressUpdated(updated));
}
bindApplicationsIfNeeded();
}
synchronized (dataModel) {
final HashSet<ItemInfo> updates = new HashSet<>();
for (ItemInfo info : dataModel.itemsIdMap) {
if (info instanceof WorkspaceItemInfo) {
WorkspaceItemInfo si = (WorkspaceItemInfo) info;
ComponentName cn = si.getTargetComponent();
if (si.hasPromiseIconUi() && (cn != null) && mInstallInfo.packageName.equals(cn.getPackageName())) {
si.setInstallProgress(mInstallInfo.progress);
if (mInstallInfo.state == PackageInstallInfo.STATUS_FAILED) {
// Mark this info as broken.
si.status &= ~WorkspaceItemInfo.FLAG_INSTALL_SESSION_ACTIVE;
}
updates.add(si);
}
}
}
for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
widget.installProgress = mInstallInfo.progress;
updates.add(widget);
}
}
if (!updates.isEmpty()) {
scheduleCallbackTask(new CallbackTask() {
@Override
public void execute(Callbacks callbacks) {
callbacks.bindRestoreItemsChange(updates);
}
});
}
}
}
use of com.android.launcher3.popup.SystemShortcut.INSTALL in project Neo-Launcher by NeoApplications.
the class PackageInstallStateChangedTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
if (mInstallInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
try {
// For instant apps we do not get package-add. Use setting events to update
// any pinned icons.
ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
}
} catch (PackageManager.NameNotFoundException e) {
// Ignore
}
// Ignore install success events as they are handled by Package add events.
return;
}
synchronized (apps) {
PromiseAppInfo updated = apps.updatePromiseInstallInfo(mInstallInfo);
if (updated != null) {
scheduleCallbackTask(c -> c.bindPromiseAppProgressUpdated(updated));
}
bindApplicationsIfNeeded();
}
synchronized (dataModel) {
final HashSet<ItemInfo> updates = new HashSet<>();
for (ItemInfo info : dataModel.itemsIdMap) {
if (info instanceof WorkspaceItemInfo) {
WorkspaceItemInfo si = (WorkspaceItemInfo) info;
ComponentName cn = si.getTargetComponent();
if (si.hasPromiseIconUi() && (cn != null) && mInstallInfo.packageName.equals(cn.getPackageName())) {
si.setInstallProgress(mInstallInfo.progress);
if (mInstallInfo.state == PackageInstallerCompat.STATUS_FAILED) {
// Mark this info as broken.
si.status &= ~WorkspaceItemInfo.FLAG_INSTALL_SESSION_ACTIVE;
}
updates.add(si);
}
}
}
for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
widget.installProgress = mInstallInfo.progress;
updates.add(widget);
}
}
if (!updates.isEmpty()) {
scheduleCallbackTask(new CallbackTask() {
@Override
public void execute(Callbacks callbacks) {
callbacks.bindRestoreItemsChange(updates);
}
});
}
}
}
Aggregations