Example usage for android.app ProgressDialog STYLE_HORIZONTAL

List of usage examples for android.app ProgressDialog STYLE_HORIZONTAL

Introduction

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

Prototype

int STYLE_HORIZONTAL

To view the source code for android.app ProgressDialog STYLE_HORIZONTAL.

Click Source Link

Document

Creates a ProgressDialog with a horizontal progress bar.

Usage

From source file:org.liberty.android.fantastischmemopro.downloader.DownloaderAnyMemo.java

private void downloadDatabase(final DownloadItem di) throws Exception {
    String filename = di.getExtras("filename");
    if (filename == null) {
        throw new Exception("Could not get filename");
    }/* www.j ava2  s.co m*/

    String sdpath = Environment.getExternalStorageDirectory().getAbsolutePath()
            + getString(R.string.default_dir);
    File outFile = new File(sdpath + filename);
    mHandler.post(new Runnable() {
        public void run() {
            mProgressDialog = new ProgressDialog(DownloaderAnyMemo.this);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgressDialog.setMessage(getString(R.string.loading_downloading));
            mProgressDialog.show();

        }
    });
    try {
        OutputStream out;
        if (outFile.exists()) {
            throw new IOException("Database already exist!");
        }
        try {
            outFile.createNewFile();
            out = new FileOutputStream(outFile);

            URL myURL = new URL(di.getAddress());
            Log.v(TAG, "URL IS: " + myURL);
            URLConnection ucon = myURL.openConnection();
            final int fileSize = ucon.getContentLength();
            mHandler.post(new Runnable() {
                public void run() {
                    mProgressDialog.setMax(fileSize);
                }
            });

            byte[] buf = new byte[8192];

            InputStream is = ucon.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is, 8192);
            Runnable increaseProgress = new Runnable() {
                public void run() {
                    mProgressDialog.setProgress(mDownloadProgress);
                }
            };
            int len = 0;
            int lenSum = 0;
            while ((len = bis.read(buf)) != -1) {
                out.write(buf, 0, len);
                lenSum += len;
                if (lenSum > fileSize / 50) {
                    /* This is tricky.
                     * The UI thread can not be updated too often.
                     * So we update it only 50 times
                     */
                    mDownloadProgress += lenSum;
                    lenSum = 0;
                    mHandler.post(increaseProgress);
                }
            }
            out.close();
            is.close();
            /* Uncompress the zip file that contains images */
            if (filename.endsWith(".zip")) {
                mHandler.post(new Runnable() {
                    public void run() {
                        mProgressDialog.setProgress(fileSize);
                        mProgressDialog.setMessage(getString(R.string.downloader_extract_zip));
                    }
                });

                BufferedOutputStream dest = null;
                BufferedInputStream ins = null;
                ZipEntry entry;
                ZipFile zipfile = new ZipFile(outFile);
                Enumeration<?> e = zipfile.entries();
                while (e.hasMoreElements()) {
                    entry = (ZipEntry) e.nextElement();
                    Log.v(TAG, "Extracting: " + entry);
                    if (entry.isDirectory()) {
                        new File(sdpath + "/" + entry.getName()).mkdir();
                    } else {
                        ins = new BufferedInputStream(zipfile.getInputStream(entry), 8192);
                        int count;
                        byte data[] = new byte[8192];
                        FileOutputStream fos = new FileOutputStream(sdpath + "/" + entry.getName());
                        dest = new BufferedOutputStream(fos, 8192);
                        while ((count = ins.read(data, 0, 8192)) != -1) {
                            dest.write(data, 0, count);
                        }
                        dest.flush();
                        dest.close();
                        ins.close();
                    }
                }
                /* Delete the zip file if it is successfully decompressed */
                outFile.delete();
            }
            /* We do not check ttf file as db */
            if (!filename.toLowerCase().endsWith(".ttf")) {
                /* Check if the db is correct */
                filename = filename.replace(".zip", ".db");
                DatabaseHelper dh = new DatabaseHelper(DownloaderAnyMemo.this, sdpath, filename);
                dh.close();
            }
        } catch (Exception e) {
            if (outFile.exists()) {
                outFile.delete();
            }
            throw new Exception(e);
        }

    } catch (Exception e) {
        Log.e(TAG, "Error downloading", e);
        throw new Exception(e);
    } finally {
        mHandler.post(new Runnable() {
            public void run() {
                mProgressDialog.dismiss();
            }
        });
    }

}

From source file:com.trailbehind.android.iburn.map.MapActivity.java

protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ABOUT:
        final ScrollView dialogView = (ScrollView) LayoutInflater.from(getBaseContext())
                .inflate(R.layout.about_dialog, null);
        final TextView aboutText = (TextView) dialogView.findViewById(R.id.message);
        aboutText.setText(Utils.getAboutText(getBaseContext()));

        final String title = getString(R.string.title_dialog_about) + " " + getString(R.string.app_name);
        return new AlertDialog.Builder(this).setView(dialogView).setIcon(R.drawable.icon).setTitle(title)
                .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }//  w w w.  j  a  v a 2s. com
                }).create();
    case DIALOG_NO_INTERNET_DOWNLOAD:
        return new AlertDialog.Builder(MapActivity.this).setTitle(R.string.title_dialog_error)
                .setMessage(R.string.error_no_internet_download)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        removeDialog(DIALOG_NO_INTERNET_DOWNLOAD);
                    }
                }).create();
    case DIALOG_SDCARD_NOT_AVAILABLE:
        return new AlertDialog.Builder(this).setIcon(R.drawable.ic_dialog_menu_generic)
                .setTitle(R.string.title_dialog_error).setMessage(R.string.error_sd_not_available)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        removeDialog(DIALOG_SDCARD_NOT_AVAILABLE);
                    }
                }).create();
    case DIALOG_DOWNLOAD_PROGRESS:
        mProgressDialog = new ProgressDialog(MapActivity.this);
        mProgressDialog.setTitle(R.string.title_dialog_download);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog.setButton(getText(android.R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                removeDialog(DIALOG_DOWNLOAD_PROGRESS);
                for (int i = 0, len = mMapDownloadThreads.length; i < len; i++) {
                    MapDownloadThread t = mMapDownloadThreads[i];
                    if (t != null) {
                        t.cancel();
                    }
                    mMapDownloadThreads[i] = null;
                }

                mFileCacheWriter.stopRunning();
                mFileCacheWriter = null;
            }
        });
        return mProgressDialog;
    case DIALOG_DOWNLOAD_ERROR:
        return new AlertDialog.Builder(MapActivity.this).setIcon(R.drawable.ic_dialog_menu_generic)
                .setTitle(R.string.title_dialog_error).setMessage(mErrorMsgId)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        removeDialog(DIALOG_SDCARD_NOT_AVAILABLE);
                    }
                }).create();
    default:
        return null;
    }
}

From source file:at.jclehner.rxdroid.Backup.java

private static void encryptAll(final Context context, final String key, final Runnable callback) {
    new AsyncTask<Void, String, Exception>() {
        private ProgressDialog mDialog;
        private List<File> mFiles;

        @Override/*from   www  .j  a  v a 2 s.c om*/
        protected void onPreExecute() {
            mFiles = Backup.getBackupFiles(context);

            mDialog = new ProgressDialog(context);
            mDialog.setTitle(R.string._msg_encrypting);
            mDialog.setCancelable(false);
            mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mDialog.setIndeterminate(false);
            mDialog.setMax(mFiles.size());
            mDialog.setProgress(0);
            mDialog.show();
        }

        @Override
        protected Exception doInBackground(Void... params) {
            int progress = 0;

            for (File file : mFiles) {
                try {
                    Backup.encrypt(context, file, key);
                } catch (IOException | ZipException e) {
                    Log.w(TAG, e);
                    return e;
                }

                mDialog.setProgress(progress++);
            }

            return null;
        }

        @Override
        protected void onCancelled() {
            super.onCancelled();
        }

        @Override
        protected void onPostExecute(Exception e) {
            if (mDialog != null) {
                mDialog.dismiss();
                mDialog = null;
            }

            if (e != null)
                Util.showExceptionDialog(mDialog.getContext(), e);
            else if (callback != null)
                callback.run();

        }
    }.execute();
}

From source file:org.skt.runtime.original.Notification.java

/**
 * Show the progress dialog.//from w  ww  . ja v  a2  s. com
 * 
 * @param title     Title of the dialog
 * @param message   The message of the dialog
 */
public synchronized void progressStart(final String title, final String message) {
    if (this.progressDialog != null) {
        this.progressDialog.dismiss();
        this.progressDialog = null;
    }
    final Notification notification = this;
    final RuntimeInterface ctx = this.ctx;
    Runnable runnable = new Runnable() {
        public void run() {
            notification.progressDialog = new ProgressDialog(ctx.getContext());
            notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            notification.progressDialog.setTitle(title);
            notification.progressDialog.setMessage(message);
            notification.progressDialog.setCancelable(true);
            notification.progressDialog.setMax(100);
            notification.progressDialog.setProgress(0);
            notification.progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    notification.progressDialog = null;
                }
            });
            notification.progressDialog.show();
        }
    };
    this.ctx.runOnUiThread(runnable);
}

From source file:gov.sfmta.sfpark.AnnotationsOverlay.java

public void loadOverlaysProgress(boolean showprice) {

    myShowPrice = showprice;/*from   ww w.  j  a  va  2  s .c o  m*/
    mOverlays.clear();

    Log.v(TAG, "Drawing annotations");

    pd = new ProgressDialog(mContext);
    pd.setCancelable(false);
    pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    pd.setMessage("Calculating availability");
    pd.setProgress(0);
    pd.setMax(MainScreenActivity.annotations.size());
    pd.show();

    ld = new LoadOverlaysTask();
    ld.execute("String");
}

From source file:fi.mikuz.boarder.gui.DropboxMenu.java

public void initializeTransfer(final ArrayList<String> boards, final boolean cleanUnusedFiles) {

    mWaitDialog = new ProgressDialog(this);
    mWaitDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mWaitDialog.setMessage("Please wait");
    mWaitDialog.show();/*www .j  a  v  a  2 s.c  o  m*/

    t = new Thread() {
        public void run() {
            Looper.prepare();

            DropboxAPI.Account account = null;
            try {
                account = mApi.accountInfo();
            } catch (DropboxException e) {
                Log.e(TAG, "Account info missing", e);
            }

            if (account != null) {

                if (mOperation == UPLOAD_OPERATION) {
                    upload(boards, cleanUnusedFiles);
                } else if (mOperation == DOWNLOAD_OPERATION) {
                    download(boards, cleanUnusedFiles);
                }
            } else {
                mWaitDialog.dismiss();
            }
        }
    };
    t.start();
}

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/*from   ww w.  j av a  2  s  .co 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:org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper.java

public void cryptoOperation(final CryptoInputParcel cryptoInput) {

    FragmentActivity activity = mUseFragment ? mFragment.getActivity() : mActivity;

    T operationInput = mCallback.createOperationInput();
    if (operationInput == null) {
        return;/*from www .ja va  2 s  . c o m*/
    }

    // Send all information needed to service to edit key in other thread
    Intent intent = new Intent(activity, KeychainService.class);

    intent.putExtra(KeychainService.EXTRA_OPERATION_INPUT, operationInput);
    intent.putExtra(KeychainService.EXTRA_CRYPTO_INPUT, cryptoInput);

    ServiceProgressHandler saveHandler = new ServiceProgressHandler(activity) {
        @Override
        public void handleMessage(Message message) {
            // handle messages by standard KeychainIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == MessageStatus.OKAY.ordinal()) {

                // get returned data bundle
                Bundle returnData = message.getData();
                if (returnData == null) {
                    return;
                }

                final OperationResult result = returnData.getParcelable(OperationResult.EXTRA_RESULT);

                onHandleResult(result);
            }
        }

        @Override
        protected void onSetProgress(String msg, int progress, int max) {
            // allow handling of progress in fragment, or delegate upwards
            if (!mCallback.onCryptoSetProgress(msg, progress, max)) {
                super.onSetProgress(msg, progress, max);
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger);

    if (mProgressMessageResource != null) {
        saveHandler.showProgressDialog(activity.getString(mProgressMessageResource),
                ProgressDialog.STYLE_HORIZONTAL, mCancellable);
    }

    activity.startService(intent);
}

From source file:org.thialfihar.android.apg.ui.EncryptFileFragment.java

private void encryptStart() {
    // Send all information needed to service to edit key in other thread
    Intent intent = new Intent(getActivity(), ApgIntentService.class);

    intent.setAction(ApgIntentService.ACTION_ENCRYPT_SIGN);

    // fill values for this action
    Bundle data = new Bundle();

    data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_URI);

    if (mEncryptInterface.isModeSymmetric()) {
        Log.d(Constants.TAG, "Symmetric encryption enabled!");
        String passphrase = mEncryptInterface.getPassphrase();
        if (passphrase.length() == 0) {
            passphrase = null;/*  w w  w  . j  a v a2 s.  co m*/
        }
        data.putString(ApgIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase);
    } else {
        data.putLong(ApgIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey());
        data.putLongArray(ApgIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys());
    }

    Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename=" + mOutputFilename);

    data.putString(ApgIntentService.ENCRYPT_INPUT_FILE, mInputFilename);
    data.putString(ApgIntentService.ENCRYPT_OUTPUT_FILE, mOutputFilename);

    boolean useAsciiArmor = mAsciiArmor.isChecked();
    data.putBoolean(ApgIntentService.ENCRYPT_USE_ASCII_ARMOR, useAsciiArmor);

    int compressionId = ((Choice) mFileCompression.getSelectedItem()).getId();
    data.putInt(ApgIntentService.ENCRYPT_COMPRESSION_ID, compressionId);

    intent.putExtra(ApgIntentService.EXTRA_DATA, data);

    // Message is received after encrypting is done in ApgIntentService
    ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(getActivity(),
            getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
        public void handleMessage(Message message) {
            // handle messages by standard ApgIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
                AppMsg.makeText(getActivity(), R.string.encrypt_sign_successful, AppMsg.STYLE_INFO).show();

                if (mDeleteAfter.isChecked()) {
                    // Create and show dialog to delete original file
                    DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                            .newInstance(mInputFilename);
                    deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
                }

                if (mShareAfter.isChecked()) {
                    // Share encrypted file
                    Intent sendFileIntent = new Intent(Intent.ACTION_SEND);
                    sendFileIntent.setType("*/*");
                    sendFileIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(mOutputFilename));
                    startActivity(Intent.createChooser(sendFileIntent, getString(R.string.title_share_file)));
                }
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    saveHandler.showProgressDialog(getActivity());

    // start service with intent
    getActivity().startService(intent);
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFileFragment.java

private void encryptStart() {
    // Send all information needed to service to edit key in other thread
    Intent intent = new Intent(getActivity(), KeychainIntentService.class);

    intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN);

    // fill values for this action
    Bundle data = new Bundle();

    data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_URI);

    if (mEncryptInterface.isModeSymmetric()) {
        Log.d(Constants.TAG, "Symmetric encryption enabled!");
        String passphrase = mEncryptInterface.getPassphrase();
        if (passphrase.length() == 0) {
            passphrase = null;/*from  w  w  w  . java  2s  . co  m*/
        }
        data.putString(KeychainIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase);
    } else {
        data.putLong(KeychainIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey());
        data.putLongArray(KeychainIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS,
                mEncryptInterface.getEncryptionKeys());
    }

    Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename=" + mOutputFilename);

    data.putString(KeychainIntentService.ENCRYPT_INPUT_FILE, mInputFilename);
    data.putString(KeychainIntentService.ENCRYPT_OUTPUT_FILE, mOutputFilename);

    boolean useAsciiArmor = mAsciiArmor.isChecked();
    data.putBoolean(KeychainIntentService.ENCRYPT_USE_ASCII_ARMOR, useAsciiArmor);

    int compressionId = ((Choice) mFileCompression.getSelectedItem()).getId();
    data.putInt(KeychainIntentService.ENCRYPT_COMPRESSION_ID, compressionId);

    intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

    // Message is received after encrypting is done in KeychainIntentService
    KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
            getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
        public void handleMessage(Message message) {
            // handle messages by standard KeychainIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                AppMsg.makeText(getActivity(), R.string.encrypt_sign_successful, AppMsg.STYLE_INFO).show();

                if (mDeleteAfter.isChecked()) {
                    // Create and show dialog to delete original file
                    DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                            .newInstance(mInputFilename);
                    deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
                }

                if (mShareAfter.isChecked()) {
                    // Share encrypted file
                    Intent sendFileIntent = new Intent(Intent.ACTION_SEND);
                    sendFileIntent.setType("*/*");
                    sendFileIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(mOutputFilename));
                    startActivity(Intent.createChooser(sendFileIntent, getString(R.string.title_share_file)));
                }
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    saveHandler.showProgressDialog(getActivity());

    // start service with intent
    getActivity().startService(intent);
}