List of usage examples for android.content Intent getLongExtra
public long getLongExtra(String name, long defaultValue)
From source file:mp.teardrop.LibraryActivity.java
/** * If the given intent has album data, set a limiter built from that * data.//from w ww. j ava 2 s. c o m */ private void loadAlbumIntent(Intent intent) //TODO: test the use case for this method { long albumId = intent.getLongExtra("albumId", -1); if (albumId != -1) { String[] fields = { intent.getStringExtra("artist"), intent.getStringExtra("album") }; String data = String.format("album_id=%d", albumId); //Limiter limiter = new Limiter(MediaUtils.TYPE_ALBUM, fields, data); Limiter limiter = new Limiter(-1, fields, data); mViewPager.setCurrentItem(mPagerAdapter.mTabOrder[mPagerAdapter.mCurrentPage]); mPagerAdapter.setLimiter(limiter); updateLimiterViews(); } }
From source file:mp.teardrop.LibraryActivity.java
/** * "Expand" the view represented by the given intent by setting the limiter * from the view and switching to the appropriate tab. * * @param intent An intent created with//from www . java 2 s . c o m * {@link LibraryAdapter#createData(View)}. */ private void expand(Intent intent) { int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID); long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID); String preGeneratedName = intent.getStringExtra("preGeneratedName"); mPagerAdapter.setLimiter(mPagerAdapter.mAdapters[type > 10 ? MediaUtils.TYPE_UNIFIED : type] .buildLimiter(type, id, preGeneratedName)); if (mPagerAdapter.getCurrentType() != MediaUtils.TYPE_DROPBOX) { //Dropbox limiter views are updated when the network // AsyncTask finishes updateLimiterViews(); } else { lockDropboxFileBrowser(); } }
From source file:com.almalence.opencam.SavingService.java
@Override public int onStartCommand(Intent intent, int flags, int startid) { long sessionID = intent.getLongExtra("sessionID", 0); if (sessionID == 0) { return START_NOT_STICKY; }//from www .ja v a 2s .c o m SavingTask task = new SavingTask(); task.sessionID = sessionID; task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); return START_NOT_STICKY; }
From source file:mp.teardrop.LibraryActivity.java
/** * Delete the media represented by the given intent and show a Toast * informing the user of this.//from w w w . ja v a2s. co m * * @param intent An intent created with * {@link LibraryAdapter#createData(View)}. */ private void delete(Intent intent) { int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID); long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID); String message = null; Resources res = getResources(); if (type == MediaUtils.TYPE_FILE) { String file = intent.getStringExtra("file"); boolean success = MediaUtils.deleteFile(new File(file)); if (!success) { message = res.getString(R.string.delete_file_failed, file); } //} else if (type == MediaUtils.TYPE_PLAYLIST) { /* } else if(false) { Playlist.deletePlaylist(getContentResolver(), id); */ } else { int count = PlaybackService.get(this).deleteMedia(type, id); message = res.getQuantityString(R.plurals.deleted, count, count); } if (message == null) { message = res.getString(R.string.deleted_item, intent.getStringExtra("title")); } Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); }
From source file:mp.teardrop.LibraryActivity.java
/** * Creates a context menu for an adapter row. * * @param menu The menu to create.//w w w . j a va2s . com * @param rowData Data for the adapter row. */ public void onCreateContextMenu(ContextMenu menu, Intent rowData) { if (rowData == null) { return; } if (rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID) == LibraryAdapter.HEADER_ID) { //menu.setHeaderTitle(getString(R.string.all_songs)); menu.add(0, MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData); menu.add(0, MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData); //menu.addSubMenu(0, MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem() // .setIntent(rowData); } else { int type = rowData.getIntExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_INVALID); //boolean isAllAdapter = type <= MediaUtils.TYPE_SONG; boolean isAllAdapter = false; //menu.setHeaderTitle(rowData.getStringExtra(LibraryAdapter.DATA_TITLE)); menu.add(0, MENU_PLAY, 0, R.string.play).setIntent(rowData); if (isAllAdapter) { menu.add(0, MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData); } menu.add(0, MENU_ENQUEUE, 0, R.string.enqueue).setIntent(rowData); if (isAllAdapter) { menu.add(0, MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData); } /* //if (type == MediaUtils.TYPE_PLAYLIST) { if(false) { menu.add(0, MENU_RENAME_PLAYLIST, 0, R.string.rename).setIntent(rowData); } else if (rowData.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false)) { menu.add(0, MENU_EXPAND, 0, R.string.expand).setIntent(rowData); } */ /* if (type == MediaUtils.TYPE_ALBUM || type == MediaUtils.TYPE_SONG) menu.add(0, MENU_MORE_FROM_ARTIST, 0, R.string.more_from_artist).setIntent (rowData); if (type == MediaUtils.TYPE_SONG) menu.add(0, MENU_MORE_FROM_ALBUM, 0, R.string.more_from_album).setIntent(rowData) ; */ /* menu.addSubMenu(0, MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem() .setIntent(rowData); menu.add(0, MENU_DELETE, 0, R.string.delete).setIntent(rowData); */ } }
From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_ADD_TAB: { if (resultCode == Activity.RESULT_OK) { final ContentValues values = new ContentValues(); values.put(Tabs.NAME, data.getStringExtra(EXTRA_NAME)); values.put(Tabs.ICON, data.getStringExtra(EXTRA_ICON)); values.put(Tabs.TYPE, data.getStringExtra(EXTRA_TYPE)); values.put(Tabs.ARGUMENTS, data.getStringExtra(EXTRA_ARGUMENTS)); values.put(Tabs.EXTRAS, data.getStringExtra(EXTRA_EXTRAS)); values.put(Tabs.POSITION, mAdapter.getCount()); mResolver.insert(Tabs.CONTENT_URI, values); SettingsActivity.setShouldNotifyChange(getActivity()); }// ww w . ja v a 2s . c om break; } case REQUEST_EDIT_TAB: { if (resultCode == Activity.RESULT_OK && data.hasExtra(EXTRA_ID)) { final ContentValues values = new ContentValues(); values.put(Tabs.NAME, data.getStringExtra(EXTRA_NAME)); values.put(Tabs.ICON, data.getStringExtra(EXTRA_ICON)); values.put(Tabs.EXTRAS, data.getStringExtra(EXTRA_EXTRAS)); final String where = Expression.equals(Tabs._ID, data.getLongExtra(EXTRA_ID, -1)).getSQL(); mResolver.update(Tabs.CONTENT_URI, values, where, null); SettingsActivity.setShouldNotifyChange(getActivity()); } break; } } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.finchuk.clock2.timers.TimerNotificationService.java
@Override protected void handleAction(@NonNull String action, Intent intent, int flags, int startId) { if (ACTION_ADD_ONE_MINUTE.equals(action)) { // While the notification's countdown would automatically be extended by one minute, // there is a noticeable delay before the minute gets added on. // Update the text immediately, because there's no harm in doing so. long id = getActionId(intent); final Timer orig = mTimers.get(id); // We have to add the minute to a copy Timer. If we had modified the original Timer, // then the controller would also add another minute to the same instance, and what // would happen after the DB update is the Timer instance with this ID ends up // being extended by 2 minutes. ///*from ww w . ja v a2 s . co m*/ // Why not just do something like: `t.endTime() + 60000`? Because extending timers that // are paused is a special case, and Timer.addOneMinute() already has the logic to handle // that. Timer copy = Timer.create(orig.hour(), orig.minute(), orig.second(), orig.group(), orig.label()); orig.copyMutableFieldsTo(copy); copy.addOneMinute(); setBase(id, copy.endTime()); updateNotification(id, true); mControllers.get(id).addOneMinute(); } else if (ACTION_CANCEL_NOTIFICATION.equals(action)) { long id = intent.getLongExtra(EXTRA_CANCEL_TIMER_ID, -1); cancelNotification(id); // TODO: SHould this be before cancelNotification()? I'm worried // that the thread's handler will have enough leeway to sneak // in a notification update before it is quit. If it did, // then at least cancelNotification should theoretically // remove it... releaseResources(id); } else { throw new IllegalArgumentException("TimerNotificationService cannot handle action " + action); } }
From source file:com.android.email.activity.MessageView.java
void initFromIntent() { Intent intent = getIntent(); mMessageId = intent.getLongExtra(EXTRA_MESSAGE_ID, -1); mMailboxId = intent.getLongExtra(EXTRA_MAILBOX_ID, -1); mDisableReplyAndForward = intent.getBooleanExtra(EXTRA_DISABLE_REPLY, false); if (mDisableReplyAndForward) { findViewById(R.id.reply).setEnabled(false); findViewById(R.id.reply_all).setEnabled(false); }/*from www . j av a 2s . co m*/ }
From source file:com.keithandthegirl.services.download.DownloadService.java
@TargetApi(8) @Override//from w ww.j a v a 2 s .c om protected void onHandleIntent(Intent requestIntent) { Log.v(TAG, "onHandleIntent : enter"); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mOriginalRequestIntent = requestIntent; Resource resourceType = Resource.valueOf(requestIntent.getStringExtra(RESOURCE_TYPE_EXTRA)); mCallback = requestIntent.getParcelableExtra(SERVICE_CALLBACK); Uri data = requestIntent.getData(); String urlPath = requestIntent.getStringExtra("urlpath"); String directory = requestIntent.getStringExtra("directory"); String filename = data.getLastPathSegment(); File root; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { switch (resourceType) { case MP3: root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS); break; case MP4: root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); break; case M4V: root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); break; case JPG: root = getExternalCacheDir(); filename = requestIntent.getLongExtra("id", -1) + ".jpg"; break; default: root = getExternalCacheDir(); break; } } else { root = Environment.getExternalStorageDirectory(); } File outputDir = new File(root, directory); outputDir.mkdirs(); File output = new File(outputDir, filename); if (output.exists()) { result = FragmentActivity.RESULT_OK; mCallback.send(result, getOriginalIntentBundle()); Log.v(TAG, "onHandleIntent : exit, image exists"); return; } switch (resourceType) { case MP3: Log.v(TAG, "onHandleIntent : saving mp3"); savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; case MP4: Log.v(TAG, "onHandleIntent : saving mp4"); savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; case M4V: Log.v(TAG, "onHandleIntent : saving m4v"); savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; case JPG: Log.v(TAG, "onHandleIntent : saving jpg"); saveBitmap(requestIntent.getStringExtra("filename"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; default: Log.w(TAG, "onHandleIntent : unknown extension '" + resourceType.getExtension() + "'"); mCallback.send(REQUEST_INVALID, getOriginalIntentBundle()); break; } Log.v(TAG, "onHandleIntent : exit"); }
From source file:com.todoroo.astrid.activity.TaskEditFragment.java
/** * Loads action item from the given intent * * @param intent/*from w w w.j ava 2s. c o m*/ */ @SuppressWarnings("nls") protected void loadItem(Intent intent) { if (model != null) { // came from bundle setIsNewTask(model.getValue(Task.TITLE).length() == 0); setupWaitingOnMe(); return; } long idParam = intent.getLongExtra(TOKEN_ID, -1L); if (idParam > -1L) { model = taskService.fetchById(idParam, Task.PROPERTIES); if (model != null && model.containsNonNullValue(Task.UUID)) uuid = model.getValue(Task.UUID); } // not found by id or was never passed an id if (model == null) { String valuesAsString = intent.getStringExtra(TOKEN_VALUES); ContentValues values = null; try { if (valuesAsString != null) values = AndroidUtilities.contentValuesFromSerializedString(valuesAsString); } catch (Exception e) { // oops, can't serialize } model = TaskService.createWithValues(values, null); getActivity().getIntent().putExtra(TOKEN_ID, model.getId()); } if (model.getValue(Task.TITLE).length() == 0) { StatisticsService.reportEvent(StatisticsConstants.CREATE_TASK); // set deletion date until task gets a title model.setValue(Task.DELETION_DATE, DateUtilities.now()); } else { StatisticsService.reportEvent(StatisticsConstants.EDIT_TASK); } setIsNewTask(model.getValue(Task.TITLE).length() == 0); setupWaitingOnMe(); if (model == null) { exceptionService.reportError("task-edit-no-task", new NullPointerException("model")); getActivity().onBackPressed(); return; } // clear notification Notifications.cancelNotifications(model.getId()); }