Example usage for android.app ProgressDialog setProgressStyle

List of usage examples for android.app ProgressDialog setProgressStyle

Introduction

In this page you can find the example usage for android.app ProgressDialog setProgressStyle.

Prototype

public void setProgressStyle(int style) 

Source Link

Document

Sets the style of this ProgressDialog, either #STYLE_SPINNER or #STYLE_HORIZONTAL .

Usage

From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java

@Override
protected Dialog onCreateDialog(final int id, final Bundle bundle) {
    Dialog dialog = null;/*from   w  ww .j  a  v a 2s. co  m*/
    switch (id) {
    case DIALOG_DOWNLOAD_ID: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.")
                .setPositiveButton("OK", new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this);
                        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        progressDialog.setMessage("Downloading...");
                        progressDialog.setCancelable(true);
                        progressDialog.show();

                        String fileId = bundle.getString(JsonKeys.ID);
                        String name = bundle.getString(JsonKeys.NAME);

                        File file = new File(Environment.getExternalStorageDirectory(), name);

                        final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file,
                                new LiveDownloadOperationListener() {
                                    @Override
                                    public void onDownloadProgress(int totalBytes, int bytesRemaining,
                                            LiveDownloadOperation operation) {
                                        int percentCompleted = computePrecentCompleted(totalBytes,
                                                bytesRemaining);

                                        progressDialog.setProgress(percentCompleted);
                                    }

                                    @Override
                                    public void onDownloadFailed(LiveOperationException exception,
                                            LiveDownloadOperation operation) {
                                        progressDialog.dismiss();
                                        showToast(exception.getMessage());
                                    }

                                    @Override
                                    public void onDownloadCompleted(LiveDownloadOperation operation) {
                                        progressDialog.dismiss();
                                        showToast("File downloaded.");
                                    }
                                });

                        progressDialog.setOnCancelListener(new OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                operation.cancel();
                            }
                        });
                    }
                }).setNegativeButton("Cancel", new Dialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });

        dialog = builder.create();
        break;
    }
    }

    if (dialog != null) {
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                removeDialog(id);
            }
        });
    }

    return dialog;
}

From source file:de.baumann.hhsmoodle.helper.helper_main.java

public static void onClose(final Activity activity) {
    PreferenceManager.setDefaultValues(activity, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
    final ProgressDialog progressDialog;

    if (sharedPref.getBoolean("backup_aut", false)) {

        try {/*  w ww  .ja v  a2 s.  c  o m*/
            helper_security.encryptBackup(activity, "/bookmarks_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/courses_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/notes_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/random_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/subject_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/schedule_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/todo_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }

        progressDialog = new ProgressDialog(activity);
        progressDialog.setMessage(activity.getString(R.string.app_close));
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.show();

        new Handler().postDelayed(new Runnable() {
            public void run() {
                sharedPref.edit().putString("loadURL", "").apply();
                helper_security.encryptDatabases(activity);
                if (progressDialog.isShowing()) {
                    progressDialog.cancel();
                }
                activity.finishAffinity();
            }
        }, 1500);

    } else {
        sharedPref.edit().putString("loadURL", "").apply();
        helper_security.encryptDatabases(activity);
        activity.finishAffinity();
    }
}

From source file:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java

/**
 * Create the underlying dialog//from www  .  j a v a  2  s. c o  m
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    ProgressDialog dialog = new ProgressDialog(getActivity());
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(false);

    int msg = getArguments().getInt("title");
    if (msg != 0)
        dialog.setMessage(getActivity().getString(msg));
    final boolean isIndet = getArguments().getBoolean("isIndeterminate");
    dialog.setIndeterminate(isIndet);
    if (isIndet) {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    }

    // We can't use "this.requestUpdateProgress()" because getDialog() will still return null
    if (!isIndet) {
        dialog.setMax(mMax);
        dialog.setProgress(mProgress);
        if (mMessage != null)
            dialog.setMessage(mMessage);
        setDialogNumberFormat(dialog);
    }

    return dialog;
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Copies an item onto the current destination in the copy preferences
 * @param item The item to copy/*w  w  w.  j  av  a  2 s  .  c  o m*/
 */
private void copy(final Item item) {
    final BaseApplication app = (BaseApplication) getActivity().getApplication();
    final IOneDriveClient oneDriveClient = app.getOneDriveClient();
    final ItemReference parentReference = new ItemReference();
    parentReference.id = getCopyPrefs().getString(COPY_DESTINATION_PREF_KEY, null);

    final ProgressDialog dialog = new ProgressDialog(getActivity(), ProgressDialog.STYLE_HORIZONTAL);
    dialog.setTitle("Copying item");
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setMessage("Waiting for copy to complete");

    final IProgressCallback<Item> progressCallback = new IProgressCallback<Item>() {
        @Override
        public void progress(final long current, final long max) {
            dialog.setMax((int) current);
            dialog.setMax((int) max);
        }

        @Override
        public void success(final Item item) {
            dialog.dismiss();
            final String string = getString(R.string.copy_success_message, item.name,
                    item.parentReference.path);
            Toast.makeText(getActivity(), string, Toast.LENGTH_LONG).show();
        }

        @Override
        public void failure(final ClientException error) {
            dialog.dismiss();
            new AlertDialog.Builder(getActivity()).setTitle(R.string.error_title).setMessage(error.getMessage())
                    .setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }
    };

    final DefaultCallback<AsyncMonitor<Item>> callback = new DefaultCallback<AsyncMonitor<Item>>(
            getActivity()) {
        @Override
        public void success(final AsyncMonitor<Item> itemAsyncMonitor) {
            final int millisBetweenPoll = 1000;
            itemAsyncMonitor.pollForResult(millisBetweenPoll, progressCallback);
        }
    };
    oneDriveClient.getDrive().getItems(item.id).getCopy(item.name, parentReference).buildRequest()
            .create(callback);
    dialog.show();
}

From source file:com.cellbots.logger.LoggerActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id != PROGRESS_ID) {
        return super.onCreateDialog(id);
    }/*from  w  w  w  .j  a v a  2s. c o  m*/
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setCancelable(false);

    // The setMessage call must be in both onCreateDialog and
    // onPrepareDialog otherwise it will
    // fail to update the dialog in onPrepareDialog.
    progressDialog.setMessage("Processing...");

    return progressDialog;
}

From source file:uk.co.armedpineapple.cth.SDLActivity.java

private void installFiles(final SharedPreferences preferences) {
    final ProgressDialog dialog = new ProgressDialog(this);
    final UnzipTask unzipTask = new UnzipTask(app.configuration.getCthPath() + "/scripts/", this) {

        @Override/*from  w  w w  .  ja  v  a 2 s . co m*/
        protected void onPreExecute() {
            super.onPreExecute();
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dialog.setMessage(getString(R.string.preparing_game_files_dialog));
            dialog.setIndeterminate(false);
            dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            dialog.setProgress(values[0]);
            dialog.setMax(values[1]);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<String> result) {
            super.onPostExecute(result);
            Exception error;
            if ((error = result.getError()) != null) {
                Log.d(LOG_TAG, "Error copying files.");
                BugSenseHandler.sendException(error);
            }

            Editor edit = preferences.edit();
            edit.putBoolean("scripts_copied", true);
            edit.putInt("last_version", currentVersion);
            edit.commit();
            dialog.hide();
            loadApplication();
        }

    };

    AsyncTask<String, Void, AsyncTaskResult<File>> copyTask = new

    AsyncTask<String, Void, AsyncTaskResult<File>>() {

        @Override
        protected AsyncTaskResult<File> doInBackground(String... params) {

            try {
                Files.copyAsset(SDLActivity.this, params[0], params[1]);
            } catch (IOException e) {

                return new AsyncTaskResult<File>(e);
            }
            return new AsyncTaskResult<File>(new File(params[1] + "/" + params[0]));
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<File> result) {
            super.onPostExecute(result);
            File f;
            if ((f = result.getResult()) != null) {
                unzipTask.execute(f);
            } else {
                BugSenseHandler.sendException(result.getError());

            }
        }

    };

    if (Files.canAccessExternalStorage()) {

        copyTask.execute(ENGINE_ZIP_FILE, getExternalCacheDir().getAbsolutePath());
    } else {
        DialogFactory.createExternalStorageWarningDialog(this, true).show();
    }
}

From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java

private void uploadPhoto() {
    final ProgressDialog progress = new ProgressDialog(DetailsActivity.this);
    progress.setMessage(getResources().getString(R.string.send));
    progress.setTitle(getResources().getString(R.string.app_name));
    progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progress.show();//w w w  .  ja va 2  s.c om

    final File mediaFile = getStoredMediaFile();
    RequestBody file = RequestBody
            .create(MediaType.parse(URLConnection.guessContentTypeFromName(mediaFile.getName())), mediaFile);
    rsapi.photoUpload(email, token, bahnhof.getId(), countryCode.toLowerCase(), file)
            .enqueue(new Callback<Void>() {
                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                    progress.dismiss();
                    switch (response.code()) {
                    case 202:
                        new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_completed);
                        break;
                    case 400:
                        new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_bad_request);
                        break;
                    case 401:
                        new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_token_invalid);
                        break;
                    case 409:
                        new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_conflict);
                        break;
                    case 413:
                        new SimpleDialogs().confirm(DetailsActivity.this, R.string.upload_too_big);
                        break;
                    default:
                        new SimpleDialogs().confirm(DetailsActivity.this,
                                String.format(getText(R.string.upload_failed).toString(), response.code()));
                    }
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                    Log.e(TAG, "Error uploading photo", t);
                    progress.dismiss();
                    new SimpleDialogs().confirm(DetailsActivity.this,
                            String.format(getText(R.string.upload_failed).toString(), t.getMessage()));
                }
            });
}

From source file:com.example.android.camera2basic.fragments.Camera2BasicFragment.java

public void upload() {

    //Crea y muestra barra de progreso
    final ProgressDialog mProgressDialog = new ProgressDialog(getActivity());

    mProgressDialog.setIndeterminate(false);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setMessage("Subiendo foto...");

    mProgressDialog.show();/* w ww  .  j  av a2 s .c o m*/

    //Retrofit
    Retrofit retrofit = new Retrofit.Builder().baseUrl(FileUploadService.ENDPOINT)
            .addConverterFactory(GsonConverterFactory.create()).build();

    // create upload service client
    FileUploadService service = retrofit.create(FileUploadService.class);

    // create RequestBody instance from file
    RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), mFile);

    // MultipartBody.Part is used to send also the actual file name
    MultipartBody.Part body = MultipartBody.Part.createFormData("fichero", mFile.getName(), requestFile);

    // finally, execute the request
    Call<ResponseBody> call = service.upload(body);
    call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

            if (response.isSuccessful()) {
                mProgressDialog.hide();//Oculta progressDialog

                showToast("Upload picture success");

                Log.v(TAG, "success");
            } else {
                mProgressDialog.hide();//Oculta progressDialog

                showToast("Upload error:" + response.code());

                Log.e(TAG, "Code: " + response.code());
            }

        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            mProgressDialog.hide();//Oculta progressDialog

            showToast("Upload error:" + t.getMessage());

            Log.e(TAG, "onfailure: " + t.getMessage());
        }
    });

}

From source file:com.uraroji.garage.android.arrraycopybench.MainActivity.java

private void startBench() {
    mResultTextView.setText("");

    final String arrayTypeStr = mArrayTypeSpinner.getSelectedItem().toString();
    final int arrayLength = Integer.parseInt(mArrayLengthSpinner.getSelectedItem().toString());
    final int benchTimes = Integer.parseInt(mBenchTimesSpinner.getSelectedItem().toString());

    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(getString(R.string.benchmarking));
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setCancelable(false);/*  w ww.j  av  a 2  s.c  o m*/
    dialog.show();

    final Handler handler = new Handler();

    if (arrayTypeStr.equals("byte")) {
        final byte[] src = new byte[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = (byte) i;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                benchResult = copyNative(src, benchTimes);
                showResult("native", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("short")) {
        final short[] src = new short[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = (short) i;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                benchResult = copyNative(src, benchTimes);
                showResult("native", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("int")) {
        final int[] src = new int[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = (int) i;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                benchResult = copyNative(src, benchTimes);
                showResult("native", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("long")) {
        final long[] src = new long[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = (long) i;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                benchResult = copyNative(src, benchTimes);
                showResult("native", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("double")) {
        final double[] src = new double[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = (double) i;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                benchResult = copyNative(src, benchTimes);
                showResult("native", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("Object")) {
        final Object[] src = new Object[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = new Object();
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("Byte")) {
        final Byte[] src = new Byte[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = new Byte((byte) i);
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("Integer")) {
        final Integer[] src = new Integer[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = new Integer((int) i);
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("Long")) {
        final Long[] src = new Long[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = new Long((long) i);
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else if (arrayTypeStr.equals("Double")) {
        final Double[] src = new Double[arrayLength];
        for (int i = 0; i < src.length; ++i) {
            src[i] = new Double((double) i);
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                BenchResult benchResult = null;

                benchResult = copyClone(src, benchTimes);
                showResult("clone", benchResult, handler);

                benchResult = copyArraycopy(src, benchTimes);
                showResult("System.arraycopy", benchResult, handler);

                benchResult = copyArraysCopyOf(src, benchTimes);
                showResult("Arrays.copyOf", benchResult, handler);

                benchResult = copyForLoop(src, benchTimes);
                showResult("for loop", benchResult, handler);

                dialog.dismiss();
            }
        }).start();
    } else {
        dialog.dismiss();
    }
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final BaseApplication application = (BaseApplication) getActivity().getApplication();
    final IOneDriveClient oneDriveClient = application.getOneDriveClient();

    if (requestCode == REQUEST_CODE_SIMPLE_UPLOAD && data != null && data.getData() != null
            && data.getData().getScheme().equalsIgnoreCase(SCHEME_CONTENT)) {

        final ProgressDialog dialog = new ProgressDialog(getActivity());
        dialog.setTitle(R.string.upload_in_progress_title);
        dialog.setMessage(getString(R.string.upload_in_progress_message));
        dialog.setIndeterminate(false);/*from  w  w w.j  a  v  a 2 s  .c o  m*/
        dialog.setCancelable(false);
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgressNumberFormat(getString(R.string.upload_in_progress_number_format));
        dialog.show();
        final AsyncTask<Void, Void, Void> uploadFile = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(final Void... params) {
                try {
                    final ContentResolver contentResolver = getActivity().getContentResolver();
                    final ContentProviderClient contentProvider = contentResolver
                            .acquireContentProviderClient(data.getData());
                    final byte[] fileInMemory = FileContent.getFileBytes(contentProvider, data.getData());
                    contentProvider.release();

                    // Fix up the file name (needed for camera roll photos, etc)
                    final String filename = FileContent.getValidFileName(contentResolver, data.getData());
                    final Option option = new QueryOption("@name.conflictBehavior", "fail");
                    oneDriveClient.getDrive().getItems(mItemId).getChildren().byId(filename).getContent()
                            .buildRequest(Collections.singletonList(option))
                            .put(fileInMemory, new IProgressCallback<Item>() {
                                @Override
                                public void success(final Item item) {
                                    dialog.dismiss();
                                    Toast.makeText(getActivity(),
                                            application.getString(R.string.upload_complete, item.name),
                                            Toast.LENGTH_LONG).show();
                                    refresh();
                                }

                                @Override
                                public void failure(final ClientException error) {
                                    dialog.dismiss();
                                    if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) {
                                        Toast.makeText(getActivity(), R.string.upload_failed_name_conflict,
                                                Toast.LENGTH_LONG).show();
                                    } else {
                                        Toast.makeText(getActivity(),
                                                application.getString(R.string.upload_failed, filename),
                                                Toast.LENGTH_LONG).show();
                                    }
                                }

                                @Override
                                public void progress(final long current, final long max) {
                                    dialog.setProgress((int) current);
                                    dialog.setMax((int) max);
                                }
                            });
                } catch (final Exception e) {
                    Log.e(getClass().getSimpleName(), e.getMessage());
                    Log.e(getClass().getSimpleName(), e.toString());
                }
                return null;
            }
        };
        uploadFile.execute();
    }
}