Search in sources :

Example 56 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_frameworks_base by ParanoidAndroid.

the class KeyguardWidgetPager method addWidget.

/*
     * We wrap widgets in a special frame which handles drawing the over scroll foreground.
     */
public void addWidget(View widget, int pageIndex) {
    KeyguardWidgetFrame frame;
    // All views contained herein should be wrapped in a KeyguardWidgetFrame
    if (!(widget instanceof KeyguardWidgetFrame)) {
        frame = new KeyguardWidgetFrame(getContext());
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        lp.gravity = Gravity.TOP;
        // The framework adds a default padding to AppWidgetHostView. We don't need this padding
        // for the Keyguard, so we override it to be 0.
        widget.setPadding(0, 0, 0, 0);
        frame.addView(widget, lp);
        // We set whether or not this widget supports vertical resizing.
        if (widget instanceof AppWidgetHostView) {
            AppWidgetHostView awhv = (AppWidgetHostView) widget;
            AppWidgetProviderInfo info = awhv.getAppWidgetInfo();
            if ((info.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) {
                frame.setWidgetLockedSmall(false);
            } else {
                // Lock the widget to be small.
                frame.setWidgetLockedSmall(true);
                if (mCenterSmallWidgetsVertically) {
                    lp.gravity = Gravity.CENTER;
                }
            }
        }
    } else {
        frame = (KeyguardWidgetFrame) widget;
    }
    ViewGroup.LayoutParams pageLp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    frame.setOnLongClickListener(this);
    frame.setWorkerHandler(mBackgroundWorkerHandler);
    if (pageIndex == -1) {
        addView(frame, pageLp);
    } else {
        addView(frame, pageIndex, pageLp);
    }
    // Update the frame content description.
    View content = (widget == frame) ? frame.getContent() : widget;
    if (content != null) {
        String contentDescription = mContext.getString(com.android.internal.R.string.keyguard_accessibility_widget, content.getContentDescription());
        frame.setContentDescription(contentDescription);
    }
    updateWidgetFrameImportantForAccessibility(frame);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View)

Example 57 with AppWidgetHostView

use of android.appwidget.AppWidgetHostView in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetHostActivity method addAppWidgetView.

void addAppWidgetView(int appWidgetId, AppWidgetProviderInfo appWidget) {
    // Inflate the AppWidget's RemoteViews
    AppWidgetHostView view = mHost.createView(this, appWidgetId, appWidget);
    // Add it to the list
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    mAppWidgetContainer.addView(view, layoutParams);
    registerForContextMenu(view);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) LinearLayout(android.widget.LinearLayout)

Example 58 with AppWidgetHostView

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

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)

Example 59 with AppWidgetHostView

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

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)

Example 60 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)

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