Example usage for android.app ProgressDialog show

List of usage examples for android.app ProgressDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

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 {/*ww  w  .  j ava 2s. 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: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.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 a  2  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: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  o m*/
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);
    // ?// w w w  .j a  v  a2 s  .  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:ca.TwentyTwenty.cropinspection.AbstractMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case android.R.id.home:
        return (true);
    case R.id.settings:
        startActivity(new Intent(this, Preferences.class));
        return (true);
    case R.id.legal:
        startActivity(new Intent(this, LegalNoticesActivity.class));
        return (true);
    case R.id.map:
        startActivity(new Intent(this, CropInspectionActivity.class));
        return (true);
    case R.id.search:
        showMe();/*  ww  w  . j  a  v a  2 s. c o m*/
        return (true);
    case R.id.sync:
        // load asynctask eventually
        ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage("loading");
        pd.show();
        return (true);
    }

    return super.onOptionsItemSelected(item);
}

From source file:im.afterclass.android.activity.RegisterActivity.java

/**
 * /*from   w w  w  .java2 s  .  c om*/
 * @param view
 */
public void register(View view) {
    final String username = userNameEditText.getText().toString().trim();
    final String pwd = passwordEditText.getText().toString().trim();
    String confirm_pwd = confirmPwdEditText.getText().toString().trim();
    if (TextUtils.isEmpty(username)) {
        Toast.makeText(this, "????", Toast.LENGTH_SHORT).show();
        userNameEditText.requestFocus();
        return;
    } else if (TextUtils.isEmpty(pwd)) {
        Toast.makeText(this, "???", Toast.LENGTH_SHORT).show();
        passwordEditText.requestFocus();
        return;
    } else if (TextUtils.isEmpty(confirm_pwd)) {
        Toast.makeText(this, "???", Toast.LENGTH_SHORT).show();
        confirmPwdEditText.requestFocus();
        return;
    } else if (!pwd.equals(confirm_pwd)) {
        Toast.makeText(this, "????", Toast.LENGTH_SHORT).show();
        return;
    }

    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(pwd)) {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage("...");
        pd.show();
        new Thread(new Runnable() {
            public void run() {
                try {
                    //sdk
                    EMChatManager.getInstance().createAccountOnServer(username, pwd);
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!RegisterActivity.this.isFinishing())
                                pd.dismiss();
                            //???
                            DemoApplication.getInstance().setUserName(username);
                            Toast.makeText(getApplicationContext(), "?", 0).show();
                            newRegister();
                            finish();
                        }
                    });
                } catch (final Exception e) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!RegisterActivity.this.isFinishing())
                                pd.dismiss();
                            if (e != null && e.getMessage() != null) {
                                String errorMsg = e.getMessage();
                                if (errorMsg.indexOf("EMNetworkUnconnectedException") != -1) {
                                    Toast.makeText(getApplicationContext(), "?",
                                            0).show();
                                } else if (errorMsg.indexOf("conflict") != -1) {
                                    Toast.makeText(getApplicationContext(), "?", 0).show();
                                } else {
                                    Toast.makeText(getApplicationContext(), ": " + e.getMessage(),
                                            1).show();
                                }

                            } else {
                                Toast.makeText(getApplicationContext(), ": ", 1).show();

                            }
                        }
                    });
                }
            }
        }).start();

    }
}

From source file:com.aibasis.parent.ui.entrance.RegisterActivity.java

/**
 * // w  ww. j  av a 2s.co m
 * 
 * @param view
 */
public void register(View view) {
    final String username = userNameEditText.getText().toString().trim();
    final String pwd = passwordEditText.getText().toString().trim();
    String confirm_pwd = confirmPwdEditText.getText().toString().trim();
    if (TextUtils.isEmpty(username)) {
        Toast.makeText(this, getResources().getString(R.string.User_name_cannot_be_empty), Toast.LENGTH_SHORT)
                .show();
        userNameEditText.requestFocus();
        return;
    } else if (TextUtils.isEmpty(pwd)) {
        Toast.makeText(this, getResources().getString(R.string.Password_cannot_be_empty), Toast.LENGTH_SHORT)
                .show();
        passwordEditText.requestFocus();
        return;
    } else if (TextUtils.isEmpty(confirm_pwd)) {
        Toast.makeText(this, getResources().getString(R.string.Confirm_password_cannot_be_empty),
                Toast.LENGTH_SHORT).show();
        confirmPwdEditText.requestFocus();
        return;
    } else if (!pwd.equals(confirm_pwd)) {
        Toast.makeText(this, getResources().getString(R.string.Two_input_password), Toast.LENGTH_SHORT).show();
        return;
    }

    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(pwd)) {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage(getResources().getString(R.string.Is_the_registered));
        pd.show();

        new Thread(new Runnable() {
            public void run() {
                //               try {
                //                  // sdk
                //                  EMChatManager.getInstance().createAccountOnServer(username, pwd);
                //                  runOnUiThread(new Runnable() {
                //                     public void run() {
                //                        if (!RegisterActivity.this.isFinishing())
                //                           pd.dismiss();
                //                        // ???
                //                        DemoApplication.getInstance().setUserName(username);
                //                        Toast.makeText(getApplicationContext(), getResources().getString(R.string.Registered_successfully), 0).show();
                //                        finish();
                //                     }
                //                  });
                //               } catch (final EaseMobException e) {
                //                  runOnUiThread(new Runnable() {
                //                     public void run() {
                //                        if (!RegisterActivity.this.isFinishing())
                //                           pd.dismiss();
                //                        int errorCode=e.getErrorCode();
                //                        if(errorCode==EMError.NONETWORK_ERROR){
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.network_anomalies), Toast.LENGTH_SHORT).show();
                //                        }else if(errorCode == EMError.USER_ALREADY_EXISTS){
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.User_already_exists), Toast.LENGTH_SHORT).show();
                //                        }else if(errorCode == EMError.UNAUTHORIZED){
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.registration_failed_without_permission), Toast.LENGTH_SHORT).show();
                //                        }else if(errorCode == EMError.ILLEGAL_USER_NAME){
                //                            Toast.makeText(getApplicationContext(), getResources().getString(R.string.illegal_user_name),Toast.LENGTH_SHORT).show();
                //                        }else{
                //                           Toast.makeText(getApplicationContext(), getResources().getString(R.string.Registration_failed) + e.getMessage(), Toast.LENGTH_SHORT).show();
                //                        }
                //                     }
                //                  });
                //               }
                accountAPI.register(username, pwd, new RequestListener() {
                    @Override
                    public void onComplete(String result) {
                        if (!RegisterActivity.this.isFinishing())
                            pd.dismiss();
                        try {
                            RegisterResult registerResult = RegisterResult.parse(result);
                            if (RegisterResult.SUCCESS.equals(registerResult.getResult())) {
                                DemoApplication.getInstance().setParentId(registerResult.getParentId());
                                DemoApplication.getInstance().setEaseId(registerResult.getEaseId());
                                DemoApplication.getInstance().setEasePassword(registerResult.getEasePassword());

                                SharePreferenceUtil sharePreferenceUtil = new SharePreferenceUtil(
                                        RegisterActivity.this);
                                sharePreferenceUtil.setParentId(registerResult.getParentId());
                            } else if (RegisterResult.USERNAME_EXISTS.equals(registerResult.getResult())) {
                                Toast.makeText(RegisterActivity.this,
                                        getResources().getString(R.string.User_already_exists),
                                        Toast.LENGTH_SHORT).show();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        finish();
                    }

                    @Override
                    public void onAPIException(APIException exception) {
                        Log.e("jijun", exception.toString());
                    }
                });

            }
        }).start();
    }
}

From source file:com.easemob.chatuidemo.activity.NewGroupActivity.java

public void setGroup(final String groupName, final String groupIntroduce, final String open,
        final String number, final String allow_invite) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setMessage("");
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    Log.i("FriMsg", groupName + groupIntroduce + open + number + allow_invite);
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    requestQueue.start();//  ww  w .jav a2 s  . c o m

    requestQueue.add(new AutoLoginRequest(this, Request.Method.POST, Model.PathLoad,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.i("FriMsg", response.toString());
                    try {
                        if (response.getString("status").equals("0")) {
                            Toast.makeText(NewGroupActivity.this, "?", 0).show();
                            NewGroupActivity.this.finish();
                        }

                    } catch (Exception e) {
                        Log.e("Activity_boshu_FriMsg", "?");
                    }
                    pd.dismiss();

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.i("FriMsg", error.getMessage());
                    pd.dismiss();

                }
            }) {
        @Override
        protected void setParams(Map<String, String> params) {
            params.put("sys", "msg");
            params.put("ctrl", "msger");
            params.put("action", "crt_group");
            params.put("group_name", groupName);
            params.put("introduce", groupIntroduce);
            params.put("maxusers", "5000");
            params.put("public", open);
            params.put("approval", "1");
            params.put("members", number);
            params.put("allow_invite", allow_invite);

        }
    });
}

From source file:com.wenwen.chatuidemo.activity.PersonFragment.java

void logout() {
    final ProgressDialog pd = new ProgressDialog(getActivity());
    pd.setMessage("..");
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    DemoApplication.getInstance().logout(new EMCallBack() {
        @Override//  w w w  .j a  va  2 s .c  o m
        public void onSuccess() {
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    pd.dismiss();
                    // ??
                    ((MainActivity) getActivity()).finish();
                    startActivity(new Intent(getActivity(), LoginActivity.class));

                }
            });
        }

        @Override
        public void onProgress(int progress, String status) {

        }

        @Override
        public void onError(int code, String message) {

        }
    });
}