formula to calculate the size • size = (number of cells * 74) – 2 • android:updatePeriodMillis - How often, in milliseconds, that this AppWidget wants to be updated. • Updates requested with updatePeriodMillis will not be delivered more than once every 30 minutes. <?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/widget" android:minHeight="72dp" android:minWidth="294dp" android:updatePeriodMillis="1000" > </appwidget-provider> Friday, 13 January, 12
Formatter f = new Formatter(); public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this mDbAdapter = new SpentableDbAdapter(context); for (int i = 0; i < N; i++) { int appWidgetId = appWidgetIds[i]; // Create an Intent to launch ExampleActivity Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); // Get the layout for the App Widget and attach an on-click listener // to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); views.setOnClickPendingIntent(R.id.button, pendingIntent); // To update a label int total = mDbAdapter.getAmountSum(); views.setTextViewText(R.id.widget1label, f.format("Total Expenses: %,d", total).toString()); // Tell the AppWidgetManager to perform an update on the current app appWidgetManager.updateAppWidget(appWidgetId, views); } } public void onReceive (Context context, Intent intent){ String action = intent.getAction(); if (action.equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE)){ AppWidgetManager gm = AppWidgetManager.getInstance(context); int[] ids = gm.getAppWidgetIds(new ComponentName(context, WidgetProvider.class)); this.onUpdate(context, gm, ids); } } } Friday, 13 January, 12