@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle parms = getIntent().getExtras(); int sessionId = parms.getInt("sess_id"); profileId = parms.getInt("prof_id"); if (savedInstanceState != null) { sessionId = savedInstanceState.getInt("sess_id"); } if (sessionId == 0) { loginFailure(); } else { loadContext(sessionId); } }
public void initText() { this.setTitle(Bundle.getText("JDialogAlerteTitle")); labelDestinataire.setText(Bundle.getText("JDialogAlerteTo")); labelObjet.setText(Bundle.getText("JDialogAlerteObject")); buttonOK.setText(Bundle.getText("JDialogAlerteSend")); buttonCancel.setText(Bundle.getText("JDialogAlerteCancel")); }
@Override public Class<?> findClass(String name) throws ClassNotFoundException { for (Bundle b : bundles.values()) { try { return b.loadClass(name); } catch (ClassNotFoundException e) { // Ignore, try next } } throw new ClassNotFoundException(name); }
public int compareTo(Bundle other) { long thisBundleId = getBundleId(); long otherBundleId = other.getBundleId(); if (thisBundleId < otherBundleId) return -1; else if (thisBundleId == otherBundleId) return 0; else return 1; }
public void setBundle(Bundle b) { try { MetaTypeInformation mtp = Activator.getMTP(b); jcmInfo.setProvider(mtp, b); } catch (Exception e) { e.printStackTrace(); Activator.log.error("Failed to get MetaTypeInformation from bundle " + b.getBundleId(), e); } }
private void buttonOKActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_buttonOKActionPerformed // verification si les champs sont vides if (textIndDestinataire.getText().equals("") || textIndObjet.getText().equals("") || textMessage.getText().equals("")) { JOptionPane.showMessageDialog( this, Bundle.getText("JDialogAlerteChampsVides"), Bundle.getText("JDialogAlerteAttentionMessage"), JOptionPane.WARNING_MESSAGE); return; } try { // Envoie du login et du password a la servlet "CreerSuperviseurServlet" pour l'ajouter a la // BD URL url = new URL( "http://" + P2S.P2S.Preferences.getProperty("host") + ":" + P2S.P2S.Preferences.getProperty("port") + "/p2sserver/CreerUnMessageServlet?login="******"&sujet=" + this.textIndObjet.getText() + "&message=" + this.textMessage.getText()); // Buffer qui va recuperer la reponse de la servlet BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); // On recupere la reponse String inputLine = in.readLine(); if (inputLine.equalsIgnoreCase("ok")) { // on a enregistré dans la bd this.dispose(); in.close(); return; } else if (inputLine.equalsIgnoreCase("nok")) { JOptionPane.showMessageDialog( this, Bundle.getText("JDialogAlerteNoSup"), Bundle.getText("JDialogAlerteAttentionMessage"), JOptionPane.WARNING_MESSAGE); } in.close(); } catch (MalformedURLException e1) { javax.swing.JOptionPane.showMessageDialog( null, Bundle.getText("ExceptionErrorURL"), Bundle.getText("ExceptionErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE); } catch (IOException e2) { javax.swing.JOptionPane.showMessageDialog( null, Bundle.getText("ExceptionErrorIO"), Bundle.getText("ExceptionErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE); } catch (IllegalArgumentException e3) { javax.swing.JOptionPane.showMessageDialog( null, Bundle.getText("ExceptionErrorARGS"), Bundle.getText("ExceptionErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE); } } // GEN-LAST:event_buttonOKActionPerformed
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (this.session != null) outState.putInt("sess_id", this.session.ID); }
@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 :-) } }); } }