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:ca.rmen.android.networkmonitor.app.log.LogActionsActivity.java

/**
 * Run the given file export, then bring up the chooser intent to share the exported file.
 *//*w  ww  .j  a v a  2s . c o  m*/
private void shareFile(final FileExport fileExport) {
    Log.v(TAG, "shareFile " + fileExport);
    // Use a horizontal progress bar style if we can show progress of the export.
    String dialogMessage = getString(R.string.export_progress_preparing_export);
    int dialogStyle = fileExport != null ? ProgressDialog.STYLE_HORIZONTAL : ProgressDialog.STYLE_SPINNER;
    DialogFragmentFactory.showProgressDialog(this, dialogMessage, dialogStyle, PROGRESS_DIALOG_TAG);

    AsyncTask<Void, Void, File> asyncTask = new AsyncTask<Void, Void, File>() {

        @Override
        protected File doInBackground(Void... params) {
            File file = null;
            if (fileExport != null) {
                if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
                    return null;
                try {
                    // Export the file in the background.
                    file = fileExport.export();
                } catch (Throwable t) {
                    Log.e(TAG, "Error exporting file " + fileExport + ": " + t.getMessage(), t);
                }
                if (file == null)
                    return null;
            }

            String reportSummary = SummaryExport.getSummary(LogActionsActivity.this);
            // Bring up the chooser to share the file.
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_subject_send_log));

            String dateRange = SummaryExport.getDataCollectionDateRange(LogActionsActivity.this);

            String messageBody = getString(R.string.export_message_text, dateRange);
            if (file != null) {
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
                sendIntent.setType("message/rfc822");
                messageBody += getString(R.string.export_message_text_file_attached);
            } else {
                sendIntent.setType("text/plain");
            }
            messageBody += reportSummary;
            sendIntent.putExtra(Intent.EXTRA_TEXT, messageBody);

            startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.action_share)));
            return file;
        }

        @Override
        protected void onPostExecute(File result) {
            super.onPostExecute(result);
            DialogFragment fragment = (DialogFragment) getSupportFragmentManager()
                    .findFragmentByTag(PROGRESS_DIALOG_TAG);
            if (fragment != null)
                fragment.dismissAllowingStateLoss();
            // Show a toast if we failed to export a file.
            if (fileExport != null && result == null)
                Toast.makeText(LogActionsActivity.this, R.string.export_error_sdcard_unmounted,
                        Toast.LENGTH_LONG).show();
            finish();
        }

    };
    asyncTask.execute();
}

From source file:com.yattatech.dbtc.activity.GenericFragmentActivity.java

public void showProgressBar(int current, int max) {
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setCanceledOnTouchOutside(false);
    mProgressDialog.setProgress(current);
    mProgressDialog.setMax(max);//from  w  w w.  j a  v a 2  s  . c om
    mProgressDialog.show();
}

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

public void importKeys(String fingerprint) {
    // Message is received after importing is done in KeychainIntentService
    KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this,
            getString(R.string.progress_importing), ProgressDialog.STYLE_HORIZONTAL, true) {
        public void handleMessage(Message message) {
            // handle messages by standard KeychainIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                // get returned data bundle
                Bundle returnData = message.getData();
                if (returnData == null) {
                    finish();//  w w w  .j  av a  2 s. c  o  m
                    return;
                }
                final ImportKeyResult result = returnData.getParcelable(OperationResult.EXTRA_RESULT);
                if (result == null) {
                    Log.e(Constants.TAG, "result == null");
                    finish();
                    return;
                }

                if (!result.success()) {
                    // only return if no success...
                    Intent data = new Intent();
                    data.putExtras(returnData);
                    returnResult(data);
                    return;
                }

                Intent certifyIntent = new Intent(QrCodeScanActivity.this, CertifyKeyActivity.class);
                certifyIntent.putExtra(CertifyKeyActivity.EXTRA_RESULT, result);
                certifyIntent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS, result.getImportedMasterKeyIds());
                startActivityForResult(certifyIntent, 0);
            }
        }
    };

    // search config
    Preferences prefs = Preferences.getPreferences(this);
    Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true,
            prefs.getPreferredKeyserver());

    // Send all information needed to service to query keys in other thread
    Intent intent = new Intent(this, KeychainIntentService.class);

    intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);

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

    data.putString(KeychainIntentService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);

    ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null);
    ArrayList<ParcelableKeyRing> selectedEntries = new ArrayList<ParcelableKeyRing>();
    selectedEntries.add(keyEntry);

    data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, selectedEntries);

    intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

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

    // show progress dialog
    serviceHandler.showProgressDialog(this);

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

From source file:com.esri.arcgisruntime.generateofflinemap.MainActivity.java

/**
 * Use the generate offline map job to generate an offline map.
 *//*w  ww .  j  ava2  s .co m*/
private void generateOfflineMap() {

    // create a progress dialog to show download progress
    ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setTitle("Generate Offline Map Job");
    progressDialog.setMessage("Taking map offline...");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setIndeterminate(false);
    progressDialog.setProgress(0);

    // when the button is clicked, start the offline map task job
    mTakeMapOfflineButton.setOnClickListener(v -> {
        progressDialog.show();

        // delete any offline map already in the cache
        String tempDirectoryPath = getCacheDir() + File.separator + "offlineMap";
        deleteDirectory(new File(tempDirectoryPath));

        // specify the extent, min scale, and max scale as parameters
        double minScale = mMapView.getMapScale();
        double maxScale = mMapView.getMap().getMaxScale();
        // minScale must always be larger than maxScale
        if (minScale <= maxScale) {
            minScale = maxScale + 1;
        }
        GenerateOfflineMapParameters generateOfflineMapParameters = new GenerateOfflineMapParameters(
                mDownloadArea.getGeometry(), minScale, maxScale);

        // create an offline map offlineMapTask with the map
        OfflineMapTask offlineMapTask = new OfflineMapTask(mMapView.getMap());

        // create an offline map job with the download directory path and parameters and start the job
        GenerateOfflineMapJob job = offlineMapTask.generateOfflineMap(generateOfflineMapParameters,
                tempDirectoryPath);

        // replace the current map with the result offline map when the job finishes
        job.addJobDoneListener(() -> {
            if (job.getStatus() == Job.Status.SUCCEEDED) {
                GenerateOfflineMapResult result = job.getResult();
                mMapView.setMap(result.getOfflineMap());
                mGraphicsOverlay.getGraphics().clear();
                mTakeMapOfflineButton.setEnabled(false);
                Toast.makeText(this, "Now displaying offline map.", Toast.LENGTH_LONG).show();
            } else {
                String error = "Error in generate offline map job: " + job.getError().getAdditionalMessage();
                Toast.makeText(this, error, Toast.LENGTH_LONG).show();
                Log.e(TAG, error);
            }
            progressDialog.dismiss();
        });

        // show the job's progress with the progress dialog
        job.addProgressChangedListener(() -> progressDialog.setProgress(job.getProgress()));

        // start the job
        job.start();
    });

}

From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(R.layout.fragment_appslist, container, false);
    // Setup layout
    recyclerView = (RecyclerView) rootView.findViewById(R.id.app_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);/*from   www  .java2  s.com*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        inflater.inflate(R.layout.fast_scroller, rootView);
        fastScroller = (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fast_scroller);
        fastScroller.setRecyclerView(recyclerView);
        recyclerView.setOnScrollListener(fastScroller.getOnScrollListener());
        scrollIndicator = (SectionTitleIndicator) rootView
                .findViewById(R.id.fast_scroller_section_title_indicator);
        fastScroller.setSectionIndicator(scrollIndicator);
    }
    // Show progress dialog
    if (progressDialog != null) {
        progressDialog.dismiss();
    }
    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setCancelable(true);
    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            task.cancel(true);
        }
    });
    if (task != null && task.getStatus().equals(AsyncTask.Status.RUNNING)) {
        progressDialog.show();
        progressDialog.setMax(task.listSize);
    }
    return rootView;
}

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

public void startEncrypt() {
    if (!inputIsValid()) {
        // Notify was created by inputIsValid.
        return;/*  w  ww .ja v a2  s.  c  om*/
    }

    // Send all information needed to service to edit key in other thread
    Intent intent = new Intent(this, KeychainIntentService.class);
    intent.setAction(KeychainIntentService.ACTION_ENCRYPT_SIGN);
    intent.putExtra(KeychainIntentService.EXTRA_DATA, createEncryptBundle());

    // Message is received after encrypting is done in KeychainIntentService
    KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this,
            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) {
                Notify.showNotify(EncryptFileActivity.this, R.string.encrypt_sign_successful,
                        Notify.Style.INFO);

                if (mDeleteAfterEncrypt) {
                    for (Uri inputUri : mInputUris) {
                        DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                                .newInstance(inputUri);
                        deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
                    }
                    mInputUris.clear();
                    notifyUpdate();
                }

                if (mShareAfterEncrypt) {
                    // Share encrypted message/file
                    startActivity(sendWithChooserExcludingEncrypt(message));
                } else {
                    // Copy to clipboard
                    copyToClipboard(message);
                    Notify.showNotify(EncryptFileActivity.this, R.string.encrypt_sign_clipboard_successful,
                            Notify.Style.INFO);
                }
            }
        }
    };
    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(serviceHandler);
    intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    serviceHandler.showProgressDialog(this);

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

From source file:org.alfresco.mobile.android.application.fragments.operations.OperationWaitingDialogFragment.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    setRetainInstance(true);//from  w w w  . j  av  a2 s .c om
    if (getArguments() != null) {
        operationType = getArguments().getInt(PARAM_TYPEID);
        intentId = getArguments().getString(PARAM_INTENTID);
        iconId = getArguments().getInt(PARAM_ICONID);
        title = getArguments().getString(PARAM_TITLEID);
        message = getArguments().getString(PARAM_MESSAGEID);
        parent = getArguments().getParcelable(PARAM_NODEID);
        nbItems = getArguments().getInt(PARAM_SIZE);
    }

    ProgressDialog dialog = new ProgressDialog(getActivity());
    if (iconId == 0) {
        iconId = R.drawable.ic_alfresco_logo;
    }
    dialog.setIcon(iconId);
    dialog.setTitle(title);
    if (message == null) {
        message = getString(R.string.waiting_operations);
    }
    dialog.setMessage(message);
    boolean indeterminate = true;
    if (nbItems > 0) {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgress(0);
        dialog.setMax(nbItems);
        indeterminate = false;
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    getActivity().getLoaderManager().restartLoader(this.hashCode(), null, this);

    return dialog;
}

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

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_SAFE_SLINGER) {
        if (resultCode == ExchangeActivity.RESULT_EXCHANGE_CANCELED) {
            return;
        }/*  w ww  .  j  av a2  s.  c o  m*/

        final FragmentActivity activity = SafeSlingerActivity.this;

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

                if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                    // get returned data bundle
                    Bundle returnData = message.getData();
                    if (returnData == null) {
                        return;
                    }
                    final ImportKeyResult result = returnData.getParcelable(OperationResult.EXTRA_RESULT);
                    if (result == null) {
                        Log.e(Constants.TAG, "result == null");
                        return;
                    }

                    if (!result.success()) {
                        //                            result.createNotify(activity).show();
                        // only return if no success...
                        Intent data = new Intent();
                        data.putExtras(returnData);
                        setResult(RESULT_OK, data);
                        finish();
                        return;
                    }

                    //                        if (mExchangeMasterKeyId == null) {
                    //                            return;
                    //                        }

                    Intent certifyIntent = new Intent(activity, CertifyKeyActivity.class);
                    certifyIntent.putExtra(CertifyKeyActivity.EXTRA_RESULT, result);
                    certifyIntent.putExtra(CertifyKeyActivity.EXTRA_KEY_IDS, result.getImportedMasterKeyIds());
                    certifyIntent.putExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, mMasterKeyId);
                    startActivityForResult(certifyIntent, KeyListActivity.REQUEST_CODE_RESULT_TO_LIST);

                    //                        mExchangeMasterKeyId = null;
                }
            }
        };

        Log.d(Constants.TAG, "importKeys started");

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

        intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);

        // instead of giving the entries by Intent extra, cache them into a
        // file to prevent Java Binder problems on heavy imports
        // read FileImportCache for more info.
        try {
            // import exchanged keys
            ArrayList<ParcelableKeyRing> it = getSlingedKeys(data.getExtras());

            // We parcel this iteratively into a file - anything we can
            // display here, we should be able to import.
            ParcelableFileCache<ParcelableKeyRing> cache = new ParcelableFileCache<ParcelableKeyRing>(activity,
                    "key_import.pcl");
            cache.writeCache(it.size(), it.iterator());

            // fill values for this action
            Bundle bundle = new Bundle();
            intent.putExtra(KeychainIntentService.EXTRA_DATA, bundle);

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

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

            // start service with intent
            activity.startService(intent);
        } catch (IOException e) {
            Log.e(Constants.TAG, "Problem writing cache file", e);
            Notify.showNotify(activity, "Problem writing cache file!", Notify.Style.ERROR);
        }
    } else {
        // give everything else down to KeyListActivity!
        setResult(resultCode, data);
        finish();
    }
}

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

public void importKey() {

    // Message is received after decrypting is done in KeychainService
    ServiceProgressHandler saveHandler = new ServiceProgressHandler(getActivity(),
            getString(R.string.progress_importing), ProgressDialog.STYLE_HORIZONTAL) {
        @Override/* w w w  .j av  a2  s.  c  o m*/
        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();

                ImportKeyResult result = returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT);

                long[] masterKeyIds = result.getImportedMasterKeyIds();

                // TODO handle masterKeyIds.length != 1...? sorta outlandish scenario

                if (!result.success() || masterKeyIds.length == 0) {
                    result.createNotify(getActivity()).show();
                    return;
                }

                Intent intent = new Intent(getActivity(), ViewKeyActivity.class);
                // use the imported masterKeyId, not the one from the yubikey, because
                // that one might* just have been a subkey of the imported key
                intent.setData(KeyRings.buildGenericKeyRingUri(masterKeyIds[0]));
                intent.putExtra(ViewKeyActivity.EXTRA_DISPLAY_RESULT, result);
                intent.putExtra(ViewKeyActivity.EXTRA_NFC_AID, mNfcAid);
                intent.putExtra(ViewKeyActivity.EXTRA_NFC_USER_ID, mNfcUserId);
                intent.putExtra(ViewKeyActivity.EXTRA_NFC_FINGERPRINTS, mNfcFingerprints);
                startActivity(intent);
                getActivity().finish();

            }

        }
    };

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

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

    intent.setAction(KeychainService.ACTION_IMPORT_KEYRING);

    ArrayList<ParcelableKeyRing> keyList = new ArrayList<>();
    keyList.add(new ParcelableKeyRing(mNfcFingerprint, null, null));
    data.putParcelableArrayList(KeychainService.IMPORT_KEY_LIST, keyList);

    {
        Preferences prefs = Preferences.getPreferences(getActivity());
        Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true,
                prefs.getPreferredKeyserver());
        data.putString(KeychainService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
    }

    intent.putExtra(KeychainService.EXTRA_DATA, data);

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

    saveHandler.showProgressDialog(getActivity());

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

}

From source file:com.fortysevendeg.labs.bbc.rest.android.activities.BeerActivity.java

/**
 * Add beer on server/*  w  w  w  .ja v  a  2 s  .  c  om*/
 */
private void addBeer() {
    if (TextUtils.isEmpty(etAlcohol.getText().toString()) || TextUtils.isEmpty(etName.getText().toString())) {
        Toast.makeText(BeerActivity.this, R.string.fieldsEmpty, Toast.LENGTH_SHORT).show();
        return;
    }
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMessage(getString(R.string.connecting));
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.show();

    BeerRequest beerRequest = new BeerRequest();
    beerRequest.setAvb(Double.parseDouble(etAlcohol.getText().toString()));
    beerRequest.setName(etName.getText().toString());
    beerRequest.setDescription(etDescription.getText().toString());
    APIService.get().addBeer(beerRequest, new ContextAwareAPIDelegate<BeerResponse>(this, BeerResponse.class) {
        @Override
        public void onResults(BeerResponse beerResponse) {
            progressDialog.dismiss();
            Toast.makeText(BeerActivity.this, R.string.beerSaved, Toast.LENGTH_SHORT).show();
            setResult(RESULT_OK);
            finish();
        }

        @Override
        public void onError(Throwable e) {
            progressDialog.dismiss();
            Toast.makeText(BeerActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
        }
    });
}