Search in sources :

Example 26 with AppWidgetManager

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);
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager)

Example 27 with AppWidgetManager

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);
        }
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 28 with AppWidgetManager

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);
}
Also used : IntentFilter(android.content.IntentFilter) RemoteViews(android.widget.RemoteViews) SharedPreferences(android.content.SharedPreferences) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 29 with AppWidgetManager

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);
}
Also used : AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 30 with AppWidgetManager

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();
}
Also used : Context(android.content.Context) RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Editor(android.content.SharedPreferences.Editor)

Aggregations

AppWidgetManager (android.appwidget.AppWidgetManager)51 ComponentName (android.content.ComponentName)32 RemoteViews (android.widget.RemoteViews)25 Intent (android.content.Intent)20 PendingIntent (android.app.PendingIntent)12 Bundle (android.os.Bundle)12 SharedPreferences (android.content.SharedPreferences)7 Context (android.content.Context)5 View (android.view.View)4 Uri (android.net.Uri)3 AppWidgetProvider (android.appwidget.AppWidgetProvider)2 PackageManager (android.content.pm.PackageManager)2 Cursor (android.database.Cursor)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 Account (android.accounts.Account)1 Service (android.app.Service)1 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)1 ContentResolver (android.content.ContentResolver)1