Example usage for android.app ProgressDialog setOnCancelListener

List of usage examples for android.app ProgressDialog setOnCancelListener

Introduction

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

Prototype

public void setOnCancelListener(@Nullable OnCancelListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is canceled.

Usage

From source file:com.nttec.everychan.chans.ponyach.PonyachModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    final Context context = preferenceGroup.getContext();
    ListPreference captchaLevel = new LazyPreferences.ListPreference(context);
    captchaLevel.setTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setDialogTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setKey(getSharedKey(PREF_KEY_CAPTCHA_LEVEL));
    captchaLevel.setEntryValues(new String[] { "3", "2", "1" });
    captchaLevel.setEntries(new String[] { "Easy", "Easy++", "Medium" });
    captchaLevel.setDefaultValue("1");
    preferenceGroup.addPreference(captchaLevel);

    EditTextPreference passcodePref = new EditTextPreference(context);
    passcodePref.setTitle(R.string.ponyach_prefs_passcode);
    passcodePref.setDialogTitle(R.string.ponyach_prefs_passcode);
    passcodePref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
    passcodePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override//from  w  ww .  ja va  2  s . c o m
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String newPasscode = (String) newValue;
            final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask();
            final ProgressDialog passAuthProgressDialog = new ProgressDialog(context);
            passAuthProgressDialog.setMessage("Logging in");
            passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    passAuthTask.cancel();
                }
            });
            passAuthProgressDialog.setCanceledOnTouchOutside(false);
            passAuthProgressDialog.show();
            Async.runAsync(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (passAuthTask.isCancelled())
                            return;
                        String url = getUsingUrl() + "passcode.php";
                        List<BasicNameValuePair> pairs = Collections
                                .singletonList(new BasicNameValuePair("passcode_just_set", newPasscode));
                        HttpRequestModel request = HttpRequestModel.builder()
                                .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build();
                        HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, null,
                                passAuthTask, false);
                        savePhpCookies();
                    } catch (final Exception e) {
                        if (context instanceof Activity) {
                            ((Activity) context).runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String message = e.getMessage() == null
                                            ? resources.getString(R.string.error_unknown)
                                            : e.getMessage();
                                    Toast.makeText(context, message, Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    } finally {
                        passAuthProgressDialog.dismiss();
                    }
                }
            });
            return false;
        }
    });
    preferenceGroup.addPreference(passcodePref);

    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setEntryValues(DOMAINS);
    domainPref.setEntries(DOMAINS);
    domainPref.setDefaultValue(DEFAULT_DOMAIN);
    domainPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            loadPhpCookies((String) newValue);
            return true;
        }
    });
    preferenceGroup.addPreference(domainPref);

    addHttpsPreference(preferenceGroup, useHttpsDefaultValue());
    addProxyPreferences(preferenceGroup);
    captchaLevel.setSummary(captchaLevel.getEntry());
    domainPref.setSummary(domainPref.getEntry());
}

From source file:com.ccxt.whl.activity.LoginActivity.java

/**
 * /*from  w w w .  ja  va 2 s  .  c o  m*/
 * 
 * @param view
 */
public void login(View view) {
    if (!CommonUtils.isNetWorkConnected(this)) {
        Toast.makeText(this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show();
        return;
    }
    final String email = usernameEditText.getText().toString();
    final String password = passwordEditText.getText().toString();
    if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)) {
        progressShow = true;
        final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
        pd.setCanceledOnTouchOutside(false);
        pd.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                progressShow = false;
            }
        });
        pd.setMessage("...");
        pd.show();
        // sdk??
        RequestParams params = new RequestParams();
        params.add("tel_email", email);
        params.add("pwd", MD5.MD5Hash(password));
        params.add("uid", uid);
        HttpRestClient.get(Constant.LOGIN_URL, params, new BaseJsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers, String rawJsonResponse, Object response) {
                Log.d("login_res_json" + rawJsonResponse);
                pd.dismiss();
                if (CommonUtils.isNullOrEmpty(rawJsonResponse)) {
                    Toast.makeText(getApplicationContext(), "?,?", 0)
                            .show();
                    return;
                }
                Map<String, Object> lm = JsonToMapList.getMap(rawJsonResponse);

                if (lm.get("status").toString() != null && lm.get("status").toString().equals("yes")) {
                    Map<String, Object> result = JsonToMapList.getMap(lm.get("result").toString());
                    String resultStr = "status:" + lm.get("status") + "\n" + "message:" + lm.get("message")
                            + "\n" + "result:" + lm.get("result") + "\n" + "uid:" + result.get("uid") + "\n"
                            + "umd5:" + result.get("umd5") + "\n" + "is_res:" + result.get("is_res") + "\n"
                            + "headurl:" + result.get("headurl") + "\n" + "name:" + result.get("name") + "\n"
                            + "sex:" + result.get("sex") + "\n" + "age:" + result.get("age") + "\n"
                            + "province:" + result.get("province") + "\n" + "city:" + result.get("city") + "\n"
                            + "pwd:" + result.get("pwd") + "\n";
                    Log.d("login_res_obj" + resultStr);
                    //???id nullsaveinfo Preference
                    //DemoApplication.getInstance().setUser(result.get("umd5").toString());
                    //System.out.println("========================"+result.get("umd5").toString());
                    /********/
                    PreferenceUtils.getInstance(getBaseContext())
                            .setSettingUserPic(result.get("headurl").toString());
                    PreferenceUtils.getInstance(getBaseContext())
                            .setSettingUserNickName(result.get("name").toString());
                    PreferenceUtils.getInstance(getBaseContext())
                            .setSettingUserSex(result.get("sex").toString());
                    PreferenceUtils.getInstance(getBaseContext())
                            .setSettingUserAge(result.get("age").toString());
                    PreferenceUtils.getInstance(getBaseContext()).setSettingUserArea(
                            result.get("province").toString() + " " + result.get("city").toString());
                    PreferenceUtils.getInstance(getBaseContext())
                            .setSettingUserZhiye(result.get("zhiye").toString());
                    PreferenceUtils.getInstance(getBaseContext())
                            .setSettingUserQianming(result.get("qianming").toString());

                    String huanxin_username = result.get("umd5").toString();
                    String huanxin_pwd = result.get("pwd").toString();
                    Log.d("log huanxin_username:" + huanxin_username + "|huanxin_pwd:" + huanxin_pwd);

                    //?? 
                    login(huanxin_username, huanxin_pwd);

                    /*???
                    progressShow = false;
                    pd.dismiss();*/

                } else {
                    Toast.makeText(getApplicationContext(), lm.get("message").toString(), 0).show();
                }

            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable, String rawJsonData,
                    Object errorResponse) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "?,?", 0).show();
            }

            @Override
            protected Object parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
                // TODO Auto-generated method stub
                return null;
            }

        });
    }
}

From source file:com.ccxt.whl.activity.LoginActivity.java

/**
 * ?/*w w w.j  a  v  a2s. c o  m*/
 * 
 * @param view
 */
public void login(final String username, final String password) {
    if (!CommonUtils.isNetWorkConnected(this)) {
        Toast.makeText(this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show();
        return;
    }
    //final String username = usernameEditText.getText().toString();
    //final String password = passwordEditText.getText().toString();
    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)) {
        progressShow = true;
        final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
        pd.setCanceledOnTouchOutside(false);
        pd.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                progressShow = false;
            }
        });
        pd.setMessage("...");
        pd.show();
        // sdk??
        EMChatManager.getInstance().login(username, password, new EMCallBack() {

            @Override
            public void onSuccess() {
                /*****************
                 * ?
                 *****************/
                if (!progressShow) {
                    return;
                }
                // ?????
                //               DemoApplication.getInstance().setUserName(username);
                DemoApplication.getInstance().setUser(username);
                DemoApplication.getInstance().setPassword(password);
                DemoApplication.getInstance().setUserNickName(name);
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.setMessage("???...");
                    }
                });
                try {
                    // demo??????username??
                    List<String> usernames = EMChatManager.getInstance().getContactUserNames();
                    Map<String, User> userlist = new HashMap<String, User>();
                    for (String username : usernames) {
                        User user = new User();
                        user.setUsername(username);
                        setUserHearder(username, user);
                        userlist.put(username, user);
                    }
                    // user""
                    User newFriends = new User();
                    newFriends.setUsername(Constant.NEW_FRIENDS_USERNAME);
                    newFriends.setNick("");
                    newFriends.setHeader("");
                    userlist.put(Constant.NEW_FRIENDS_USERNAME, newFriends);
                    // "?"
                    User groupUser = new User();
                    groupUser.setUsername(Constant.GROUP_USERNAME);
                    groupUser.setNick("?");
                    groupUser.setHeader("");
                    userlist.put(Constant.GROUP_USERNAME, groupUser);

                    // 
                    DemoApplication.getInstance().setContactList(userlist);
                    /***?MainActivity?db* /
                    // db
                    UserDao dao = new UserDao(LoginActivity.this);
                    List<User> users = new ArrayList<User>(userlist.values());
                    dao.saveContactList(users);/**/

                    // ??,sdkEMGroupManagerdb
                    EMGroupManager.getInstance().getGroupsFromServer();
                    // after login, we join groups in separate threads;
                    EMGroupManager.getInstance().joinGroupsAfterLogin();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (!LoginActivity.this.isFinishing())
                    pd.dismiss();
                // ?
                startActivity(new Intent(LoginActivity.this, MainActivity.class));
                finish();
            }

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

            }

            @Override
            public void onError(int code, final String message) {
                if (!progressShow) {
                    return;
                }
                //Log.d("log","code"+code);
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();

                        Toast.makeText(getApplicationContext(), ": " + message, 0).show();

                    }
                });
            }
        });
    }
}

From source file:com.nttec.everychan.chans.fourchan.FourchanModule.java

private void addPasscodePreference(PreferenceGroup preferenceGroup) {
    final Context context = preferenceGroup.getContext();
    PreferenceScreen passScreen = preferenceGroup.getPreferenceManager().createPreferenceScreen(context);
    passScreen.setTitle("4chan pass");
    EditTextPreference passTokenPreference = new EditTextPreference(context);
    EditTextPreference passPINPreference = new EditTextPreference(context);
    Preference passLoginPreference = new Preference(context);
    Preference passClearPreference = new Preference(context);
    passTokenPreference.setTitle("Token");
    passTokenPreference.setDialogTitle("Token");
    passTokenPreference.setKey(getSharedKey(PREF_KEY_PASS_TOKEN));
    passTokenPreference.getEditText().setSingleLine();
    passTokenPreference.getEditText()/*from  w  w w.  j  a  va 2  s .  co m*/
            .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    passPINPreference.setTitle("PIN");
    passPINPreference.setDialogTitle("PIN");
    passPINPreference.setKey(getSharedKey(PREF_KEY_PASS_PIN));
    passPINPreference.getEditText().setSingleLine();
    passPINPreference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    passLoginPreference.setTitle("Log In");
    passLoginPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (!useHttps())
                Toast.makeText(context, "Using HTTPS even if HTTP is selected", Toast.LENGTH_SHORT).show();
            final String token = preferences.getString(getSharedKey(PREF_KEY_PASS_TOKEN), "");
            final String pin = preferences.getString(getSharedKey(PREF_KEY_PASS_PIN), "");
            final String authUrl = "https://sys.4chan.org/auth"; //only https
            final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask();
            final ProgressDialog passAuthProgressDialog = new ProgressDialog(context);
            passAuthProgressDialog.setMessage("Logging in");
            passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    passAuthTask.cancel();
                }
            });
            passAuthProgressDialog.setCanceledOnTouchOutside(false);
            passAuthProgressDialog.show();
            Async.runAsync(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (passAuthTask.isCancelled())
                            return;
                        setPasscodeCookie(null, true);
                        List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                        pairs.add(new BasicNameValuePair("act", "do_login"));
                        pairs.add(new BasicNameValuePair("id", token));
                        pairs.add(new BasicNameValuePair("pin", pin));
                        HttpRequestModel request = HttpRequestModel.builder()
                                .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build();
                        String response = HttpStreamer.getInstance().getStringFromUrl(authUrl, request,
                                httpClient, null, passAuthTask, false);
                        if (passAuthTask.isCancelled())
                            return;
                        if (response.contains("Your device is now authorized")) {
                            String passId = null;
                            for (Cookie cookie : httpClient.getCookieStore().getCookies()) {
                                if (cookie.getName().equals("pass_id")) {
                                    String value = cookie.getValue();
                                    if (!value.equals("0")) {
                                        passId = value;
                                        break;
                                    }
                                }
                            }
                            if (passId == null) {
                                showToast("Could not get pass id");
                            } else {
                                setPasscodeCookie(passId, true);
                                showToast("Success! Your device is now authorized.");
                            }
                        } else if (response.contains("Your Token must be exactly 10 characters")) {
                            showToast("Incorrect token");
                        } else if (response.contains("You have left one or more fields blank")) {
                            showToast("You have left one or more fields blank");
                        } else if (response.contains("Incorrect Token or PIN")) {
                            showToast("Incorrect Token or PIN");
                        } else {
                            Matcher m = Pattern
                                    .compile("<strong style=\"color: red; font-size: larger;\">(.*?)</strong>")
                                    .matcher(response);
                            if (m.find()) {
                                showToast(m.group(1));
                            } else {
                                showWebView(response);
                            }
                        }
                    } catch (Exception e) {
                        showToast(e.getMessage() == null ? resources.getString(R.string.error_unknown)
                                : e.getMessage());
                    } finally {
                        passAuthProgressDialog.dismiss();
                    }
                }

                private void showToast(final String message) {
                    if (context instanceof Activity) {
                        ((Activity) context).runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(context, message, Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                }

                private void showWebView(final String html) {
                    if (context instanceof Activity) {
                        ((Activity) context).runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                WebView webView = new WebView(context);
                                webView.getSettings().setSupportZoom(true);
                                webView.loadData(html, "text/html", null);
                                new AlertDialog.Builder(context).setView(webView)
                                        .setNeutralButton(android.R.string.ok, null).show();
                            }
                        });
                    }
                }
            });
            return true;
        }
    });
    passClearPreference.setTitle("Reset pass cookie");
    passClearPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            setPasscodeCookie(null, true);
            Toast.makeText(context, "Cookie is reset", Toast.LENGTH_LONG).show();
            return true;
        }
    });
    passScreen.addPreference(passTokenPreference);
    passScreen.addPreference(passPINPreference);
    passScreen.addPreference(passLoginPreference);
    passScreen.addPreference(passClearPreference);
    preferenceGroup.addPreference(passScreen);
}

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

public void login(final String currentUsername, final String currentPassword, final ProgressDialog pd) {
    if (!CommonUtils.isNetWorkConnected(getActivity())) {
        Toast.makeText(getActivity(), R.string.network_isnot_available, Toast.LENGTH_SHORT).show();
        return;/* w w w  .  ja v  a 2s. com*/
    }
    if (TextUtils.isEmpty(currentUsername)) {
        Toast.makeText(getActivity(), R.string.User_name_cannot_be_empty, Toast.LENGTH_SHORT).show();
        return;
    }
    if (TextUtils.isEmpty(currentPassword)) {
        Toast.makeText(getActivity(), R.string.Password_cannot_be_empty, Toast.LENGTH_SHORT).show();
        return;
    }

    progressShow = true;
    pd.setCanceledOnTouchOutside(false);
    pd.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            progressShow = false;
        }
    });
    pd.setMessage(getString(R.string.Is_landing));
    pd.show();

    final long start = System.currentTimeMillis();
    // sdk??
    EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {

        @Override
        public void onSuccess() {
            if (!progressShow) {
                return;
            }
            // ?????
            HXApplication.getInstance().setUserName(currentUsername);
            HXApplication.getInstance().setPassword(currentPassword);

            try {
                // ** ?logout???
                // ** manually load all local groups and
                EMGroupManager.getInstance().loadAllGroups();
                EMChatManager.getInstance().loadAllConversations();
                // ??
                initializeContacts();
            } catch (Exception e) {
                e.printStackTrace();
                // ?????
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        HXApplication.getInstance().logout(null);
                        Toast.makeText(getActivity().getApplicationContext(), R.string.login_failure_failed, 1)
                                .show();
                    }
                });
                return;
            }
            // ?nickname ios?nick
            boolean updatenick = EMChatManager.getInstance()
                    .updateCurrentUserNick(HXApplication.currentUserNick.trim());
            if (!updatenick) {
                Log.e("LoginActivity", "update current user nick fail");
            }
            if (!getActivity().isFinishing() && pd.isShowing()) {
                pd.dismiss();
            }
            // ?
            startMainActivity();
        }

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

        @Override
        public void onError(final int code, final String message) {
            if (!progressShow) {
                return;
            }
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    pd.dismiss();
                    Toast.makeText(getActivity().getApplicationContext(),
                            getString(R.string.Login_failed) + message, Toast.LENGTH_SHORT).show();
                }
            });
        }
    });
}

From source file:net.sylvek.sharemyposition.ShareMyPosition.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    default:/*  w w w. jav a 2  s  . c  o m*/
        return super.onCreateDialog(id);
    case MAP_DLG:
        final View sharedMapView = LayoutInflater.from(this).inflate(R.layout.sharedmap, null);
        final FrameLayout map = (FrameLayout) sharedMapView.findViewById(R.id.sharedmap);
        map.addView(this.sharedMap);
        final CheckBox latlonAddress = (CheckBox) sharedMapView.findViewById(R.id.add_lat_lon_location);
        final CheckBox geocodeAddress = (CheckBox) sharedMapView.findViewById(R.id.add_address_location);
        final RadioButton nourl = (RadioButton) sharedMapView.findViewById(R.id.add_no_url_location);
        final RadioButton url = (RadioButton) sharedMapView.findViewById(R.id.add_url_location);
        final RadioButton gmap = (RadioButton) sharedMapView.findViewById(R.id.add_native_location);
        final EditText body = (EditText) sharedMapView.findViewById(R.id.body);
        final ToggleButton track = (ToggleButton) sharedMapView.findViewById(R.id.add_track_location);

        latlonAddress.setChecked(pref.getBoolean(PREF_LAT_LON_CHECKED, true));
        geocodeAddress.setChecked(pref.getBoolean(PREF_ADDRESS_CHECKED, true));
        final boolean isUrl = pref.getBoolean(PREF_URL_CHECKED, true);
        final boolean isGmap = pref.getBoolean(PREF_GMAP_CHECKED, false);
        url.setChecked(isUrl);
        gmap.setChecked(isGmap);
        nourl.setChecked(!isUrl && !isGmap);
        body.setText(pref.getString(PREF_BODY_DEFAULT, getString(R.string.body)));
        track.setChecked(pref.getBoolean(PREF_TRACK_CHECKED, false));

        if (track.isChecked()) {
            latlonAddress.setEnabled(false);
            latlonAddress.setChecked(false);
            geocodeAddress.setEnabled(false);
            geocodeAddress.setChecked(false);
            url.setEnabled(false);
            url.setChecked(true);
            gmap.setEnabled(false);
            gmap.setChecked(false);
            nourl.setEnabled(false);
            nourl.setChecked(false);
        }

        track.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                latlonAddress.setEnabled(!isChecked);
                latlonAddress.setChecked(!isChecked);
                geocodeAddress.setEnabled(!isChecked);
                geocodeAddress.setChecked(!isChecked);
                url.setEnabled(!isChecked);
                url.setChecked(true);
                gmap.setEnabled(!isChecked);
                gmap.setChecked(!isChecked);
                nourl.setEnabled(!isChecked);
                nourl.setChecked(!isChecked);
            }
        });

        return new AlertDialog.Builder(this).setTitle(R.string.app_name).setView(sharedMapView)
                .setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface arg0) {
                        finish();
                    }
                }).setNeutralButton(R.string.options, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        /* needed to display neutral button */
                    }
                }).setPositiveButton(R.string.share_it, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        final boolean isLatLong = ((CheckBox) sharedMapView
                                .findViewById(R.id.add_lat_lon_location)).isChecked();
                        final boolean isGeocodeAddress = ((CheckBox) sharedMapView
                                .findViewById(R.id.add_address_location)).isChecked();
                        final boolean isUrl = ((RadioButton) sharedMapView.findViewById(R.id.add_url_location))
                                .isChecked();
                        final boolean isGmap = ((RadioButton) sharedMapView
                                .findViewById(R.id.add_native_location)).isChecked();
                        final EditText body = (EditText) sharedMapView.findViewById(R.id.body);
                        final boolean isTracked = ((ToggleButton) sharedMapView
                                .findViewById(R.id.add_track_location)).isChecked();
                        final String uuid = UUID.randomUUID().toString();

                        pref.edit().putBoolean(PREF_LAT_LON_CHECKED, isLatLong)
                                .putBoolean(PREF_ADDRESS_CHECKED, isGeocodeAddress)
                                .putBoolean(PREF_URL_CHECKED, isUrl).putBoolean(PREF_GMAP_CHECKED, isGmap)
                                .putString(PREF_BODY_DEFAULT, body.getText().toString())
                                .putBoolean(PREF_TRACK_CHECKED, isTracked).commit();

                        final Intent t = new Intent(Intent.ACTION_SEND);
                        t.setType("text/plain");
                        t.addCategory(Intent.CATEGORY_DEFAULT);
                        final Intent share = Intent.createChooser(t, getString(R.string.app_name));
                        final GeoPoint p = sharedMap.getMapCenter();

                        final String text = body.getText().toString();
                        share(p.getLatitude(), p.getLongitude(), t, share, text, isGeocodeAddress, isUrl,
                                isGmap, isLatLong, isTracked, uuid);
                    }
                }).create();
    case PROGRESS_DLG:
        final ProgressDialog dlg = new ProgressDialog(this);
        dlg.setTitle(getText(R.string.app_name));
        dlg.setMessage(getText(R.string.progression_desc));
        dlg.setIndeterminate(true);
        dlg.setCancelable(true);
        dlg.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        return dlg;
    case PROVIDERS_DLG:
        return new AlertDialog.Builder(this).setTitle(R.string.app_name).setCancelable(false)
                .setIcon(android.R.drawable.ic_menu_help).setMessage(R.string.providers_needed)
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }

                }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent gpsProperty = new Intent(
                                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(gpsProperty);
                    }
                }).create();
    }
}

From source file:com.yeldi.yeldibazaar.AppDetails.java

private ProgressDialog createProgressDialog(String file, int p, int max) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    pd.setMessage(getString(R.string.download_server) + ":\n " + file);
    pd.setMax(max);/*from w  w w  . j av  a2  s  .  c  o m*/
    pd.setProgress(p);
    pd.setCancelable(true);
    pd.setCanceledOnTouchOutside(false);
    pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            downloadHandler.cancel();
        }
    });
    pd.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    pd.cancel();
                }
            });
    pd.show();
    return pd;
}

From source file:fm.smart.r1.activity.CreateItemActivity.java

public void onClick(View v) {
    EditText cueInput = (EditText) findViewById(R.id.cue);
    EditText responseInput = (EditText) findViewById(R.id.response);
    Spinner posInput = (Spinner) findViewById(R.id.pos);
    EditText characterResponseInput = (EditText) findViewById(R.id.response_character);
    EditText characterCueInput = (EditText) findViewById(R.id.cue_character);
    final String cue = cueInput.getText().toString();
    final String response = responseInput.getText().toString();
    final String pos = posInput.getSelectedItem().toString();
    final String character_cue = characterCueInput.getText().toString();
    final String character_response = characterResponseInput.getText().toString();
    String pos_code = Utils.POS_MAP.get(pos);
    if (TextUtils.isEmpty(pos_code)) {
        pos_code = "NONE";
    }//from   w w w  .  j  a v  a  2 s  .  co m
    final String final_pos_code = pos_code;

    if (Main.isNotLoggedIn(this)) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setClassName(this, LoginActivity.class.getName());
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid
        // navigation
        // back to this?
        LoginActivity.return_to = CreateItemActivity.class.getName();
        LoginActivity.params = new HashMap<String, String>();
        LoginActivity.params.put("list_id", list_id);
        LoginActivity.params.put("cue", cue);
        LoginActivity.params.put("response", response);
        LoginActivity.params.put("cue_language", cue_language);
        LoginActivity.params.put("response_language", response_language);
        LoginActivity.params.put("pos", pos);
        LoginActivity.params.put("character_cue", character_cue);
        LoginActivity.params.put("character_response", character_response);
        startActivity(intent);
    } else {
        // TODO cue and response languages need to be inferred from list we are
        // adding to ... Might want to fix those, i.e. not allow variation
        // on
        // search ...
        // TODO wondering whether there is some way to edit existing items
        // ...

        final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
        myOtherProgressDialog.setTitle("Please Wait ...");
        myOtherProgressDialog.setMessage("Creating Item ...");
        myOtherProgressDialog.setIndeterminate(true);
        myOtherProgressDialog.setCancelable(true);

        final Thread create_item = new Thread() {
            public void run() {
                // TODO make this interruptable .../*if
                // (!this.isInterrupted())*/
                CreateItemActivity.create_item_result = createItem(cue, cue_language, character_cue,
                        final_pos_code, response, response_language, character_response, list_id);

                myOtherProgressDialog.dismiss();

            }
        };
        myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                create_item.interrupt();
            }
        });
        OnCancelListener ocl = new OnCancelListener() {
            public void onCancel(DialogInterface arg0) {
                create_item.interrupt();
            }
        };
        myOtherProgressDialog.setOnCancelListener(ocl);
        myOtherProgressDialog.show();
        create_item.start();
    }
}

From source file:id.ridon.keude.AppDetailsData.java

private ProgressDialog getProgressDialog(String file) {
    if (progressDialog == null) {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setMessage(getString(R.string.download_server) + ":\n " + file);
        pd.setCancelable(true);/*from   www  .  ja  v a2s  .c om*/
        pd.setCanceledOnTouchOutside(false);

        // The indeterminate-ness will get overridden on the first progress event we receive.
        pd.setIndeterminate(true);

        pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                Log.d(TAG, "User clicked 'cancel' on download, attempting to interrupt download thread.");
                if (downloadHandler != null) {
                    downloadHandler.cancel();
                    cleanUpFinishedDownload();
                } else {
                    Log.e(TAG, "Tried to cancel, but the downloadHandler doesn't exist.");
                }
                progressDialog = null;
                Toast.makeText(AppDetails.this, getString(R.string.download_cancelled), Toast.LENGTH_LONG)
                        .show();
            }
        });
        pd.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        pd.cancel();
                    }
                });
        progressDialog = pd;
    }
    return progressDialog;
}