Search in sources :

Example 26 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class LongClickReceiver method onReceive.

public void onReceive(final Context context, final Intent intent) {
    final OmegaLauncher launcher = LongClickReceiver.bR.get();
    if (launcher != null) {
        final ComponentKey dl = AppSearchProvider.uriToComponent(intent.getData(), context);
        final LauncherActivityInfo resolveActivity = LauncherAppsCompat.getInstance(context).resolveActivity(new Intent(Intent.ACTION_MAIN).setComponent(dl.componentName), dl.user);
        if (resolveActivity == null) {
            return;
        }
        final ItemDragListener onDragListener = new ItemDragListener(resolveActivity, intent.getSourceBounds());
        onDragListener.init(launcher, false);
        launcher.getDragLayer().setOnDragListener(onDragListener);
        final ClipData clipData = new ClipData(new ClipDescription("", new String[] { onDragListener.getMimeType() }), new ClipData.Item(""));
        final Bundle bundle = new Bundle();
        bundle.putParcelable("clip_data", clipData);
        this.setResult(-1, null, bundle);
    }
}
Also used : OmegaLauncher(com.saggitt.omega.OmegaLauncher) Bundle(android.os.Bundle) ComponentKey(com.android.launcher3.util.ComponentKey) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Intent(android.content.Intent) ClipData(android.content.ClipData) ClipDescription(android.content.ClipDescription)

Example 27 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class AppLaunchActivity method startUri.

private void startUri(Uri uri) {
    try {
        ComponentKey dl = AppSearchProvider.uriToComponent(uri, this);
        ItemInfo dVar = new AppItemInfoWithIcon(dl);
        if (!getPackageManager().isSafeMode() || Utilities.isSystemApp(this, dVar.getIntent())) {
            if (dl.user.equals(android.os.Process.myUserHandle())) {
                startActivity(dVar.getIntent());
            } else {
                LauncherAppsCompat.getInstance(this).startActivityForProfile(dl.componentName, dl.user, getIntent().getSourceBounds(), null);
            }
            View view = new View(this);
            view.setTag(dVar);
            String predictionRank = uri.getQueryParameter("predictionRank");
            new LogContainerProvider(this, TextUtils.isEmpty(predictionRank) ? -1 : Integer.parseInt(predictionRank)).addView(view);
            return;
        }
        Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
    }
}
Also used : ItemInfo(com.android.launcher3.ItemInfo) ComponentKey(com.android.launcher3.util.ComponentKey) View(android.view.View)

Example 28 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class AppSearchProvider method call.

public Bundle call(final String s, final String s2, final Bundle bundle) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        Log.d("AppSearchProvider", "Content provider accessed on main thread");
        return null;
    }
    if ("loadIcon".equals(s))
        try {
            final Uri parse = Uri.parse(s2);
            final ComponentKey dl = uriToComponent(parse, this.getContext());
            final Callable<Bitmap> g = () -> {
                final AppItemInfoWithIcon d = new AppItemInfoWithIcon(dl);
                mApp.getIconCache().getTitleAndIcon(d, false);
                return d.iconBitmap;
            };
            final Bundle bundle2 = new Bundle();
            bundle2.putParcelable("suggest_icon_1", mLooper.submit(g).get());
            return bundle2;
        } catch (Exception ex) {
            Log.e("AppSearchProvider", "Unable to load icon " + ex);
            return null;
        }
    return super.call(s, s2, bundle);
}
Also used : Bundle(android.os.Bundle) ComponentKey(com.android.launcher3.util.ComponentKey) Uri(android.net.Uri) Callable(java.util.concurrent.Callable) TimeoutException(java.util.concurrent.TimeoutException) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException)

Example 29 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class AppSearchProvider method openFile.

public ParcelFileDescriptor openFile(final Uri uri, final String s) throws FileNotFoundException {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        Log.e("AppSearchProvider", "Content provider accessed on main thread");
        return null;
    }
    try {
        final ComponentKey dl = uriToComponent(uri, getContext());
        final String s2 = "image/png";
        final Callable<Bitmap> g = () -> {
            final AppItemInfoWithIcon d = new AppItemInfoWithIcon(dl);
            mApp.getIconCache().getTitleAndIcon(d, false);
            return d.iconBitmap;
        };
        return openPipeHelper(uri, s2, null, mLooper.submit(g), this.mPipeDataWriter);
    } catch (Exception ex) {
        throw new FileNotFoundException(ex.getMessage());
    }
}
Also used : Bitmap(android.graphics.Bitmap) ComponentKey(com.android.launcher3.util.ComponentKey) FileNotFoundException(java.io.FileNotFoundException) TimeoutException(java.util.concurrent.TimeoutException) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException)

Example 30 with ComponentKey

use of com.android.launcher3.util.ComponentKey in project Neo-Launcher by NeoApplications.

the class PredictionUiStateManager method fillInPredictedRank.

/**
 * Fill in predicted_rank field based on app prediction.
 * Only applicable when {@link ItemInfo#itemType} is one of the followings:
 * {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
 * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
 * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
 */
public static void fillInPredictedRank(@NonNull ItemInfo itemInfo, @NonNull LauncherLogProto.Target target) {
    final PredictionUiStateManager manager = PredictionUiStateManager.INSTANCE.getNoCreate();
    if (manager == null || itemInfo.getTargetComponent() == null || itemInfo.user == null || (itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT && itemInfo.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)) {
        return;
    }
    final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
    final List<ComponentKeyMapper> predictedApps = manager.getCurrentState().apps;
    IntStream.range(0, predictedApps.size()).filter((i) -> k.equals(predictedApps.get(i).getComponentKey())).findFirst().ifPresent((rank) -> target.predictedRank = rank);
}
Also used : ComponentKey(com.android.launcher3.util.ComponentKey)

Aggregations

ComponentKey (com.android.launcher3.util.ComponentKey)98 ComponentName (android.content.ComponentName)40 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)26 ArrayList (java.util.ArrayList)26 ShortcutInfo (android.content.pm.ShortcutInfo)21 UserHandle (android.os.UserHandle)20 HashMap (java.util.HashMap)19 ShortcutKey (com.android.launcher3.shortcuts.ShortcutKey)17 PackageUserKey (com.android.launcher3.util.PackageUserKey)17 Intent (android.content.Intent)16 HashSet (java.util.HashSet)16 Context (android.content.Context)15 ItemInfo (com.android.launcher3.model.data.ItemInfo)14 List (java.util.List)13 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)12 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)11 AppTarget (android.app.prediction.AppTarget)10 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)10 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)10 QueryResult (com.android.launcher3.shortcuts.ShortcutRequest.QueryResult)10