Search in sources :

Example 76 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project TBLauncher by TBog.

the class WidgetManager method restoreWidget.

// public List<AppWidgetProviderInfo> getWidgetsForPackage(String packageName) {
// List<AppWidgetProviderInfo> providers;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// providers = mAppWidgetManager.getInstalledProvidersForPackage(packageName, null);
// } else {
// providers = new ArrayList<>();
// for (AppWidgetProviderInfo prov : mAppWidgetManager.getInstalledProviders()) {
// if (prov.provider.getPackageName().equals(packageName)) {
// providers.add(prov);
// }
// }
// }
// return providers;
// }
private void restoreWidget(WidgetRecord rec) {
    final int appWidgetId = rec.appWidgetId;
    Context ctx = mLayout.getContext().getApplicationContext();
    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    if (appWidgetInfo == null)
        return;
    AppWidgetHostView hostView = mAppWidgetHost.createView(ctx, appWidgetId, appWidgetInfo);
    addWidgetToLayout(hostView, appWidgetInfo, rec);
}
Also used : Context(android.content.Context) AppWidgetHostView(android.appwidget.AppWidgetHostView) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 77 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project TBLauncher by TBog.

the class WidgetManager method addWidgetToLayout.

private void addWidgetToLayout(AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo, WidgetRecord rec) {
    View placeholder = mLayout.getPlaceholder(appWidgetInfo.provider);
    WidgetLayout.LayoutParams params = null;
    if (placeholder != null)
        params = (WidgetLayout.LayoutParams) placeholder.getLayoutParams();
    if (params == null) {
        params = new WidgetLayout.LayoutParams(rec.width, rec.height);
        params.leftMargin = rec.left;
        params.topMargin = rec.top;
        params.screenPage = rec.screen;
        params.placement = WidgetLayout.LayoutParams.Placement.MARGIN_TL_AS_POSITION;
    }
    hostView.setMinimumWidth(appWidgetInfo.minWidth);
    hostView.setMinimumHeight(appWidgetInfo.minHeight);
    hostView.setAppWidget(rec.appWidgetId, appWidgetInfo);
    hostView.updateAppWidgetSize(null, rec.width, rec.height, rec.width, rec.height);
    hostView.setOnLongClickListener(v -> {
        if (v instanceof WidgetView) {
            ListPopup menu = getConfigPopup((WidgetView) v);
            TBApplication.getApplication(v.getContext()).registerPopup(menu);
            menu.show(v, 0.f);
            return true;
        }
        return false;
    });
    // replace placeholder (if it exists) with the widget
    {
        int insertPosition = mLayout.indexOfChild(placeholder);
        if (insertPosition != -1)
            mLayout.removeViewAt(insertPosition);
        mLayout.addView(hostView, insertPosition, params);
    }
    Context context = mLayout.getContext();
    // remove from `mPlaceholders`
    {
        for (Iterator<PlaceholderWidgetRecord> iterator = mPlaceholders.iterator(); iterator.hasNext(); ) {
            PlaceholderWidgetRecord placeholderWidget = iterator.next();
            if (placeholderWidget.provider.equals(appWidgetInfo.provider)) {
                DBHelper.removeWidgetPlaceholder(context, INVALID_WIDGET_ID, placeholderWidget.provider.flattenToString());
                iterator.remove();
            }
        }
    }
}
Also used : WidgetLayout(rocks.tbog.tblauncher.ui.WidgetLayout) Context(android.content.Context) PlaceholderWidgetRecord(rocks.tbog.tblauncher.db.PlaceholderWidgetRecord) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) Iterator(java.util.Iterator) WidgetView(rocks.tbog.tblauncher.ui.WidgetView) ImageView(android.widget.ImageView) WidgetView(rocks.tbog.tblauncher.ui.WidgetView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) TextView(android.widget.TextView)

Example 78 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetHostViewLoader method preloadWidget.

/**
 * Start preloading the widget.
 */
private boolean preloadWidget() {
    final LauncherAppWidgetProviderInfo pInfo = mInfo.info;
    if (pInfo.isCustomWidget()) {
        return false;
    }
    final Bundle options = getDefaultOptionsForWidget(mLauncher, mInfo);
    // If there is a configuration activity, do not follow thru bound and inflate.
    if (mInfo.getHandler().needsConfigure()) {
        mInfo.bindOptions = options;
        return false;
    }
    mBindWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
            if (LOGD) {
                Log.d(TAG, "Binding widget, id: " + mWidgetLoadingId);
            }
            if (new WidgetManagerHelper(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, pInfo, options)) {
                // Widget id bound. Inflate the widget.
                mHandler.post(mInflateWidgetRunnable);
            }
        }
    };
    mInflateWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            if (LOGD) {
                Log.d(TAG, "Inflating widget, id: " + mWidgetLoadingId);
            }
            if (mWidgetLoadingId == -1) {
                return;
            }
            AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView((Context) mLauncher, mWidgetLoadingId, pInfo);
            mInfo.boundWidget = hostView;
            // We used up the widget Id in binding the above view.
            mWidgetLoadingId = -1;
            hostView.setVisibility(View.INVISIBLE);
            int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(mInfo);
            // We want the first widget layout to be the correct size. This will be important
            // for width size reporting to the AppWidgetManager.
            DragLayer.LayoutParams lp = new DragLayer.LayoutParams(unScaledSize[0], unScaledSize[1]);
            lp.x = lp.y = 0;
            lp.customPosition = true;
            hostView.setLayoutParams(lp);
            if (LOGD) {
                Log.d(TAG, "Adding host view to drag layer");
            }
            mLauncher.getDragLayer().addView(hostView);
            mView.setTag(mInfo);
        }
    };
    if (LOGD) {
        Log.d(TAG, "About to bind/inflate widget");
    }
    mHandler.post(mBindWidgetRunnable);
    return true;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) Context(android.content.Context) AppWidgetHostView(android.appwidget.AppWidgetHostView) DragLayer(com.android.launcher3.dragndrop.DragLayer) Bundle(android.os.Bundle)

Example 79 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_packages_apps_Trebuchet by LineageOS.

the class Launcher method completeTwoStageWidgetDrop.

@Thunk
void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) {
    CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId);
    Runnable onCompleteRunnable = null;
    int animationType = 0;
    AppWidgetHostView boundWidget = null;
    if (resultCode == RESULT_OK) {
        animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
        final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, requestArgs.getWidgetHandler().getProviderInfo(this));
        boundWidget = layout;
        onCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                completeAddAppWidget(appWidgetId, requestArgs, layout, null);
                mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
            }
        };
    } else if (resultCode == RESULT_CANCELED) {
        mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
    }
    if (mDragLayer.getAnimatedView() != null) {
        mWorkspace.animateWidgetDrop(requestArgs, cellLayout, (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, animationType, boundWidget, true);
    } else if (onCompleteRunnable != null) {
        // The animated view may be null in the case of a rotation during widget configuration
        onCompleteRunnable.run();
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) Thunk(com.android.launcher3.util.Thunk)

Example 80 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_packages_apps_Trebuchet by LineageOS.

the class SecondaryDropTarget method supportsAccessibilityDrop.

@Override
public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
    if (view instanceof AppWidgetHostView) {
        if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
            setupUi(RECONFIGURE);
            return true;
        }
        return false;
    } else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) {
        setupUi(DISMISS_PREDICTION);
        return true;
    }
    setupUi(UNINSTALL);
    Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
    if (uninstallDisabled == null) {
        UserManager userManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
        Bundle restrictions = userManager.getUserRestrictions(info.user);
        uninstallDisabled = restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false) || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false);
        mUninstallDisabledCache.put(info.user, uninstallDisabled);
    }
    // Cancel any pending alarm and set cache expiry after some time
    mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
    mCacheExpireAlarm.setOnAlarmListener(this);
    if (uninstallDisabled) {
        return false;
    }
    if (info instanceof ItemInfoWithIcon) {
        ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
        if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) {
            return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0;
        }
    }
    return getUninstallTarget(info) != null;
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) UserManager(android.os.UserManager) Bundle(android.os.Bundle) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon)

Aggregations

AppWidgetHostView (android.appwidget.AppWidgetHostView)87 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)32 View (android.view.View)23 Bundle (android.os.Bundle)22 Point (android.graphics.Point)19 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)16 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)16 Context (android.content.Context)15 SuppressLint (android.annotation.SuppressLint)13 TextView (android.widget.TextView)12 Intent (android.content.Intent)10 ImageView (android.widget.ImageView)9 AppWidgetHost (android.appwidget.AppWidgetHost)7 ViewGroup (android.view.ViewGroup)7 LinearLayout (android.widget.LinearLayout)7 DragView (com.android.launcher3.dragndrop.DragView)7 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)7 Test (org.junit.Test)5 Rect (android.graphics.Rect)4 DraggableView (com.android.launcher3.dragndrop.DraggableView)4