Example usage for android.app ProgressDialog setMessage

List of usage examples for android.app ProgressDialog setMessage

Introduction

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

Prototype

@Override
    public void setMessage(CharSequence message) 

Source Link

Usage

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  w w  w. j a  v  a  2  s.  co  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:com.nextgis.mobile.map.LocalGeoJsonLayer.java

private static List<Feature> geoJSONFeaturesToFeatures(JSONArray geoJSONFeatures, boolean isWGS84,
        Context context, ProgressDialog progressDialog) throws JSONException {

    List<Feature> features = new ArrayList<Feature>();
    List<Field> fields = new ArrayList<Field>();
    int geometryType = GTNone;

    progressDialog.setMessage(context.getString(R.string.message_loading_progress));
    progressDialog.setMax(geoJSONFeatures.length());
    for (int i = 0; i < geoJSONFeatures.length(); i++) {
        progressDialog.setProgress(i);/*from   w ww .j  a  v  a  2  s  . c o m*/
        JSONObject jsonFeature = geoJSONFeatures.getJSONObject(i);

        //get geometry
        JSONObject jsonGeometry = jsonFeature.getJSONObject(GEOJSON_GEOMETRY);
        GeoGeometry geometry = GeoGeometry.fromJson(jsonGeometry);

        if (geometryType == GTNone) {
            geometryType = geometry.getType();
        } else if (!Geo.isGeometryTypeSame(geometryType, geometry.getType())) {
            //skip different geometry type
            continue;
        }

        //reproject if needed
        if (isWGS84) {
            geometry.setCRS(CRS_WGS84);
            geometry.project(CRS_WEB_MERCATOR);
        } else {
            geometry.setCRS(CRS_WEB_MERCATOR);
        }

        Feature feature = new Feature(fields);
        feature.setGeometry(geometry);
        //TODO: add to RTree for fast spatial queries

        //normalize attributes
        JSONObject jsonAttributes = jsonFeature.getJSONObject(GEOJSON_PROPERTIES);
        Iterator<String> iter = jsonAttributes.keys();
        while (iter.hasNext()) {
            String key = iter.next();
            Object value = jsonAttributes.get(key);

            int nType = -1;
            //check type
            if (value instanceof Integer || value instanceof Long) {
                nType = FTInteger;
            } else if (value instanceof Double || value instanceof Float) {
                nType = FTReal;
            } else if (value instanceof Date) {
                nType = FTDateTime;
            } else if (value instanceof String) {
                nType = FTString;
            } else if (value instanceof JSONObject) {
                nType = -1;
                //the some list - need to check it type FTIntegerList, FTRealList, FTStringList
            }

            int nField = -1;
            for (int j = 0; j < fields.size(); j++) {
                if (fields.get(j).getFieldName().equals(key)) {
                    nField = j;
                }
            }

            if (nField == -1) { //add new field
                Field field = new Field(key, key, nType);
                nField = fields.size();
                fields.add(field);
            }

            feature.setField(nField, value);
        }

        features.add(feature);
    }

    return features;
}

From source file:com.huison.DriverAssistant_Web.util.LoginHelper.java

public static void forgetPassword(final BaseActivity activity, final String username) {
    UmengEventSender.sendEvent(activity, UmengEventTypes.forgetPW);
    final ProgressDialog pd = new ProgressDialog(activity);
    pd.setMessage("");
    pd.show();//from w  ww  . j a v a  2  s.c  o  m
    AsyncHttpClient client = activity.getAsyncHttpClient();
    RequestParams params = new RequestParams();
    /*
     * Map<String, String> map = new HashMap<String, String>();
     * map.put("sessionkey", BaseActivity.getSESSIONKEY());
     * map.put("userid", username); map.put("mob", phone);
     * map.put("version", activity.getVersionName()); params.put("action",
     * FORGET_PASSWORD_ACTION); params.put("xml", BaseActivity.getXML(map));
     * Log.v("XML:",BaseActivity.getXML(map));
     */
    try {
        JSONObject p = new JSONObject();
        p.put("mobile", username);
        p.put("password", "wangjile");
        p.put("method", "forget");
        p.put("version", activity.getVersionName());
        p.put("devicetype", "android");
        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("", p.toString());
        String data = Util.DesJiaMi(p.toString(), "czxms520");
        // Log.v("",data);
        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) {
            pd.dismiss();
            try {
                result = Util.decrypt(result, "czxms520");
                Log.v(TAG, "JSON" + result);
                JSONObject jo = new JSONObject(result);
                String code = jo.getString("code");
                String msg = getJSONValueAsString(jo, "message");
                if (code.equals("0")) {
                    activity.showMessageBoxAndFinish(msg);
                } else {
                    activity.showMessageBox(msg);
                }
            } catch (JSONException e) {
                activity.showMessageBox(activity.getText(R.string.server404));
                Log.e("change password error", Log.getStackTraceString(e));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        public void onFailureAnyway(int statusCode, Header[] headers, Throwable throwable,
                BaseBinaryResponse jsonResponse) {
            pd.dismiss();
            activity.showMessageBox(activity.getText(R.string.server404));
        }

        @Override
        public void onSuccessAnyway(int statusCode, Header[] headers, BaseBinaryResponse jsonResponse) {
        }
    });
    TimeCounter.countTime(activity, pd);
}

From source file:com.huison.DriverAssistant_Web.util.LoginHelper.java

public static void changePassword(final BaseActivity activity, final String username, final String phone,
        final String oldPassword, final String newPassword) {
    UmengEventSender.sendEvent(activity, UmengEventTypes.changePW);
    final ProgressDialog pd = new ProgressDialog(activity);
    pd.setMessage("");
    pd.show();//from   w ww  . j  a  v  a 2s .c om
    AsyncHttpClient client = activity.getAsyncHttpClient();
    RequestParams params = new RequestParams();
    /*
     * Map<String, String> map = new HashMap<String, String>();
     * map.put("sessionkey", BaseActivity.getSESSIONKEY());
     * map.put("userid", username); map.put("mob", phone);
     * map.put("oldpasswork", oldPassword); map.put("passwork",
     * newPassword); map.put("version", activity.getVersionName());
     * params.put("action", CHANGE_PASSWORD_ACTION); params.put("xml",
     * BaseActivity.getXML(map));
     */
    try {
        JSONObject p = new JSONObject();
        p.put("mobile", phone);
        p.put("password", oldPassword);
        p.put("method", "editpassword");
        p.put("version", activity.getVersionName());
        p.put("devicetype", "android");
        p.put("newpassword", newPassword);
        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("", p.toString());
        String data = Util.DesJiaMi(p.toString(), "czxms520");
        // Log.v("",data);
        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) {
            try {
                result = Util.decrypt(result, "czxms520");
                Log.v(TAG, "JSON" + result);
                JSONObject jo = new JSONObject(result);
                String code = jo.getString("code");
                String msg = getJSONValueAsString(jo, "message");
                if (code.equals("0")) {
                    // jo = jo.getJSONObject("data");
                    activity.showMessageBoxAndFinish(msg);
                    activity.setPassword(newPassword);
                } else {
                    activity.showMessageBox(msg);
                }
            } catch (JSONException e) {
                activity.showMessageBox(activity.getText(R.string.server404));
                Log.e("change password error", Log.getStackTraceString(e));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        public void onFailureAnyway(int statusCode, Header[] headers, Throwable throwable,
                BaseBinaryResponse jsonResponse) {
            pd.dismiss();
            activity.showMessageBox(activity.getText(R.string.server404));
        }

        @Override
        public void onSuccessAnyway(int statusCode, Header[] headers, BaseBinaryResponse jsonResponse) {
            pd.dismiss();
            // ChangePasswordActivity.instance.finish();
        }
    });
    TimeCounter.countTime(activity, pd);
}

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

/**
 * Create a LocalGeoJsonLayer from the GeoJson data submitted by uri.
 *//*w ww.  ja v  a2  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.huison.DriverAssistant_Web.util.LoginHelper.java

public static void login(final BaseActivity activity, final String username, final String password,
        final boolean autoLogin) {
    Log.i(TAG, "call login func:" + username + "/" + password);
    ctx = activity;/*  w w w  .ja  v a  2s  .co  m*/
    UmengEventSender.sendEvent(activity, UmengEventTypes.login);
    final ProgressDialog pd = new ProgressDialog(activity);
    pd.setMessage(activity.getString(R.string.logging_wait));
    pd.show();
    AsyncHttpClient client = activity.getAsyncHttpClient();
    RequestParams params = new RequestParams();
    try {
        JSONObject p = new JSONObject();
        p.put("mobile", username);
        p.put("password", password);
        p.put("method", "login");
        p.put("version", activity.getVersionName());
        p.put("devicetype", "android");
        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.i(TAG, "request parameters: " + p.toString());
        String data = Util.DesJiaMi(p.toString(), "czxms520");
        Log.i(TAG, "post data:" + data);
        params.put("data", data);
    } catch (Exception e) {
        activity.showMessageBox(activity.getString(R.string.wrong_profile));
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return;
    }
    // params.put("xml", BaseActivity.getXML(map));
    Log.i(TAG, "AsyncHttpClient post:" + BaseActivity.REQUESTURL);
    client.post(BaseActivity.REQUESTURL, params, new JsonHttpResponseHandler() {
        @Override
        public void onDispatchSuccess(int statusCode, Header[] headers, String result) {
            Log.i(TAG, "onDispatchSuccess: " + result);
            pd.dismiss();
            try {
                Log.i(TAG, "decrypting...");
                result = Util.decrypt(result, "czxms520");
                Log.v(TAG, "result decrypted :" + result);
                JSONObject jo = new JSONObject(result);
                String code = jo.getString("code");
                String msg = getJSONValueAsString(jo, "message");
                if (code.equals("0")) {
                    jo = new JSONObject(jo.getString("data"));
                    // 
                    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;
                    }
                    Env.isLogined = BaseActivity.isLogined = true;
                    Log.v(TAG, ":1");
                    activity.markLogin(phone, phone, password, autoLogin, "", 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);
                    }
                    // sendMsg(ConfigActivity.thiz,0);
                    //  start
                    HomeActivity.now_mobile = phone;
                    //  end
                    // 
                    // 
                    Log.v("", "kk" + phone);
                    LoginActivity.instance.finish();
                    Util.saveFile(phone, Environment.getExternalStorageDirectory() + "/xmsphone.txt");
                    SharedPreferences.Editor sharedata = activity.getSharedPreferences("MyData", 0).edit();
                    sharedata.putString("isJZMM_czxms", "true");
                    sharedata.commit();
                    Log.i(TAG, ":2");
                    sendMsg(0);
                    sendMsg(ConfigActivity.thiz, 2);
                    activity.finish();
                } else {
                    Log.e(TAG, "server notify failed: error:" + msg);
                    LoginActivity.pw.setText("");
                    activity.showMessageBox(msg);
                }
            } catch (JSONException e) {
                Log.e(TAG, "login error" + Log.getStackTraceString(e));
                e.printStackTrace();
                activity.showMessageBox(activity.getText(R.string.server404));
            } catch (Exception e) {
                Log.e(TAG, Log.getStackTraceString(e));
                //e.printStackTrace();
                activity.showMessageBox(",.");
            }
        }

        @Override
        public void onFailureAnyway(int statusCode, Header[] headers, Throwable throwable,
                BaseBinaryResponse jsonResponse) {
            Log.i(TAG, "onFailureAnyway: " + statusCode);
            pd.dismiss();
            activity.showMessageBox(activity.getText(R.string.server404));
        }

        @Override
        public void onSuccessAnyway(int statusCode, Header[] headers, BaseBinaryResponse jsonResponse) {
            Log.i(TAG, "onSuccessAnyway: " + statusCode);
        }
    });
    TimeCounter.countTime(activity, pd);
}

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);//from w  ww. ja  v  a2  s . c o m
    pd.show();
    /*
     * 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:be.ac.ucl.lfsab1509.llncampus.UCLouvain.java

/**
 * Launch the download of the courses list and store them in the database.
 * /*  ww  w.  j  ava  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.mobicage.rogerthat.util.ui.UIUtils.java

public static ProgressDialog showProgressDialog(final Context context, CharSequence title, CharSequence message,
        boolean indeterminate, boolean cancelable, DialogInterface.OnCancelListener onCancelListener,
        int progressStyle, boolean show) {
    ProgressDialog dialog = new ProgressDialog(context);
    dialog.setTitle(title);/*  ww  w  .  j av a2s  .co  m*/
    dialog.setMessage(message);
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(cancelable);
    dialog.setProgressNumberFormat(null);
    dialog.setProgressPercentFormat(null);
    dialog.setOnCancelListener(onCancelListener);
    dialog.setProgressStyle(progressStyle);
    dialog.setOnShowListener(new ProgressDialog.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ProgressDialog progressDialog = (ProgressDialog) dialog;
            ProgressBar progressBar = (ProgressBar) progressDialog.findViewById(android.R.id.progress);
            UIUtils.setColors(context, progressBar);
        }
    });
    if (show) {
        dialog.show();
    }
    return dialog;
}

From source file:org.jraf.android.piclabel.app.form.ProgressDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ProgressDialog res = new ProgressDialog(getActivity());
    res.setMessage(getString(R.string.common_pleaseWait));
    return res;//w w  w .  j  a  v a2s  .  c  o m
}