List of usage examples for android.content Intent getLongExtra
public long getLongExtra(String name, long defaultValue)
From source file:com.granita.tasks.notification.NotificationActionIntentService.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) @Override// www . ja va 2s.c o m protected void onHandleIntent(Intent intent) { mAuthority = getString(R.string.org_dmfs_tasks_authority); final String action = intent.getAction(); final Context context = this; if (intent.hasExtra(EXTRA_NOTIFICATION_ID)) { Uri taskUri = intent.getData(); int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.cancel(notificationId); if (ACTION_COMPLETE.equals(action)) { markCompleted(taskUri); } else if (intent.hasExtra(EXTRA_TASK_DUE) && intent.hasExtra(EXTRA_TIMEZONE)) { long due = intent.getLongExtra(EXTRA_TASK_DUE, -1); String tz = intent.getStringExtra(EXTRA_TIMEZONE); boolean allDay = intent.getBooleanExtra(EXTRA_ALLDAY, false); if (ACTION_DELAY_1H.equals(action)) { Time time = new Time(tz); time.set(due); time.allDay = false; time.hour++; time.normalize(true); delayTask(taskUri, time); } else if (ACTION_DELAY_1D.equals(action)) { if (tz == null) { tz = "UTC"; } Time time = new Time(tz); time.set(due); time.allDay = allDay; time.monthDay++; time.normalize(true); delayTask(taskUri, time); } } } else if (intent.hasExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION)) { /* * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent to add some extra data, it must unparcel the * NotificationAction object. It throws a ClassNotFoundException when unparcelling. To avoid this, do the marshalling ourselves. */ final NotificationAction notificationAction; final byte[] data = intent.getByteArrayExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION); if (data != null) { final Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); notificationAction = NotificationAction.CREATOR.createFromParcel(in, NotificationAction.class.getClassLoader()); } else { return; } if (NotificationActionUtils.ACTION_UNDO.equals(action)) { NotificationActionUtils.cancelUndoTimeout(context, notificationAction); NotificationActionUtils.cancelUndoNotification(context, notificationAction); resendNotification(notificationAction); } else if (ACTION_COMPLETE.equals(action)) { // All we need to do is switch to an Undo notification NotificationActionUtils.createUndoNotification(context, notificationAction); NotificationActionUtils.registerUndoTimeout(this, notificationAction); } else { if (NotificationActionUtils.ACTION_UNDO_TIMEOUT.equals(action) || NotificationActionUtils.ACTION_DESTRUCT.equals(action)) { // Process the action NotificationActionUtils.cancelUndoTimeout(this, notificationAction); NotificationActionUtils.processUndoNotification(this, notificationAction); processDesctructiveNotification(notificationAction); } } } }
From source file:org.mariotaku.twidere.activity.support.MediaViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); }/*from w w w.j a va 2s .co m*/ setContentView(R.layout.activity_media_viewer); mPagerAdapter = new MediaPagerAdapter(this); mViewPager.setAdapter(mPagerAdapter); mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.element_spacing_normal)); mViewPager.setOnPageChangeListener(this); final Intent intent = getIntent(); final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1); final ParcelableMedia[] media = Utils.newParcelableArray(intent.getParcelableArrayExtra(EXTRA_MEDIA), ParcelableMedia.CREATOR); final ParcelableMedia currentMedia = intent.getParcelableExtra(EXTRA_CURRENT_MEDIA); mPagerAdapter.setMedia(accountId, media); final int currentIndex = ArrayUtils.indexOf(media, currentMedia); if (currentIndex != -1) { mViewPager.setCurrentItem(currentIndex, false); } if (isMediaStatusEnabled() && intent.hasExtra(EXTRA_STATUS)) { mMediaStatusContainer.setVisibility(View.VISIBLE); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); final Fragment f = new ViewStatusDialogFragment(); final Bundle args = new Bundle(); args.putParcelable(EXTRA_STATUS, intent.getParcelableExtra(EXTRA_STATUS)); args.putBoolean(EXTRA_SHOW_MEDIA_PREVIEW, false); args.putBoolean(EXTRA_SHOW_EXTRA_TYPE, false); f.setArguments(args); ft.replace(R.id.media_status, f); ft.commit(); } else { mMediaStatusContainer.setVisibility(View.GONE); } updatePositionTitle(); }
From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java
/** * If the given intent has type data, set a limiter built from that * data./*from w ww. j a va 2 s .c o m*/ */ private void loadLimiterIntent(Intent intent) { Limiter limiter = null; int type = intent.getIntExtra("type", -1); long id = intent.getLongExtra("id", -1); String folder = intent.getStringExtra("folder"); if (type == MediaUtils.TYPE_FILE && folder != null) { limiter = FileSystemAdapter.buildLimiter(new File(folder)); } else if (type != -1 && id != -1) { MediaAdapter adapter = new MediaAdapter(this, type, null, null); adapter.commitQuery(adapter.query()); limiter = adapter.buildLimiter(id); } if (limiter != null) { int tab = mPagerAdapter.setLimiter(limiter); if (tab == -1 || tab == mViewPager.getCurrentItem()) updateLimiterViews(); else mViewPager.setCurrentItem(tab); } }
From source file:org.cowboycoders.cyclisimo.widgets.TrackWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); String action = intent.getAction(); if (context.getString(R.string.track_paused_broadcast_action).equals(action) || context.getString(R.string.track_resumed_broadcast_action).equals(action) || context.getString(R.string.track_started_broadcast_action).equals(action) || context.getString(R.string.track_stopped_broadcast_action).equals(action) || context.getString(R.string.track_update_broadcast_action).equals(action)) { long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager .getAppWidgetIds(new ComponentName(context, TrackWidgetProvider.class)); for (int appWidgetId : appWidgetIds) { RemoteViews remoteViews = getRemoteViews(context, trackId, HEIGHT_SIZE.get(appWidgetId, DEFAULT_SIZE)); appWidgetManager.updateAppWidget(appWidgetId, remoteViews); }//from ww w . j ava 2s . c o m } }
From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java
/** * Adds songs matching the data from the given intent to the song timeline. * * @param intent An intent created with//from www .j a v a2 s.c om * {@link LibraryAdapter#createData(View)}. * @param action One of LibraryActivity.ACTION_* */ private void pickSongs(Intent intent, final int action) { int effectiveAction = action; // mutable copy long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID); int type = mCurrentAdapter.getMediaType(); // special handling if we pick one song to be played that is already in queue boolean songPicked = (id >= 0 && type == MediaUtils.TYPE_SONG); // not invalid, not play all if (songPicked && effectiveAction == ACTION_PLAY) { int songPosInQueue = PlaybackService.get(this).getQueuePositionForSongId(id); if (songPosInQueue > -1) { // we picked for play one song that is already present in the queue, just jump to it PlaybackService.get(this).jumpToQueuePosition(songPosInQueue); Toast.makeText(this, R.string.jumping_to_song, Toast.LENGTH_SHORT).show(); return; } } boolean all = false; if (action == ACTION_PLAY_ALL || action == ACTION_ENQUEUE_ALL) { boolean notPlayAllAdapter = type > MediaUtils.TYPE_SONG || id == LibraryAdapter.HEADER_ID; if (effectiveAction == ACTION_ENQUEUE_ALL && notPlayAllAdapter) { effectiveAction = ACTION_ENQUEUE; } else if (effectiveAction == ACTION_PLAY_ALL && notPlayAllAdapter) { effectiveAction = ACTION_PLAY; } else { all = true; } } if (id == LibraryAdapter.HEADER_ID) all = true; // page header was clicked -> force all mode QueryTask query = buildQueryFromIntent(intent, false, (all ? mCurrentAdapter : null)); query.mode = modeForAction[effectiveAction]; PlaybackService.get(this).addSongs(query); if (mDefaultAction == ACTION_LAST_USED && mLastAction != action) { mLastAction = action; updateHeaders(); } }
From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); String action = intent.getAction(); if (context.getString(R.string.track_paused_broadcast_action).equals(action) || context.getString(R.string.track_resumed_broadcast_action).equals(action) || context.getString(R.string.track_started_broadcast_action).equals(action) || context.getString(R.string.track_stopped_broadcast_action).equals(action) || context.getString(R.string.track_update_broadcast_action).equals(action)) { long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L); updateAllAppWidgets(context, trackId); }// w w w .j a v a 2 s. co m }
From source file:ch.blinkenlights.android.vanilla.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 w ww .j av a2s . c o m*/ * {@link LibraryAdapter#createData(View)}. */ private void expand(Intent intent) { mBottomBarControls.showSearch(false); int type = intent.getIntExtra("type", MediaUtils.TYPE_INVALID); long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID); int tab = mPagerAdapter.setLimiter(mPagerAdapter.mAdapters[type].buildLimiter(id)); if (tab == -1 || tab == mViewPager.getCurrentItem()) updateLimiterViews(); else mViewPager.setCurrentItem(tab); }
From source file:com.xandy.calendar.EventInfoActivity.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); // Get the info needed for the fragment Intent intent = getIntent(); int attendeeResponse = 0; mEventId = -1;//from www.j a v a 2s .c o m boolean isDialog = false; ArrayList<ReminderEntry> reminders = null; if (icicle != null) { mEventId = icicle.getLong(EventInfoFragment.BUNDLE_KEY_EVENT_ID); mStartMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_START_MILLIS); mEndMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_END_MILLIS); attendeeResponse = icicle.getInt(EventInfoFragment.BUNDLE_KEY_ATTENDEE_RESPONSE); isDialog = icicle.getBoolean(EventInfoFragment.BUNDLE_KEY_IS_DIALOG); reminders = Utils.readRemindersFromBundle(icicle); } else if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { mStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0); mEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0); attendeeResponse = intent.getIntExtra(ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_NONE); Uri data = intent.getData(); if (data != null) { try { List<String> pathSegments = data.getPathSegments(); int size = pathSegments.size(); if (size > 2 && "EventTime".equals(pathSegments.get(2))) { // Support non-standard VIEW intent format: //dat = content://com.android.calendar/events/[id]/EventTime/[start]/[end] mEventId = Long.parseLong(pathSegments.get(1)); if (size > 4) { mStartMillis = Long.parseLong(pathSegments.get(3)); mEndMillis = Long.parseLong(pathSegments.get(4)); } } else { mEventId = Long.parseLong(data.getLastPathSegment()); } } catch (NumberFormatException e) { if (mEventId == -1) { // do nothing here , deal with it later } else if (mStartMillis == 0 || mEndMillis == 0) { // Parsing failed on the start or end time , make sure the times were not // pulled from the intent's extras and reset them. mStartMillis = 0; mEndMillis = 0; } } } } if (mEventId == -1) { Log.w(TAG, "No event id"); Toast.makeText(this, R.string.event_not_found, Toast.LENGTH_SHORT).show(); finish(); } // If we do not support showing full screen event info in this configuration, // close the activity and show the event in AllInOne. Resources res = getResources(); if (!res.getBoolean(R.bool.agenda_show_event_info_full_screen) && !res.getBoolean(R.bool.show_event_info_full_screen)) { CalendarController.getInstance(this).launchViewEvent(mEventId, mStartMillis, mEndMillis, attendeeResponse); finish(); return; } setContentView(R.layout.simple_frame_layout); // Get the fragment if exists mInfoFragment = (EventInfoFragment) getSupportFragmentManager().findFragmentById(R.id.main_frame); // Remove the application title ActionBar bar = getActionBar(); if (bar != null) { bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME); } // Create a new fragment if none exists if (mInfoFragment == null) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis, attendeeResponse, isDialog, (isDialog ? EventInfoFragment.DIALOG_WINDOW_STYLE : EventInfoFragment.FULL_WINDOW_STYLE), reminders); ft.replace(R.id.main_frame, mInfoFragment); ft.commit(); } }
From source file:com.android.calendar.EventInfoActivity.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); // Get the info needed for the fragment Intent intent = getIntent(); int attendeeResponse = 0; mEventId = -1;/*from w w w . j a v a 2 s . c o m*/ boolean isDialog = false; ArrayList<ReminderEntry> reminders = null; if (icicle != null) { mEventId = icicle.getLong(EventInfoFragment.BUNDLE_KEY_EVENT_ID); mStartMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_START_MILLIS); mEndMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_END_MILLIS); attendeeResponse = icicle.getInt(EventInfoFragment.BUNDLE_KEY_ATTENDEE_RESPONSE); isDialog = icicle.getBoolean(EventInfoFragment.BUNDLE_KEY_IS_DIALOG); reminders = Utils.readRemindersFromBundle(icicle); } else if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { mStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0); mEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0); attendeeResponse = intent.getIntExtra("attendeeStatus", Attendees.ATTENDEE_STATUS_NONE); Uri data = intent.getData(); if (data != null) { try { List<String> pathSegments = data.getPathSegments(); int size = pathSegments.size(); if (size > 2 && "EventTime".equals(pathSegments.get(2))) { // Support non-standard VIEW intent format: // dat = // content://com.android.calendar/events/[id]/EventTime/[start]/[end] mEventId = Long.parseLong(pathSegments.get(1)); if (size > 4) { mStartMillis = Long.parseLong(pathSegments.get(3)); mEndMillis = Long.parseLong(pathSegments.get(4)); } } else { mEventId = Long.parseLong(data.getLastPathSegment()); } } catch (NumberFormatException e) { if (mEventId == -1) { // do nothing here , deal with it later } else if (mStartMillis == 0 || mEndMillis == 0) { // Parsing failed on the start or end time , make sure // the times were not // pulled from the intent's extras and reset them. mStartMillis = 0; mEndMillis = 0; } } } } if (mEventId == -1) { Log.w(TAG, "No event id"); Toast.makeText(this, R.string.event_not_found, Toast.LENGTH_SHORT).show(); finish(); } // If we do not support showing full screen event info in this // configuration, // close the activity and show the event in AllInOne. Resources res = getResources(); if (!res.getBoolean(R.bool.agenda_show_event_info_full_screen) && !res.getBoolean(R.bool.show_event_info_full_screen)) { CalendarController.getInstance(this).launchViewEvent(mEventId, mStartMillis, mEndMillis, attendeeResponse); finish(); return; } setContentView(R.layout.simple_frame_layout); // Get the fragment if exists mInfoFragment = (EventInfoFragment) getSupportFragmentManager().findFragmentById(R.id.main_frame); // Remove the application title ActionBar bar = getActionBar(); if (bar != null) { bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP); } // Create a new fragment if none exists if (mInfoFragment == null) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis, attendeeResponse, isDialog, (isDialog ? EventInfoFragment.DIALOG_WINDOW_STYLE : EventInfoFragment.FULL_WINDOW_STYLE), reminders); ft.replace(R.id.main_frame, mInfoFragment); ft.commit(); } }
From source file:com.bluros.updater.UpdatesSettings.java
private void checkForDownloadCompleted(Intent intent) { if (intent == null) { return;//from w ww. j a v a 2s . c o m } long downloadId = intent.getLongExtra(EXTRA_FINISHED_DOWNLOAD_ID, -1); if (downloadId < 0) { return; } String fullPathName = intent.getStringExtra(EXTRA_FINISHED_DOWNLOAD_PATH); if (fullPathName == null) { return; } String fileName = new File(fullPathName).getName(); // If this is an incremental, find matching target and mark it as downloaded. String incrementalFor = intent.getStringExtra(EXTRA_FINISHED_DOWNLOAD_INCREMENTAL_FOR); if (incrementalFor != null) { UpdatePreference pref = (UpdatePreference) mUpdatesList.findPreference(incrementalFor); if (pref != null) { pref.setStyle(UpdatePreference.STYLE_DOWNLOADED); pref.getUpdateInfo().setFileName(fileName); onStartUpdate(pref); } } else { // Find the matching preference so we can retrieve the UpdateInfo UpdatePreference pref = (UpdatePreference) mUpdatesList.findPreference(fileName); if (pref != null) { pref.setStyle(UpdatePreference.STYLE_DOWNLOADED); onStartUpdate(pref); } } resetDownloadState(); }