Search in sources :

Example 66 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_404Launcher by P-404.

the class LauncherModelHelper method executeTaskForTest.

/**
 * Synchronously executes the task and returns all the UI callbacks posted.
 */
public List<Runnable> executeTaskForTest(ModelUpdateTask task) throws Exception {
    LauncherModel model = getModel();
    if (!model.isModelLoaded()) {
        ReflectionHelpers.setField(model, "mModelLoaded", true);
    }
    Executor mockExecutor = mock(Executor.class);
    model.enqueueModelUpdateTask(new ModelUpdateTask() {

        @Override
        public void init(LauncherAppState app, LauncherModel model, BgDataModel dataModel, AllAppsList allAppsList, Executor uiExecutor) {
            task.init(app, model, dataModel, allAppsList, mockExecutor);
        }

        @Override
        public void run() {
            task.run();
        }
    });
    MODEL_EXECUTOR.submit(() -> null).get();
    ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
    verify(mockExecutor, atLeast(0)).execute(captor.capture());
    return captor.getAllValues();
}
Also used : LauncherModel(com.android.launcher3.LauncherModel) ModelUpdateTask(com.android.launcher3.LauncherModel.ModelUpdateTask) Executor(java.util.concurrent.Executor) LauncherAppState(com.android.launcher3.LauncherAppState) BgDataModel(com.android.launcher3.model.BgDataModel) AllAppsList(com.android.launcher3.model.AllAppsList)

Example 67 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project Launcher3 by chislon.

the class LauncherBackupHelper method backupIcons.

/**
 * Write all the static icon resources we need to render placeholders
 * for a package that is not installed.
 *
 * @param in notes from last backup
 * @param data output stream for key/value pairs
 * @param out notes about this backup
 * @param keys keys to mark as clean in the notes for next backup
 * @throws IOException
 */
private void backupIcons(Journal in, BackupDataOutput data, Journal out, ArrayList<Key> keys) throws IOException {
    // persist icons that haven't been persisted yet
    final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
    if (appState == null) {
        // try again later
        dataChanged();
        if (DEBUG)
            Log.d(TAG, "Launcher is not initialized, delaying icon backup");
        return;
    }
    final ContentResolver cr = mContext.getContentResolver();
    final IconCache iconCache = appState.getIconCache();
    final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
    // read the old ID set
    Set<String> savedIds = getSavedIdsByType(Key.ICON, in);
    if (DEBUG)
        Log.d(TAG, "icon savedIds.size()=" + savedIds.size());
    int startRows = out.rows;
    if (DEBUG)
        Log.d(TAG, "starting here: " + startRows);
    String where = Favorites.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_APPLICATION;
    Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, where, null, null);
    Set<String> currentIds = new HashSet<String>(cursor.getCount());
    try {
        cursor.moveToPosition(-1);
        while (cursor.moveToNext()) {
            final long id = cursor.getLong(ID_INDEX);
            final String intentDescription = cursor.getString(INTENT_INDEX);
            try {
                Intent intent = Intent.parseUri(intentDescription, 0);
                ComponentName cn = intent.getComponent();
                Key key = null;
                String backupKey = null;
                if (cn != null) {
                    key = getKey(Key.ICON, cn.flattenToShortString());
                    backupKey = keyToBackupKey(key);
                    currentIds.add(backupKey);
                } else {
                    Log.w(TAG, "empty intent on application favorite: " + id);
                }
                if (savedIds.contains(backupKey)) {
                    if (DEBUG)
                        Log.d(TAG, "already saved icon " + backupKey);
                    // remember that we already backed this up previously
                    keys.add(key);
                } else if (backupKey != null) {
                    if (DEBUG)
                        Log.d(TAG, "I can count this high: " + out.rows);
                    if ((out.rows - startRows) < MAX_ICONS_PER_PASS) {
                        if (DEBUG)
                            Log.d(TAG, "saving icon " + backupKey);
                        Bitmap icon = iconCache.getIcon(intent);
                        keys.add(key);
                        if (icon != null && !iconCache.isDefaultIcon(icon)) {
                            byte[] blob = packIcon(dpi, icon);
                            writeRowToBackup(key, blob, out, data);
                        }
                    } else {
                        if (DEBUG)
                            Log.d(TAG, "scheduling another run for icon " + backupKey);
                        // too many icons for this pass, request another.
                        dataChanged();
                    }
                }
            } catch (URISyntaxException e) {
                Log.w(TAG, "invalid URI on application favorite: " + id);
            } catch (IOException e) {
                Log.w(TAG, "unable to save application icon for favorite: " + id);
            }
        }
    } finally {
        cursor.close();
    }
    if (DEBUG)
        Log.d(TAG, "icon currentIds.size()=" + currentIds.size());
    // these IDs must have been deleted
    savedIds.removeAll(currentIds);
    out.rows += removeDeletedKeysFromBackup(savedIds, data);
}
Also used : Intent(android.content.Intent) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) ComponentName(android.content.ComponentName) Key(com.android.launcher3.backup.BackupProtos.Key) HashSet(java.util.HashSet)

Example 68 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project Launcher3 by chislon.

the class AppsCustomizePagedView method onPackagesUpdated.

public void onPackagesUpdated(ArrayList<Object> widgetsAndShortcuts) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    // Get the list of widgets and shortcuts
    mWidgets.clear();
    for (Object o : widgetsAndShortcuts) {
        if (o instanceof AppWidgetProviderInfo) {
            AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o;
            if (!app.shouldShowAppOrWidgetProvider(widget.provider)) {
                continue;
            }
            widget.label = widget.label.trim();
            if (widget.minWidth > 0 && widget.minHeight > 0) {
                // Ensure that all widgets we show can be added on a workspace of this size
                int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget);
                int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget);
                int minSpanX = Math.min(spanXY[0], minSpanXY[0]);
                int minSpanY = Math.min(spanXY[1], minSpanXY[1]);
                if (minSpanX <= (int) grid.numColumns && minSpanY <= (int) grid.numRows) {
                    mWidgets.add(widget);
                } else {
                    Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + widget.minWidth + ", " + widget.minHeight + ")");
                }
            } else {
                Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + widget.minWidth + ", " + widget.minHeight + ")");
            }
        } else {
            // just add shortcuts
            mWidgets.add(o);
        }
    }
    updatePageCountsAndInvalidateData();
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragObject(com.android.launcher3.DropTarget.DragObject) Point(android.graphics.Point)

Example 69 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project Launcher3 by chislon.

the class CellLayout method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        Drawable bg;
        if (mUseActiveGlowBackground) {
            // In the mini case, we draw the active_glow bg *over* the active background
            bg = mActiveGlowBackground;
        } else {
            bg = mNormalBackground;
        }
        bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
        bg.setBounds(mBackgroundRect);
        bg.draw(canvas);
    }
    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }
    // requires an expanded clip rect (due to the glow's blur radius)
    if (mPressedOrFocusedIcon != null) {
        final int padding = mPressedOrFocusedIcon.getPressedOrFocusedBackgroundPadding();
        final Bitmap b = mPressedOrFocusedIcon.getPressedOrFocusedBackground();
        if (b != null) {
            int offset = getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth);
            int left = getPaddingLeft() + (int) Math.ceil(offset / 2f);
            int top = getPaddingTop();
            canvas.drawBitmap(b, mPressedOrFocusedIcon.getLeft() + left - padding, mPressedOrFocusedIcon.getTop() + top - padding, null);
        }
    }
    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }
    int previewOffset = FolderRingAnimator.sPreviewSize;
    // The folder outer / inner ring image(s)
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderRingAnimator fra = mFolderOuterRings.get(i);
        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset;
            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }
            // Draw inner ring
            d = FolderRingAnimator.sSharedInnerRingDrawable;
            width = (int) (fra.getInnerRingSize() * getChildrenScale());
            height = width;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();
        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) FolderRingAnimator(com.android.launcher3.FolderIcon.FolderRingAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) Paint(android.graphics.Paint) View(android.view.View) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 70 with LauncherAppState

use of com.android.launcher3.LauncherAppState in project android_packages_apps_404Launcher by P-404.

the class WidgetsPredictionUpdateTask method execute.

/**
 * Uses the app predication result to infer widgets that the user may want to use.
 *
 * <p>The algorithm uses the app prediction ranking to create a widgets ranking which only
 * includes one widget per app and excludes widgets that have already been added to the
 * workspace.
 */
@Override
public void execute(LauncherAppState appState, BgDataModel dataModel, AllAppsList apps) {
    Set<ComponentKey> widgetsInWorkspace = dataModel.appWidgets.stream().map(widget -> new ComponentKey(widget.providerName, widget.user)).collect(Collectors.toSet());
    Map<PackageUserKey, List<WidgetItem>> allWidgets = dataModel.widgetsModel.getAllWidgetsWithoutShortcuts();
    FixedContainerItems fixedContainerItems = mPredictorState.items;
    fixedContainerItems.items.clear();
    if (FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER.get()) {
        for (AppTarget app : mTargets) {
            PackageUserKey packageUserKey = new PackageUserKey(app.getPackageName(), app.getUser());
            if (allWidgets.containsKey(packageUserKey)) {
                List<WidgetItem> notAddedWidgets = allWidgets.get(packageUserKey).stream().filter(item -> !widgetsInWorkspace.contains(new ComponentKey(item.componentName, item.user))).collect(Collectors.toList());
                if (notAddedWidgets.size() > 0) {
                    // Even an apps have more than one widgets, we only include one widget.
                    fixedContainerItems.items.add(new PendingAddWidgetInfo(notAddedWidgets.get(0).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
                }
            }
        }
    } else {
        Map<ComponentKey, WidgetItem> widgetItems = allWidgets.values().stream().flatMap(List::stream).distinct().collect(Collectors.toMap(widget -> (ComponentKey) widget, widget -> widget));
        for (AppTarget app : mTargets) {
            if (TextUtils.isEmpty(app.getClassName())) {
                continue;
            }
            ComponentKey targetWidget = new ComponentKey(new ComponentName(app.getPackageName(), app.getClassName()), app.getUser());
            if (widgetItems.containsKey(targetWidget)) {
                fixedContainerItems.items.add(new PendingAddWidgetInfo(widgetItems.get(targetWidget).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
            }
        }
    }
    bindExtraContainerItems(fixedContainerItems);
// Don't store widgets prediction to disk because it is not used frequently.
}
Also used : CONTAINER_WIDGETS_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION) ComponentName(android.content.ComponentName) LauncherAppState(com.android.launcher3.LauncherAppState) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) Set(java.util.Set) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) List(java.util.List) ComponentKey(com.android.launcher3.util.ComponentKey) Map(java.util.Map) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ComponentKey(com.android.launcher3.util.ComponentKey) PackageUserKey(com.android.launcher3.util.PackageUserKey) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTarget(android.app.prediction.AppTarget) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) List(java.util.List) ComponentName(android.content.ComponentName)

Aggregations

ArrayList (java.util.ArrayList)62 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)56 Context (android.content.Context)39 LauncherAppState (com.android.launcher3.LauncherAppState)38 HashSet (java.util.HashSet)37 ShortcutInfo (android.content.pm.ShortcutInfo)33 List (java.util.List)33 ComponentName (android.content.ComponentName)32 ItemInfo (com.android.launcher3.model.data.ItemInfo)30 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)24 Point (android.graphics.Point)24 LauncherApps (android.content.pm.LauncherApps)23 IconCache (com.android.launcher3.icons.IconCache)23 LauncherIcons (com.android.launcher3.icons.LauncherIcons)23 AppInfo (com.android.launcher3.model.data.AppInfo)22 PackageManager (android.content.pm.PackageManager)20 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)20 HashMap (java.util.HashMap)20 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)19 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)19