List of usage examples for android.widget ProgressBar setProgress
@android.view.RemotableViewMethod public synchronized void setProgress(int progress)
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
private void uploadVideoToServer(String file, final Message menssage, final JSONObject dataSend, final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText, final ImageView messageContent) { try {// w ww . ja v a 2 s.c om RequestParams p = new RequestParams(); final File archivo = new File(file); p.put("video", archivo); activity.runOnUiThread(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressText.setText("0%"); } }); SpeakHttp.client.setTimeout(70000); SpeakHttp.client.setResponseTimeout(70000); SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/video", p, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, final JSONObject response) { super.onSuccess(statusCode, headers, response); try { JSONObject jsonObject = response.getJSONObject("data_response"); JSONArray photoArray = new JSONArray(); photoArray.put(0, jsonObject.getString("file_name")); dataSend.put("videos", photoArray); menssage.fileName = photoArray.toString(); } catch (JSONException e) { e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { menssage.status = 1; SpeakSocket.mSocket.emit("message", dataSend); } else { menssage.status = -1; } menssage.fileUploaded = true; menssage.save(); activity.runOnUiThread(new Runnable() { @Override public void run() { if (menssage.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(menssage.photo, 0, menssage.photo.length); messageContent.setImageBitmap(bmp); progressLayout.setVisibility(View.GONE); System.gc(); } } }); } @Override public void onProgress(final long bytesWritten, final long totalSize) { if (bytesWritten != totalSize) { activity.runOnUiThread(new Runnable() { @Override public void run() { double prog = (100 / (double) totalSize) * (double) bytesWritten; progressBar.setProgress((int) Math.round(prog)); progressText.setText((int) Math.round(prog) + "%"); Log.e("PROGRESO", (int) Math.round(prog) + ""); } }); } } @Override public void onFinish() { System.gc(); } }, activity); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
private void uploadAudioToServer(String file, final MsgGroups menssage, final JSONObject dataSend, final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText) { try {//www .java2s . co m RequestParams p = new RequestParams(); File archivo = new File(file); p.put("audio", archivo); activity.runOnUiThread(new Runnable() { @Override public void run() { progressText.setText("0%"); } }); SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/audio", p, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, final JSONObject response) { super.onSuccess(statusCode, headers, response); try { final JSONObject dataResponse = response.getJSONObject("data_response"); Log.e("Respuesta", dataResponse.toString()); JSONArray photoArray = new JSONArray(); photoArray.put(0, dataResponse.getString("file_name")); dataSend.put("audios", photoArray); menssage.fileName = photoArray.toString(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")) .executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (menssage.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); targets.put(targets.length(), newContact); } } } dataSend.put("targets", targets); menssage.receptores = targets.toString(); SpeakSocket.mSocket.emit("message", dataSend); } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")) .executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (menssage.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); targets.put(targets.length(), newContact); } } } menssage.receptores = targets.toString(); } } } catch (JSONException e) { e.printStackTrace(); } menssage.fileUploaded = true; menssage.save(); activity.runOnUiThread(new Runnable() { @Override public void run() { progressLayout.setVisibility(View.GONE); System.gc(); } }); } @Override public void onProgress(final long bytesWritten, final long totalSize) { if (bytesWritten != totalSize) { activity.runOnUiThread(new Runnable() { @Override public void run() { double prog = (100 / (double) totalSize) * (double) bytesWritten; progressBar.setProgress((int) Math.round(prog)); progressText.setText((int) Math.round(prog) + "%"); Log.e("PROGRESO", (int) Math.round(prog) + ""); } }); } } @Override public void onFinish() { System.gc(); } }, activity); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
private void uploadPhotoToServer(String file, final MsgGroups menssage, final JSONObject dataSend, final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText, final ImageView messageContent) { try {//ww w . j a v a 2 s . c o m RequestParams p = new RequestParams(); final File archivo = new File(file); p.put("image", archivo); activity.runOnUiThread(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressText.setText("0%"); } }); SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/photo", p, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, final JSONObject response) { super.onSuccess(statusCode, headers, response); try { JSONObject jsonObject = response.getJSONObject("data_response"); JSONArray photoArray = new JSONArray(); photoArray.put(0, jsonObject.getString("file_name")); dataSend.put("photos", photoArray); menssage.fileName = photoArray.toString(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")) .executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (menssage.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); targets.put(targets.length(), newContact); } } } dataSend.put("targets", targets); menssage.receptores = targets.toString(); SpeakSocket.mSocket.emit("message", dataSend); } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")) .executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (menssage.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); targets.put(targets.length(), newContact); } } } menssage.receptores = targets.toString(); } } } catch (JSONException e) { e.printStackTrace(); } menssage.fileUploaded = true; menssage.save(); activity.runOnUiThread(new Runnable() { @Override public void run() { if (menssage.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(menssage.photo, 0, menssage.photo.length); messageContent.setImageBitmap(bmp); progressLayout.setVisibility(View.GONE); System.gc(); } } }); } @Override public void onProgress(final long bytesWritten, final long totalSize) { if (bytesWritten != totalSize) { activity.runOnUiThread(new Runnable() { @Override public void run() { double prog = (100 / (double) totalSize) * (double) bytesWritten; progressBar.setProgress((int) Math.round(prog)); progressText.setText((int) Math.round(prog) + "%"); } }); } } @Override public void onFinish() { System.gc(); } }, activity); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
private void uploadVideoToServer(String file, final MsgGroups menssage, final JSONObject dataSend, final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText, final ImageView messageContent) { try {//from w w w . j av a 2 s .c o m RequestParams p = new RequestParams(); final File archivo = new File(file); p.put("video", archivo); activity.runOnUiThread(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressText.setText("0%"); } }); SpeakHttp.client.setTimeout(70000); SpeakHttp.client.setResponseTimeout(70000); SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/video", p, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, final JSONObject response) { super.onSuccess(statusCode, headers, response); try { JSONObject jsonObject = response.getJSONObject("data_response"); JSONArray photoArray = new JSONArray(); photoArray.put(0, jsonObject.getString("file_name")); dataSend.put("videos", photoArray); menssage.fileName = photoArray.toString(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")) .executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (menssage.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); targets.put(targets.length(), newContact); } } } dataSend.put("targets", targets); menssage.receptores = targets.toString(); SpeakSocket.mSocket.emit("message", dataSend); } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")) .executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (menssage.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); targets.put(targets.length(), newContact); } } } menssage.receptores = targets.toString(); } } } catch (JSONException e) { e.printStackTrace(); } menssage.fileUploaded = true; menssage.save(); activity.runOnUiThread(new Runnable() { @Override public void run() { if (menssage.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(menssage.photo, 0, menssage.photo.length); messageContent.setImageBitmap(bmp); progressLayout.setVisibility(View.GONE); System.gc(); } } }); } @Override public void onProgress(final long bytesWritten, final long totalSize) { if (bytesWritten != totalSize) { activity.runOnUiThread(new Runnable() { @Override public void run() { double prog = (100 / (double) totalSize) * (double) bytesWritten; progressBar.setProgress((int) Math.round(prog)); progressText.setText((int) Math.round(prog) + "%"); } }); } } @Override public void onFinish() { System.gc(); } }, activity); } catch (FileNotFoundException e) { e.printStackTrace(); } }