Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // //////////////////////////////////
- /**
- *
- * Async Task to upload media
- */
- // INNER CLASSS teitterrrrrrrrrrrrrrrrrrrr
- public class UploadMediaAsyncTask extends AsyncTask<Void, Void, Void> {
- private final ProgressDialog dialog = new ProgressDialog(activity);
- protected void onPreExecute() {
- this.dialog.setMessage("Downloading...");
- this.dialog.setCancelable(false);
- this.dialog.show();
- }
- //
- //
- protected Void doInBackground(Void... params) {
- if (finalurl != null) {
- URL url = null;
- try {
- url = new URL(finalurl);
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- InputStream input = null;
- try {
- input = url.openStream();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- String filename = name + ".jpg";
- File storagePath = (Environment
- .getExternalStorageDirectory());
- File dest = new File(storagePath + "/CityAppImages");
- String dessdt = dest.getAbsolutePath();
- Log.d("sss", "ass " + dessdt);
- if (!dest.exists()) {
- dest.mkdirs();
- }
- File city = new File(dest, filename);
- imagePath = city.getAbsolutePath();
- Log.d("qqqqqqqqqqqqqqqqqqqqqqq", "zz " + imagePath);
- FileOutputStream output = new FileOutputStream(city);
- try {
- byte[] buffer = new byte[1024];
- Log.d("buffer", "dddddddddddddddddddd" + buffer);
- int bytesRead = 0;
- while ((bytesRead = input
- .read(buffer, 0, buffer.length)) >= 0) {
- output.write(buffer, 0, bytesRead);
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- output.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- input.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return null;
- // (null);
- }
- protected void onPostExecute(Void result) {
- // Here if you wish to do future process for ex. move to another
- // activity do here
- // if (dialog.isShowing()) {
- // dialog.dismiss();
- // if (imagePath != null) {
- // BitmapFactory.Options options = new BitmapFactory.Options();
- //
- // Log.d("sssss", "dddddd");
- // options.inJustDecodeBounds = true;
- // // image path `String` where your image is located
- // BitmapFactory.decodeFile(imagePath, options);
- //
- // int bitmapWidth = 400;
- // int bitmapHeight = 250;
- // final int height = options.outHeight;
- // final int width = options.outWidth;
- // int inSampleSize = 1;
- // if (height > bitmapHeight || width > bitmapWidth) {
- // if (width > height) {
- // inSampleSize = Math.round((float) height
- // / (float) bitmapHeight);
- // } else {
- // inSampleSize = Math.round((float) width
- // / (float) bitmapWidth);
- // }
- // }
- //
- // options.inJustDecodeBounds = false;
- // options.inSampleSize = inSampleSize;
- //
- // bmpScalef = BitmapFactory.decodeFile(imagePath, options);
- //
- // // imgggg.setImageBitmap(bmpScale);
- // ByteArrayOutputStream bos = new ByteArrayOutputStream();
- //
- // // bmpScale.compress(CompressFormat.JPEG, 100, bos);
- // bmpScalef.compress(CompressFormat.JPEG, 75, bos);
- //
- // // globaly..................................
- // data = bos.toByteArray();
- Log.d("ssss", "sssss");
- // }
- // }
- if (dialog.isShowing()) {
- dialog.dismiss();
- // up_edittextbox.setText("");
- }
- if (imagePath != null) {
- abc();
- }
- }
- private void abc() {
- // TODO Auto-generated method stub
- Intent ii = new Intent(activity, TwiiterFinally.class);
- ii.putExtra("imagePath", imagePath);
- ii.putExtra("text", "");
- activity.startActivity(ii);
- }
- }
- public String dateToString(Date date, String format) {
- SimpleDateFormat df = new SimpleDateFormat(format);
- return df.format(date);
- }
Advertisement
Add Comment
Please, Sign In to add comment