use of android.appwidget.AppWidgetManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsAppWidgetProvider method updateWidget.
/**
* Updates the widget when something changes, or when a button is pushed.
*
* @param context
*/
public static void updateWidget(Context context) {
RemoteViews views = buildUpdate(context);
// Update specific list of appWidgetIds if given, otherwise default to all
final AppWidgetManager gm = AppWidgetManager.getInstance(context);
gm.updateAppWidget(THIS_APPWIDGET, views);
checkObserver(context);
}
use of android.appwidget.AppWidgetManager in project android_frameworks_base by ResurrectionRemix.
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);
}
}
}
use of android.appwidget.AppWidgetManager in project android_packages_apps_Torch by CyanogenMod.
the class TorchWidgetProvider method updateState.
void updateState(Context context, int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Intent stateIntent = context.registerReceiver(null, new IntentFilter(TorchSwitch.TORCH_STATE_CHANGED));
boolean on = stateIntent != null && stateIntent.getIntExtra("state", 0) != 0;
views.setOnClickPendingIntent(R.id.btn, getLaunchPendingIntent(context, appWidgetId));
if (on) {
views.setImageViewResource(R.id.img_torch, WidgetState.ON.getImgDrawable());
views.setImageViewResource(R.id.ind_torch, WidgetState.ON.getIndDrawable());
} else {
views.setImageViewResource(R.id.img_torch, WidgetState.OFF.getImgDrawable());
views.setImageViewResource(R.id.ind_torch, WidgetState.OFF.getIndDrawable());
}
if (prefs.getBoolean("widget_strobe_" + appWidgetId, false)) {
views.setTextViewText(R.id.ind_text, context.getString(R.string.label_strobe));
} else if (prefs.getBoolean("widget_bright_" + appWidgetId, false)) {
views.setTextViewText(R.id.ind_text, context.getString(R.string.label_high));
}
final AppWidgetManager gm = AppWidgetManager.getInstance(context);
gm.updateAppWidget(appWidgetId, views);
}
use of android.appwidget.AppWidgetManager in project android_packages_apps_Torch by CyanogenMod.
the class TorchWidgetProvider method updateAllStates.
public void updateAllStates(Context context) {
final AppWidgetManager am = AppWidgetManager.getInstance(context);
int[] appWidgetIds = am.getAppWidgetIds(new ComponentName(context, this.getClass()));
for (int appWidgetId : appWidgetIds) this.updateState(context, appWidgetId);
}
use of android.appwidget.AppWidgetManager in project android_packages_apps_Torch by CyanogenMod.
the class WidgetOptionsActivity method addWidget.
void addWidget() {
Editor editor = mPreferences.edit();
editor.putBoolean("widget_strobe_" + mAppWidgetId, mPreferences.getBoolean("widget_strobe", false));
//TODO: Fix temporary patch
//had to do +1 to fix division by zero crash, only temporary fix:
editor.putInt("widget_strobe_freq_" + mAppWidgetId, 666 / (1 + mPreferences.getInt("widget_strobe_freq", 5)));
editor.putBoolean("widget_bright_" + mAppWidgetId, mPreferences.getBoolean("widget_bright", false));
editor.commit();
//Initialize widget view for first update
Context context = getApplicationContext();
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
Intent launchIntent = new Intent();
launchIntent.setClass(context, TorchWidgetProvider.class);
launchIntent.addCategory(Intent.CATEGORY_ALTERNATIVE);
launchIntent.setData(Uri.parse("custom:" + mAppWidgetId + "/0"));
PendingIntent pi = PendingIntent.getBroadcast(context, 0, /* no requestCode */
launchIntent, 0);
views.setOnClickPendingIntent(R.id.btn, pi);
if (mPreferences.getBoolean("widget_strobe_" + mAppWidgetId, false)) {
views.setTextViewText(R.id.ind_text, context.getString(R.string.label_strobe));
} else if (mPreferences.getBoolean("widget_bright_" + mAppWidgetId, false)) {
views.setTextViewText(R.id.ind_text, context.getString(R.string.label_high));
}
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
appWidgetManager.updateAppWidget(mAppWidgetId, views);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
//close the activity
finish();
}
Aggregations