@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 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); }
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(); }
@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); } }
/** 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(); } }
@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) { String lastTimeStamp = intent.getStringExtra("lastTimestamp"); if (lastTimeStamp == null) { lastTimeStamp = "0"; } // remote logging latest data ArrayList<StatForm> stats = dataHelper.getLoggingRecordByTimestamp(lastTimeStamp); if (stats.size() > 0) { rest.createStats( stats, new RetrofitDialogCallback<Stat>(getApplicationContext(), null) { @Override public void onSuccess(Stat stat, Response response) { /*not much to do*/ } @Override public void onFailure(RetrofitError retrofitError) { /*not much to do*/ } }); } }
@Override public void onCreate(Bundle savedInstanceState) { // locks the screen in portrait mode setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); super.onCreate(savedInstanceState); setContentView(R.layout.downloader); mtext = (TextView) findViewById(R.id.mtext); progress_text = (TextView) findViewById(R.id.progress_text); progress_download = (ProgressBar) findViewById(R.id.progress_download); // resume capability paused = false; resume_pause = (Button) findViewById(R.id.resume); // Create and launch the download thread downloadThread = new DownloadThread(this); downloadThread.start(); // Create the Handler. It will implicitly bind to the Looper // that is internally created for this thread (since it is the UI thread) handler = new Handler(); resume_pause.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { if (!paused) { paused = true; resume_pause.setText("Resume"); // writeProgress(completed_downloads,total_files_to_download); downloadThread.requestStop(); downloadThread = null; } else { resume_pause.setText("Pause"); paused = false; initial_value = readProgress()[0]; final_value = links.size(); for (int i = initial_value; i < links.size(); i++) { downloadThread = new DownloadThread(download_photos.this); downloadThread.start(); downloadThread.enqueueDownload( new DownloadTask( links.get(i), path, i + 1, links.size(), download_photos.this)); } } } }); // load preferences for this activity mPrefs = getSharedPreferences("COMMON", MODE_PRIVATE); // This declaration is solely meant for reading the checkbox preference for downloading high res // pics. SharedPreferences dl_prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); // The global variable is set after reading the checkbox preference. dl_high_res_pics = dl_prefs.getBoolean("download_high_res", false); // load fb access token and its expiry values String access_token = mPrefs.getString("access_token", null); long expires = mPrefs.getLong("access_expires", 0); if (access_token != null) { facebook.setAccessToken(access_token); } if (expires != 0) { facebook.setAccessExpires(expires); } // get friend_name and album_name from the intent which started this activity Intent starting_intent = getIntent(); album_id = starting_intent.getStringExtra("id"); album_name = starting_intent.getStringExtra("name"); friend_name = starting_intent.getStringExtra("friend_name"); // real album and friend name may contain characters not suitable for file names. // regex pattern includes most of the invalid characters in file names legal_album_name = album_name.replaceAll("[.\\\\/:*?\"<>|]?[\\\\/:*?\"<>|]*", ""); legal_friend_name = friend_name.replaceAll("[.\\\\/:*?\"<>|]?[\\\\/:*?\"<>|]*", ""); // initialise the directory structure for download path = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + getText(R.string.app_name) + "/" + legal_friend_name + "/" + legal_album_name); if (dl_high_res_pics) path = new File(path.toString() + "/" + getText(R.string.folder_name_high_res)); resume_file = new File(path, "resume.txt"); // implements actions to done after receiving json object class meRequestListener extends BaseRequestListener { @Override public void onComplete(String response, Object state) { try { Log.i(TAG, response); json = Util.parseJson(response); // photos are in the form of a json array child = json.getJSONArray("data"); int total = child.length(); // contains links to photos links = new ArrayList<String>(total); // adds link to each photo to our list after replacing the "https" from url // DownloadManager does not support https in gingerbread for (int i = 0; i < total; i++) { photo_json = child.getJSONObject(i); if (dl_high_res_pics) { JSONArray image_set = photo_json.getJSONArray("images"); // highest resolution picture has the index zero in the images jsonarray JSONObject highest_res_pic = image_set.getJSONObject(0); String http_replaced = highest_res_pic.getString("source").replaceFirst("https", "http"); links.add(i, http_replaced); } else { // source property of the json object points to the photo's link String http_replaced = photo_json.getString("source").replaceFirst("https", "http"); links.add(i, http_replaced); } } download_photos.this.runOnUiThread( new Runnable() { public void run() { // mytask = new DownloadImageTask(); // mytask.execute(links); // start downloading using asynctask // new DownloadImageTask().execute(links); // downloadThread.setPath(path); // downloadThread.setWholeTasks(links.size()); if (resume_file.exists()) { initial_value = readProgress()[0]; final_value = links.size(); // case if the task is already completed if (initial_value == final_value) { completed = true; resume_pause.setVisibility(View.GONE); progress_download.setMax(final_value); progress_download.setProgress(0); // bug in progress bar progress_download.setProgress(initial_value); progress_text.setText("Completed."); mtext.setText( getText(R.string.download_textview_message_1) + " " + path.toString() + ". "); } // case if some of the photos are already downloaded else { progress_download.setMax(links.size()); // progress_download.setProgress(0); //bug in progress bar progress_download.setProgress(initial_value); // N.B if i= initial_value -1, then one image will be downloaded again. so to // save cost we start with i = initial_value for (int i = initial_value; i < links.size(); i++) { mtext.setText( getText(R.string.download_textview_message_1) + " " + path.toString() + ". "); // downloadThread.setRunningTask(i + 1); downloadThread.enqueueDownload( new DownloadTask( links.get(i), path, i + 1, final_value, download_photos.this)); } } } // case if the task is entirely new task else { for (int i = 0; i < links.size(); i++) { mtext.setText( getText(R.string.download_textview_message_1) + " " + path.toString() + ". "); // downloadThread.setRunningTask(i + 1); downloadThread.enqueueDownload( new DownloadTask( links.get(i), path, i + 1, links.size(), download_photos.this)); } } } }); } catch (JSONException ex) { Log.e(TAG, "JSONEXception : " + ex.getMessage()); } } } // makes asynchronous request to facebook graph api // the actions to be performed after receiving json response is implemented above Bundle parameters = new Bundle(); // facebook returns only 25 photos when limit is not specified. parameters.putString("limit", max_photos_in_album); if (!completed) mAsyncRunner.request(album_id + "/photos", parameters, new meRequestListener()); if (!facebook.isSessionValid()) { facebook.authorize( this, permissions, new DialogListener() { // save fb access token and its expiry values to prefernces of this activity @Override public void onComplete(Bundle values) { SharedPreferences.Editor editor = mPrefs.edit(); editor.putString("access_token", facebook.getAccessToken()); editor.putLong("access_expires", facebook.getAccessExpires()); editor.commit(); } @Override public void onFacebookError(FacebookError error) { Log.e(TAG, "Facebook Error : " + error.getMessage()); } @Override public void onError(DialogError e) { Log.e(TAG, e.getMessage()); } @Override public void onCancel() { // do nothing LOL :-) } }); } }