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.esri.arcgisruntime.generateofflinemap.MainActivity.java

/**
 * Use the generate offline map job to generate an offline map.
 *///from   w  w w . j a  v a2  s  .c  o 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:com.mobicage.rogerthat.GetLocationActivity.java

@Override
protected void onServiceBound() {
    T.UI();/*from   w  ww . j  a  v a  2 s .c o m*/
    setContentView(R.layout.get_location);

    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setMessage(getString(R.string.updating_location));
    mProgressDialog.setCancelable(true);
    mProgressDialog.setCanceledOnTouchOutside(true);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            T.UI();
            if (mLocationManager != null) {
                try {
                    mLocationManager.removeUpdates(mLocationListener);
                } catch (SecurityException e) {
                    L.bug(e); // Should never happen
                }
            }
        }
    });
    mProgressDialog.setMax(10000);

    mUseGPS = (CheckBox) findViewById(R.id.use_gps_provider);
    mGetCurrentLocationButton = (Button) findViewById(R.id.get_current_location);
    mAddress = (EditText) findViewById(R.id.address);
    mCalculate = (Button) findViewById(R.id.calculate);

    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (mLocationManager == null) {
        mGetCurrentLocationButton.setEnabled(false);
    } else {
        mUseGPS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked && !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    new AlertDialog.Builder(GetLocationActivity.this).setMessage(R.string.gps_is_not_enabled)
                            .setPositiveButton(R.string.yes, new SafeDialogInterfaceOnClickListener() {
                                @Override
                                public void safeOnClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    startActivityForResult(intent, TURNING_ON_GPS);
                                }
                            }).setNegativeButton(R.string.no, new SafeDialogInterfaceOnClickListener() {
                                @Override
                                public void safeOnClick(DialogInterface dialog, int which) {
                                    mUseGPS.setChecked(false);
                                }
                            }).create().show();
                }
            }
        });

        mGetCurrentLocationButton.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                T.UI();
                if (mService.isPermitted(Manifest.permission.ACCESS_FINE_LOCATION)) {
                    getMyLocation();
                } else {
                    ActivityCompat.requestPermissions(GetLocationActivity.this,
                            new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                            PERMISSION_REQUEST_ACCESS_FINE_LOCATION);
                }
            }
        });
    }

    mCalculate.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            final ProgressDialog pd = new ProgressDialog(GetLocationActivity.this);
            pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            pd.setMessage(getString(R.string.updating_location));
            pd.setCancelable(false);
            pd.setIndeterminate(true);
            pd.show();
            final String addressText = mAddress.getText().toString();
            mService.postOnIOHandler(new SafeRunnable() {
                @Override
                protected void safeRun() throws Exception {
                    Geocoder geoCoder = new Geocoder(GetLocationActivity.this, Locale.getDefault());
                    try {
                        List<Address> addresses = geoCoder.getFromLocationName(addressText, 5);
                        if (addresses.size() > 0) {
                            Address address = addresses.get(0);
                            final Location location = new Location("");
                            location.setLatitude(address.getLatitude());
                            location.setLongitude(address.getLongitude());
                            mService.postOnUIHandler(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    pd.dismiss();
                                    mLocation = location;
                                    showMap();
                                }
                            });
                            return;
                        }
                    } catch (IOException e) {
                        L.d("Failed to geo code address " + addressText, e);
                    }
                    mService.postOnUIHandler(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            pd.dismiss();
                            UIUtils.showLongToast(GetLocationActivity.this,
                                    getString(R.string.failed_to_lookup_address));
                        }
                    });
                }
            });
        }
    });
}

From source file:com.nanosheep.bikeroute.Feedback.java

@Override
public Dialog onCreateDialog(final int id) {
    AlertDialog.Builder builder;/*from  w w  w .  j  a v a  2 s. co m*/
    ProgressDialog pDialog;
    Dialog dialog;
    switch (id) {
    case R.id.send:
        pDialog = new ProgressDialog(this);
        pDialog.setCancelable(true);
        pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pDialog.setMessage(getText(R.string.send_msg));
        pDialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(final DialogInterface arg0) {
                removeDialog(R.id.send);
            }
        });
        pDialog.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(final DialogInterface arg0) {
                submitHandler.cancel(true);
            }

        });
        dialog = pDialog;
        break;
    case R.id.thanks:
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getText(R.string.thanks_message)).setCancelable(true)
                .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.dismiss();
                        finish();
                    }
                });
        dialog = builder.create();
        break;
    case R.id.feedback_fail:
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getText(R.string.feedback_fail_message)).setCancelable(true)
                .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.dismiss();
                    }
                });
        dialog = builder.create();
        break;
    default:
        dialog = null;
    }
    return dialog;
}

From source file:com.esri.arcgisruntime.sample.editandsyncfeatures.MainActivity.java

/**
 * Create a progress dialog to show sync state
 *//*  ww w  .  j  ava2  s.c o  m*/
private void createProgressDialog(Job job) {

    ProgressDialog syncProgressDialog = new ProgressDialog(this);
    syncProgressDialog.setTitle("Sync Geodatabase Job");
    syncProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    syncProgressDialog.setCanceledOnTouchOutside(false);
    syncProgressDialog.show();

    job.addProgressChangedListener(() -> syncProgressDialog.setProgress(job.getProgress()));

    job.addJobDoneListener(syncProgressDialog::dismiss);
}

From source file:com.artur.softwareproject.BluetoothConnectionListAdapter.java

@Override
@NonNull/*w ww.j  a v  a 2  s .co  m*/
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    ViewHolder mViewHolder;

    if (convertView == null) {
        mViewHolder = new ViewHolder();

        LayoutInflater ListInflater = LayoutInflater.from(getContext());

        convertView = ListInflater.inflate(R.layout.bluetooth_list_pattern, parent, false);

        mViewHolder.bluetoothConnectionName = (TextView) convertView
                .findViewById(R.id.bluetooth_connection_name);

        mViewHolder.bluetoothConnectionStatus = (TextView) convertView
                .findViewById(R.id.bluetooth_connection_status);

        convertView.setTag(mViewHolder);

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //What happens if you press on the list items at the bluetooth activity.
                Animation animation = new AlphaAnimation(0.3f, 1.0f);

                animation.setDuration(1000);

                v.startAnimation(animation);

                intent = new Intent(contextActivity, BluetoothService.class);
                intent.putExtra("device", bDevices.get(position));
                intent.putExtra("deviceList", bDevices);

                contextActivity.startService(intent);

                final ProgressDialog connectingDialog = new ProgressDialog(contextActivity);

                connectDialog = connectingDialog;

                connectingDialog.setMessage("Connecting...");
                connectingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                connectingDialog.setCancelable(false);
                connectingDialog.show();

                final ConnectionHandlerClass connectHandler = new ConnectionHandlerClass(bclaReference);

                connectThread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        int stop = 0;
                        int counter = 0;

                        //Timeout after 10 seconds.
                        while (stop == 0 && counter < 5) {
                            stop = getConnected();
                            counter++;
                            sleep(2000);
                        }

                        //Timeout occurred after 10s of waiting and stop is still 0.
                        if (stop == 0 && counter == 4) {
                            timeout = true;
                        }

                        connectHandler.sendEmptyMessage(0);
                    }
                });

                connectThread.start();
            }
        });
    } else {
        mViewHolder = (ViewHolder) convertView.getTag();
    }

    mViewHolder.bluetoothConnectionName.setText(bluetoothAddress.get(position));
    mViewHolder.bluetoothConnectionStatus.setText(bluetoothName.get(position));

    return convertView;
}

From source file:it.scoppelletti.mobilepower.app.ProgressDialogFragment.java

/**
 * Crea il dialogo./*from   w w  w .j  av  a  2s  .c om*/
 * 
 * @param  savedInstanceState Stato dell&rsquo;istanza.
 * @return                    Dialogo.
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int max, resId;
    ProgressDialog dlg;
    Bundle args = getArguments();

    dlg = new ProgressDialog(getActivity(), AppUtils.getDialogTheme());

    resId = args.getInt(ProgressDialogFragment.ARG_TITLEID);
    dlg.setTitle(getString(resId));
    max = args.getInt(ProgressDialogFragment.ARG_MAX, -1);

    if (max > 0) {
        dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dlg.setIndeterminate(false);
        dlg.setMax(max);
    } else {
        dlg.setIndeterminate(true);
        dlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }

    dlg.setCancelable(args.getBoolean(ProgressDialogFragment.ARG_CANCELABLE));
    dlg.setCanceledOnTouchOutside(false);

    return dlg;
}

From source file:com.gmail.nagamatu.radiko.installer.RadikoInstallerActivity.java

private Dialog onCreateProgressDialog() {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setMessage("Loading...");
    dialog.setCancelable(false);//from  w w w  .  j  a  va  2 s . c o m
    return dialog;
}

From source file:net.kazzz.NFCTagWriter.java

/**
 * ????????/*from  w w w. j  a  v a  2s . c o m*/
 * ?VICC???????
 * 
 */
public void onClick(final View v) {
    try {
        final int id = v.getId();
        if (id != R.id.btn_write)
            return;

        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setIndeterminate(true);

        AsyncTask<Void, Void, ?> writeDataTask = null;
        if (isFeliCaLiteTag(mNfcTag)) {
            // FeliCatLite
            writeDataTask = new FeliCaLiteWriteTask(this, mNfcTag);
        } else

        if (isISO15693Tag(mNfcTag)) {
            final CheckBox chkUseNDEF = (CheckBox) findViewById(R.id.chk_useNDEF);
            //ISO15693
            writeDataTask = new ISO15693WriteTask(this, mNfcTag, chkUseNDEF.isChecked());
        }
        // ??
        writeDataTask.execute();

    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG, "writeData", e);
        Toast.makeText(v.getContext(), "???? : " + e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:ch.kanti_baden.pu_marc_14b.traffictimewaste.SORT_TYPE.java

private void setupRecyclerViewAsync(@NonNull final ViewGroup viewGroup) {
    final ProgressDialog progressDialog = ProgressDialog.show(this,
            getResources().getString(R.string.progress_loading_posts),
            getResources().getString(R.string.progress_please_wait), true, false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    DatabaseLink.DatabaseListener listener = new DatabaseLink.DatabaseListener() {
        @Override//from   w w  w.j a va2 s. c  o  m
        void onGetResponse(String str) {
            final Post[] posts;
            try {
                JSONObject json = new JSONObject(str);
                posts = DatabaseLink.parseJson(json);
            } catch (JSONException e) {
                onError("JSON is invalid. Error: " + e.getMessage() + ", JSON: " + str);
                return;
            }

            if (progressDialog.isShowing())
                progressDialog.dismiss();

            final Post[] sortedPosts = sortPosts(posts);

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // Inflate layout post_list
                    View rootView = View.inflate(PostListActivity.this, R.layout.post_list, null);
                    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.post_list);

                    // Setup refresh action
                    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) rootView
                            .findViewById(R.id.swipe_refresh);
                    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                        @Override
                        public void onRefresh() {
                            recreate();
                        }
                    });

                    // Set adapter with posts
                    recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(sortedPosts));

                    // Add to ViewGroup
                    viewGroup.addView(rootView);
                }
            });
        }

        @Override
        void onError(String error) {
            if (progressDialog.isShowing())
                progressDialog.dismiss();

            new AlertDialog.Builder(progressDialog.getContext()).setTitle("Error").setMessage(error).show();
        }
    };

    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction()))
        DatabaseLink.instance.getPostsWithTag(listener, intent.getStringExtra(SearchManager.QUERY));
    else
        DatabaseLink.instance.getAllPosts(listener);
    Log.v("TrafficTimeWaste", "Querying db...");
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.PhotoUploadWidget.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == Crop.REQUEST_CROP) {
        handleCrop(resultCode, data);//from  ww w  .j a v a2s  . co m
    } else if (requestCode == PICK_IMAGE) {
        if (resultCode == Activity.RESULT_OK) {
            if (data != null && data.getData() != null) {
                if (mRatio == null) {
                    final Uri selectedImage = data.getData();

                    final ProgressDialog progressDialog = new ProgressDialog(mActivity);
                    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    progressDialog.setMessage(mActivity.getString(R.string.processing));
                    progressDialog.setCancelable(false);
                    progressDialog.show();

                    new SafeAsyncTask<Object, Object, Boolean>() {
                        @Override
                        protected Boolean safeDoInBackground(Object... params) {
                            L.d("Processing picture: " + selectedImage.getPath());
                            try {
                                File tmpUploadFile = getTmpUploadPhotoLocation();
                                if (tmpUploadFile.getAbsolutePath().equals(selectedImage.getPath())) {
                                    return true;
                                } else {
                                    InputStream is = mActivity.getContentResolver()
                                            .openInputStream(selectedImage);
                                    if (is != null) {
                                        try {
                                            OutputStream out = new FileOutputStream(tmpUploadFile);
                                            try {
                                                IOUtils.copy(is, out, 1024);
                                            } finally {
                                                out.close();
                                            }
                                        } finally {
                                            is.close();
                                        }
                                        return true;
                                    }
                                }
                            } catch (FileNotFoundException e) {
                                L.d(e);
                            } catch (Exception e) {
                                L.bug("Unknown exception occured while processing picture: "
                                        + selectedImage.toString(), e);
                            }

                            return false;
                        };

                        @Override
                        protected void safeOnPostExecute(Boolean result) {
                            progressDialog.dismiss();
                            if (result) {
                                handleSelection();
                            } else {
                                UIUtils.showLongToast(getContext(), R.string.crop__pick_error);
                            }
                        }

                        @Override
                        protected void safeOnCancelled(Boolean result) {
                        }

                        @Override
                        protected void safeOnProgressUpdate(Object... values) {
                        }

                        @Override
                        protected void safeOnPreExecute() {
                        };
                    }.execute();

                } else {
                    beginCrop(data.getData());
                    return;
                }
            } else {
                if (mRatio == null) {
                    handleSelection();
                } else {
                    beginCrop(mUriSavedImage);
                }
            }
        }
    } else {
        L.bug("Unexpected request code in onActivityResult: " + requestCode);
    }
}