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);
}
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);
}
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);
}
}
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();
}
}
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();
}
Aggregations