use of android.appwidget.AppWidgetManager in project android_frameworks_base by crdroidandroid.
the class TestAppWidgetProvider method onReceive.
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "intent=" + intent);
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
Log.d(TAG, "ENABLED");
} else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
Log.d(TAG, "DISABLED");
} else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
Log.d(TAG, "UPDATE");
// BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
Bundle extras = intent.getExtras();
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
// END_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
SharedPreferences prefs = context.getSharedPreferences(TestAppWidgetProvider.PREFS_NAME, 0);
String prefix = prefs.getString(PREF_PREFIX_KEY, "hai");
AppWidgetManager gm = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
views.setTextViewText(R.id.oh_hai_text, prefix + ": " + SystemClock.elapsedRealtime());
if (false) {
gm.updateAppWidget(appWidgetIds, views);
} else {
gm.updateAppWidget(new ComponentName("com.android.tests.appwidgethost", "com.android.tests.appwidgethost.TestAppWidgetProvider"), views);
}
}
}
use of android.appwidget.AppWidgetManager in project Shuttle by timusus.
the class BaseWidgetConfigure method onClick.
@Override
public void onClick(View view) {
if (view.getId() == R.id.btn_done) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), layoutId);
BaseWidgetProvider.setupButtons(this, remoteViews, appWidgetId, getRootViewId());
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, resultValue);
// Send broadcast intent to any running MediaPlaybackService so it can
// wrap around with an immediate update.
Intent updateIntent = new Intent(MusicService.ServiceCommand.SERVICE_COMMAND);
updateIntent.putExtra(MusicService.MediaButtonCommand.CMD_NAME, getUpdateCommandString());
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { appWidgetId });
updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
sendBroadcast(updateIntent);
finish();
}
if (view.getId() == R.id.btn_background_color) {
backgroundColorDialog = new ColorChooserDialog.Builder(this, R.string.color_pick).allowUserColorInputAlpha(true).show(getSupportFragmentManager());
}
if (view.getId() == R.id.btn_text_color) {
textColorDialog = new ColorChooserDialog.Builder(this, R.string.color_pick).allowUserColorInputAlpha(true).show(getSupportFragmentManager());
}
}
use of android.appwidget.AppWidgetManager in project cw-andtutorials by commonsguy.
the class WidgetService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
ComponentName me = new ComponentName(this, AppWidget.class);
RemoteViews updateViews = new RemoteViews("apt.tutorial", R.layout.widget);
RestaurantHelper helper = new RestaurantHelper(this);
AppWidgetManager mgr = AppWidgetManager.getInstance(this);
try {
Cursor c = helper.getReadableDatabase().rawQuery("SELECT COUNT(*) FROM restaurants", null);
c.moveToFirst();
int count = c.getInt(0);
c.close();
if (count > 0) {
int offset = (int) (count * Math.random());
String[] args = { String.valueOf(offset) };
c = helper.getReadableDatabase().rawQuery("SELECT _ID, name FROM restaurants LIMIT 1 OFFSET ?", args);
c.moveToFirst();
updateViews.setTextViewText(R.id.name, c.getString(1));
Intent i = new Intent(this, DetailForm.class);
i.putExtra(LunchList.ID_EXTRA, c.getString(0));
PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
updateViews.setOnClickPendingIntent(R.id.name, pi);
} else {
updateViews.setTextViewText(R.id.title, this.getString(R.string.empty));
}
} finally {
helper.close();
}
Intent i = new Intent(this, WidgetService.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
updateViews.setOnClickPendingIntent(R.id.next, pi);
mgr.updateAppWidget(me, updateViews);
}
use of android.appwidget.AppWidgetManager in project bitcoin-wallet by bitcoin-wallet.
the class WalletBalanceWidgetProvider method updateWidgets.
public static void updateWidgets(final Context context, final Wallet wallet) {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
final ComponentName providerName = new ComponentName(context, WalletBalanceWidgetProvider.class);
try {
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
if (appWidgetIds.length > 0) {
final Coin balance = wallet.getBalance(BalanceType.ESTIMATED);
WalletBalanceWidgetProvider.updateWidgets(context, appWidgetManager, appWidgetIds, balance);
}
} catch (// system server dead?
final RuntimeException x) {
log.warn("cannot update app widgets", x);
}
}
use of android.appwidget.AppWidgetManager in project platform_frameworks_base by android.
the class TestAppWidgetProvider method onReceive.
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "intent=" + intent);
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
Log.d(TAG, "ENABLED");
} else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
Log.d(TAG, "DISABLED");
} else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
if (true)
return;
Log.d(TAG, "UPDATE");
Bundle extras = intent.getExtras();
int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
AppWidgetManager gm = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
views.setTextViewText(R.id.oh_hai_text, "hai: " + SystemClock.elapsedRealtime());
if (false) {
gm.updateAppWidget(appWidgetIds, views);
} else {
gm.updateAppWidget(new ComponentName("com.android.tests.appwidgetprovider", "com.android.tests.appwidgetprovider.TestAppWidgetProvider"), views);
}
}
}
Aggregations