List of usage examples for android.content Intent hasExtra
public boolean hasExtra(String name)
From source file:com.android.documentsui.DocumentsActivity.java
private void buildDefaultState() { mState = new State(); final Intent intent = getIntent(); final String action = intent.getAction(); if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) { mState.action = ACTION_OPEN;/*from w w w. j a v a 2 s . c o m*/ } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) { mState.action = ACTION_CREATE; } else if (Intent.ACTION_GET_CONTENT.equals(action)) { mState.action = ACTION_GET_CONTENT; } else if (DocumentsContract.ACTION_MANAGE_ROOT.equals(action)) { mState.action = ACTION_MANAGE; } if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) { mState.allowMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); } if (mState.action == ACTION_MANAGE) { mState.acceptMimes = new String[] { "*/*" }; mState.allowMultiple = true; } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) { mState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES); } else { mState.acceptMimes = new String[] { intent.getType() }; } mState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false); mState.forceAdvanced = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false); mState.showAdvanced = mState.forceAdvanced | SettingsActivity.getDisplayAdvancedDevices(this); }
From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java
@Override protected void onResume() { super.onResume(); // CameraManager must be initialized here, not in onCreate(). This is // necessary because we don't // want to open the camera driver and measure the screen size if we're // going to show the help on // first launch. That led to bugs where the scanning rectangle was the // wrong size and partially // off screen. cameraManager = new CameraManager(getApplication()); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); viewfinderView.setCameraManager(cameraManager); resultView = findViewById(R.id.result_view); statusView = (TextView) findViewById(R.id.status_view); handler = null;/*from w w w . j a v a2s .c om*/ lastResult = null; resetStatusView(); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); SurfaceHolder surfaceHolder = surfaceView.getHolder(); if (hasSurface) { // The activity was paused but not stopped, so the surface still // exists. Therefore // surfaceCreated() won't be called, so init the camera here. initCamera(surfaceHolder); } else { // Install the callback and wait for surfaceCreated() to init the // camera. surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } beepManager.updatePrefs(); inactivityTimer.onResume(); Intent intent = getIntent(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true) && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true)); source = IntentSource.NONE; decodeFormats = null; characterSet = null; if (intent != null) { String action = intent.getAction(); String dataString = intent.getDataString(); if (Intents.Scan.ACTION.equals(action)) { // Scan the formats the intent requested, and return the result // to the calling activity. source = IntentSource.NATIVE_APP_INTENT; decodeFormats = DecodeFormatManager.parseDecodeFormats(intent); if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) { int width = intent.getIntExtra(Intents.Scan.WIDTH, 0); int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0); if (width > 0 && height > 0) { cameraManager.setManualFramingRect(width, height); } } String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE); if (customPromptMessage != null) { statusView.setText(customPromptMessage); } } else if (dataString != null && dataString.contains(PRODUCT_SEARCH_URL_PREFIX) && dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) { // Scan only products and send the result to mobile Product // Search. source = IntentSource.PRODUCT_SEARCH_LINK; sourceUrl = dataString; decodeFormats = DecodeFormatManager.PRODUCT_FORMATS; } else if (isZXingURL(dataString)) { // Scan formats requested in query string (all formats if none // specified). // If a return URL is specified, send the results there. // Otherwise, handle it ourselves. source = IntentSource.ZXING_LINK; sourceUrl = dataString; Uri inputUri = Uri.parse(sourceUrl); returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM); returnRaw = inputUri.getQueryParameter(RAW_PARAM) != null; decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri); } characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET); } }
From source file:com.kafilicious.popularmovies.ui.activity.DetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_details_main); final Toolbar toolbar = (Toolbar) findViewById(R.id.myToolbar); setSupportActionBar(toolbar);/* w w w. ja va2 s .c om*/ if (getSupportActionBar() != null) { getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } final Intent intent = this.getIntent(); titleTextView = (TextView) findViewById(R.id.title_details); releaseDateTextView = (TextView) findViewById(R.id.year_details); ratingTextView = (TextView) findViewById(R.id.rating_score_detail); voteCountTextView = (TextView) findViewById(R.id.num_of_votes_detail); voteAverageTextView = (TextView) findViewById(R.id.vote_average_details); videoErrorTV = (TextView) findViewById(R.id.video_error_tv); reviewErrorTV = (TextView) findViewById(R.id.review_error_tv); ratingBar = (RatingBar) findViewById(R.id.rating_bar_detail); backDropImageView = (ImageView) findViewById(R.id.iv_backdrop); favoriteButton = (Button) findViewById(R.id.favorite); int orientation = this.getResources().getConfiguration().orientation; scrollView = (NestedScrollView) findViewById(R.id.nested_scrollView); if (scrollView != null) { scrollView.setFillViewport(true); } tabLayout = (TabLayout) findViewById(R.id.movie_details_tabLayout); viewPager = (ViewPager) findViewById(R.id.movie_details_container); dbHelper = new MovieDbHelper(this); sectionPagerAdapter = new SectionPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(sectionPagerAdapter); tabLayout.setupWithViewPager(viewPager); if (movieIsStored()) { favoriteButton.setText(R.string.button_text_marked); } else { favoriteButton.setText(R.string.button_text); } if (intent != null && intent.hasExtra(MOVIE_TITLE)) { movieTitle = intent.getStringExtra(MOVIE_TITLE); id = Integer.parseInt(intent.getStringExtra(MOVIE_ID)); final String movieRelease = intent.getStringExtra(MOVIE_RELEASE); final String movieVoteCount = intent.getStringExtra(MOVIE_VOTE_COUNT); movieOverview = intent.getStringExtra(MOVIE_OVERVIEW); final String movieVoteAverage = intent.getStringExtra(MOVIE_VOTE_AVERAGE); final String moviePoster = intent.getStringExtra(MOVIE_POSTER); final String movieBackdrop = intent.getStringExtra(MOVIE_BACK_DROP); getSupportActionBar().setTitle(intent.getStringExtra(MOVIE_TITLE) + " (" + intent.getStringExtra(MOVIE_RELEASE).substring(0, 4) + ")"); selectionArgs = new String[] { String.valueOf(id) }; titleTextView.setText(movieTitle); releaseDateTextView.setText(movieRelease.substring(0, 4)); voteAverageTextView.setText(movieVoteAverage + "/10"); voteCountTextView.setText(movieVoteCount); String url2 = NetworkUtils.buildMovieUrl(movieBackdrop, 1).toString(); Picasso.with(this).load(url2).into(backDropImageView); double voteAverage = Double.parseDouble(movieVoteAverage); voteAverage = (voteAverage / 10) * 5; String rating = String.format("%.1f", voteAverage); voteAverage = Double.parseDouble(rating); ratingTextView.setText(rating); ratingBar.setRating((float) voteAverage); ratingBar.setStepSize((float) 0.1); text = intent.getStringExtra(MOVIE_TITLE) + "(" + intent.getStringExtra(MOVIE_RELEASE).substring(0, 4) + ")"; if (orientation == Configuration.ORIENTATION_PORTRAIT) { favoriteButton.setVisibility(View.GONE); fab = (FloatingActionButton) findViewById(R.id.fab); collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbar); layoutDetail = (LinearLayout) findViewById(R.id.layout_detail_card); layoutDetail.setVisibility(View.GONE); posterDetailCard = (ImageView) findViewById(R.id.poster_detail_card); titleDetailCard = (TextView) findViewById(R.id.movie_title); releaseDetailCard = (TextView) findViewById(R.id.movie_release_date); ratingDetailCard = (TextView) findViewById(R.id.rating); ratingScoreDetailCard = (TextView) findViewById(R.id.rating_score_details); voteCountDetailCard = (TextView) findViewById(R.id.num_of_votes_details); ratingBarPortrait = (RatingBar) findViewById(R.id.rating_bar_details); myAppBarLayout = (AppBarLayout) findViewById(R.id.myAppbar); if (movieIsStored()) { fab.setImageResource(R.drawable.ic_star_black_24dp); } else { fab.setImageResource(R.drawable.ic_star_border_black_24dp); } myAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int i) { if (i == -collapsingToolbarLayout.getHeight() + toolbar.getHeight()) { collapsingToolbarLayout .setCollapsedTitleTextColor(getResources().getColor(android.R.color.white)); layoutDetail.setVisibility(View.VISIBLE); } else { layoutDetail.setVisibility(View.GONE); collapsingToolbarLayout .setExpandedTitleColor(getResources().getColor(R.color.transparent)); } } }); titleDetailCard.setText(movieTitle); releaseDetailCard.setText(movieRelease); ratingDetailCard.setText(movieVoteAverage + "/10"); voteCountDetailCard.setText(movieVoteCount); ratingScoreDetailCard.setText(rating); ratingBarPortrait.setRating((float) voteAverage); ratingBarPortrait.setStepSize((float) 0.1); ratingBarPortrait.setNumStars(5); String url = NetworkUtils.buildMovieUrl(moviePoster, 0).toString(); Picasso.with(this).load(url).into(posterDetailCard); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (movieIsStored()) { fab.setImageResource(R.drawable.ic_star_border_black_24dp); int deletedMovie = getContentResolver().delete(MovieContract.MovieEntry.CONTENT_URI, selection, selectionArgs); Log.i("Movie deleted", String.valueOf(deletedMovie)); Toast.makeText(DetailActivity.this, movieTitle + " has being removed from My Favorites", Toast.LENGTH_LONG).show(); } else { fab.setImageResource(R.drawable.ic_star_black_24dp); ContentValues values = new ContentValues(); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_TITLE, movieTitle); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_ID, String.valueOf(id)); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_OVERVIEW, movieOverview); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_VOTE_COUNT, movieVoteCount); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_VOTE_AVERAGE, movieVoteAverage); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_BACKDROP_PATH, movieBackdrop); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_POSTR_PATH, moviePoster); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_RELEASE_DATE, movieRelease); Uri updatedMovie = getContentResolver().insert(MovieContract.MovieEntry.CONTENT_URI, values); Log.i("Movie Added ", String.valueOf(updatedMovie) + " | Title: " + movieTitle); Toast.makeText(DetailActivity.this, movieTitle + " has being added to My Favorites", Toast.LENGTH_LONG).show(); } } }); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { favoriteButton.setVisibility(View.VISIBLE); favoriteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (movieIsStored()) { favoriteButton.setText(R.string.button_text); int deletedMovie = getContentResolver().delete(MovieContract.MovieEntry.CONTENT_URI, selection, selectionArgs); Log.i("Movie deleted", String.valueOf(deletedMovie)); Toast.makeText(DetailActivity.this, movieTitle + " has being removed from My Favorites", Toast.LENGTH_LONG).show(); } else { favoriteButton.setText(R.string.button_text_marked); ContentValues values = new ContentValues(); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_TITLE, movieTitle); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_ID, String.valueOf(id)); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_OVERVIEW, movieOverview); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_VOTE_COUNT, movieVoteCount); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_VOTE_AVERAGE, movieVoteAverage); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_BACKDROP_PATH, movieBackdrop); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_POSTR_PATH, moviePoster); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_RELEASE_DATE, movieRelease); Uri updatedMovie = getContentResolver().insert(MovieContract.MovieEntry.CONTENT_URI, values); Log.i("Movie Added", String.valueOf(updatedMovie) + " | Title: " + movieTitle); Toast.makeText(DetailActivity.this, movieTitle + " has being added to My Favorites", Toast.LENGTH_LONG).show(); } } }); } Log.i("Results", "ID set successful"); } }
From source file:com.dvn.vindecoder.ui.seller.AddDriverActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == GALLERY_REQUEST) { if (resultCode == RESULT_OK) { if (data != null) { uri = data.getData();// w ww. j a v a2s . c o m BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; try { // BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); options.inSampleSize = calculateInSampleSize(options, 100, 100); options.inJustDecodeBounds = false; Bitmap image = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); if (check_img_status == 1) { img_view_drivingLicense.setImageBitmap(image); } else if (check_img_status == 2) { insurance_plate_img_view.setImageBitmap(image); } else if (check_img_status == 3) { passport_imageView.setImageBitmap(image); } } catch (Exception e) { e.printStackTrace(); } } else { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } else if (resultCode == RESULT_CANCELED) { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } else if (requestCode == CAMERA_REQUEST) { if (resultCode == RESULT_OK) { if (data.hasExtra("data")) { Bitmap bitmap = (Bitmap) data.getExtras().get("data"); uri = getImageUri(AddDriverActivity.this, bitmap); File finalFile = new File(getRealPathFromUri(uri)); //img_view_drivingLicense.setImageBitmap(bitmap); if (check_img_status == 1) { img_view_drivingLicense.setImageBitmap(bitmap); } else if (check_img_status == 2) { insurance_plate_img_view.setImageBitmap(bitmap); } else if (check_img_status == 3) { passport_imageView.setImageBitmap(bitmap); } } else if (data.getExtras() == null) { Toast.makeText(getApplicationContext(), "No extras to retrieve!", Toast.LENGTH_SHORT).show(); BitmapDrawable thumbnail = new BitmapDrawable(getResources(), data.getData().getPath()); //img_view_drivingLicense.setImageDrawable(thumbnail); if (check_img_status == 1) { img_view_drivingLicense.setImageDrawable(thumbnail); } else if (check_img_status == 2) { insurance_plate_img_view.setImageDrawable(thumbnail); } else if (check_img_status == 3) { passport_imageView.setImageDrawable(thumbnail); } } } else if (resultCode == RESULT_CANCELED) { Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); } } }
From source file:com.findcab.activity.LocationOverlay.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); // System.out.println("requestCode------------------------------->"+requestCode); switch (requestCode) { case SEND://from w w w . j a va 2 s. co m if (data != null) { TripsInfo tempInfo = new TripsInfo(); if (data.hasExtra("appointent")) { tempInfo.setAppointment(data.getStringExtra("appointent")); } if (data.hasExtra("create_at")) { tempInfo.setCreated_at(data.getStringExtra("create_at")); } if (data.hasExtra("end")) { tempInfo.setEnd(data.getStringExtra("end")); } if (data.hasExtra("end_lat")) { tempInfo.setEnd_lat(data.getStringExtra("end_lat")); } if (data.hasExtra("end_lng")) { tempInfo.setEnd_lng(data.getStringExtra("end_lng")); end = data.getStringExtra("end"); } if (data.hasExtra("id")) { tempInfo.setId(data.getIntExtra("id", 0)); } if (data.hasExtra("passenger_id")) { tempInfo.setPassenger_id(data.getIntExtra("passenger_id", 0)); } if (data.hasExtra("start")) { tempInfo.setStart(data.getStringExtra("start")); start = data.getStringExtra("start"); } if (data.hasExtra("start_lat")) { tempInfo.setStart_lat(data.getStringExtra("start_lat")); } if (data.hasExtra("start_lng")) { tempInfo.setStart_lng(data.getStringExtra("start_lng")); } //??? getConversations(); callingHandler.sendEmptyMessage(Constant.SUCCESS); } break; case CANCLE_CALLING: // ?? sendTrips(); break; case TIMEOUT: waitingTime = WAITING; // isWaiting = true; // isStartCount = true; getDrivers(); sendTrips(); break; case CANCLE_ANSWER: String id = String.valueOf(lastConversation.getId()); changeConversationsStatus("1", id); break; default: break; } }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
private void buildDefaultState() { mState = new State(); final Intent intent = virtualIntent; final String action = intent.getAction(); if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) { mState.action = ACTION_OPEN;//from w ww. j a v a 2 s.co m } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) { mState.action = ACTION_CREATE; } else if (Intent.ACTION_GET_CONTENT.equals(action)) { mState.action = ACTION_GET_CONTENT; } else if (DocumentsContract.ACTION_MANAGE_ROOT.equals(action)) { mState.action = ACTION_MANAGE; } if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) { mState.allowMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); } if (mState.action == ACTION_MANAGE) { mState.acceptMimes = new String[] { "*/*" }; mState.allowMultiple = true; } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) { mState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES); } else { mState.acceptMimes = new String[] { intent.getType() }; } mState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false); mState.forceAdvanced = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false); mState.showAdvanced = mState.forceAdvanced | SettingsActivity.getDisplayAdvancedDevices(this); }
From source file:com.frostwire.android.gui.activities.MainActivity.java
@Override protected void onNewIntent(Intent intent) { if (intent == null || isShutdown(intent)) { return;// w ww . j av a2 s . c o m } if (isGoHome(intent)) { finish(); return; } String action = intent.getAction(); if (action != null) { switch (action) { case Constants.ACTION_SHOW_TRANSFERS: intent.setAction(null); controller.showTransfers(TransferStatus.ALL); break; case Intent.ACTION_VIEW: openTorrentUrl(intent); break; case Constants.ACTION_START_TRANSFER_FROM_PREVIEW: if (Ref.alive(NewTransferDialog.srRef)) { SearchFragment.startDownload(this, NewTransferDialog.srRef.get(), getString(R.string.download_added_to_queue)); UXStats.instance().log(UXAction.DOWNLOAD_CLOUD_FILE_FROM_PREVIEW); } break; case Constants.ACTION_REQUEST_SHUTDOWN: UXStats.instance().log(UXAction.MISC_NOTIFICATION_EXIT); showShutdownDialog(); break; } } if (intent.hasExtra(Constants.EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION)) { async(this, MainActivity::onDownloadCompleteNotification, intent); } if (intent.hasExtra(Constants.EXTRA_FINISH_MAIN_ACTIVITY)) { finish(); } }
From source file:com.google.appinventor.components.runtime.Form.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.i(LOG_TAG, "Form " + formName + " got onActivityResult, requestCode = " + requestCode + ", resultCode = " + resultCode); if (requestCode == SWITCH_FORM_REQUEST_CODE) { // Assume this is a multiple screen application, and a secondary // screen has closed. Process the result as a JSON-encoded string. // This can also happen if the user presses the back button, in which case // there's no data. String resultString;/* w w w . j ava2 s. co m*/ if (data != null && data.hasExtra(RESULT_NAME)) { resultString = data.getStringExtra(RESULT_NAME); } else { resultString = ""; } Object decodedResult = decodeJSONStringForForm(resultString, "other screen closed"); // nextFormName was set when this screen opened the secondary screen OtherScreenClosed(nextFormName, decodedResult); } else { // Another component (such as a ListPicker, ActivityStarter, etc) is expecting this result. ActivityResultListener component = activityResultMap.get(requestCode); if (component != null) { component.resultReturned(requestCode, resultCode, data); } } }
From source file:com.android.deskclock.timer.TimerReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { if (Timers.LOGGING) { Log.v(TAG, "Received intent " + intent.toString()); }//www. j a v a 2s . c o m String actionType = intent.getAction(); // This action does not need the timers data if (Timers.NOTIF_IN_USE_CANCEL.equals(actionType)) { cancelInUseNotification(context); return; } // Get the updated timers data. if (mTimers == null) { mTimers = new ArrayList<>(); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); TimerObj.getTimersFromSharedPrefs(prefs, mTimers); if (AlarmService.PRE_SHUTDOWN_ACTION.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status TimerObj timerRing = Timers.findExpiredTimer(mTimers); if (timerRing != null) { timerRing.mState = TimerObj.STATE_STOPPED; stopRingtoneIfNoTimesup(context); } return; } // These actions do not provide a timer ID, but do use the timers data if (Timers.NOTIF_IN_USE_SHOW.equals(actionType)) { showInUseNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_SHOW.equals(actionType)) { showTimesUpNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_CANCEL.equals(actionType)) { cancelTimesUpNotification(context); return; } // Remaining actions provide a timer Id if (!intent.hasExtra(Timers.TIMER_INTENT_EXTRA)) { // No data to work with, do nothing Log.e(TAG, "got intent without Timer data"); return; } // Get the timer out of the Intent int timerId = intent.getIntExtra(Timers.TIMER_INTENT_EXTRA, -1); if (timerId == -1) { Log.d(TAG, "OnReceive:intent without Timer data for " + actionType); } TimerObj t = Timers.findTimer(mTimers, timerId); if (Timers.TIMES_UP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, " timer not found in list - do nothing"); return; } t.setState(TimerObj.STATE_TIMESUP); t.writeToSharedPref(prefs); Events.sendEvent(R.string.category_timer, R.string.action_fire, 0); /// M: We acquire the lock here because in some rare scenario, the wake lock is release /// by alarm before it could be acquired by Timer activity causing state to be suspended AlarmAlertWakeLock.acquireScreenCpuWakeLock(context); // Play ringtone by using TimerRingService service with a default alarm. Log.d(TAG, "playing ringtone"); Intent si = new Intent(); si.setClass(context, TimerRingService.class); context.startService(si); // Update the in-use notification if (getNextRunningTimer(mTimers, false, Utils.getTimeNow()) == null) { // Found no running timers. cancelInUseNotification(context); } else { showInUseNotification(context); } /** * M: To show time up notification to avoid the case: pausing the * current activity(eg: touch home key) when time is up, it cause * the TimerAlertFullScreen can not be started, and this cause no * notification in status bar but the timer has sound. @{ */ Utils.showTimesUpNotifications(context); /** @} */ // Start the TimerAlertFullScreen activity. Intent timersAlert = new Intent(context, TimerAlertFullScreen.class); timersAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); context.startActivity(timersAlert); } else if (Timers.RESET_TIMER.equals(actionType) || Timers.DELETE_TIMER.equals(actionType) || Timers.TIMER_DONE.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status stopRingtoneIfNoTimesup(context); if (t != null) { cancelTimesUpNotification(context, t); } } else if (Timers.NOTIF_TIMES_UP_STOP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to stop not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to stop but timer not in times-up state - do nothing"); return; } // Update timer state t.setState(t.getDeleteAfterUse() ? TimerObj.STATE_DELETED : TimerObj.STATE_RESTART); t.mTimeLeft = t.mOriginalLength = t.mSetupLength; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply(); cancelTimesUpNotification(context, t); // Done with timer - delete from data base if (t.getDeleteAfterUse()) { t.deleteFromSharedPref(prefs); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.NOTIF_TIMES_UP_PLUS_ONE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to +1m not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to +1m but timer not in times up state - do nothing"); return; } // Restarting the timer with 1 minute left. t.setState(TimerObj.STATE_RUNNING); t.mStartTime = Utils.getTimeNow(); t.mTimeLeft = t.mOriginalLength = TimerObj.MINUTE_IN_MILLIS; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply(); cancelTimesUpNotification(context, t); // If the app is not open, refresh the in-use notification if (!prefs.getBoolean(Timers.NOTIF_APP_OPEN, false)) { showInUseNotification(context); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.TIMER_UPDATE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, " timer to update not found in list - do nothing"); return; } // Refresh buzzing notification if (t.mState == TimerObj.STATE_TIMESUP) { // Must cancel the previous notification to get all updates displayed correctly cancelTimesUpNotification(context, t); showTimesUpNotification(context, t); } } if (intent.getBooleanExtra(Timers.UPDATE_NEXT_TIMESUP, true)) { // Update the next "Times up" alarm unless explicitly told not to. updateNextTimesup(context); } }
From source file:com.zhaojian.jolly.selectphotos.PhotoViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photo_viewer); mContentView = (ViewGroup) findViewById(R.id.fl_root); mController = PhotoUploadController.getFromContext(this); final Intent intent = getIntent(); mMode = intent.getIntExtra(EXTRA_MODE, MODE_ALL_VALUE); if (mMode == MODE_ALL_VALUE) { mBucketId = intent.getStringExtra(EXTRA_BUCKET_ID); }// w ww.ja v a 2 s . c o m back_btn = (LinearLayout) findViewById(R.id.back_btn); finish_btn = (Button) findViewById(R.id.finish_btn); checkImageView = (CheckableImageView) findViewById(R.id.iv_large_selection_btn); mViewPager = (ViewPager) findViewById(R.id.vp_photos); mViewPager.setOffscreenPageLimit(2); mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.viewpager_margin)); mViewPager.setOnPageChangeListener(this); checkImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { checkImageView.toggle(); // Update the controller updateController(); finish_btn.setText("?(" + mController.getSelectedCount() + ")"); } }); back_btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { finish(); } }); finish_btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { setResult(RESULT_PHOTOVIEW); finish(); } }); finish_btn.setText("?(" + mController.getSelectedCount() + ")"); if (mMode == MODE_ALL_VALUE) { mAdapter = new UserPhotosViewPagerAdapter(this); getLoaderManager().initLoader(0, null, this); } else { mAdapter = new SelectedPhotosViewPagerAdapter(this); } mViewPager.setAdapter(mAdapter); if (intent.hasExtra(EXTRA_POSITION)) { mRequestedPosition = intent.getIntExtra(EXTRA_POSITION, 0); mViewPager.setCurrentItem(mRequestedPosition); } /** * Nasty hack, basically we need to know when the ViewPager is laid out, * we then manually call onPageSelected. This is to fix onPageSelected * not being called on the first item. */ mViewPager.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") public void onGlobalLayout() { mViewPager.getViewTreeObserver().removeGlobalOnLayoutListener(this); onPageSelected(mViewPager.getCurrentItem()); } }); }