List of usage examples for android.app ProgressDialog setCancelable
public void setCancelable(boolean flag)
From source file:Main.java
public static ProgressDialog creativeProgressBar(Context context, String comment) { ProgressDialog dialog = new ProgressDialog(context); if (comment == null) dialog.setMessage("Please wait while loading..."); else/*from w w w . ja v a2 s .c om*/ dialog.setMessage(comment); dialog.setIndeterminate(true); dialog.setCancelable(true); return dialog; }
From source file:Main.java
public static ProgressDialog createProgressDialog(Context mContext) { final ProgressDialog dialog = new ProgressDialog(mContext); try {/*from w ww .j a v a 2 s .com*/ Activity a = (Activity) mContext; a.runOnUiThread(new Runnable() { @Override public void run() { dialog.show(); } }); } catch (WindowManager.BadTokenException e) { } dialog.setCancelable(false); return dialog; }
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);// www . j a v a 2 s .c o m dialog.setMax(progressMax); dialog.setCancelable(false); dialog.setIndeterminate(false); if (progressMax > 1) { dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); } return dialog; }
From source file:be.ac.ucl.lfsab1509.llncampus.UCLouvain.java
/** * Launch the download of the courses list and store them in the database. * //from w ww . ja v a 2 s .c om * @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 {/*www.j a v a2 s.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.huison.DriverAssistant_Web.util.LoginHelper.java
public static void register(final BaseActivity activity, final String username, final String phone, final String password, final String tjrphone, final String yzm) { UmengEventSender.sendEvent(activity, UmengEventTypes.register); final ProgressDialog pd = new ProgressDialog(activity); pd.setMessage("..."); pd.setCanceledOnTouchOutside(false); pd.setCancelable(false); pd.show();//from ww w . ja va 2 s . c o m /* * Map<String, String> map = new HashMap<String, String>(); * map.put("sessionkey", BaseActivity.getSESSIONKEY()); * map.put("userid", username); map.put("mob", phone); * map.put("passwork", password); map.put("version", * activity.getVersionName()); map.put("imei", * DeviceUniqueIdentifier.getIMEIorMEID(activity)); map.put("imsi", * DeviceUniqueIdentifier.getIMSI(activity)); map.put("mac", * DeviceUniqueIdentifier.getMacAddress(activity)); map.put("channel", * getChannel(activity)); map.put("referee", tjrphone); map.put("Lng", ; * map.put("Lat", HomeActivity.gps_jdHomeActivity.gps_wd)); * map.put("Code", yzm); */ AsyncHttpClient client = activity.getAsyncHttpClient(); RequestParams params = new RequestParams(); /* * params.put("action", REGISTER_ACTION); params.put("xml", * BaseActivity.getXML(map)); */ try { JSONObject p = new JSONObject(); p.put("mobile", phone); p.put("password", password); p.put("method", "register"); p.put("version", activity.getVersionName()); p.put("devicetype", "android"); p.put("channel", getChannel(activity)); p.put("imei", DeviceUniqueIdentifier.getIMEIorMEID(activity)); p.put("imsi", "android" + DeviceUniqueIdentifier.getIMSI(activity)); p.put("lat", Env.latitude); p.put("lng", Env.longitude); p.put("mac", DeviceUniqueIdentifier.getMacAddress(activity)); p.put("referee", tjrphone); p.put("username", username); p.put("code", yzm); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date curDate = new Date(System.currentTimeMillis());// String time = formatter.format(curDate); p.put("time", time); Log.v("JSON", p.toString()); String data = Util.DesJiaMi(p.toString(), "czxms520"); params.put("data", data); } catch (Exception e) { e.printStackTrace(); } client.post(BaseActivity.REQUESTURL, params, new JsonHttpResponseHandler() { @Override public void onDispatchSuccess(int statusCode, Header[] headers, String result) { Log.v("", "1"); pd.dismiss(); try { result = Util.decrypt(result, "czxms520"); Log.v("JSON", result); JSONObject jo = new JSONObject(result); String code = jo.getString("code"); /* * boolean registerFlag = getJSONValueAsString(jo, "code") * .equals("0"); */ String msg = getJSONValueAsString(jo, "message"); if (code.equals("0")) { String data = jo.getString("data"); jo = new JSONObject(data); /* * registerFlag = getJSONValueAsString(jo, "logincode") * .equals("0"); */ // msg = getJSONValueAsString(jo, "loginmessage"); /* * String passwordMD5 = getJSONValueAsString( jo, * "pass"); */ /* * // String breakRuleRemind = * getJSONValueAsString( jo, "wzxx"); // String * changeLicenseRemind = getJSONValueAsString( jo, * "hzxx"); // String examineRemind = * getJSONValueAsString(jo, "nsxx"); */ // vip /* * boolean isVip = getJSONValueAsString(jo, "Vip") * .equals("true"); // String * blackPointUpdateTime = getJSONValueAsString( jo, * "wzhdtime"); // String toolUpdateTime = * getJSONValueAsString( jo, "sygjtime"); // * String favorUpdateTime = getJSONValueAsString( jo, * "yhtime"); */ /* * boolean isVip = getJSONValueAsString(jo, "Vip") * .equals("true"); */ // String loginTime = getJSONValueAsString(jo, "LastLogin"); // String lastLoginTime = getJSONValueAsString(jo, "LastLogin"); // SESSIONKEY /* * String sessionKey = getJSONValueAsString( jo, * "sessionkey"); */ String urlHead = getJSONValueAsString(jo, "PhotoUrl"); String photoUrl = getJSONValueAsString(jo, "PhotoUrl"); String phone = getJSONValueAsString(jo, "Mobile"); Boolean vip = false; if (String.valueOf(jo.getInt("Vip")).equals("1")) { vip = true; } else { vip = false; } Log.v("VIP", String.valueOf(vip)); activity.markLogin(phone, phone, password, true, "", loginTime, lastLoginTime, vip); if (!photoUrl.equals("")) { // String finalHeadUrl = URLDecoder.decode(photoUrl, "utf-8"); BaseActivity.setUserHeadUrl(finalHeadUrl); BaseActivity.setUserHeadDrawable(null); } else { BaseActivity.setUserHeadUrl(""); BaseActivity.setUserHeadDrawable(null); } try { pd.dismiss(); } catch (Exception e) { e.printStackTrace(); } sendMsg(ConfigActivity.thiz, 0); activity.finish(); } else { activity.showMessageBox(msg); } } catch (JSONException e) { e.printStackTrace(); // activity.markLogout(); // sendMsg(activity,1); activity.showMessageBox(activity.getText(R.string.server404)); Log.e("register error", Log.getStackTraceString(e)); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); activity.showMessageBox(""); } } @Override public void onFailureAnyway(int statusCode, Header[] headers, Throwable throwable, BaseBinaryResponse jsonResponse) { Log.v("C", "1"); pd.dismiss(); activity.showMessageBox(activity.getText(R.string.server404)); } @Override public void onSuccessAnyway(int statusCode, Header[] headers, BaseBinaryResponse jsonResponse) { pd.dismiss(); Log.v("A", "1"); } }); Log.v("B", "1"); TimeCounter.countTime(activity, pd); }
From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java
/** * Create a LocalGeoJsonLayer from the GeoJson data submitted by uri. *///from w w w . j a va2 s . c om 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: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); // ?/* ww w . ja v a 2s .c om*/ 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:org.pixmob.droidlink.ui.AuthenticationProgressDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setCancelable(false); dialog.setMessage(getString(R.string.auth_pending)); return dialog; }
From source file:com.rukman.emde.smsgroups.fragments.ProgressDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle arguments = this.getArguments(); ProgressDialog dialog = new ProgressDialog(this.getActivity()); dialog.setCancelable(false); dialog.setMessage(getResources().getText(arguments.getInt(MESSAGE))); dialog.setTitle(getResources().getText(arguments.getInt(TITLE))); return dialog; }