@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); setTitle("Second Activity"); Intent inIntent = getIntent(); String calc = inIntent.getStringExtra("calc"); final double first = inIntent.getDoubleExtra("first", 0); final double second = inIntent.getDoubleExtra("second", 0); final double result; Button ret = (Button) findViewById(R.id.ret); if (calc.equals("plus")) result = Double.parseDouble(String.format("%.3f", first + second)); else if (calc.equals("minus")) result = Double.parseDouble(String.format("%.3f", first - second)); else if (calc.equals("multiply")) result = Double.parseDouble(String.format("%.3f", first * second)); else if (calc.equals("divider")) result = Double.parseDouble(String.format("%.3f", first / second)); else result = 0; ret.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent outIntent = new Intent(getApplicationContext(), MainActivity.class); outIntent.putExtra("result", result); setResult(RESULT_OK, outIntent); finish(); } }); }
public void run() { int timedCount = 0; while (!Thread.interrupted()) { try { Thread.sleep(SEC_POLL_DELAY); } catch (InterruptedException e) { break; } // 5400 seconds = 90 min if (timedCount == 5400) { timedCount = 0; Intent dialogIntent = new Intent(getBaseContext(), BlockerActivity.class); dialogIntent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); dialogIntent.putExtra( "AlertInfo", "You've used your phone for 90 minutes NON-STOP. Please take a break!"); getApplication().startActivity(dialogIntent); } timedCount++; synchronized (mPauseLock) { while (mPaused) { try { mPauseLock.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); incoming = (TextView) findViewById(R.id.incoming); btnPush = (Button) findViewById(R.id.btn_push); Intent intent = new Intent(WebSocketService.START_TEAM_GAME_SERVICE_INTENT); intent.putExtra("url", "ws://192.168.38.12:8081"); // startService(new Intent(this, WebSocketService.class)); startService(intent); bindService(new Intent(this, WebSocketService.class), connection, Context.BIND_AUTO_CREATE); btnPush.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { try { Bundle bundle = new Bundle(); bundle.putString("text", "bugoga!"); Message msg = Message.obtain(null, WebSocketService.MSG_SEND_COMMAND); msg.replyTo = messenger; msg.setData(bundle); serviceMessenger.send(msg); } catch (RemoteException e) { e.printStackTrace(); } } }); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.folderex); Intent gintent = getIntent(); getPath = gintent.getStringExtra("path"); dbPath = gintent.getStringExtra("dbpath"); FileList _FileList = new FileList(this); _FileList.setOnPathChangedListener(_OnPathChanged); _FileList.setOnFileSelected(_OnFileSelected); LinearLayout layout = (LinearLayout) findViewById(R.id.LinearLayout01); layout.addView(_FileList); Util.print("getPath = " + getPath); String path = " "; if (getPath.equals("empty")) { File root = Environment.getExternalStorageDirectory(); _FileList.setPath(root.getAbsolutePath()); path = root.getAbsolutePath(); } else { _FileList.setPath(getPath); path = getPath; } Util.print("path = " + path); _FileList.setFocusable(true); _FileList.setFocusableInTouchMode(true); ((TextView) findViewById(R.id.TextView01)).setSelected(true); }
void acctSelected(ServiceAcctInfo info) { Account acct = new Account(); acct.name = info.desc; acct.service = info; DialogInterface.OnClickListener emptyClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {} }; AcctTables db = new AcctTables(this); try { db.openWritable(); try { db.pushAccount(acct); } catch (SQLiteException e) { AlertDialog dlg = Utilities.buildAlert( this, e, "Unable to add account", "Internal Error", emptyClickListener); dlg.show(); return; } } finally { db.close(); } Intent i = getIntent(); i.putExtra("acct_id", acct.ID); setResult(RESULT_OK, i); finish(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = getIntent(); Uri uri = intent.getData(); if (uri != null) { MainActivity.addLink(this, uri.toString()); Uri newUri = Uri.parse("view-source:" + uri.toString()); startChrome(newUri); } if (Intent.ACTION_SEND.equals(intent.getAction())) { Bundle extras = intent.getExtras(); if (extras != null) { String text = extras.getString(Intent.EXTRA_TEXT); Pattern pattern = Pattern.compile(URL_PATTERN); if (text != null) { Matcher m = pattern.matcher(text); if (m.find()) { String url = m.group(1); MainActivity.addLink(this, url); Uri newUri = Uri.parse("view-source:" + url); startChrome(newUri); } } } } this.finish(); }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { RssItem item = rssList.get(position); Intent intent = new Intent(RssReaderActivity.this, RssDetailActivity.class); intent.putExtra("rss_title", item.getTitle()); intent.putExtra("rss_link", item.getLink()); RssReaderActivity.this.startActivity(intent); }
/** * When the back button is pressed, update the MidiOptions. Return the updated options as the * 'result' of this Activity. */ @Override public void onBackPressed() { Intent intent = new Intent(); updateOptions(); intent.putExtra(SettingsActivity.settingsID, options); setResult(Activity.RESULT_OK, intent); super.onBackPressed(); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.meat_toppings); Intent i = getIntent(); size = i.getStringExtra("size"); numVeggieToppings = i.getIntExtra("numVeggieToppings", 0); setMeatToppingsView(); setNextButton(); }
private static Intent setUpIntent() { Intent command = new Intent(context, ProviderAPI.class); command.setAction(action); command.putExtra(ProviderAPI.PARAMETERS, parameters); command.putExtra(ProviderAPI.RECEIVER_KEY, result_receiver); return command; }
/** * Shows <tt>AuthorizationRequestedDialog</tt> for the request with given <tt>id</tt>. * * @param id request identifier for which new dialog will be displayed. */ public static void showDialog(Long id) { Context ctx = JitsiApplication.getGlobalContext(); Intent showIntent = new Intent(ctx, AuthorizationRequestedDialog.class); showIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); showIntent.putExtra(EXTRA_REQUEST_ID, id); ctx.startActivity(showIntent); }
@Override public void onItemClick(AdapterView<?> l, View v, int position, long id) { if (l.getId() == R.id.photosGridView) { String clickedItem = photosGridViewContents[position]; Intent intent = new Intent(PhotoGridActivity.this, PhotoViewerActivity.class); intent.putExtra( "filename", clickedItem); // use putExtra method of Intent here for passing additional information to // PhotoViewerActivity startActivity(intent); } }
public void startChrome(Uri uri) { Intent it = new Intent(Intent.ACTION_VIEW); it.setData(uri); it.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); it.setClassName("com.android.chrome", "com.google.android.apps.chrome.Main"); try { startActivity(it); } catch (ActivityNotFoundException ex) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?id=com.android.chrome")); startActivity(intent); } }
private void finishWithPath(String path) { if (pathSettingKey != null && !pathSettingKey.isEmpty()) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); SharedPreferences.Editor editor = settings.edit(); editor.putString(pathSettingKey, path); editor.commit(); } Intent intent = new Intent(); intent.putExtra("PATH", path); setResult(RESULT_OK, intent); finish(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { // found this from StackOverflow if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } else { // -----------I wrote this code below this line---------------------------------- jpegData = intent.getExtras().getByteArray("image"); Bitmap img = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); Drawable d = new BitmapDrawable(img); profilePicture.setBackground(d); } }
@Override public void onReceive(Context context, Intent intent) { ComponentName currentComponent = intent.getParcelableExtra(getString(R.string.component_name)); _recordUsage(currentComponent, false); }
public void doRestart() { try { String action = "org.mozilla.gecko.restart"; Intent intent = new Intent(action); intent.setClassName(getPackageName(), getPackageName() + ".Restarter"); addEnvToIntent(intent); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); Log.i(LOG_FILE_NAME, intent.toString()); GeckoAppShell.killAnyZombies(); startActivity(intent); } catch (Exception e) { Log.i(LOG_FILE_NAME, "error doing restart", e); } finish(); // Give the restart process time to start before we die GeckoAppShell.waitForAnotherGeckoProc(); }
private void restartService() { Intent restartServiceIntent = new Intent(getApplicationContext(), ((Object) this).getClass()); restartServiceIntent.setPackage(getPackageName()); PendingIntent restartServicePendingIntent = PendingIntent.getService( getApplicationContext(), 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT); // ensure fire off AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(ALARM_SERVICE); alarmService.set( AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePendingIntent); }
@Override public void onFinish() { Intent intent; if (mPref.getCheckedTutorial() == true) { // 튜토리얼을 했을 경우 intent = new Intent(AC_Loading.this, AC_Main.class); } else { // 튜토리얼을 안했을 경우 intent = new Intent(AC_Loading.this, AC_Help_tutorial.class); } intent.putExtra("tutorial", true); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); overridePendingTransition(R.anim.fadein, R.anim.fadeout); cTimer.cancel(); finish(); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.receiver); final Button cancelbtn = (Button) findViewById(R.id.ButtonCancel); // cancelbtn.setEnabled(false); cancelbtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // streamtask.cancel(true); finish(); } }); try { Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if ((!(Intent.ACTION_SEND.equals(action))) || (type == null)) { throw new RuntimeException("Unknown intent action or type"); } if (!("text/plain".equals(type))) { throw new RuntimeException("Type is not text/plain"); } String extra = intent.getStringExtra(Intent.EXTRA_TEXT); if (extra == null) { throw new RuntimeException("Cannot get shared text"); } final DownloadStreamTask streamtask = new DownloadStreamTask(this); // Once created, a task is executed very simply: streamtask.execute(extra); } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } }
// code which handles the action for each menu item public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: { Intent preferences_intent = new Intent(); preferences_intent.setComponent( new ComponentName(download_photos.this, preferences.class)); preferences_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplicationContext().startActivity(preferences_intent); return true; } case R.id.logout: { try { download_photos.this.facebook.logout(getApplicationContext()); } catch (IOException e) { e.printStackTrace(); } mPrefs = getSharedPreferences("COMMON", MODE_PRIVATE); SharedPreferences.Editor editor = mPrefs.edit(); editor.putString("access_token", null); editor.putLong("access_expires", 0); editor.putBoolean("logout", true); editor.commit(); finish(); return true; } case R.id.about: { // shows our customized about dialog AboutDialog about = new AboutDialog(this); about.show(); return true; } // lets deal with default case default: return super.onOptionsItemSelected(item); } }
public String showFilePicker(String aMimeType) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(aMimeType); GeckoApp.this.startActivityForResult( Intent.createChooser(intent, getString(R.string.choose_file)), FILE_PICKER_REQUEST); String filePickerResult = ""; try { while (null == (filePickerResult = mFilePickerResult.poll(1, TimeUnit.MILLISECONDS))) { Log.i("GeckoApp", "processing events from showFilePicker "); GeckoAppShell.processNextNativeEvent(); } } catch (InterruptedException e) { Log.i(LOG_FILE_NAME, "showing file picker ", e); } return filePickerResult; }
@Override protected void onNewIntent(Intent intent) { if (checkLaunchState(LaunchState.GeckoExiting)) { // We're exiting and shouldn't try to do anything else just incase // we're hung for some reason we'll force the process to exit System.exit(0); return; } final String action = intent.getAction(); if (ACTION_DEBUG.equals(action) && checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) { mMainHandler.postDelayed( new Runnable() { public void run() { Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait"); setLaunchState(LaunchState.Launching); launch(null); } }, 1000 * 5 /* 5 seconds */); Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching"); return; } if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent)) return; if (Intent.ACTION_MAIN.equals(action)) { Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN"); GeckoAppShell.sendEventToGecko(new GeckoEvent("")); } else if (Intent.ACTION_VIEW.equals(action)) { String uri = intent.getDataString(); GeckoAppShell.sendEventToGecko(new GeckoEvent(uri)); Log.i(LOG_FILE_NAME, "onNewIntent: " + uri); } else if (ACTION_WEBAPP.equals(action)) { String uri = intent.getStringExtra("args"); GeckoAppShell.sendEventToGecko(new GeckoEvent(uri)); Log.i(LOG_FILE_NAME, "Intent : WEBAPP - " + uri); } else if (ACTION_BOOKMARK.equals(action)) { String args = intent.getStringExtra("args"); GeckoAppShell.sendEventToGecko(new GeckoEvent(args)); Log.i(LOG_FILE_NAME, "Intent : BOOKMARK - " + args); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == GET_SESSION) { if (resultCode == RESULT_CANCELED) { cancel(); } else { int sessionId = data.getIntExtra("sess_id", 0); loadContext(sessionId); } } }
public void addEnvToIntent(Intent intent) { Map<String, String> envMap = System.getenv(); Set<Map.Entry<String, String>> envSet = envMap.entrySet(); Iterator<Map.Entry<String, String>> envIter = envSet.iterator(); int c = 0; while (envIter.hasNext()) { Map.Entry<String, String> entry = envIter.next(); intent.putExtra("env" + c, entry.getKey() + "=" + entry.getValue()); c++; } }
@Override public void onNewIntent(Intent intent) { try { if (intent.getExtras().getBoolean("rss_update")) { rssFeed = dbQuery.getUpdatedRssFeed(); updateListView(); } } catch (NullPointerException e) { e.printStackTrace(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { String filePickerResult = ""; if (data != null && resultCode == RESULT_OK) { try { ContentResolver cr = getContentResolver(); Uri uri = data.getData(); Cursor cursor = GeckoApp.mAppContext .getContentResolver() .query(uri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null); String name = null; if (cursor != null) { try { if (cursor.moveToNext()) { name = cursor.getString(0); } } finally { cursor.close(); } } String fileName = "tmp_"; String fileExt = null; int period; if (name == null || (period = name.lastIndexOf('.')) == -1) { String mimeType = cr.getType(uri); fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType); } else { fileExt = name.substring(period); fileName = name.substring(0, period); } File file = File.createTempFile(fileName, fileExt, sGREDir); FileOutputStream fos = new FileOutputStream(file); InputStream is = cr.openInputStream(uri); byte[] buf = new byte[4096]; int len = is.read(buf); while (len != -1) { fos.write(buf, 0, len); len = is.read(buf); } fos.close(); filePickerResult = file.getAbsolutePath(); } catch (Exception e) { Log.e(LOG_FILE_NAME, "showing file picker", e); } } try { mFilePickerResult.put(filePickerResult); } catch (InterruptedException e) { Log.i(LOG_FILE_NAME, "error returning file picker result", e); } }
public void mOnClickSave(View v) { String inputPath = nowPath; UseDb db = new UseDb(); File files = new File(inputPath); if (files.exists() == true) { db.setValue(this, dbPath, nowPath); Intent intent = new Intent(this, Loading.class); intent.putExtra("path", nowPath); startActivity(intent); finish(); } else { Toast.makeText( FolderEx.this, getResources().getString(R.string.sp_msg_notexistfolder), Toast.LENGTH_SHORT) .show(); } }
@Override protected void onNewIntent(Intent intent) { OrientationUtil.setOrientation(this, intent); if (!Intent.ACTION_SEARCH.equals(intent.getAction())) { return; } String pattern = intent.getStringExtra(SearchManager.QUERY); myBookmarkSearchPatternOption.setValue(pattern); final LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>(); pattern = pattern.toLowerCase(); for (Bookmark b : myAllBooksAdapter.bookmarks()) { if (MiscUtil.matchesIgnoreCase(b.getText(), pattern)) { bookmarks.add(b); } } if (!bookmarks.isEmpty()) { showSearchResultsTab(bookmarks); } else { UIUtil.showErrorMessage(this, "bookmarkNotFound"); } }
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction() == "android.intent.action.SCREEN_ON") { timedRunnable.onResume(); ActivityManager.RecentTaskInfo currentTask = activityManager.getRecentTasks(1, ActivityManager.RECENT_IGNORE_UNAVAILABLE).get(0); ComponentName currentComponent = currentTask.baseIntent.getComponent(); _recordUsage(currentComponent, false); } else { timedRunnable.onPause(); _recordUsage(null, true); } }