Example usage for android.app ProgressDialog dismiss

List of usage examples for android.app ProgressDialog dismiss

Introduction

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

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:com.shafiq.myfeedle.core.MyfeedleNotifications.java

@Override
public boolean onContextItemSelected(final MenuItem item) {
    if (item.getItemId() == CLEAR) {
        final ProgressDialog loadingDialog = new ProgressDialog(this);
        final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {

            @Override//from   w  w w .j  a v  a 2  s . c om
            protected Void doInBackground(Void... arg0) {
                // clear all notifications
                ContentValues values = new ContentValues();
                values.put(Notifications.CLEARED, 1);
                MyfeedleNotifications.this.getContentResolver().update(
                        Notifications.getContentUri(MyfeedleNotifications.this), values,
                        Notifications._ID + "=?",
                        new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) });
                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                if (loadingDialog.isShowing()) {
                    loadingDialog.dismiss();
                }
                MyfeedleNotifications.this.finish();
            }
        };
        loadingDialog.setMessage(getString(R.string.loading));
        loadingDialog.setCancelable(true);
        loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (!asyncTask.isCancelled())
                    asyncTask.cancel(true);
            }
        });
        loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        loadingDialog.show();
        asyncTask.execute();
    }
    return super.onContextItemSelected(item);
    // clear
}

From source file:com.app.khclub.base.easeim.activity.ContactlistFragment.java

/**
 * ?//from   w w  w  . jav  a2 s .  c om
 * 
 * @param toDeleteUser
 */
public void deleteContact(final User tobeDeleteUser) {
    String st1 = getResources().getString(R.string.deleting);
    final String st2 = getResources().getString(R.string.Delete_failed);
    final ProgressDialog pd = new ProgressDialog(getActivity());
    pd.setMessage(st1);
    pd.setCanceledOnTouchOutside(false);
    pd.show();

    // ?
    RequestParams params = new RequestParams();
    params.addBodyParameter("user_id", UserManager.getInstance().getUser().getUid() + "");
    params.addBodyParameter("target_id", tobeDeleteUser.getUsername().replace(KHConst.KH, ""));

    HttpManager.post(KHConst.DELETE_FRIEND, params,
            new JsonRequestCallBack<String>(new LoadDataHandler<String>() {
                @Override
                public void onSuccess(JSONObject jsonResponse, String flag) {
                    super.onSuccess(jsonResponse, flag);
                    int status = jsonResponse.getInteger(KHConst.HTTP_STATUS);
                    if (status == KHConst.STATUS_SUCCESS) {
                        new Thread(new Runnable() {
                            public void run() {
                                try {
                                    EMContactManager.getInstance().deleteContact(tobeDeleteUser.getUsername());
                                    // db?
                                    UserDao dao = new UserDao(getActivity());
                                    dao.deleteContact(tobeDeleteUser.getUsername());
                                    ((KHHXSDKHelper) HXSDKHelper.getInstance()).getContactList()
                                            .remove(tobeDeleteUser.getUsername());
                                    getActivity().runOnUiThread(new Runnable() {
                                        public void run() {
                                            pd.dismiss();
                                            adapter.remove(tobeDeleteUser);
                                            adapter.notifyDataSetChanged();
                                        }
                                    });
                                    // ?
                                    InviteMessgeDao msgDao = new InviteMessgeDao(getActivity());
                                    msgDao.deleteMessage(toBeProcessUser.getUsername());
                                } catch (final Exception e) {
                                    getActivity().runOnUiThread(new Runnable() {
                                        public void run() {
                                            pd.dismiss();
                                            Toast.makeText(getActivity(), st2 + e.getMessage(), 1).show();
                                        }
                                    });
                                }
                            }
                        }).start();
                    } else {
                        ToastUtil.show(getActivity(), R.string.net_error);
                        pd.dismiss();
                    }
                }

                @Override
                public void onFailure(HttpException arg0, String arg1, String flag) {
                    super.onFailure(arg0, arg1, flag);
                    ToastUtil.show(getActivity(), R.string.net_error);
                    pd.dismiss();
                }
            }, null));

    // new Thread(new Runnable() {
    // public void run() {
    // try {
    // EMContactManager.getInstance().deleteContact(tobeDeleteUser.getUsername());
    // // db?
    // UserDao dao = new UserDao(getActivity());
    // dao.deleteContact(tobeDeleteUser.getUsername());
    // ((KHHXSDKHelper)HXSDKHelper.getInstance()).getContactList().remove(tobeDeleteUser.getUsername());
    // getActivity().runOnUiThread(new Runnable() {
    // public void run() {
    // pd.dismiss();
    // adapter.remove(tobeDeleteUser);
    // adapter.notifyDataSetChanged();
    //
    // }
    // });
    // // ?
    // InviteMessgeDao msgDao = new InviteMessgeDao(getActivity());
    // msgDao.deleteMessage(toBeProcessUser.getUsername());
    // } catch (final Exception e) {
    // getActivity().runOnUiThread(new Runnable() {
    // public void run() {
    // pd.dismiss();
    // Toast.makeText(getActivity(), st2 + e.getMessage(), 1).show();
    // }
    // });
    //
    // }
    //
    // }
    // }).start();
}

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;//from w ww  . j  a v  a  2 s. co  m
    }
    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:eu.dirtyharry.androidopsiadmin.Main.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == GET_QR && resultCode == RESULT_OK) {
        contents = data.getExtras().getString("la.droid.qr.result");
        if (checkQR(contents)) {
            try {
                pc = (JSONObject) new JSONTokener(contents).nextValue();
                hosttocheck = pc.getString("dns");
            } catch (JSONException e) {
                e.printStackTrace();//from  w  ww  .ja v a2  s  . c  om
            }
            final ProgressDialog dialog = ProgressDialog.show(Main.this,
                    getString(R.string.gen_title_pleasewait),
                    String.format(getString(R.string.pd_checkifopsiclientexists), hosttocheck), true);
            final Handler handler = new Handler() {
                public void handleMessage(Message msg) {
                    if (hostexistsinopsi && doit.equals("true")) {
                        if (customtags) {
                            Intent i = new Intent(Main.this, ShowBarcodeData.class);
                            Bundle b = new Bundle();
                            b.putString("qrdata", contents);
                            i.putExtras(b);
                            startActivity(i);
                        } else {
                            Intent i = new Intent(Main.this, ShowOpsiClientOptions.class);
                            Bundle b = new Bundle();
                            b.putString("qrdata", contents);
                            i.putExtras(b);
                            startActivity(i);
                        }
                    } else if (!hostexistsinopsi) {
                        new Functions().msgBox(Main.this, getString(R.string.gen_title_error),
                                String.format(getString(R.string.general_noopsihost), hosttocheck), false);
                    } else {
                        Toast.makeText(Main.this,
                                String.format(getString(R.string.to_servernotrechable), serverip),
                                Toast.LENGTH_LONG).show();
                    }
                    dialog.dismiss();
                }
            };

            Thread checkUpdate = new Thread() {
                public void run() {
                    Looper.prepare();

                    if (eu.dirtyharry.androidopsiadmin.Networking.isServerUp(serverip, serverport,
                            serverusername, serverpasswd)) {
                        doit = "true";
                        if (eu.dirtyharry.androidopsiadmin.Networking.checkIfHostExistsInOpsi(hosttocheck,
                                serverip, serverport, serverusername, serverpasswd)) {
                            hostexistsinopsi = true;
                        } else {
                            hostexistsinopsi = false;
                        }
                    } else {
                        doit = "serverdown";
                    }
                    handler.sendEmptyMessage(0);

                }
            };
            checkUpdate.start();

        } else {
            new Functions().msgBox(Main.this, getString(R.string.gen_title_error),
                    getString(R.string.at_novalidqr), false);
        }
    } else if (requestCode == GET_OPSI_CLIENT_REQUEST && resultCode == Activity.RESULT_OK) {
        if (data.getStringExtra("message").equals("refresh")) {
            getOpsiClientsTask();
        }
        // } else if (requestCode == SHOW_OPSI_DEPOT_REQUEST
        // && resultCode == Activity.RESULT_OK) {
        // resultconfignames = data.getExtras().getStringArrayList(
        // "choosenones");
        // resultconfigvalues = data.getExtras().getStringArrayList(
        // "choosenonesvalues");
        // event_opsisenddepotconfigchanges();
    }
}

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();/*  w  w  w. j av a 2 s  .  com*/
    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.slownet5.pgprootexplorer.filemanager.ui.FileManagerActivity.java

private void setupRoot() {
    if (alreadySetup()) {
        afterInitSetup(true);//  ww  w .java 2 s  .com
        return;
    }
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setIndeterminate(true);
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setTitle("Setting up root");
    dialog.setCancelable(false);
    ;
    dialog.setMax(100);
    final String os = SystemUtils.getSystemArchitecture();
    Log.d(TAG, "setupRoot: architecture is: " + os);
    class Setup extends AsyncTask<Void, Integer, Boolean> {

        @Override
        protected Boolean doInBackground(Void... params) {
            new File(SharedData.CRYPTO_FM_PATH).mkdirs();
            String filename = SharedData.CRYPTO_FM_PATH + "/toybox";
            AssetManager asset = getAssets();
            try {

                InputStream stream = asset.open("toybox");

                OutputStream out = new FileOutputStream(filename);
                byte[] buffer = new byte[4096];
                int read;
                int total = 0;
                while ((read = stream.read(buffer)) != -1) {
                    total += read;
                    out.write(buffer, 0, read);
                }
                Log.d(TAG, "doInBackground: total written bytes: " + total);
                stream.close();
                out.flush();
                out.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                return false;
            }
            RootUtils.initRoot(filename);

            return true;
        }

        @Override
        protected void onPreExecute() {
            dialog.setMessage("Please wait....");
            dialog.show();
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            dialog.dismiss();
            if (aBoolean) {
                SharedPreferences.Editor prefs = getSharedPreferences(CommonConstants.COMMON_SHARED_PEREFS_NAME,
                        Context.MODE_PRIVATE).edit();
                prefs.putBoolean(CommonConstants.ROOT_TOYBOX, true);
                prefs.apply();
                prefs.commit();
                afterInitSetup(true);

            } else {
                afterInitSetup(aBoolean);
            }
        }
    }
    new Setup().execute();
}

From source file:com.example.research.whatis.MainActivity.java

public String invokeSynonymsAPI() throws IOException, JSONException {
    if (OCRedText.length() > 0) {
        final ProgressDialog dialog = ProgressDialog.show(MainActivity.this, "Loading ...",
                "Fetching synonym for " + OCRedText, true, false);
        final Thread thread = new Thread(new Runnable() {
            @Override//from www.  jav  a  2  s .c  o m
            public void run() {
                String synonymURL = "http://words.bighugelabs.com/api/2/4bbcc4ae52f1e82bd08e683a72665f7b/";

                synonymURL += OCRedText.toString() + "/json";
                synonymURL = synonymURL.replaceAll("\\s", "");

                Log.d("API", "Invokes Synonyms" + synonymURL);

                URL url = null;
                try {
                    url = new URL(synonymURL);
                    connection = (HttpURLConnection) url.openConnection();
                    connection.setDoOutput(true);
                    connection.setDoInput(true);
                    connection.setRequestMethod("GET");

                    connection.setRequestProperty("Content-Type", "application/json");
                    //connection.setRequestProperty("Content-Length", Integer.toString(OCRedText.length()));

                    OutputStream stream = connection.getOutputStream();
                    stream.close();

                    //fabulous/json

                    httpCode = connection.getResponseCode();

                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (ProtocolException e) {
                    e.printStackTrace();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                // Doing UI related code in UI thread
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dialog.dismiss();
                        // Success request
                        try {
                            if (httpCode == HttpURLConnection.HTTP_OK) {
                                // Get response stream
                                String jsonResponse = GetResponseToString(connection.getInputStream());
                                JSONObject reader = new JSONObject(jsonResponse);
                                Log.d("Synonyms JSONResp ", jsonResponse.toString());
                                Log.d("Synonyms Reader", reader.toString());

                                JSONArray text = null;
                                try {
                                    JSONObject obj = reader.getJSONObject("adjective");
                                    text = obj.getJSONArray("syn");
                                } catch (JSONException e) {
                                    e.printStackTrace();

                                    try {
                                        JSONObject obj = reader.getJSONObject("noun");
                                        text = obj.getJSONArray("syn");
                                    } catch (JSONException e1) {
                                        JSONObject obj = reader.getJSONObject("verb");
                                        text = obj.getJSONArray("syn");
                                    }
                                }

                                if (text != null) {
                                    synonym = text.get(0).toString();
                                } else {
                                    synonym = "<ERROR IN API>";
                                }

                                FileOutputStream fos = openFileOutput("synonym.txt", Context.MODE_APPEND);
                                fos.write(synonym.getBytes());
                                fos.close();
                            } else {
                                // Error occurred
                                String jsonResponse = GetResponseToString(connection.getErrorStream());

                                JSONObject reader = new JSONObject(jsonResponse);
                                JSONArray text = reader.getJSONArray("ErrorMessage");

                                synonym = text.get(0).toString();
                                // Error message
                                //                                    Toast.makeText(MainActivity.this, "Error Message: " + synonym, Toast.LENGTH_LONG).show();
                                System.out.println();
                            }

                            connection.disconnect();

                            TextView view = (TextView) findViewById(R.id.textView);
                            view.setVisibility(View.VISIBLE);
                            ListView lView = (ListView) findViewById(R.id.listView);
                            lView.setVisibility(View.GONE);

                            view.setText(OCRedText + ":" + synonym);
                            dbHelper.insertWord(OCRedText, synonym, "", "http://words.bighugelabs.com");
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
        thread.start();
    } else {
        synonym = "";
    }

    return synonym;
}

From source file:com.piusvelte.sonet.core.OAuthLogin.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setResult(RESULT_CANCELED);// ww w  . j av  a  2s  .  co m
    mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext());
    mLoadingDialog = new ProgressDialog(this);
    mLoadingDialog.setMessage(getString(R.string.loading));
    mLoadingDialog.setCancelable(true);
    mLoadingDialog.setOnCancelListener(this);
    mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this);
    Intent intent = getIntent();
    if (intent != null) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE);
            mServiceName = Sonet.getServiceName(getResources(), service);
            mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID);
            mSonetWebView = new SonetWebView();
            final ProgressDialog loadingDialog = new ProgressDialog(this);
            final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() {
                @Override
                protected String doInBackground(String... args) {
                    try {
                        return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3],
                                Boolean.parseBoolean(args[4]), mHttpClient);
                    } catch (OAuthMessageSignerException e) {
                        e.printStackTrace();
                    } catch (OAuthNotAuthorizedException e) {
                        e.printStackTrace();
                    } catch (OAuthExpectationFailedException e) {
                        e.printStackTrace();
                    } catch (OAuthCommunicationException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(String url) {
                    if (loadingDialog.isShowing())
                        loadingDialog.dismiss();
                    // load the webview
                    if (url != null) {
                        mSonetWebView.open(url);
                    } else {
                        (Toast.makeText(OAuthLogin.this,
                                String.format(getString(R.string.oauth_error), mServiceName),
                                Toast.LENGTH_LONG)).show();
                        OAuthLogin.this.finish();
                    }
                }
            };
            loadingDialog.setMessage(getString(R.string.loading));
            loadingDialog.setCancelable(true);
            loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    if (!asyncTask.isCancelled())
                        asyncTask.cancel(true);
                    dialog.cancel();
                    OAuthLogin.this.finish();
                }
            });
            loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (!asyncTask.isCancelled())
                                asyncTask.cancel(true);
                            dialog.cancel();
                            OAuthLogin.this.finish();
                        }
                    });
            switch (service) {
            case TWITTER:
                mSonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET);
                asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL),
                        String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL),
                        String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(),
                        Boolean.toString(true));
                loadingDialog.show();
                break;
            case FACEBOOK:
                mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, FACEBOOK_ID,
                        FACEBOOK_CALLBACK.toString()));
                break;
            case MYSPACE:
                mSonetOAuth = new SonetOAuth(MYSPACE_KEY, MYSPACE_SECRET);
                asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE,
                        MYSPACE_CALLBACK.toString(), Boolean.toString(true));
                loadingDialog.show();
                break;
            case FOURSQUARE:
                mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, FOURSQUARE_KEY,
                        FOURSQUARE_CALLBACK.toString()));
                break;
            case LINKEDIN:
                mSonetOAuth = new SonetOAuth(LINKEDIN_KEY, LINKEDIN_SECRET);
                asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE,
                        LINKEDIN_CALLBACK.toString(), Boolean.toString(true));
                loadingDialog.show();
                break;
            case SMS:
                Cursor c = getContentResolver().query(Accounts.getContentUri(this),
                        new String[] { Accounts._ID }, Accounts.SERVICE + "=?",
                        new String[] { Integer.toString(SMS) }, null);
                if (c.moveToFirst()) {
                    (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show();
                } else {
                    addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS,
                            null);
                }
                c.close();
                finish();
                break;
            case RSS:
                // prompt for RSS url
                final EditText rss_url = new EditText(this);
                rss_url.setSingleLine();
                new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url)
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, int which) {
                                // test the url and add if valid, else Toast error
                                mLoadingDialog.show();
                                (new AsyncTask<String, Void, String>() {
                                    String url;

                                    @Override
                                    protected String doInBackground(String... params) {
                                        url = rss_url.getText().toString();
                                        return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url));
                                    }

                                    @Override
                                    protected void onPostExecute(String response) {
                                        mLoadingDialog.dismiss();
                                        if (response != null) {
                                            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                            DocumentBuilder db;
                                            try {
                                                db = dbf.newDocumentBuilder();
                                                InputSource is = new InputSource();
                                                is.setCharacterStream(new StringReader(response));
                                                Document doc = db.parse(is);
                                                // test parsing...
                                                NodeList nodes = doc.getElementsByTagName(Sitem);
                                                if (nodes.getLength() > 0) {
                                                    // check for an image
                                                    NodeList images = doc.getElementsByTagName(Simage);
                                                    if (images.getLength() > 0) {
                                                        NodeList imageChildren = images.item(0).getChildNodes();
                                                        Node n = imageChildren.item(0);
                                                        if (n.getNodeName().toLowerCase().equals(Surl)) {
                                                            if (n.hasChildNodes()) {
                                                                n.getChildNodes().item(0).getNodeValue();
                                                            }
                                                        }
                                                    }
                                                    NodeList children = nodes.item(0).getChildNodes();
                                                    String date = null;
                                                    String title = null;
                                                    String description = null;
                                                    String link = null;
                                                    int values_count = 0;
                                                    for (int child = 0, c2 = children.getLength(); (child < c2)
                                                            && (values_count < 4); child++) {
                                                        Node n = children.item(child);
                                                        if (n.getNodeName().toLowerCase().equals(Spubdate)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                date = n.getChildNodes().item(0).getNodeValue();
                                                            }
                                                        } else if (n.getNodeName().toLowerCase()
                                                                .equals(Stitle)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                title = n.getChildNodes().item(0)
                                                                        .getNodeValue();
                                                            }
                                                        } else if (n.getNodeName().toLowerCase()
                                                                .equals(Sdescription)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                StringBuilder sb = new StringBuilder();
                                                                NodeList descNodes = n.getChildNodes();
                                                                for (int dn = 0, dn2 = descNodes
                                                                        .getLength(); dn < dn2; dn++) {
                                                                    Node descNode = descNodes.item(dn);
                                                                    if (descNode
                                                                            .getNodeType() == Node.TEXT_NODE) {
                                                                        sb.append(descNode.getNodeValue());
                                                                    }
                                                                }
                                                                // strip out the html tags
                                                                description = sb.toString()
                                                                        .replaceAll("\\<(.|\n)*?>", "");
                                                            }
                                                        } else if (n.getNodeName().toLowerCase()
                                                                .equals(Slink)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                link = n.getChildNodes().item(0).getNodeValue();
                                                            }
                                                        }
                                                    }
                                                    if (Sonet.HasValues(
                                                            new String[] { title, description, link, date })) {
                                                        final EditText url_name = new EditText(OAuthLogin.this);
                                                        url_name.setSingleLine();
                                                        new AlertDialog.Builder(OAuthLogin.this)
                                                                .setTitle(R.string.rss_channel)
                                                                .setView(url_name)
                                                                .setPositiveButton(android.R.string.ok,
                                                                        new DialogInterface.OnClickListener() {
                                                                            @Override
                                                                            public void onClick(
                                                                                    DialogInterface dialog1,
                                                                                    int which) {
                                                                                addAccount(
                                                                                        url_name.getText()
                                                                                                .toString(),
                                                                                        null, null, 0, RSS,
                                                                                        url);
                                                                                dialog1.dismiss();
                                                                                dialog.dismiss();
                                                                                finish();
                                                                            }
                                                                        })
                                                                .setNegativeButton(android.R.string.cancel,
                                                                        new DialogInterface.OnClickListener() {
                                                                            @Override
                                                                            public void onClick(
                                                                                    DialogInterface dialog1,
                                                                                    int which) {
                                                                                dialog1.dismiss();
                                                                                dialog.dismiss();
                                                                                finish();
                                                                            }
                                                                        })
                                                                .show();
                                                    } else {
                                                        (Toast.makeText(OAuthLogin.this,
                                                                "Feed is missing standard fields",
                                                                Toast.LENGTH_LONG)).show();
                                                    }
                                                } else {
                                                    (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                            Toast.LENGTH_LONG)).show();
                                                    dialog.dismiss();
                                                    finish();
                                                }
                                            } catch (ParserConfigurationException e) {
                                                Log.e(TAG, e.toString());
                                                (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                        Toast.LENGTH_LONG)).show();
                                                dialog.dismiss();
                                                finish();
                                            } catch (SAXException e) {
                                                Log.e(TAG, e.toString());
                                                (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                        Toast.LENGTH_LONG)).show();
                                                dialog.dismiss();
                                                finish();
                                            } catch (IOException e) {
                                                Log.e(TAG, e.toString());
                                                (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                        Toast.LENGTH_LONG)).show();
                                                dialog.dismiss();
                                                finish();
                                            }
                                        } else {
                                            (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG))
                                                    .show();
                                            dialog.dismiss();
                                            finish();
                                        }
                                    }
                                }).execute(rss_url.getText().toString());
                            }
                        }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                finish();
                            }
                        }).show();
                break;
            case IDENTICA:
                mSonetOAuth = new SonetOAuth(IDENTICA_KEY, IDENTICA_SECRET);
                asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL),
                        String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL),
                        String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(),
                        Boolean.toString(true));
                loadingDialog.show();
                break;
            case GOOGLEPLUS:
                mSonetWebView.open(
                        String.format(GOOGLEPLUS_AUTHORIZE, GOOGLE_CLIENTID, "urn:ietf:wg:oauth:2.0:oob"));
                break;
            case CHATTER:
                mSonetWebView
                        .open(String.format(CHATTER_URL_AUTHORIZE, CHATTER_KEY, CHATTER_CALLBACK.toString()));
                break;
            case PINTEREST:
                Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this),
                        new String[] { Accounts._ID }, Accounts.SERVICE + "=?",
                        new String[] { Integer.toString(PINTEREST) }, null);
                if (pinterestAccount.moveToFirst()) {
                    (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG))
                            .show();
                } else {
                    (Toast.makeText(OAuthLogin.this,
                            "Pinterest currently allows only public, non-authenticated viewing.",
                            Toast.LENGTH_LONG)).show();
                    String[] values = getResources().getStringArray(R.array.service_values);
                    String[] entries = getResources().getStringArray(R.array.service_entries);
                    for (int i = 0, l = values.length; i < l; i++) {
                        if (Integer.toString(PINTEREST).equals(values[i])) {
                            addAccount(entries[i], null, null, 0, PINTEREST, null);
                            break;
                        }
                    }
                }
                pinterestAccount.close();
                finish();
                break;
            default:
                this.finish();
            }
        }
    }
}

From source file:com.commonsware.android.EMusicDownloader.SingleBook.java

private void getInfoFromXML() {

    final ProgressDialog dialog = ProgressDialog.show(this, "", getString(R.string.loading), true, true);
    setProgressBarIndeterminateVisibility(true);

    Thread t3 = new Thread() {
        public void run() {

            waiting(200);/*w  w w.j  ava  2 s  .  c  o m*/

            try {

                URL url = new URL(urlAddress);
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                XMLHandlerSingleBook myXMLHandler = new XMLHandlerSingleBook();
                xr.setContentHandler(myXMLHandler);
                xr.parse(new InputSource(url.openStream()));

                genre = myXMLHandler.genre;
                publisher = myXMLHandler.publisher;
                narrator = myXMLHandler.narrator;
                edition = myXMLHandler.edition;
                artist = myXMLHandler.author;
                authorId = myXMLHandler.authorId;
                if (edition == null) {
                    edition = "";
                }
                date = myXMLHandler.releaseDate;
                rating = myXMLHandler.rating;
                sampleURL = myXMLHandler.sampleURL;
                imageURL = myXMLHandler.imageURL;

                statuscode = myXMLHandler.statuscode;

                if (statuscode != 200 && statuscode != 206) {
                    throw new Exception();
                }

                blurb = myXMLHandler.blurb;
                blurb = blurb.replace("<br> ", "<br>");
                blurbSource = myXMLHandler.blurbSource;

                handlerSetContent.sendEmptyMessage(0);
                dialog.dismiss();
                updateImage();

            } catch (Exception e) {

                final Exception ef = e;
                nameTextView.post(new Runnable() {
                    public void run() {
                        nameTextView.setText(R.string.couldnt_get_book_info);
                    }
                });
                dialog.dismiss();

            }

            handlerDoneLoading.sendEmptyMessage(0);

        }
    };
    t3.start();
}

From source file:com.piusvelte.sonet.OAuthLogin.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setResult(RESULT_CANCELED);/*from  w  w w .j  a va2  s .c  om*/
    mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext());
    mLoadingDialog = new ProgressDialog(this);
    mLoadingDialog.setMessage(getString(R.string.loading));
    mLoadingDialog.setCancelable(true);
    mLoadingDialog.setOnCancelListener(this);
    mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this);
    Intent intent = getIntent();
    if (intent != null) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE);
            mServiceName = Sonet.getServiceName(getResources(), service);
            mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID);
            mSonetWebView = new SonetWebView();
            final ProgressDialog loadingDialog = new ProgressDialog(this);
            final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() {
                @Override
                protected String doInBackground(String... args) {
                    try {
                        return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3],
                                Boolean.parseBoolean(args[4]), mHttpClient);
                    } catch (OAuthMessageSignerException e) {
                        e.printStackTrace();
                    } catch (OAuthNotAuthorizedException e) {
                        e.printStackTrace();
                    } catch (OAuthExpectationFailedException e) {
                        e.printStackTrace();
                    } catch (OAuthCommunicationException e) {
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(String url) {
                    if (loadingDialog.isShowing())
                        loadingDialog.dismiss();
                    // load the webview
                    if (url != null) {
                        mSonetWebView.open(url);
                    } else {
                        (Toast.makeText(OAuthLogin.this,
                                String.format(getString(R.string.oauth_error), mServiceName),
                                Toast.LENGTH_LONG)).show();
                        OAuthLogin.this.finish();
                    }
                }
            };
            loadingDialog.setMessage(getString(R.string.loading));
            loadingDialog.setCancelable(true);
            loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    if (!asyncTask.isCancelled())
                        asyncTask.cancel(true);
                    dialog.cancel();
                    OAuthLogin.this.finish();
                }
            });
            loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (!asyncTask.isCancelled())
                                asyncTask.cancel(true);
                            dialog.cancel();
                            OAuthLogin.this.finish();
                        }
                    });
            switch (service) {
            case TWITTER:
                mSonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET);
                asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL),
                        String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL),
                        String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(),
                        Boolean.toString(true));
                loadingDialog.show();
                break;
            case FACEBOOK:
                mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL,
                        BuildConfig.FACEBOOK_ID, FACEBOOK_CALLBACK.toString()));
                break;
            case MYSPACE:
                mSonetOAuth = new SonetOAuth(BuildConfig.MYSPACE_KEY, BuildConfig.MYSPACE_SECRET);
                asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE,
                        MYSPACE_CALLBACK.toString(), Boolean.toString(true));
                loadingDialog.show();
                break;
            case FOURSQUARE:
                mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, BuildConfig.FOURSQUARE_KEY,
                        FOURSQUARE_CALLBACK.toString()));
                break;
            case LINKEDIN:
                mSonetOAuth = new SonetOAuth(BuildConfig.LINKEDIN_KEY, BuildConfig.LINKEDIN_SECRET);
                asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE,
                        LINKEDIN_CALLBACK.toString(), Boolean.toString(true));
                loadingDialog.show();
                break;
            case SMS:
                Cursor c = getContentResolver().query(Accounts.getContentUri(this),
                        new String[] { Accounts._ID }, Accounts.SERVICE + "=?",
                        new String[] { Integer.toString(SMS) }, null);
                if (c.moveToFirst()) {
                    (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show();
                } else {
                    addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS,
                            null);
                }
                c.close();
                finish();
                break;
            case RSS:
                // prompt for RSS url
                final EditText rss_url = new EditText(this);
                rss_url.setSingleLine();
                new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url)
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialog, int which) {
                                // test the url and add if valid, else Toast error
                                mLoadingDialog.show();
                                (new AsyncTask<String, Void, String>() {
                                    String url;

                                    @Override
                                    protected String doInBackground(String... params) {
                                        url = rss_url.getText().toString();
                                        return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url));
                                    }

                                    @Override
                                    protected void onPostExecute(String response) {
                                        mLoadingDialog.dismiss();
                                        if (response != null) {
                                            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                            DocumentBuilder db;
                                            try {
                                                db = dbf.newDocumentBuilder();
                                                InputSource is = new InputSource();
                                                is.setCharacterStream(new StringReader(response));
                                                Document doc = db.parse(is);
                                                // test parsing...
                                                NodeList nodes = doc.getElementsByTagName(Sitem);
                                                if (nodes.getLength() > 0) {
                                                    // check for an image
                                                    NodeList images = doc.getElementsByTagName(Simage);
                                                    if (images.getLength() > 0) {
                                                        NodeList imageChildren = images.item(0).getChildNodes();
                                                        Node n = imageChildren.item(0);
                                                        if (n.getNodeName().toLowerCase().equals(Surl)) {
                                                            if (n.hasChildNodes()) {
                                                                n.getChildNodes().item(0).getNodeValue();
                                                            }
                                                        }
                                                    }
                                                    NodeList children = nodes.item(0).getChildNodes();
                                                    String date = null;
                                                    String title = null;
                                                    String description = null;
                                                    String link = null;
                                                    int values_count = 0;
                                                    for (int child = 0, c2 = children.getLength(); (child < c2)
                                                            && (values_count < 4); child++) {
                                                        Node n = children.item(child);
                                                        if (n.getNodeName().toLowerCase().equals(Spubdate)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                date = n.getChildNodes().item(0).getNodeValue();
                                                            }
                                                        } else if (n.getNodeName().toLowerCase()
                                                                .equals(Stitle)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                title = n.getChildNodes().item(0)
                                                                        .getNodeValue();
                                                            }
                                                        } else if (n.getNodeName().toLowerCase()
                                                                .equals(Sdescription)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                StringBuilder sb = new StringBuilder();
                                                                NodeList descNodes = n.getChildNodes();
                                                                for (int dn = 0, dn2 = descNodes
                                                                        .getLength(); dn < dn2; dn++) {
                                                                    Node descNode = descNodes.item(dn);
                                                                    if (descNode
                                                                            .getNodeType() == Node.TEXT_NODE) {
                                                                        sb.append(descNode.getNodeValue());
                                                                    }
                                                                }
                                                                // strip out the html tags
                                                                description = sb.toString()
                                                                        .replaceAll("\\<(.|\n)*?>", "");
                                                            }
                                                        } else if (n.getNodeName().toLowerCase()
                                                                .equals(Slink)) {
                                                            values_count++;
                                                            if (n.hasChildNodes()) {
                                                                link = n.getChildNodes().item(0).getNodeValue();
                                                            }
                                                        }
                                                    }
                                                    if (Sonet.HasValues(
                                                            new String[] { title, description, link, date })) {
                                                        final EditText url_name = new EditText(OAuthLogin.this);
                                                        url_name.setSingleLine();
                                                        new AlertDialog.Builder(OAuthLogin.this)
                                                                .setTitle(R.string.rss_channel)
                                                                .setView(url_name)
                                                                .setPositiveButton(android.R.string.ok,
                                                                        new DialogInterface.OnClickListener() {
                                                                            @Override
                                                                            public void onClick(
                                                                                    DialogInterface dialog1,
                                                                                    int which) {
                                                                                addAccount(
                                                                                        url_name.getText()
                                                                                                .toString(),
                                                                                        null, null, 0, RSS,
                                                                                        url);
                                                                                dialog1.dismiss();
                                                                                dialog.dismiss();
                                                                                finish();
                                                                            }
                                                                        })
                                                                .setNegativeButton(android.R.string.cancel,
                                                                        new DialogInterface.OnClickListener() {
                                                                            @Override
                                                                            public void onClick(
                                                                                    DialogInterface dialog1,
                                                                                    int which) {
                                                                                dialog1.dismiss();
                                                                                dialog.dismiss();
                                                                                finish();
                                                                            }
                                                                        })
                                                                .show();
                                                    } else {
                                                        (Toast.makeText(OAuthLogin.this,
                                                                "Feed is missing standard fields",
                                                                Toast.LENGTH_LONG)).show();
                                                    }
                                                } else {
                                                    (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                            Toast.LENGTH_LONG)).show();
                                                    dialog.dismiss();
                                                    finish();
                                                }
                                            } catch (ParserConfigurationException e) {
                                                Log.e(TAG, e.toString());
                                                (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                        Toast.LENGTH_LONG)).show();
                                                dialog.dismiss();
                                                finish();
                                            } catch (SAXException e) {
                                                Log.e(TAG, e.toString());
                                                (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                        Toast.LENGTH_LONG)).show();
                                                dialog.dismiss();
                                                finish();
                                            } catch (IOException e) {
                                                Log.e(TAG, e.toString());
                                                (Toast.makeText(OAuthLogin.this, "Invalid feed",
                                                        Toast.LENGTH_LONG)).show();
                                                dialog.dismiss();
                                                finish();
                                            }
                                        } else {
                                            (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG))
                                                    .show();
                                            dialog.dismiss();
                                            finish();
                                        }
                                    }
                                }).execute(rss_url.getText().toString());
                            }
                        }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                finish();
                            }
                        }).show();
                break;
            case IDENTICA:
                mSonetOAuth = new SonetOAuth(BuildConfig.IDENTICA_KEY, BuildConfig.IDENTICA_SECRET);
                asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL),
                        String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL),
                        String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(),
                        Boolean.toString(true));
                loadingDialog.show();
                break;
            case GOOGLEPLUS:
                mSonetWebView.open(String.format(GOOGLEPLUS_AUTHORIZE, BuildConfig.GOOGLECLIENT_ID,
                        "urn:ietf:wg:oauth:2.0:oob"));
                break;
            case CHATTER:
                mSonetWebView.open(String.format(CHATTER_URL_AUTHORIZE, BuildConfig.CHATTER_KEY,
                        CHATTER_CALLBACK.toString()));
                break;
            case PINTEREST:
                Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this),
                        new String[] { Accounts._ID }, Accounts.SERVICE + "=?",
                        new String[] { Integer.toString(PINTEREST) }, null);
                if (pinterestAccount.moveToFirst()) {
                    (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG))
                            .show();
                } else {
                    (Toast.makeText(OAuthLogin.this,
                            "Pinterest currently allows only public, non-authenticated viewing.",
                            Toast.LENGTH_LONG)).show();
                    String[] values = getResources().getStringArray(R.array.service_values);
                    String[] entries = getResources().getStringArray(R.array.service_entries);
                    for (int i = 0, l = values.length; i < l; i++) {
                        if (Integer.toString(PINTEREST).equals(values[i])) {
                            addAccount(entries[i], null, null, 0, PINTEREST, null);
                            break;
                        }
                    }
                }
                pinterestAccount.close();
                finish();
                break;
            default:
                this.finish();
            }
        }
    }
}