use of android.appwidget.AppWidgetHostView in project android_frameworks_base by ParanoidAndroid.
the class KeyguardHostView method addWidget.
private boolean addWidget(int appId, int pageIndex, boolean updateDbIfFailed) {
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appId);
if (appWidgetInfo != null) {
AppWidgetHostView view = mAppWidgetHost.createView(mContext, appId, appWidgetInfo);
addWidget(view, pageIndex);
return true;
} else {
if (updateDbIfFailed) {
Log.w(TAG, "*** AppWidgetInfo for app widget id " + appId + " was null for user" + mUserId + ", deleting");
mAppWidgetHost.deleteAppWidgetId(appId);
mLockPatternUtils.removeAppWidget(appId);
}
return false;
}
}
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 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();
}
}
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);
}
}
}
Aggregations