Search in sources :

Example 36 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_packages_apps_Launcher2 by CyanogenMod.

the class AppsCustomizePagedView method cleanupWidgetPreloading.

private void cleanupWidgetPreloading(boolean widgetWasAdded) {
    if (!widgetWasAdded) {
        // If the widget was not added, we may need to do further cleanup.
        PendingAddWidgetInfo info = mCreateWidgetInfo;
        mCreateWidgetInfo = null;
        if (mWidgetCleanupState == WIDGET_PRELOAD_PENDING) {
            // We never did any preloading, so just remove pending callbacks to do so
            removeCallbacks(mBindWidgetRunnable);
            removeCallbacks(mInflateWidgetRunnable);
        } else if (mWidgetCleanupState == WIDGET_BOUND) {
            // Delete the widget id which was allocated
            if (mWidgetLoadingId != -1) {
                mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId);
            }
            // We never got around to inflating the widget, so remove the callback to do so.
            removeCallbacks(mInflateWidgetRunnable);
        } else if (mWidgetCleanupState == WIDGET_INFLATED) {
            // Delete the widget id which was allocated
            if (mWidgetLoadingId != -1) {
                mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId);
            }
            // The widget was inflated and added to the DragLayer -- remove it.
            AppWidgetHostView widget = info.boundWidget;
            mLauncher.getDragLayer().removeView(widget);
        }
    }
    mWidgetCleanupState = WIDGET_NO_CLEANUP_REQUIRED;
    mWidgetLoadingId = -1;
    mCreateWidgetInfo = null;
    PagedViewWidget.resetShortPressTarget();
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView)

Example 37 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_packages_apps_Launcher2 by CyanogenMod.

the class AppsCustomizePagedView method preloadWidget.

private void preloadWidget(final PendingAddWidgetInfo info) {
    final AppWidgetProviderInfo pInfo = info.info;
    final Bundle options = getDefaultOptionsForWidget(mLauncher, info);
    if (pInfo.configure != null) {
        info.bindOptions = options;
        return;
    }
    mWidgetCleanupState = WIDGET_PRELOAD_PENDING;
    mBindWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
            // SDK level check.
            if (options == null) {
                if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, info.componentName)) {
                    mWidgetCleanupState = WIDGET_BOUND;
                }
            } else {
                if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, info.componentName, options)) {
                    mWidgetCleanupState = WIDGET_BOUND;
                }
            }
        }
    };
    post(mBindWidgetRunnable);
    mInflateWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            if (mWidgetCleanupState != WIDGET_BOUND) {
                return;
            }
            AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView(getContext(), mWidgetLoadingId, pInfo);
            info.boundWidget = hostView;
            mWidgetCleanupState = WIDGET_INFLATED;
            hostView.setVisibility(INVISIBLE);
            int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(info.spanX, info.spanY, info, false);
            // 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);
            mLauncher.getDragLayer().addView(hostView);
        }
    };
    post(mInflateWidgetRunnable);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) Bundle(android.os.Bundle) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 38 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project Fairphone by Kwamecorp.

the class LauncherTransitionable method completeTwoStageWidgetDrop.

private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
    CellLayout cellLayout = (CellLayout) mWorkspace.getChildAt(mPendingAddInfo.screen);
    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, mPendingAddWidgetInfo);
        boundWidget = layout;
        onCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                completeAddAppWidget(appWidgetId, mPendingAddInfo.container, mPendingAddInfo.screen, layout, null);
                exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false, null);
            }
        };
    } else if (resultCode == RESULT_CANCELED) {
        animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
        onCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false, null);
            }
        };
    }
    if (mDragLayer.getAnimatedView() != null) {
        mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout, (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, animationType, boundWidget, true);
    } else {
        // The animated view may be null in the case of a rotation during
        // widget configuration
        onCompleteRunnable.run();
    }
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) SuppressLint(android.annotation.SuppressLint)

Example 39 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project Fairphone by Kwamecorp.

the class LauncherTransitionable method addAppWidgetFromDrop.

/**
	 * Process a widget drop.
	 * 
	 * @param info
	 *            The PendingAppWidgetInfo of the widget being added.
	 * @param screen
	 *            The screen where it should be added
	 * @param cell
	 *            The cell it should be added to, optional
	 * @param position
	 *            The location on the screen where it was dropped, optional
	 */
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen, int[] cell, int[] span, int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screen = info.screen = screen;
    mPendingAddInfo.dropPos = loc;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;
    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }
    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);
    } else {
        // In this case, we either need to start an activity to get
        // permission to bind
        // the widget, or we need to start an activity to configure the
        // widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;
        boolean success = false;
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) Bundle(android.os.Bundle) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) SuppressLint(android.annotation.SuppressLint)

Example 40 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project Fairphone by Kwamecorp.

the class Workspace method animateWidgetDrop.

public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView, final Runnable onCompleteRunnable, int animationType, final View finalView, boolean external) {
    Rect from = new Rect();
    mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from);
    int[] finalPos = new int[2];
    float[] scaleXY = new float[2];
    boolean scalePreview = !(info instanceof PendingAddShortcutInfo);
    getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, external, scalePreview);
    Resources res = mLauncher.getResources();
    int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200;
    // In the case where we've prebound the widget, we remove it from the DragLayer
    if (finalView instanceof AppWidgetHostView && external) {
        Log.d(TAG, "6557954 Animate widget drop, final view is appWidgetHostView");
        mLauncher.getDragLayer().removeView(finalView);
    }
    if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null) {
        Bitmap crossFadeBitmap = createWidgetBitmap(info, finalView);
        dragView.setCrossFadeBitmap(crossFadeBitmap);
        dragView.crossFade((int) (duration * 0.8f));
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && external) {
        scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]);
    }
    DragLayer dragLayer = mLauncher.getDragLayer();
    if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) {
        mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f, DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration);
    } else {
        int endStyle;
        if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) {
            endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE;
        } else {
            endStyle = DragLayer.ANIMATION_END_DISAPPEAR;
            ;
        }
        Runnable onComplete = new Runnable() {

            @Override
            public void run() {
                if (finalView != null) {
                    finalView.setVisibility(VISIBLE);
                }
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }
            }
        };
        dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], finalPos[1], 1, 1, 1, scaleXY[0], scaleXY[1], onComplete, endStyle, duration, this);
    }
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) Resources(android.content.res.Resources) Point(android.graphics.Point)

Aggregations

AppWidgetHostView (android.appwidget.AppWidgetHostView)45 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)18 Point (android.graphics.Point)11 View (android.view.View)10 Context (android.content.Context)6 Intent (android.content.Intent)6 Bundle (android.os.Bundle)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 AppWidgetHost (android.appwidget.AppWidgetHost)5 LinearLayout (android.widget.LinearLayout)5 Test (org.junit.Test)5 Rect (android.graphics.Rect)4 Resources (android.content.res.Resources)3 Bitmap (android.graphics.Bitmap)3 RecognizerIntent (android.speech.RecognizerIntent)3 LauncherIntent (mobi.intuitit.android.content.LauncherIntent)3 SuppressLint (android.annotation.SuppressLint)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Paint (android.graphics.Paint)1