Search in sources :

Example 6 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method widgetsRestored.

public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) {
    if (!changedInfo.isEmpty()) {
        DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, mLauncher.getAppWidgetHost());
        LauncherAppWidgetInfo item = changedInfo.get(0);
        final AppWidgetProviderInfo widgetInfo;
        WidgetManagerHelper widgetHelper = new WidgetManagerHelper(getContext());
        if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            widgetInfo = widgetHelper.findProvider(item.providerName, item.user);
        } else {
            widgetInfo = widgetHelper.getLauncherAppWidgetInfo(item.appWidgetId);
        }
        if (widgetInfo != null) {
            // Re-inflate the widgets which have changed status
            widgetRefresh.run();
        } else {
            // widgetRefresh will automatically run when the packages are updated.
            // For now just update the progress bars
            mapOverItems(new ItemOperator() {

                @Override
                public boolean evaluate(ItemInfo info, View view) {
                    if (view instanceof PendingAppWidgetHostView && changedInfo.contains(info)) {
                        ((LauncherAppWidgetInfo) info).installProgress = 100;
                        ((PendingAppWidgetHostView) view).applyState();
                    }
                    // process all the shortcuts
                    return false;
                }
            });
        }
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView)

Example 7 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherAccessibilityDelegate method getSupportedResizeActions.

private List<OptionItem> getSupportedResizeActions(View host, LauncherAppWidgetInfo info) {
    List<OptionItem> actions = new ArrayList<>();
    AppWidgetProviderInfo providerInfo = ((LauncherAppWidgetHostView) host).getAppWidgetInfo();
    if (providerInfo == null) {
        return actions;
    }
    CellLayout layout;
    if (host.getParent() instanceof DragView) {
        layout = (CellLayout) ((DragView) host.getParent()).getContentViewParent().getParent();
    } else {
        layout = (CellLayout) host.getParent().getParent();
    }
    if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0) {
        if (layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY) || layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY)) {
            actions.add(new OptionItem(mLauncher, R.string.action_increase_width, R.drawable.ic_widget_width_increase, IGNORE, v -> performResizeAction(R.string.action_increase_width, host, info)));
        }
        if (info.spanX > info.minSpanX && info.spanX > 1) {
            actions.add(new OptionItem(mLauncher, R.string.action_decrease_width, R.drawable.ic_widget_width_decrease, IGNORE, v -> performResizeAction(R.string.action_decrease_width, host, info)));
        }
    }
    if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) {
        if (layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1) || layout.isRegionVacant(info.cellX, info.cellY - 1, info.spanX, 1)) {
            actions.add(new OptionItem(mLauncher, R.string.action_increase_height, R.drawable.ic_widget_height_increase, IGNORE, v -> performResizeAction(R.string.action_increase_height, host, info)));
        }
        if (info.spanY > info.minSpanY && info.spanY > 1) {
            actions.add(new OptionItem(mLauncher, R.string.action_decrease_height, R.drawable.ic_widget_height_decrease, IGNORE, v -> performResizeAction(R.string.action_decrease_height, host, info)));
        }
    }
    return actions;
}
Also used : Rect(android.graphics.Rect) Bundle(android.os.Bundle) AccessibilityDelegate(android.view.View.AccessibilityDelegate) KeyboardDragAndDropView(com.android.launcher3.keyboard.KeyboardDragAndDropView) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) BubbleTextView(com.android.launcher3.BubbleTextView) OptionsPopupView(com.android.launcher3.views.OptionsPopupView) IGNORE(com.android.launcher3.logging.StatsLogManager.LauncherEvent.IGNORE) Handler(android.os.Handler) AccessibilityAction(android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) Log(android.util.Log) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) RectF(android.graphics.RectF) ACTION_LONG_CLICK(android.view.accessibility.AccessibilityNodeInfo.ACTION_LONG_CLICK) Launcher(com.android.launcher3.Launcher) Favorites(com.android.launcher3.LauncherSettings.Favorites) DragOptions(com.android.launcher3.dragndrop.DragOptions) SparseArray(android.util.SparseArray) WidgetSizes(com.android.launcher3.widget.util.WidgetSizes) List(java.util.List) NotificationListener(com.android.launcher3.notification.NotificationListener) ShortcutUtil(com.android.launcher3.util.ShortcutUtil) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Workspace(com.android.launcher3.Workspace) NORMAL(com.android.launcher3.LauncherState.NORMAL) Folder(com.android.launcher3.folder.Folder) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) ArrowPopup(com.android.launcher3.popup.ArrowPopup) KeyEvent(android.view.KeyEvent) AppInfo(com.android.launcher3.model.data.AppInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) ArrayList(java.util.ArrayList) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) ItemLongClickListener(com.android.launcher3.touch.ItemLongClickListener) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AnimatorListeners.forSuccessCallback(com.android.launcher3.anim.AnimatorListeners.forSuccessCallback) DragObject(com.android.launcher3.DropTarget.DragObject) DragListener(com.android.launcher3.dragndrop.DragController.DragListener) IntArray(com.android.launcher3.util.IntArray) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) Point(android.graphics.Point) TextUtils(android.text.TextUtils) CellLayout(com.android.launcher3.CellLayout) OptionItem(com.android.launcher3.views.OptionsPopupView.OptionItem) R(com.android.launcher3.R) Thunk(com.android.launcher3.util.Thunk) Collections(java.util.Collections) DragView(com.android.launcher3.dragndrop.DragView) OptionItem(com.android.launcher3.views.OptionsPopupView.OptionItem) CellLayout(com.android.launcher3.CellLayout) ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragView(com.android.launcher3.dragndrop.DragView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 8 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherAccessibilityDelegate method performResizeAction.

private boolean performResizeAction(int action, View host, LauncherAppWidgetInfo info) {
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) host.getLayoutParams();
    CellLayout layout = (CellLayout) host.getParent().getParent();
    layout.markCellsAsUnoccupiedForView(host);
    if (action == R.string.action_increase_width) {
        if (((host.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) && layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY)) || !layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY)) {
            lp.cellX--;
            info.cellX--;
        }
        lp.cellHSpan++;
        info.spanX++;
    } else if (action == R.string.action_decrease_width) {
        lp.cellHSpan--;
        info.spanX--;
    } else if (action == R.string.action_increase_height) {
        if (!layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1)) {
            lp.cellY--;
            info.cellY--;
        }
        lp.cellVSpan++;
        info.spanY++;
    } else if (action == R.string.action_decrease_height) {
        lp.cellVSpan--;
        info.spanY--;
    }
    layout.markCellsAsOccupiedForView(host);
    WidgetSizes.updateWidgetSizeRanges(((LauncherAppWidgetHostView) host), mLauncher, info.spanX, info.spanY);
    host.requestLayout();
    mLauncher.getModelWriter().updateItemInDatabase(info);
    announceConfirmation(mLauncher.getString(R.string.widget_resized, info.spanX, info.spanY));
    return true;
}
Also used : CellLayout(com.android.launcher3.CellLayout) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 9 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class Launcher method completeRestoreAppWidget.

/**
 * Restores a pending widget.
 *
 * @param appWidgetId The app widget id
 */
private LauncherAppWidgetInfo completeRestoreAppWidget(int appWidgetId, int finalRestoreFlag) {
    LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
    if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
        Log.e(TAG, "Widget update called, when the widget no longer exists.");
        return null;
    }
    LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
    info.restoreStatus = finalRestoreFlag;
    if (info.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
        info.pendingItemInfo = null;
    }
    if (((PendingAppWidgetHostView) view).isReinflateIfNeeded()) {
        view.reInflate();
    }
    getModelWriter().updateItemInDatabase(info);
    return info;
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView)

Example 10 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.

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) {
        List<AppInfo> updatedAppInfos = apps.updatePromiseInstallInfo(mInstallInfo);
        if (!updatedAppInfos.isEmpty()) {
            for (AppInfo appInfo : updatedAppInfos) {
                scheduleCallbackTask(c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
            }
        }
        bindApplicationsIfNeeded();
    }
    synchronized (dataModel) {
        final HashSet<ItemInfo> updates = new HashSet<>();
        dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
            if (si.hasPromiseIconUi() && mInstallInfo.packageName.equals(si.getTargetPackage())) {
                si.setProgressLevel(mInstallInfo);
                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(callbacks -> callbacks.bindRestoreItemsChange(updates));
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ItemInfo(com.android.launcher3.model.data.ItemInfo) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) AppInfo(com.android.launcher3.model.data.AppInfo) HashSet(java.util.HashSet)

Aggregations

LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)201 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)73 LargeTest (androidx.test.filters.LargeTest)70 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)70 Test (org.junit.Test)70 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)68 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)61 ItemInfo (com.android.launcher3.model.data.ItemInfo)56 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)55 ArrayList (java.util.ArrayList)54 AppWidgetHostView (android.appwidget.AppWidgetHostView)53 View (android.view.View)50 FolderInfo (com.android.launcher3.model.data.FolderInfo)48 DragView (com.android.launcher3.dragndrop.DragView)41 HashSet (java.util.HashSet)38 AppInfo (com.android.launcher3.model.data.AppInfo)37 ComponentName (android.content.ComponentName)33 IntArray (com.android.launcher3.util.IntArray)31 Point (android.graphics.Point)30 Bundle (android.os.Bundle)30