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:Main.java

public static Dialog setLoadingDialog(Activity activity, String message) {
    ProgressDialog progressDialog = new ProgressDialog(activity);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage(message);/* ww w  . ja  v a2 s . co m*/
    return progressDialog;
}

From source file:Main.java

public static ProgressDialog makeProgressDialog(Context ctx) {
    ProgressDialog p = new ProgressDialog(ctx);
    p.setCancelable(false);//from  w  w  w  .  j  a  va2  s  .c  o  m
    p.setCanceledOnTouchOutside(false);
    p.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    p.setIndeterminate(true);
    return p;
}

From source file:Main.java

public static ProgressDialog setupProgressDialog(Context ctx) {
    ProgressDialog progressDialog = new ProgressDialog(ctx);
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Loading...");
    return progressDialog;
}

From source file:Main.java

public static ProgressDialog getCustomProgressDialog(Context context, String content,
        boolean canceledOnTouchOutside, int dialogTheam) {
    ProgressDialog progressDialog = dialogTheam == 0 ? new ProgressDialog(context)
            : new ProgressDialog(context, dialogTheam);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage(content);/*  w w  w . j av  a  2s . co m*/
    progressDialog.setIndeterminate(true);
    progressDialog.setCanceledOnTouchOutside(canceledOnTouchOutside);
    return progressDialog;
}

From source file:com.lostad.app.base.util.DownloadUtil.java

public static void downFileAsyn(final Activity ctx, final String upgradeUrl, final String savedPath,
        final MyCallback<Boolean> callback) {
    final ProgressDialog xh_pDialog = new ProgressDialog(ctx);
    // ?//from www  . j a  v a 2s  .c  o  m
    xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    // ProgressDialog 
    xh_pDialog.setTitle("???");
    // ProgressDialog???
    xh_pDialog.setMessage("...");
    // ProgressDialog
    // xh_pDialog.setIcon(R.drawable.img2);
    // ProgressDialog ??? false ??
    xh_pDialog.setIndeterminate(false);
    // ProgressDialog ?
    // xh_pDialog.setProgress(100);
    // ProgressDialog ???
    xh_pDialog.setCancelable(true);
    // ProgressDialog
    xh_pDialog.show();

    new Thread() {
        public void run() {

            boolean downloadSuccess = true;
            FileOutputStream fileOutputStream = null;
            try {
                Looper.prepare();
                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(upgradeUrl);

                File f = new File(savedPath);
                if (!f.exists()) {
                    f.createNewFile();
                }

                HttpResponse response = client.execute(get);
                HttpEntity entity = response.getEntity();
                // ?
                Long length = entity.getContentLength();
                xh_pDialog.setMax(length.intValue());
                //
                InputStream is = entity.getContent();
                fileOutputStream = null;

                if (is != null && length > 0) {

                    fileOutputStream = new FileOutputStream(f);

                    byte[] buf = new byte[1024];
                    int ch = -1;
                    int count = 0;
                    while ((ch = is.read(buf)) != -1) {

                        if (xh_pDialog.isShowing()) {
                            fileOutputStream.write(buf, 0, ch);
                            // ?
                            count += ch;
                            xh_pDialog.setProgress(count);
                        } else {
                            downloadSuccess = false;
                            break;// ?
                        }
                    }

                } else {
                    callback.onCallback(false);
                }

                if (downloadSuccess && fileOutputStream != null) {
                    xh_pDialog.dismiss();
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    callback.onCallback(true);// ?
                }
                Looper.loop();
            } catch (FileNotFoundException e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
                xh_pDialog.dismiss();
            } catch (Exception e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
            } finally {
                try {
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }.start();

}

From source file:be.ac.ucl.lfsab1509.llncampus.UCLouvain.java

/**
 * Launch the download of the courses list and store them in the database.
 * //  w w w.  j av a  2s.  c  o  m
 * @param context
 *          Application context.
 * @param username
 *          UCL global user identifier.
 * @param password
 *          UCL password.
 * @param end
 *          Runnable to be executed at the end of the download.
 * @param mHandler
 *          Handler to manage messages and threads.
 *          
 */
public static void downloadCoursesFromUCLouvain(final LLNCampusActivity context, final String username,
        final String password, final Runnable end, final Handler mHandler) {
    Time t = new Time();
    t.setToNow();
    int year = t.year;
    // A new academic year begin in September (8th month on 0-based count).
    if (t.month < 8) {
        year--;
    }
    final int academicYear = year;

    mHandler.post(new Runnable() {

        public void run() {

            final ProgressDialog mProgress = new ProgressDialog(context);
            mProgress.setCancelable(false);
            mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgress.setMax(100);
            mProgress.setMessage(context.getString(R.string.connection));
            mProgress.show();

            new Thread(new Runnable() {
                /**
                 * Set the progress to the value n and show the message nextStep
                 * @param n
                 *          The progress value.
                 * @param nextStep
                 *          The message to show (indicate the next step to be processed).
                 */
                public void progress(final int n, final String nextStep) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            mProgress.setProgress(n);
                            mProgress.setMessage(nextStep);
                        }
                    });
                    Log.d("UCLouvain", nextStep);
                }

                /**
                 * Notify to the user an error.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void sendError(String msg) {
                    notify(context.getString(R.string.error) + " :" + msg);
                    mProgress.cancel();
                }

                /**
                 * Notify to the user a message.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void notify(final String msg) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            context.notify(msg);
                        }
                    });
                }

                public void run() {
                    progress(0, context.getString(R.string.connection_ucl));
                    UCLouvain uclouvain = new UCLouvain(username, password);

                    progress(20, context.getString(R.string.fetch_info));
                    ArrayList<Offer> offers = uclouvain.getOffers(academicYear);

                    if (offers == null || offers.isEmpty()) {
                        sendError(context.getString(R.string.error_academic_year) + academicYear);
                        return;
                    }

                    int i = 40;
                    ArrayList<Course> courses = new ArrayList<Course>();
                    for (Offer o : offers) {
                        progress(i, context.getString(R.string.get_courses) + o.getOfferName());
                        ArrayList<Course> offerCourses = uclouvain.getCourses(o);
                        if (offerCourses != null && !offerCourses.isEmpty()) {
                            courses.addAll(offerCourses);
                        } else {
                            Log.e("CoursListEditActivity", "Error : No course for offer [" + o.getOfferCode()
                                    + "] " + o.getOfferName());
                        }
                        i += (int) (30. / offers.size());
                    }

                    if (courses.isEmpty()) {
                        sendError(context.getString(R.string.courses_empty));
                        return;
                    }

                    // Remove old courses.
                    progress(70, context.getString(R.string.cleaning_db));
                    LLNCampus.getDatabase().delete("Courses", "", null);
                    LLNCampus.getDatabase().delete("Horaire", "", null);

                    // Add new data.
                    i = 80;
                    for (Course c : courses) {
                        progress(i, context.getString(R.string.add_courses_db));
                        ContentValues cv = new ContentValues();
                        cv.put("CODE", c.getCourseCode());
                        cv.put("NAME", c.getCoursName());

                        LLNCampus.getDatabase().insert("Courses", cv);
                        i += (int) (20. / courses.size());
                    }

                    progress(100, context.getString(R.string.end));
                    mProgress.cancel();
                    mHandler.post(end);
                }
            }).start();
        }
    });
}

From source file:com.nextgis.mobile.map.LocalTMSLayer.java

protected static void create(final MapBase map, String layerName, int tmsType, Uri uri) {
    String sErr = map.getContext().getString(R.string.error_occurred);
    try {/*from  w w  w  .ja  v a2s.c o  m*/
        InputStream inputStream = map.getContext().getContentResolver().openInputStream(uri);
        if (inputStream != null) {
            ProgressDialog progressDialog = new ProgressDialog(map.getContext());
            progressDialog.setMessage(map.getContext().getString(R.string.message_zip_extract_progress));
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setCancelable(true);
            progressDialog.show();

            File outputPath = map.cretateLayerStorage();
            //create layer description file
            JSONObject oJSONRoot = new JSONObject();
            oJSONRoot.put(JSON_NAME_KEY, layerName);
            oJSONRoot.put(JSON_VISIBILITY_KEY, true);
            oJSONRoot.put(JSON_TYPE_KEY, LAYERTYPE_LOCAL_TMS);
            oJSONRoot.put(JSON_TMSTYPE_KEY, tmsType);

            new UnZipTask(map.getMapEventsHandler(), inputStream, outputPath, oJSONRoot, progressDialog)
                    .execute();
            return;
        }
    } catch (FileNotFoundException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (JSONException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    }
    //if we here something wrong occurred
    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
}

From source file:com.android.gallery3d.ui.MenuExecutor.java

private static ProgressDialog createProgressDialog(Context context, int titleId, int progressMax) {
    ProgressDialog dialog = new ProgressDialog(context);
    dialog.setTitle(titleId);//from   w  ww.j av  a2 s  . c  om
    dialog.setMax(progressMax);
    dialog.setCancelable(false);
    dialog.setIndeterminate(false);
    if (progressMax > 1) {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    }
    return dialog;
}

From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java

/**
 * Create a LocalGeoJsonLayer from the GeoJson data submitted by uri.
 *//* ww w  .j  a v  a 2  s  . com*/
protected static void create(final MapBase map, String layerName, Uri uri) {

    String sErr = map.getContext().getString(R.string.error_occurred);
    ProgressDialog progressDialog = new ProgressDialog(map.getContext());

    try {
        InputStream inputStream = map.getContext().getContentResolver().openInputStream(uri);
        if (inputStream != null) {

            progressDialog.setMessage(map.getContext().getString(R.string.message_loading_progress));
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setCancelable(true);
            progressDialog.show();

            int nSize = inputStream.available();
            int nIncrement = 0;
            progressDialog.setMax(nSize);

            //read all geojson
            BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

            StringBuilder responseStrBuilder = new StringBuilder();

            String inputStr;
            while ((inputStr = streamReader.readLine()) != null) {
                nIncrement += inputStr.length();
                progressDialog.setProgress(nIncrement);
                responseStrBuilder.append(inputStr);
            }

            progressDialog.setMessage(map.getContext().getString(R.string.message_opening_progress));

            JSONObject geoJSONObject = new JSONObject(responseStrBuilder.toString());

            if (!geoJSONObject.has(GEOJSON_TYPE)) {
                sErr += ": " + map.getContext().getString(R.string.error_geojson_unsupported);
                Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                progressDialog.hide();
                return;
            }

            //check crs
            boolean isWGS84 = true; //if no crs tag - WGS84 CRS

            if (geoJSONObject.has(GEOJSON_CRS)) {
                JSONObject crsJSONObject = geoJSONObject.getJSONObject(GEOJSON_CRS);

                //the link is unsupported yet.
                if (!crsJSONObject.getString(GEOJSON_TYPE).equals(GEOJSON_NAME)) {
                    sErr += ": " + map.getContext().getString(R.string.error_geojson_crs_unsupported);
                    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                    progressDialog.hide();
                    return;
                }

                JSONObject crsPropertiesJSONObject = crsJSONObject.getJSONObject(GEOJSON_PROPERTIES);
                String crsName = crsPropertiesJSONObject.getString(GEOJSON_NAME);

                if (crsName.equals("urn:ogc:def:crs:OGC:1.3:CRS84")) { // WGS84
                    isWGS84 = true;
                } else if (crsName.equals("urn:ogc:def:crs:EPSG::3857")) { //Web Mercator
                    isWGS84 = false;
                } else {
                    sErr += ": " + map.getContext().getString(R.string.error_geojson_crs_unsupported);
                    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                    progressDialog.hide();
                    return;
                }
            }

            //load contents to memory and reproject if needed
            JSONArray geoJSONFeatures = geoJSONObject.getJSONArray(GEOJSON_TYPE_FEATURES);

            if (0 == geoJSONFeatures.length()) {
                sErr += ": " + map.getContext().getString(R.string.error_geojson_crs_unsupported);
                Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
                progressDialog.hide();
                return;
            }

            List<Feature> features = geoJSONFeaturesToFeatures(geoJSONFeatures, isWGS84, map.getContext(),
                    progressDialog);

            create(map, layerName, features);
        }

    } catch (UnsupportedEncodingException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (IOException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    } catch (JSONException e) {
        Log.d(TAG, "Exception: " + e.getLocalizedMessage());
        sErr += ": " + e.getLocalizedMessage();
    }

    progressDialog.hide();
    //if we here something wrong occurred
    Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show();
}

From source file:org.deviceconnect.android.deviceplugin.linking.setting.fragment.dialog.DiscoveryDeviceDialogFragment.java

@NonNull
@Override//from   w  w w . j  a  v a  2 s  .  c o m
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    String message = getArguments().getString(EXTRA_MESSAGE);
    ProgressDialog progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage(message);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setCancelable(false);
    return progressDialog;
}