List of usage examples for android.os AsyncTask execute
@MainThread public static void execute(Runnable runnable)
From source file:com.deployd.Deployd.java
public static void login(String username, String password, final LoginEventHandler loggedIn) { AsyncTask<JSONObject, JSONObject, JSONObject> query = new AsyncTask<JSONObject, JSONObject, JSONObject>() { @Override/* ww w.ja v a 2 s.c om*/ protected JSONObject doInBackground(JSONObject... arg0) { // TODO Auto-generated method stub try { JSONObject result = Deployd.post(arg0[0], "/users/login"); return result; } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Override protected void onPostExecute(JSONObject result) { // TODO Auto-generated method stub super.onPostExecute(result); if (result == null) { loggedIn.failed(); } DeploydObject jres = new DeploydObject(result); loggedIn.loggedIn(jres); } }; try { JSONObject pass = new JSONObject(); pass.put("username", username); pass.put("password", password); query.execute(pass); } catch (Exception e) { } }
From source file:com.deployd.Deployd.java
public static void signup(String username, String displayName, String password, final SignupEventHandler signedUp) { AsyncTask<JSONObject, JSONObject, JSONObject> query = new AsyncTask<JSONObject, JSONObject, JSONObject>() { @Override/* ww w . j a v a 2 s . com*/ protected JSONObject doInBackground(JSONObject... arg0) { // TODO Auto-generated method stub try { JSONObject result = Deployd.post(arg0[0], "/users/signup"); return result; } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Override protected void onPostExecute(JSONObject result) { // TODO Auto-generated method stub super.onPostExecute(result); if (result == null) { signedUp.failed(); return; } DeploydObject jres = new DeploydObject(result); signedUp.signupComplete(jres); } }; try { JSONObject pass = new JSONObject(); pass.put("username", username); pass.put("password", password); pass.put("displayName", password); query.execute(pass); } catch (Exception e) { } }
From source file:com.m2dl.mini_projet.mini_projet_android.fragment.PhotoDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.menu_photo_view, container, false); if (getArguments() != null) { mainActivity = ((MainActivity) getActivity()); myBitmap = getArguments().getParcelable(ARG_PHOTO); ImageView bitmapDialog = (ImageView) v.findViewById(R.id.imageView); bitmapDialog.setImageBitmap(myBitmap); coordLat = getArguments().getDouble(ARG_COORD_LAT); coordLong = getArguments().getDouble(ARG_COORD_LONG); imageFilePath = getArguments().getString(ARG_FILE_PATH); }/*from w ww .ja va2s . c o m*/ getDialog().setTitle("Uploader votre photo"); etPseudo = (EditText) v.findViewById(R.id.editTextPseudo); etTags = (EditText) v.findViewById(R.id.editTextTags); Button buttonAnnuler = (Button) v.findViewById(R.id.buttonAnnuler); buttonAnnuler.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { getDialog().dismiss(); } }); Button buttonConfirmer = (Button) v.findViewById(R.id.buttonConfirmer); buttonConfirmer.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Date currentDate = new Date(System.currentTimeMillis()); Boolean authorConfirmed, tagsConfirmed; if (!etPseudo.getText().toString().isEmpty()) { authorConfirmed = true; } else { authorConfirmed = false; etPseudo.setError("Ce champs est obligatoire"); } if (!etTags.getText().toString().isEmpty()) { tagsConfirmed = true; } else { tagsConfirmed = false; etTags.setError("Veuillez rentrer au moins un tag"); } if (tagsConfirmed && authorConfirmed) { final Photo myPhoto = new Photo(etPseudo.getText().toString(), coordLat, coordLong, currentDate); String[] myTags = etTags.getText().toString().split(","); for (String tag : myTags) { Tag myTag = new Tag(tag.replaceAll("\\s", "")); myPhoto.putTag(myTag); } String tag = etTags.getText().toString().replaceAll("\\s", ""); final boolean[] uploaded = { false }; final Image p = factory(myPhoto, tag, myBitmap); final Callback<Image> callback = new Callback<Image>() { @Override public void success(Image photo, Response response) { myPhoto.setUrl(photo.url()); mainActivity.putInPhotoMarkers(myPhoto); uploaded[0] = true; getDialog().dismiss(); } @Override public void failure(RetrofitError error) { System.err.println("Could not post photo"); } }; final SimpleImageTag simpleImageTag = ServiceGenerator.createService(SimpleImageTag.class); AsyncTask<InputStream, Void, String> task = new AsyncTask<InputStream, Void, String>() { @Override protected String doInBackground(InputStream... params) { String id = CloudinaryHelper.upload(params[0]); p.setId(id); simpleImageTag.postImage(p, callback); return id; } }; try { task.execute(new FileInputStream(new File(imageFilePath))); } catch (FileNotFoundException e) { e.printStackTrace(); } final ProgressDialog progDialog = ProgressDialog.show(mainActivity, "Upload de l'image en cours...", "Veuillez patienter", true); new Thread() { public void run() { try { while (!uploaded[0]) ; } catch (Exception e) { Log.e(MainActivity.TAG, e.getMessage()); } progDialog.dismiss(); } }.start(); } } }); return v; }
From source file:org.brandroid.openmanager.util.EventHandler.java
public static AsyncTask execute(AsyncTask job, String... params) { if (OpenExplorer.BEFORE_HONEYCOMB) job.execute((Object[]) params); else/*from www. ja va 2s .c o m*/ job.executeOnExecutor(getExecutor(), (Object[]) params); return job; }
From source file:org.brandroid.openmanager.util.EventHandler.java
public static AsyncTask execute(AsyncTask job, OpenFile... params) { if (OpenExplorer.BEFORE_HONEYCOMB) job.execute((Object[]) params); else/* ww w . j ava 2 s . c o m*/ job.executeOnExecutor(getExecutor(), (Object[]) params); return job; }
From source file:org.brandroid.openmanager.util.EventHandler.java
public static AsyncTask<OpenPath, Integer, Integer> execute(AsyncTask<OpenPath, Integer, Integer> job, OpenPath... params) {// w ww . ja v a2s.com if (OpenExplorer.BEFORE_HONEYCOMB) job.execute(params); else job.executeOnExecutor(getExecutor(), params); return job; }
From source file:org.tigase.mobile.muc.MucRoomFragment.java
protected void sendMessage() { if (ed == null) return;// www. ja v a 2s. c om String t = ed.getText().toString(); ed.setText(""); if (t == null || t.length() == 0) return; if (DEBUG) Log.d(TAG, "Send: " + t); AsyncTask<String, Void, Void> task = new AsyncTask<String, Void, Void>() { @Override public Void doInBackground(String... ts) { String t = ts[0]; Log.d(TAG, "Send: " + t); try { room.sendMessage(t); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return null; } }; task.execute(t); updatePresenceImage(); }
From source file:com.nononsenseapps.filepicker.sample.ftp.FtpPickerFragment.java
/** * Name is validated to be non-null, non-empty and not containing any * slashes./* w ww. j a v a2s .c o m*/ * * @param name The name of the folder the user wishes to create. */ @Override public void onNewFolder(@NonNull String name) { AsyncTask<String, Void, FtpFile> task = new AsyncTask<String, Void, FtpFile>() { @Override protected FtpFile doInBackground(String... names) { FtpFile result = null; if (names.length > 0) { result = onNewFolderAsync(names[0]); } return result; } @Override protected void onPostExecute(FtpFile folder) { if (folder != null) { refresh(folder); } else { Toast.makeText(getContext(), R.string.nnf_create_folder_error, Toast.LENGTH_SHORT).show(); } } }; task.execute(name); }
From source file:org.labcrypto.wideroid.helpers.DownloadHelper.java
public byte[] downloadAsByteArray(final String url) throws IOException { try {/*from ww w . j a v a2 s . co m*/ AsyncTask<Void, Void, byte[]> asyncTask = new AsyncTask<Void, Void, byte[]>() { @Override protected byte[] doInBackground(Void... params) { HttpGet httpGet = null; try { HttpClient httpClient = AndroidHttpClient.newInstance(""); httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() != 200) { return null; } return EntityUtils.toByteArray(httpResponse.getEntity()); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { try { if (httpGet != null) { httpGet.abort(); } } catch (Exception e) { } } } }; asyncTask.execute(new Void[] {}); return asyncTask.get(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:mr.robotto.MrRobottoEngine.java
/** * Loads the scene asynchronously// w w w . j a v a2s.com * @param inputStream stream containing the scene */ public void loadSceneTreeAsync(final InputStream inputStream) { AsyncTask<InputStream, Void, MrSceneTree> task = new AsyncTask<InputStream, Void, MrSceneTree>() { @Override protected MrSceneTree doInBackground(InputStream... params) { InputStream inputStream = params[0]; MrMrrLoader loader = new MrMrrLoader(inputStream); try { MrSceneTree tree = loader.parse(); return tree; } catch (IOException e) { cancel(true); e.printStackTrace(); } catch (JSONException e) { cancel(true); e.printStackTrace(); } return null; } @Override protected void onPostExecute(MrSceneTree tree) { super.onPostExecute(tree); if (tree != null) { mSceneTree = tree; mController = mSceneTree.getController(); //mController = new MrSceneTreeController(tree, new MrSceneTreeRender()); initialize(); } } }; task.execute(inputStream); }