List of usage examples for android.content Intent setClass
public @NonNull Intent setClass(@NonNull Context packageContext, @NonNull Class<?> cls)
From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { if (Timers.LOGGING) { Log.v(TAG, "Received intent " + intent.toString()); }/*ww w .j av a 2s. co 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<TimerObj>(); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); TimerObj.getTimersFromSharedPrefs(prefs, mTimers); // 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.mState = TimerObj.STATE_TIMESUP; t.writeToSharedPref(prefs); // 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); } // 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.TIMER_RESET.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); } 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.mState = t.getDeleteAfterUse() ? TimerObj.STATE_DELETED : TimerObj.STATE_DONE; t.mTimeLeft = t.mOriginalLength - (Utils.getTimeNow() - t.mStartTime); t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.FROM_NOTIFICATION, 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.mState = 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.FROM_NOTIFICATION, 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)) { // 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); } } // Update the next "Times up" alarm updateNextTimesup(context); }
From source file:com.example.mynsocial.BluetoothChat.java
public void FinalResult() { loginPreferences = getSharedPreferences("loginPrefs", MODE_PRIVATE); loginPrefsEditor = loginPreferences.edit(); if (myscore > youscore) { fbcaption = "Win"; wincount = loginPreferences.getInt("win", 0); loginPrefsEditor.putInt("win", wincount + 1); loginPrefsEditor.commit();// w w w . j a va2s . c om new SaveProductDetails().execute(); Log.e(TAG, "+++ i win+++"); } else if (myscore < youscore) { fbcaption = "Lose"; Log.e(TAG, "+++ i lost +++"); } else { fbcaption = "Deuce"; } finalscore = myscore + ":" + youscore; // publishFeedDialog(); Intent intent = new Intent(); intent.setClass(BluetoothChat.this, Result.class); Bundle bundle = new Bundle(); if (fbcaption.equals("Win")) { bundle.putString("fbcaption", "I win the game!"); bundle.putString("score", finalscore); intent.putExtras(bundle); } else if (fbcaption.equals("Lose")) { bundle.putString("fbcaption", "I lose the game!"); bundle.putString("score", finalscore); intent.putExtras(bundle); } else if (fbcaption.equals("Deuce")) { bundle.putString("fbcaption", "We deuce!"); bundle.putString("score", finalscore); intent.putExtras(bundle); } //BluetoothChat.this.finish(); startActivity(intent); }
From source file:com.miqtech.master.client.ui.StartActivity.java
@Override public void onClick(View v) { if (v.getId() == R.id.tvSkip) { Intent intent = new Intent(); if (isFirstStartOrUpdateVersion()) { PreferencesUtil.saveStartInfo(StartActivity.this); intent.setClass(StartActivity.this, GuideActivity.class); startActivity(intent);// w ww.ja va2 s . co m } else { intent.setClass(context, MainActivity.class); if (mConfig != null && mConfig.getUpdate_msg() != null) { intent.putExtra("versionInfo", mConfig.getUpdate_msg()); } if (!isJumpFromWeb) { startActivity(intent); } else { Intent extraIntent = new Intent(); extraIntent.setClassName(StartActivity.this, data.getString("action")); String id = data.getString("id"); String key = data.getString("key"); extraIntent.putExtra(key, key.contains("activityId") ? Integer.parseInt(id) : id); startActivities(new Intent[] { intent, extraIntent }); } } timer.cancel(); onBackPressed(); } else if (v.getId() == R.id.ivAd) { String strConfig = PreferencesUtil.getConfig(this); mConfig = new Gson().fromJson(strConfig, Config.class); if (mConfig != null && mConfig.getStartup_ad() != null) { int type = mConfig.getStartup_ad().getType(); String target = mConfig.getStartup_ad().getTarget(); if (type == 1) { Intent mainIntent = new Intent(); mainIntent.setClass(this, MainActivity.class); Intent h5Intent = new Intent(); h5Intent.setClass(this, SubjectActivity.class); h5Intent.putExtra("url", target); h5Intent.putExtra(SubjectActivity.HTML5_TYPE, SubjectActivity.START_AD); Intent[] intents = new Intent[] { mainIntent, h5Intent }; startActivities(intents); timer.cancel(); } else if (type == 2) { if (target.equals("10")) { Intent mainIntent = new Intent(); mainIntent.setClass(this, MainActivity.class); Intent warIntent = new Intent(); warIntent.setClass(this, OfficalEventActivity.class); warIntent.putExtra("matchId", mConfig.getStartup_ad().getTarget_id()); Intent[] intents = new Intent[] { mainIntent, warIntent }; startActivities(intents); timer.cancel(); } else if (target.equals("11")) { Intent mainIntent = new Intent(); mainIntent.setClass(this, MainActivity.class); Intent recreationIntent = new Intent(); recreationIntent.setClass(this, RecreationMatchDetailsActivity.class); recreationIntent.putExtra("id", mConfig.getStartup_ad().getTarget_id()); Intent[] intents = new Intent[] { mainIntent, recreationIntent }; startActivities(intents); timer.cancel(); } else if (target.equals("12")) { Intent mainIntent = new Intent(); mainIntent.setClass(this, MainActivity.class); Intent yuezhnIntent = new Intent(); yuezhnIntent.setClass(this, YueZhanDetailsActivity.class); yuezhnIntent.putExtra("id", mConfig.getStartup_ad().getTarget_id()); Intent[] intents = new Intent[] { mainIntent, yuezhnIntent }; startActivities(intents); timer.cancel(); } } } } }
From source file:com.mediatek.galleryfeature.stereo.fancycolor.FancyColorActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int action = item.getItemId(); switch (action) { case R.id.action_refine: mEffectManager.setMaskBufferToSegment(); Intent intent = new Intent(STEREO_PICK_ACTION); intent.setClass(FancyColorActivity.this, StereoRefineActivity.class); intent.setDataAndType(mSourceUri, mIntent.getType()).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivityForResult(intent, REQUEST_STEREO_PICK); break;//w w w. j a v a 2 s . com default: break; } return true; }
From source file:com.abcvoipsip.ui.account.AccountsEditListFragment.java
/** * Helper function to show the details of a selected item, either by * displaying a fragment in-place in the current UI, or starting a * whole new activity in which it is displayed. *///from w w w .ja va 2s .com private void showDetails(long profileId, String wizard) { //curCheckPosition = index; /* if (dualPane) { // If we are not currently showing a fragment for the new // position, we need to create and install a new one. AccountEditFragment df = AccountEditFragment.newInstance(profileId); //df.setOnQuitListener(this); // Execute a transaction, replacing any existing fragment // with this one inside the frame. FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.details, df, null); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.setTransition(FragmentTransaction.TRANSIT_NONE); //if(profileId != Profile.INVALID_ID) { // ft.addToBackStack(null); //} ft.commit(); } else { */ // Otherwise we need to launch a new activity to display // the dialog fragment with selected text. Intent intent = new Intent(); //intent.setClass(getActivity(), AccountEdit.class); intent.setClass(getActivity(), BasePrefsWizard.class); if (profileId != SipProfile.INVALID_ID) { intent.putExtra(SipProfile.FIELD_ID, profileId); } intent.putExtra(SipProfile.FIELD_WIZARD, wizard); startActivity(intent); /* } */ }
From source file:com.guardtrax.ui.screens.SplashScreen.java
private void initialize() { if (locationManagerObj == null) { locationManagerObj = (LocationManager) getSystemService(Context.LOCATION_SERVICE); try {//from w ww .j a v a 2 s .c om gps_enabled = locationManagerObj.isProviderEnabled(LocationManager.GPS_PROVIDER); //network_enabled = locationManagerObj.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ex) { } } // don't start listeners if no provider is enabled - Changed to to look for both //if (!gps_enabled) if (!gps_enabled && !network_enabled) { AlertDialog.Builder dialog = new AlertDialog.Builder(SplashScreen.this); dialog.setTitle("Info"); dialog.setMessage("Please enable GPS!"); dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { System.exit(0); } }); dialog.show(); } else { Runnable showWaitDialog = new Runnable() { @Override public void run() { Looper.prepare(); int i = 0; //if syncComplete is true already it means that we are not trying to sync, hence delay so that splash screen can close slowly if (syncComplete) { try { Thread.sleep(1000); } catch (Exception e) { } } else { while (!syncComplete || i++ < 10) { try { Thread.sleep(1000); } catch (Exception e) { break; } } //make sure background task is completed. If not, force it closed if (!syncComplete) { try { if (syncdb.getStatus() != AsyncTask.Status.FINISHED) syncdb.cancel(true); } catch (Exception e) { } } } //After receiving first GPS Fix dismiss the Progress Dialog dialog.dismiss(); //calling the tab class causes the current tab to be displayed (set to tab(0) which is the HomeScreen) Intent intent = new Intent(); intent.setClass(SplashScreen.this, HomeScreen.class); startActivity(intent); //transition from splash to main menu is slowed down to a fade by this command overridePendingTransition(R.anim.activityfadein, R.anim.splashfadeout); SplashScreen.this.finish(); } }; // Create a Dialog to let the User know that we're waiting for a GPS Fix dialog = ProgressDialog.show(SplashScreen.this, "Please wait", "Initializing ...", true); Thread t = new Thread(showWaitDialog); t.start(); } }
From source file:com.miz.mizuu.ShowDetails.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (getIntent().getExtras().getBoolean("isFromWidget")) { Intent i = new Intent(Intent.ACTION_VIEW); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); i.putExtra("startup", String.valueOf(Main.SHOWS)); i.setClass(getApplicationContext(), Main.class); startActivity(i);// w ww . j a v a 2s.c om } finish(); return true; case R.id.menuDeleteShow: deleteShow(); break; case R.id.change_cover: searchCover(); break; case R.id.identify_show: identifyShow(); break; } return false; }
From source file:com.github.tdudziak.gps_lock_lock.ControlActivity.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent; switch ((int) id) { case R.id.menuItemSettings: intent = new Intent(this, AppPreferenceActivity.class); startActivityForResult(intent, 0); break;//from w w w . ja v a 2 s . co m case R.id.menuItemHelp: intent = new Intent(this, AboutActivity.class); startActivityForResult(intent, 0); break; case R.id.menuItemRestart: intent = new Intent(LockService.ACTION_RESTART); intent.setClass(this, LockService.class); startService(intent); break; case R.id.menuItemStop: intent = new Intent(LockService.ACTION_SHUTDOWN); intent.setClass(this, LockService.class); startService(intent); break; } }
From source file:com.miz.mizuu.fragments.CollectionLibraryFragment.java
private void showDetails(int arg2) { Intent intent = new Intent(); intent.putExtra("tmdbId", mMovies.get(mMovieKeys.get(arg2)).getTmdbId()); intent.setClass(getActivity(), MovieDetails.class); startActivityForResult(intent, 0);// ww w.j a v a2 s . c o m }
From source file:gov.nasa.arc.geocam.geocam.CameraActivity.java
private void saveImage() { Log.d(GeoCamMobile.DEBUG_ID,//from w w w . ja v a 2 s . c o m "Saving orientation: " + mOrientation[2] + "," + mOrientation[1] + "," + mOrientation[0]); // Store orientation data in description field of mediastore using JSON encoding JSONObject imageData = new JSONObject(); try { imageData.put("rpy", GeoCamMobile.rpySerialize(mOrientation[2], mOrientation[1], mOrientation[0])); imageData.put("yawRef", GeoCamMobile.YAW_MAGNETIC); imageData.put("uuid", UUID.randomUUID()); Log.d(GeoCamMobile.DEBUG_ID, "Saving image with data: " + imageData.toString()); } catch (JSONException e) { Log.d(GeoCamMobile.DEBUG_ID, "Error while adding JSON data to image"); } mImageData = imageData; double lat, lon; if (mLocation == null) { lat = 0.0; lon = 0.0; } else { lat = mLocation.getLatitude(); lon = mLocation.getLongitude(); } // Add some parameters to the image that will be stored in the Image ContentProvider ContentValues values = new ContentValues(); String name = String.valueOf(System.currentTimeMillis()); values.put(MediaStore.Images.Media.DISPLAY_NAME, name + ".jpg"); values.put(MediaStore.Images.Media.TITLE, name); values.put(MediaStore.Images.Media.DESCRIPTION, mImageData.toString()); values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.Images.Media.SIZE, mImageBytes.length); values.put(MediaStore.Images.Media.LATITUDE, lat); values.put(MediaStore.Images.Media.LONGITUDE, lon); // There appears to be a bug where saveImage() sometimes fails to actually create an entry // in the db so we do one retry int initNumEntries = getMediaStoreNumEntries(); mImageUri = saveImage(values); if (getMediaStoreNumEntries() <= initNumEntries) { Log.d(GeoCamMobile.DEBUG_ID, "Retrying save"); mImageUri = saveImage(values); } mImageBytes = null; Log.d(GeoCamMobile.DEBUG_ID, "Trying to force a GC"); System.gc(); dismissDialog(DIALOG_SAVE_PROGRESS); // Start camera preview activity Intent i = new Intent(Intent.ACTION_VIEW, mImageUri); i.setClass(getApplication(), CameraPreviewActivity.class); i.putExtra("data", mImageData.toString()); startActivity(i); }