List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID
String EXTRA_APPWIDGET_ID
To view the source code for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.
Click Source Link
From source file:ch.fixme.status.Widget.java
public void onReceive(Context ctxt, Intent intent) { String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { // Remove widget alarm int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); PendingIntent pi = PendingIntent.getService(ctxt, widgetId, getIntent(ctxt, widgetId), 0); AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE); am.cancel(pi);/*from w w w . jav a2 s . c om*/ // remove preference SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt); Editor edit = prefs.edit(); edit.remove(Main.PREF_API_URL_WIDGET + widgetId); edit.remove(Main.PREF_INIT_WIDGET + widgetId); edit.remove(Main.PREF_LAST_WIDGET + widgetId); edit.remove(Main.PREF_FORCE_WIDGET + widgetId); edit.commit(); // Log.i(Main.TAG, "Remove widget alarm for id=" + widgetId); } else if (intent.hasExtra(WIDGET_IDS) && AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { int[] ids = intent.getExtras().getIntArray(WIDGET_IDS); onUpdate(ctxt, AppWidgetManager.getInstance(ctxt), ids); } else super.onReceive(ctxt, intent); }
From source file:io.github.hidroh.materialistic.appwidget.WidgetConfigActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);// w ww. j av a 2s . co m if (getIntent().getExtras() == null || (mAppWidgetId = getIntent().getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)) == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } supportRequestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_widget_config); if (savedInstanceState == null) { Bundle args = new Bundle(); args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); getSupportFragmentManager().beginTransaction() .replace(R.id.widget_preferences, Fragment.instantiate(this, WidgetConfigurationFragment.class.getName(), args), WidgetConfigurationFragment.class.getName()) .commit(); } //noinspection ConstantConditions findViewById(R.id.button_ok).setOnClickListener(v -> configure()); }
From source file:org.dmfs.tasks.homescreen.TaskListWidgetSettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_widget_configuration); Intent intent = getIntent();// ww w.ja v a2 s . c om if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { mAppWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); // make the result intent and set the result to canceled mResultIntent = new Intent(); mResultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_CANCELED, mResultIntent); } TaskListSelectionFragment fragment = new TaskListSelectionFragment(this); getSupportFragmentManager().beginTransaction().add(R.id.task_list_selection_container, fragment).commit(); }
From source file:com.granita.tasks.homescreen.TaskListWidgetSettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_widget_configuration); Intent intent = getIntent();/*from ww w.j av a2 s. c om*/ if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { mAppWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID); // make the result intent and set the result to canceled mResultIntent = new Intent(); mResultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_CANCELED, mResultIntent); } TaskListSelectionFragment fragment = new TaskListSelectionFragment(this); //fragment.setMListener(this); getSupportFragmentManager().beginTransaction().add(R.id.task_list_selection_container, fragment).commit(); }
From source file:at.wada811.dayscounter.view.activity.SettingsActivity.java
public static PendingIntent createPendingIntent(Context context, int appWidgetId) { Intent intent = new Intent(context, SettingsActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); return PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:ch.fixme.status.Widget_config.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.widget_config); mPrefs = PreferenceManager.getDefaultSharedPreferences(Widget_config.this); getDirTask = new GetDirTask(); getDirTask.execute(ParseGeneric.API_DIRECTORY); Intent intent = getIntent();//from www . ja v a2 s. co m Bundle extras = intent.getExtras(); mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); findViewById(R.id.choose_ok).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Editor edit = mPrefs.edit(); edit.putBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, ((CheckBox) findViewById(R.id.choose_transparency)).isChecked()); edit.commit(); setWidgetAlarm(); finish(); } }); ((CheckBox) findViewById(R.id.choose_transparency)) .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TRANSPARENCY, Prefs.DEFAULT_WIDGET_TRANSPARENCY)); ((CheckBox) findViewById(R.id.choose_text)) .setChecked(mPrefs.getBoolean(Prefs.KEY_WIDGET_TEXT, Prefs.DEFAULT_WIDGET_TEXT)); ((EditText) findViewById(R.id.choose_update)).addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String inter = s.toString(); if (!"".equals(inter) && !"0".equals(inter)) { Editor edit = mPrefs.edit(); edit.putString(Prefs.KEY_CHECK_INTERVAL, inter); edit.commit(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.tortel.deploytrack.WidgetPickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check for light theme Prefs.load(this); if (Prefs.useLightTheme()) { setTheme(R.style.Theme_DeployThemeLight); }/*from w w w . j a v a 2s . c om*/ setContentView(R.layout.activity_widget_config); Bundle extras = getIntent().getExtras(); if (extras != null) { mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } mResultIntent = new Intent(); //Set it to cancelled until explicitly told to save setResult(RESULT_CANCELED, mResultIntent); mWidgetManager = AppWidgetManager.getInstance(this); mAdapter = new DeploymentFragmentAdapter(this, getSupportFragmentManager()); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(mAdapter); SmartTabLayout indicator = (SmartTabLayout) findViewById(R.id.indicator); indicator.setViewPager(pager); indicator.setOnPageChangeListener(new PageChangeListener()); pager.setCurrentItem(mCurrentPosition); Log.d("WidgetPicker started with mWidgetId " + mWidgetId); }
From source file:com.dpcsoftware.mn.Widget1Config.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);//ww w .j av a 2 s. c o m wPrefs = getSharedPreferences(App.WIDGET_PREFS_FNAME, MODE_PRIVATE); Intent intent = getIntent(); Bundle extras = intent.getExtras(); wId = AppWidgetManager.INVALID_APPWIDGET_ID; if (extras != null) wId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); else finish(); setContentView(R.layout.widget1_config); resultIntent = new Intent(); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, wId); ActionBar abar = getSupportActionBar(); abar.setTitle("Configuraes do Widget"); SQLiteDatabase db = DatabaseHelper.quickDb(this, DatabaseHelper.MODE_READ); Cursor c = db.rawQuery("SELECT " + Db.Table3._ID + "," + Db.Table3.COLUMN_NGRUPO + " FROM " + Db.Table3.TABLE_NAME + " ORDER BY " + Db.Table3.COLUMN_NGRUPO + " ASC", null); SimpleCursorAdapter sAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, new String[] { Db.Table3.COLUMN_NGRUPO }, new int[] { android.R.id.text1 }, 0); sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp = ((Spinner) findViewById(R.id.spinner1)); sp.setAdapter(sAdapter); }
From source file:st.brothas.mtgoxwidget.MtGoxWidgetProvider.java
static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) { WidgetPreferences preferences = MtGoxPreferencesActivity.getWidgetPreferences(context, appWidgetId); if (preferences == null) { // Don't do anything unless the rate service has been chosen. // Show a "please remove this widget and add a new one" appWidgetManager.updateAppWidget(appWidgetId, new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me)); return;/*from w ww . j a v a2 s. c om*/ } RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); Intent clickIntent = new Intent(context, GraphPopupActivity.class); clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE // cached intent will be used for all widget instances! PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0); views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent); views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName()); MtGoxDataOpenHelper dbHelper = new MtGoxDataOpenHelper(context); MtGoxTickerData prevData = dbHelper.getLastTickerData(preferences); MtGoxTickerData newData; JSONObject latestQuoteJSON = getLatestQuoteJSON(preferences); if (latestQuoteJSON != null) { newData = preferences.getRateService().parseJSON(latestQuoteJSON); newData.setCurrencyConversion(preferences.getCurrencyConversion()); storeLastValueIfNotNull(dbHelper, newData); updateViews(views, prevData, newData, preferences); } else if (prevData != null) { newData = prevData; updateViews(views, prevData, newData, preferences); } else { updateViewsWithError(views, preferences); } appWidgetManager.updateAppWidget(appWidgetId, views); }
From source file:com.ravi.apps.android.newsbytes.widget.NewsWidgetProvider.java
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d(LOG_TAG, context.getString(R.string.log_on_update)); // Update each app widget instance with remote view and corresponding remote adapter. for (int appWidgetId : appWidgetIds) { // Create the remote views object for the widget instance. RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_news); // Create the intent that starts the service which will provide the views for this collection. Intent serviceIntent = new Intent(context, NewsWidgetRemoteViewsService.class); // Add the app widget id to the intent extras. serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME))); // Set the remote adapter onto the scores list view in the remote view. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { remoteView.setRemoteAdapter(R.id.widget_list_view, serviceIntent); } else {// w w w . ja va 2 s.c o m remoteView.setRemoteAdapter(appWidgetId, R.id.widget_list_view, serviceIntent); } // Create an intent to launch the main activity and set it on the remote view's title. Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); remoteView.setOnClickPendingIntent(R.id.widget, pendingIntent); // Create and add the list item click pending intent template. Intent listItemClickIntent = new Intent(context, MainActivity.class); listItemClickIntent.setAction(context.getString(R.string.action_item_clicked)) .setData(Uri.parse(listItemClickIntent.toUri(Intent.URI_INTENT_SCHEME))); // Set the pending intent template. PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(listItemClickIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteView.setPendingIntentTemplate(R.id.widget_list_view, clickPendingIntentTemplate); // Set an empty view in case of no data. remoteView.setEmptyView(R.id.widget_list_view, R.id.widget_empty); // Call app widget manager to update the app widget instance. appWidgetManager.updateAppWidget(appWidgetId, remoteView); } super.onUpdate(context, appWidgetManager, appWidgetIds); }