List of usage examples for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID
int INVALID_APPWIDGET_ID
To view the source code for android.appwidget AppWidgetManager INVALID_APPWIDGET_ID.
Click Source Link
From source file:com.piusvelte.taplock.client.core.TapLockSettings.java
@Override protected void onResume() { super.onResume(); Intent intent = getIntent();/*from ww w. jav a 2s . com*/ if (mInWriteMode) { if (intent != null) { String action = intent.getAction(); if (mInWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) && intent.hasExtra(EXTRA_DEVICE_NAME)) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String name = intent.getStringExtra(EXTRA_DEVICE_NAME); if ((tag != null) && (name != null)) { // write the device and address String lang = "en"; // don't write the passphrase! byte[] textBytes = name.getBytes(); byte[] langBytes = null; int langLength = 0; try { langBytes = lang.getBytes("US-ASCII"); langLength = langBytes.length; } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } int textLength = textBytes.length; byte[] payload = new byte[1 + langLength + textLength]; // set status byte (see NDEF spec for actual bits) payload[0] = (byte) langLength; // copy langbytes and textbytes into payload if (langBytes != null) { System.arraycopy(langBytes, 0, payload, 1, langLength); } System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength); NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], payload); NdefMessage message = new NdefMessage( new NdefRecord[] { record, NdefRecord.createApplicationRecord(getPackageName()) }); // Get an instance of Ndef for the tag. Ndef ndef = Ndef.get(tag); if (ndef != null) { try { ndef.connect(); if (ndef.isWritable()) { ndef.writeNdefMessage(message); } ndef.close(); Toast.makeText(this, "tag written", Toast.LENGTH_LONG).show(); } catch (IOException e) { Log.e(TAG, e.toString()); } catch (FormatException e) { Log.e(TAG, e.toString()); } } else { NdefFormatable format = NdefFormatable.get(tag); if (format != null) { try { format.connect(); format.format(message); format.close(); Toast.makeText(getApplicationContext(), "tag written", Toast.LENGTH_LONG); } catch (IOException e) { Log.e(TAG, e.toString()); } catch (FormatException e) { Log.e(TAG, e.toString()); } } } mNfcAdapter.disableForegroundDispatch(this); } } } mInWriteMode = false; } else { SharedPreferences sp = getSharedPreferences(KEY_PREFS, MODE_PRIVATE); onSharedPreferenceChanged(sp, KEY_DEVICES); // check if configuring a widget if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { final String[] displayNames = TapLock.getDeviceNames(mDevices); final int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle("Select device for widget") .setItems(displayNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // set the successful widget result Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); setResult(RESULT_OK, resultValue); // broadcast the new widget to update JSONObject deviceJObj = mDevices.get(which); dialog.cancel(); TapLockSettings.this.finish(); try { sendBroadcast(TapLock .getPackageIntent(TapLockSettings.this, TapLockWidget.class) .setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) .putExtra(EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME))); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }).create(); mDialog.show(); } } } // start the service before binding so that the service stays around for faster future connections startService(TapLock.getPackageIntent(this, TapLockService.class)); bindService(TapLock.getPackageIntent(this, TapLockService.class), this, BIND_AUTO_CREATE); int serverVersion = sp.getInt(KEY_SERVER_VERSION, 0); if (mShowTapLockSettingsInfo && (mDevices.size() == 0)) { if (serverVersion < SERVER_VERSION) sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit(); mShowTapLockSettingsInfo = false; Intent i = TapLock.getPackageIntent(this, TapLockInfo.class); i.putExtra(EXTRA_INFO, getString(R.string.info_taplocksettings)); startActivity(i); } else if (serverVersion < SERVER_VERSION) { // TapLockServer has been updated sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit(); mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle(R.string.ttl_hasupdate) .setMessage(R.string.msg_hasupdate) .setNeutralButton(R.string.button_getserver, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mDialog = new AlertDialog.Builder(TapLockSettings.this) .setTitle(R.string.msg_pickinstaller) .setItems(R.array.installer_entries, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); final String installer_file = getResources() .getStringArray(R.array.installer_values)[which]; mDialog = new AlertDialog.Builder(TapLockSettings.this) .setTitle(R.string.msg_pickdownloader) .setItems(R.array.download_entries, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); String action = getResources() .getStringArray( R.array.download_values)[which]; if (ACTION_DOWNLOAD_SDCARD.equals(action) && copyFileToSDCard(installer_file)) Toast.makeText(TapLockSettings.this, "Done!", Toast.LENGTH_SHORT) .show(); else if (ACTION_DOWNLOAD_EMAIL .equals(action) && copyFileToSDCard( installer_file)) { Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND); emailIntent.setType( "application/java-archive"); emailIntent.putExtra(Intent.EXTRA_TEXT, getString( R.string.email_instructions)); emailIntent.putExtra( Intent.EXTRA_SUBJECT, getString(R.string.app_name)); emailIntent.putExtra( Intent.EXTRA_STREAM, Uri.parse("file://" + Environment .getExternalStorageDirectory() .getPath() + "/" + installer_file)); startActivity(Intent.createChooser( emailIntent, getString( R.string.button_getserver))); } } }) .create(); mDialog.show(); } }).create(); mDialog.show(); } }).create(); mDialog.show(); } } }
From source file:com.forrestguice.suntimeswidget.notes.SuntimesNotes3.java
@Override public void updateNote(Context context, Calendar now, int transition) { int choice = WidgetSettings.loadTimeNoteRisePref(context, AppWidgetManager.INVALID_APPWIDGET_ID).ordinal(); NoteData chosenNote = notesList.get(choice); NoteData updatedNote = new NoteData(chosenNote); updateNote(updatedNote, now);//from www. j a v a 2s.com if (currentNote == null || !currentNote.equals(updatedNote)) { //Log.d("updateNote", "changing the note to " + updatedNote.toString() + "[" + choice + "]"); setNote(updatedNote, NoteChangedListener.TRANSITION_NEXT); } }
From source file:com.forrestguice.suntimeswidget.notes.SuntimesNotes2.java
@Override public void updateNote(Context context, Calendar now, int transition) { SolarEvents noteMode;// w ww . j a v a 2 s. c o m Date time = now.getTime(); Date sunrise = dataset.dataActual.sunriseCalendarToday().getTime(); Date sunsetAstroTwilight = dataset.dataAstro.sunsetCalendarToday().getTime(); boolean afterSunriseToday = time.after(sunrise); if (afterSunriseToday && time.before(sunsetAstroTwilight)) { // a time after sunrise (but before night) int setChoice = WidgetSettings.loadTimeNoteSetPref(context, AppWidgetManager.INVALID_APPWIDGET_ID) .ordinal(); Date sunset = dataset.dataActual.sunsetCalendarToday().getTime(); if (time.before(sunset) && setChoice <= SolarEvents.SUNSET.ordinal()) { Date noon = dataset.dataNoon.sunriseCalendarToday().getTime(); if (time.before(noon) && setChoice <= 0) { // morning: note the time until noon noteMode = SolarEvents.NOON; } else { // afternoon: note the time until sunset noteMode = SolarEvents.SUNSET; } } else { Date civilTwilight = dataset.dataCivil.sunsetCalendarToday().getTime(); if (time.before(civilTwilight) && setChoice <= SolarEvents.EVENING_CIVIL.ordinal()) { // civil twilight: note time until end of civil twilight noteMode = SolarEvents.EVENING_CIVIL; } else { Date nauticalTwilight = dataset.dataNautical.sunsetCalendarToday().getTime(); if (time.before(nauticalTwilight) && setChoice <= SolarEvents.EVENING_NAUTICAL.ordinal()) { // nautical twilight: note time until end of nautical twilight noteMode = SolarEvents.EVENING_NAUTICAL; } else { // astronomical twilight: note time until night noteMode = SolarEvents.EVENING_ASTRONOMICAL; } } } } else { // a time before sunrise int riseChoice = WidgetSettings.loadTimeNoteRisePref(context, AppWidgetManager.INVALID_APPWIDGET_ID) .ordinal(); Date astroTwilight = afterSunriseToday ? dataset.dataAstro.sunriseCalendarOther().getTime() : dataset.dataAstro.sunriseCalendarToday().getTime(); if (time.before(astroTwilight) && riseChoice <= SolarEvents.MORNING_ASTRONOMICAL.ordinal()) { // night: note time until astro twilight today noteMode = SolarEvents.MORNING_ASTRONOMICAL; } else { Date nauticalTwilight = afterSunriseToday ? dataset.dataNautical.sunriseCalendarOther().getTime() : dataset.dataNautical.sunriseCalendarToday().getTime(); if (time.before(nauticalTwilight) && riseChoice <= SolarEvents.MORNING_NAUTICAL.ordinal()) { // astronomical twilight: note time until nautical twilight noteMode = SolarEvents.MORNING_NAUTICAL; } else { Date civilTwilight = afterSunriseToday ? dataset.dataCivil.sunriseCalendarOther().getTime() : dataset.dataCivil.sunriseCalendarToday().getTime(); if (time.before(civilTwilight) && riseChoice <= SolarEvents.MORNING_CIVIL.ordinal()) { // nautical twilight: note time until civil twilight noteMode = SolarEvents.MORNING_CIVIL; } else { if (riseChoice <= 3) { // civil twilight: note time until sunrise noteMode = SolarEvents.SUNRISE; } else { // civil twilight: note time until noon noteMode = SolarEvents.NOON; } } } } } NoteData note = notesMap.get(noteMode); updateNote(note, dataset.now()); if (currentNote == null || !currentNote.equals(note)) { setNote(note, NoteChangedListener.TRANSITION_NEXT); } }
From source file:com.piusvelte.taplock.client.core.TapLockService.java
private void buildWidget(int appWidgetId) { RemoteViews rv = new RemoteViews(getPackageName(), R.layout.widget); String deviceName = null;//from www . ja va 2s .c om for (JSONObject deviceJObj : mDevices) { if (deviceJObj.has(KEY_WIDGETS) && deviceJObj.has(KEY_NAME)) { JSONArray widgetsJArr = null; try { widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS); } catch (JSONException e) { e.printStackTrace(); } if (widgetsJArr != null) { for (int i = 0, l = widgetsJArr.length(); (i < l) && (deviceName == null); i++) { int widgetId; try { widgetId = widgetsJArr.getInt(i); } catch (JSONException e) { widgetId = AppWidgetManager.INVALID_APPWIDGET_ID; e.printStackTrace(); } if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) && (appWidgetId == widgetId)) { try { deviceName = deviceJObj.getString(KEY_NAME); } catch (JSONException e) { e.printStackTrace(); } break; } } } if (deviceName != null) break; } } if (deviceName == null) deviceName = "unknown"; rv.setTextViewText(R.id.device_name, deviceName); rv.setOnClickPendingIntent(R.id.widget_icon, PendingIntent.getActivity(this, 0, TapLock.getPackageIntent(this, TapLockToggle.class) .setData(Uri.parse(String.format(getString(R.string.device_uri), deviceName))), Intent.FLAG_ACTIVITY_NEW_TASK)); AppWidgetManager.getInstance(this).updateAppWidget(appWidgetId, rv); }
From source file:com.songcode.materialnotes.ui.NotesListActivity.java
private void batchDelete() { new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() { protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) { HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget(); if (!isSyncMode()) { // if not synced, delete notes directly if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter.getSelectedItemIds())) { } else { Log.e(TAG, "Delete notes error, should not happens"); }/*w ww. j av a2s .c o m*/ } else { // in sync mode, we'll move the deleted note into the trash // folder if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) { Log.e(TAG, "Move notes to trash folder error, should not happens"); } } return widgets; } @Override protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) { if (widgets != null) { for (AppWidgetAttribute widget : widgets) { if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) { updateWidget(widget.widgetId, widget.widgetType); } } } mModeCallBack.finishActionMode(); } }.execute(); }
From source file:com.heneryh.aquanotes.service.SyncService.java
/** * Poll the next widget update in the queue. */// w w w . j av a 2 s . c om private static int getNextUpdate() { synchronized (sLock) { if (sControllerIds.peek() == null) { return AppWidgetManager.INVALID_APPWIDGET_ID; } else { return sControllerIds.poll(); } } }
From source file:com.songcode.materialnotes.ui.NotesListActivity.java
private void deleteFolder(long folderId) { if (folderId == Notes.ID_ROOT_FOLDER) { Log.e(TAG, "Wrong folder id, should not happen " + folderId); return;//from w w w.j a va2s .c o m } HashSet<Long> ids = new HashSet<Long>(); ids.add(folderId); HashSet<AppWidgetAttribute> widgets = DataUtils.getFolderNoteWidget(mContentResolver, folderId); if (!isSyncMode()) { // if not synced, delete folder directly DataUtils.batchDeleteNotes(mContentResolver, ids); } else { // in sync mode, we'll move the deleted folder into the trash folder DataUtils.batchMoveToFolder(mContentResolver, ids, Notes.ID_TRASH_FOLER); } if (widgets != null) { for (AppWidgetAttribute widget : widgets) { if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID && widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) { updateWidget(widget.widgetId, widget.widgetType); } } } }
From source file:com.piusvelte.sonet.core.SonetService.java
protected void putValidatedUpdates(int[] appWidgetIds, int reload) { int[] awi = Sonet.getWidgets(getApplicationContext(), AppWidgetManager.getInstance(getApplicationContext())); if ((appWidgetIds != null) && (appWidgetIds.length > 0)) { // check for phantom widgets for (int appWidgetId : appWidgetIds) { // About.java will send an invalid appwidget id if ((appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) || Sonet.arrayContains(awi, appWidgetId)) { putNewUpdate(appWidgetId, reload); } else { // remove phantom widgets getContentResolver().delete(Widgets.getContentUri(SonetService.this), Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Widget_accounts.getContentUri(SonetService.this), Widget_accounts.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Statuses.getContentUri(SonetService.this), Statuses.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); }//from w w w. ja v a2 s.c om } } else if ((awi != null) && (awi.length > 0)) { for (int appWidgetId : awi) { putNewUpdate(appWidgetId, reload); } } }
From source file:com.shafiq.myfeedle.core.MyfeedleService.java
protected void putValidatedUpdates(int[] appWidgetIds, int reload) { int[] awi = Myfeedle.getWidgets(getApplicationContext(), AppWidgetManager.getInstance(getApplicationContext())); if ((appWidgetIds != null) && (appWidgetIds.length > 0)) { // check for phantom widgets for (int appWidgetId : appWidgetIds) { // About.java will send an invalid appwidget id if ((appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) || Myfeedle.arrayContains(awi, appWidgetId)) { putNewUpdate(appWidgetId, reload); } else { // remove phantom widgets getContentResolver().delete(Widgets.getContentUri(MyfeedleService.this), Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Widget_accounts.getContentUri(MyfeedleService.this), Widget_accounts.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Statuses.getContentUri(MyfeedleService.this), Statuses.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); }//from w w w .j ava 2 s .co m } } else if ((awi != null) && (awi.length > 0)) { for (int appWidgetId : awi) { putNewUpdate(appWidgetId, reload); } } }
From source file:com.piusvelte.sonet.core.SonetService.java
private Cursor getSettingsCursor(int appWidgetId) { Cursor settings = getContentResolver().query(Widgets_settings.getContentUri(this), new String[] { Widgets.HASBUTTONS, Widgets.BUTTONS_COLOR, Widgets.BUTTONS_BG_COLOR, Widgets.BUTTONS_TEXTSIZE, Widgets.SCROLLABLE, Widgets.DISPLAY_PROFILE, Widgets.MARGIN, Widgets.INTERVAL, Widgets.BACKGROUND_UPDATE }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(appWidgetId), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (!settings.moveToFirst()) { settings.close();//from w ww . j ava 2 s .co m settings = getContentResolver().query(Widgets_settings.getContentUri(this), new String[] { Widgets.HASBUTTONS, Widgets.BUTTONS_COLOR, Widgets.BUTTONS_BG_COLOR, Widgets.BUTTONS_TEXTSIZE, Widgets.SCROLLABLE, Widgets.DISPLAY_PROFILE, Widgets.MARGIN, Widgets.INTERVAL, Widgets.BACKGROUND_UPDATE }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (!settings.moveToFirst()) initAccountSettings(this, AppWidgetManager.INVALID_APPWIDGET_ID, Sonet.INVALID_ACCOUNT_ID); // don't insert a duplicate row if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) initAccountSettings(this, appWidgetId, Sonet.INVALID_ACCOUNT_ID); } return settings; }