Guest User

Untitled

a guest
Aug 1st, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. // //////////////////////////////////
  2.  
  3. /**
  4. *
  5. * Async Task to upload media
  6. */
  7. // INNER CLASSS teitterrrrrrrrrrrrrrrrrrrr
  8. public class UploadMediaAsyncTask extends AsyncTask<Void, Void, Void> {
  9.  
  10. private final ProgressDialog dialog = new ProgressDialog(activity);
  11.  
  12. protected void onPreExecute() {
  13. this.dialog.setMessage("Downloading...");
  14. this.dialog.setCancelable(false);
  15. this.dialog.show();
  16. }
  17.  
  18. //
  19. //
  20. protected Void doInBackground(Void... params) {
  21.  
  22. if (finalurl != null) {
  23. URL url = null;
  24. try {
  25. url = new URL(finalurl);
  26. } catch (MalformedURLException e) {
  27. // TODO Auto-generated catch block
  28. e.printStackTrace();
  29. }
  30. InputStream input = null;
  31. try {
  32. input = url.openStream();
  33. } catch (IOException e) {
  34. // TODO Auto-generated catch block
  35. e.printStackTrace();
  36. }
  37. try {
  38. String filename = name + ".jpg";
  39. File storagePath = (Environment
  40. .getExternalStorageDirectory());
  41. File dest = new File(storagePath + "/CityAppImages");
  42. String dessdt = dest.getAbsolutePath();
  43.  
  44. Log.d("sss", "ass " + dessdt);
  45. if (!dest.exists()) {
  46. dest.mkdirs();
  47.  
  48. }
  49.  
  50. File city = new File(dest, filename);
  51.  
  52. imagePath = city.getAbsolutePath();
  53.  
  54. Log.d("qqqqqqqqqqqqqqqqqqqqqqq", "zz " + imagePath);
  55.  
  56. FileOutputStream output = new FileOutputStream(city);
  57.  
  58. try {
  59. byte[] buffer = new byte[1024];
  60.  
  61. Log.d("buffer", "dddddddddddddddddddd" + buffer);
  62. int bytesRead = 0;
  63. while ((bytesRead = input
  64. .read(buffer, 0, buffer.length)) >= 0) {
  65. output.write(buffer, 0, bytesRead);
  66. }
  67. } catch (IOException e) {
  68. // TODO Auto-generated catch block
  69. e.printStackTrace();
  70. }
  71.  
  72. try {
  73. output.close();
  74. } catch (IOException e) {
  75. // TODO Auto-generated catch block
  76. e.printStackTrace();
  77. }
  78.  
  79. } catch (FileNotFoundException e) {
  80. // TODO Auto-generated catch block
  81. e.printStackTrace();
  82. }
  83.  
  84. try {
  85. input.close();
  86. } catch (IOException e) {
  87. // TODO Auto-generated catch block
  88. e.printStackTrace();
  89. }
  90. }
  91.  
  92. return null;
  93.  
  94. // (null);
  95.  
  96. }
  97.  
  98. protected void onPostExecute(Void result) {
  99.  
  100. // Here if you wish to do future process for ex. move to another
  101. // activity do here
  102.  
  103. // if (dialog.isShowing()) {
  104. // dialog.dismiss();
  105.  
  106. // if (imagePath != null) {
  107.  
  108. // BitmapFactory.Options options = new BitmapFactory.Options();
  109. //
  110. // Log.d("sssss", "dddddd");
  111. // options.inJustDecodeBounds = true;
  112. // // image path `String` where your image is located
  113. // BitmapFactory.decodeFile(imagePath, options);
  114. //
  115. // int bitmapWidth = 400;
  116. // int bitmapHeight = 250;
  117. // final int height = options.outHeight;
  118. // final int width = options.outWidth;
  119. // int inSampleSize = 1;
  120. // if (height > bitmapHeight || width > bitmapWidth) {
  121. // if (width > height) {
  122. // inSampleSize = Math.round((float) height
  123. // / (float) bitmapHeight);
  124. // } else {
  125. // inSampleSize = Math.round((float) width
  126. // / (float) bitmapWidth);
  127. // }
  128. // }
  129. //
  130. // options.inJustDecodeBounds = false;
  131. // options.inSampleSize = inSampleSize;
  132. //
  133. // bmpScalef = BitmapFactory.decodeFile(imagePath, options);
  134. //
  135. // // imgggg.setImageBitmap(bmpScale);
  136. // ByteArrayOutputStream bos = new ByteArrayOutputStream();
  137. //
  138. // // bmpScale.compress(CompressFormat.JPEG, 100, bos);
  139. // bmpScalef.compress(CompressFormat.JPEG, 75, bos);
  140. //
  141. // // globaly..................................
  142. // data = bos.toByteArray();
  143. Log.d("ssss", "sssss");
  144.  
  145. // }
  146.  
  147. // }
  148.  
  149. if (dialog.isShowing()) {
  150. dialog.dismiss();
  151. // up_edittextbox.setText("");
  152. }
  153. if (imagePath != null) {
  154. abc();
  155. }
  156.  
  157. }
  158.  
  159. private void abc() {
  160. // TODO Auto-generated method stub
  161.  
  162. Intent ii = new Intent(activity, TwiiterFinally.class);
  163. ii.putExtra("imagePath", imagePath);
  164. ii.putExtra("text", "");
  165. activity.startActivity(ii);
  166. }
  167.  
  168. }
  169.  
  170. public String dateToString(Date date, String format) {
  171. SimpleDateFormat df = new SimpleDateFormat(format);
  172. return df.format(date);
  173. }
Advertisement
Add Comment
Please, Sign In to add comment