use of android.appwidget.AppWidgetHostView in project ADWLauncher2 by boombuler.
the class WidgetCellLayout method onViewportIn.
/**
* Called when this cell layout get into the viewport
*/
public void onViewportIn() {
View child;
AppWidgetHostView widgetView;
AppWidgetProviderInfo widgetInfo;
Intent intent;
for (int i = this.getChildCount() - 1; i >= 0; i--) {
try {
child = this.getChildAt(i);
if (child instanceof AppWidgetHostView) {
widgetView = ((AppWidgetHostView) child);
widgetInfo = widgetView.getAppWidgetInfo();
int appWidgetId = widgetView.getAppWidgetId();
intent = new Intent(LauncherIntent.Notification.NOTIFICATION_IN_VIEWPORT).setComponent(widgetInfo.provider);
intent.putExtra(LauncherIntent.Extra.EXTRA_APPWIDGET_ID, appWidgetId);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
getContext().sendBroadcast(intent);
}
} catch (Exception e) {
// LauncherApplication.reportExceptionStack(e);
}
}
}
use of android.appwidget.AppWidgetHostView in project ADWLauncher2 by boombuler.
the class Launcher method editWidget.
protected void editWidget(final View widget) {
if (mWorkspace != null) {
mIsWidgetEditMode = true;
final CellLayout screen = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentScreen());
if (screen != null) {
mEditingAppWidget = (LauncherAppWidgetInfo) widget.getTag();
final long itemId = mEditingAppWidget.id;
final Intent motosize = new Intent("com.motorola.blur.home.ACTION_SET_WIDGET_SIZE");
final int appWidgetId = ((AppWidgetHostView) widget).getAppWidgetId();
final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
if (appWidgetInfo != null) {
motosize.setComponent(appWidgetInfo.provider);
}
motosize.putExtra("appWidgetId", appWidgetId);
motosize.putExtra("com.motorola.blur.home.EXTRA_NEW_WIDGET", true);
final int minw = (mWorkspace.getWidth() - screen.getLeftPadding() - screen.getRightPadding()) / screen.getCountX();
final int minh = (mWorkspace.getHeight() - screen.getBottomPadding() - screen.getTopPadding()) / screen.getCountY();
mScreensEditor = new ResizeViewHandler(this);
// Create a default HightlightView if we found no face in the picture.
int width = (mEditingAppWidget.spanX * minw);
int height = (mEditingAppWidget.spanY * minh);
final Rect screenRect = new Rect(0, 0, mWorkspace.getWidth() - screen.getRightPadding(), mWorkspace.getHeight() - screen.getBottomPadding());
final int x = mEditingAppWidget.cellX * minw;
final int y = mEditingAppWidget.cellY * minh;
final int[] spans = new int[] { 1, 1 };
final int[] position = new int[] { 1, 1 };
final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) widget.getLayoutParams();
RectF widgetRect = new RectF(x, y, x + width, y + height);
mScreensEditor.setup(null, screenRect, widgetRect, false, false, minw - 10, minh - 10);
mDragLayer.addView(mScreensEditor);
mScreensEditor.setOnValidateSizingRect(new ResizeViewHandler.OnSizeChangedListener() {
@Override
public void onTrigger(RectF r) {
if (r != null) {
final float left = Math.round(r.left / minw) * minw;
final float top = Math.round(r.top / minh) * minh;
final float right = left + (Math.max(Math.round(r.width() / (minw)), 1) * minw);
final float bottom = top + (Math.max(Math.round(r.height() / (minh)), 1) * minh);
r.set(left, top, right, bottom);
}
}
});
final Rect checkRect = new Rect();
(mScreensEditor).setOnSizeChangedListener(new ResizeViewHandler.OnSizeChangedListener() {
@Override
public void onTrigger(RectF r) {
int[] tmpspans = { Math.max(Math.round(r.width() / (minw)), 1), Math.max(Math.round(r.height() / (minh)), 1) };
int[] tmpposition = { Math.round(r.left / minw), Math.round(r.top / minh) };
checkRect.set(tmpposition[0], tmpposition[1], tmpposition[0] + tmpspans[0], tmpposition[1] + tmpspans[1]);
boolean ocupada = ocuppiedArea(screen.getScreen(), itemId, checkRect);
if (!ocupada) {
(mScreensEditor).setColliding(false);
} else {
(mScreensEditor).setColliding(true);
}
if (tmpposition[0] != position[0] || tmpposition[1] != position[1] || tmpspans[0] != spans[0] || tmpspans[1] != spans[1]) {
if (!ocupada) {
position[0] = tmpposition[0];
position[1] = tmpposition[1];
spans[0] = tmpspans[0];
spans[1] = tmpspans[1];
lp.cellX = position[0];
lp.cellY = position[1];
lp.cellHSpan = spans[0];
lp.cellVSpan = spans[1];
widget.setLayoutParams(lp);
mEditingAppWidget.cellX = lp.cellX;
mEditingAppWidget.cellY = lp.cellY;
mEditingAppWidget.spanX = lp.cellHSpan;
mEditingAppWidget.spanY = lp.cellVSpan;
widget.setTag(mEditingAppWidget);
//send the broadcast
motosize.putExtra("spanX", spans[0]);
motosize.putExtra("spanY", spans[1]);
Launcher.this.sendBroadcast(motosize);
Log.d("RESIZEHANDLER", "sent resize broadcast");
}
}
}
});
}
}
}
use of android.appwidget.AppWidgetHostView in project android_frameworks_base by DirtyUnicorns.
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_frameworks_base by ResurrectionRemix.
the class AppWidgetHostActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mAppWidgetManager = AppWidgetManager.getInstance(this);
setContentView(R.layout.appwidget_host);
mHost = new AppWidgetHost(this, HOST_ID) {
protected AppWidgetHostView onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
return new MyAppWidgetView(appWidgetId);
}
};
findViewById(R.id.add_appwidget).setOnClickListener(mOnClickListener);
mAppWidgetContainer = (AppWidgetContainerView) findViewById(R.id.appwidget_container);
if (false) {
if (false) {
mHost.deleteHost();
} else {
AppWidgetHost.deleteAllHosts();
}
}
}
use of android.appwidget.AppWidgetHostView in project android_frameworks_base by ResurrectionRemix.
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);
}
Aggregations