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.aibasis.parent.ui.entrance.LoginActivity.java

/**
 * /*w  ww  .  j  a v a2s.  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;
    }
    currentUsername = usernameEditText.getText().toString().trim();
    currentPassword = passwordEditText.getText().toString().trim();

    if (TextUtils.isEmpty(currentUsername)) {
        Toast.makeText(this, R.string.User_name_cannot_be_empty, Toast.LENGTH_SHORT).show();
        return;
    }
    if (TextUtils.isEmpty(currentPassword)) {
        Toast.makeText(this, R.string.Password_cannot_be_empty, Toast.LENGTH_SHORT).show();
        return;
    }

    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(getString(R.string.Is_landing));
    pd.show();

    final long start = System.currentTimeMillis();

    accountAPI.login(currentUsername, currentPassword, new RequestListener() {
        @Override
        public void onComplete(String result) {
            try {
                final LoginResult loginResult = LoginResult.parse(result);
                if (LoginResult.SUCCESS.equals(loginResult.getResult())) {
                    // sdk??
                    EMChatManager.getInstance().login(loginResult.getEaseId(), loginResult.getEasePassword(),
                            new EMCallBack() {

                                @Override
                                public void onSuccess() {
                                    if (!progressShow) {
                                        return;
                                    }
                                    // ?????
                                    DemoApplication.getInstance().setUserName(currentUsername);
                                    DemoApplication.getInstance().setPassword(currentPassword);
                                    DemoApplication.getInstance().setEaseId(loginResult.getEaseId());
                                    DemoApplication.getInstance()
                                            .setEasePassword(loginResult.getEasePassword());
                                    DemoApplication.getInstance().setParentId(loginResult.getParentId());

                                    SharePreferenceUtil sharePreferenceUtil = new SharePreferenceUtil(
                                            LoginActivity.this);
                                    sharePreferenceUtil
                                            .setParentId(DemoApplication.getInstance().getParentId());

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

                                    finish();
                                }

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

                                @Override
                                public void onError(final int code, final String message) {
                                    if (!progressShow) {
                                        return;
                                    }
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            pd.dismiss();
                                            Toast.makeText(getApplicationContext(),
                                                    getString(R.string.Login_failed) + message,
                                                    Toast.LENGTH_SHORT).show();
                                        }
                                    });
                                }
                            });
                } else if (LoginResult.FAILED.equals(loginResult.getResult())) {
                    {
                        Toast.makeText(getApplicationContext(), getString(R.string.Login_failed),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onAPIException(APIException exception) {

        }
    });
}

From source file:org.cafemember.ui.LaunchActivity.java

private void runLinkRequest(final String username, final String group, final String sticker,
        final String botUser, final String botChat, final String message, final boolean hasUrl,
        final Integer messageId, final int state) {
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setCancelable(false);
    int requestId = 0;

    if (username != null) {
        TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
        req.username = username;/*from   w  ww . ja v a  2s  . com*/
        requestId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
            @Override
            public void run(final TLObject response, final TLRPC.TL_error error) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (!LaunchActivity.this.isFinishing()) {
                            try {
                                progressDialog.dismiss();
                            } catch (Exception e) {
                                FileLog.e("tmessages", e);
                            }
                            if (error == null && actionBarLayout != null) {
                                final TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                                MessagesController.getInstance().putUsers(res.users, false);
                                MessagesController.getInstance().putChats(res.chats, false);
                                MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, false,
                                        true);

                                if (botChat != null) {
                                    final TLRPC.User user = !res.users.isEmpty() ? res.users.get(0) : null;
                                    if (user == null || user.bot && user.bot_nochats) {
                                        try {
                                            Toast.makeText(LaunchActivity.this,
                                                    LocaleController.getString("BotCantJoinGroups",
                                                            R.string.BotCantJoinGroups),
                                                    Toast.LENGTH_SHORT).show();
                                        } catch (Exception e) {
                                            FileLog.e("tmessages", e);
                                        }
                                        return;
                                    }
                                    Bundle args = new Bundle();
                                    args.putBoolean("onlySelect", true);
                                    args.putInt("dialogsType", 2);
                                    args.putString("addToGroupAlertString",
                                            LocaleController.formatString("AddToTheGroupTitle",
                                                    R.string.AddToTheGroupTitle, UserObject.getUserName(user),
                                                    "%1$s"));
                                    DialogsActivity fragment = new DialogsActivity(args);
                                    fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
                                        @Override
                                        public void didSelectDialog(DialogsActivity fragment, long did,
                                                boolean param) {
                                            Bundle args = new Bundle();
                                            args.putBoolean("scrollToTopOnResume", true);
                                            args.putInt("chat_id", -(int) did);
                                            if (mainFragmentsStack.isEmpty() || MessagesController
                                                    .checkCanOpenChat(args, mainFragmentsStack
                                                            .get(mainFragmentsStack.size() - 1))) {
                                                NotificationCenter.getInstance()
                                                        .postNotificationName(NotificationCenter.closeChats);
                                                MessagesController.getInstance().addUserToChat(-(int) did, user,
                                                        null, 0, botChat, null);
                                                actionBarLayout.presentFragment(new ChatActivity(args), true,
                                                        false, true);
                                            }
                                        }
                                    });
                                    presentFragment(fragment);
                                } else {
                                    long dialog_id;
                                    boolean isBot = false;
                                    Bundle args = new Bundle();
                                    if (!res.chats.isEmpty()) {
                                        args.putInt("chat_id", res.chats.get(0).id);
                                        dialog_id = -res.chats.get(0).id;
                                    } else {
                                        args.putInt("user_id", res.users.get(0).id);
                                        dialog_id = res.users.get(0).id;
                                    }
                                    if (botUser != null && res.users.size() > 0 && res.users.get(0).bot) {
                                        args.putString("botUser", botUser);
                                        isBot = true;
                                    }
                                    if (messageId != null) {
                                        args.putInt("message_id", messageId);
                                    }
                                    BaseFragment lastFragment = !mainFragmentsStack.isEmpty()
                                            ? mainFragmentsStack.get(mainFragmentsStack.size() - 1)
                                            : null;
                                    if (lastFragment == null
                                            || MessagesController.checkCanOpenChat(args, lastFragment)) {
                                        if (isBot && lastFragment != null
                                                && lastFragment instanceof ChatActivity
                                                && ((ChatActivity) lastFragment).getDialogId() == dialog_id) {
                                            ((ChatActivity) lastFragment).setBotUser(botUser);
                                        } else {
                                            ChatActivity fragment = new ChatActivity(args);
                                            NotificationCenter.getInstance()
                                                    .postNotificationName(NotificationCenter.closeChats);
                                            actionBarLayout.presentFragment(fragment, false, true, true);
                                        }
                                    }
                                }
                            } else {
                                try {
                                    Toast.makeText(LaunchActivity.this, LocaleController.getString(
                                            "NoUsernameFound", R.string.NoUsernameFound), Toast.LENGTH_SHORT)
                                            .show();
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                            }
                        }
                    }
                });
            }
        });
    } else if (group != null) {
        if (state == 0) {
            final TLRPC.TL_messages_checkChatInvite req = new TLRPC.TL_messages_checkChatInvite();
            req.hash = group;
            requestId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                @Override
                public void run(final TLObject response, final TLRPC.TL_error error) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            if (!LaunchActivity.this.isFinishing()) {
                                try {
                                    progressDialog.dismiss();
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                if (error == null && actionBarLayout != null) {
                                    TLRPC.ChatInvite invite = (TLRPC.ChatInvite) response;
                                    if (invite.chat != null && !ChatObject.isLeftFromChat(invite.chat)) {
                                        MessagesController.getInstance().putChat(invite.chat, false);
                                        ArrayList<TLRPC.Chat> chats = new ArrayList<>();
                                        chats.add(invite.chat);
                                        MessagesStorage.getInstance().putUsersAndChats(null, chats, false,
                                                true);
                                        Bundle args = new Bundle();
                                        args.putInt("chat_id", invite.chat.id);
                                        if (mainFragmentsStack.isEmpty() || MessagesController.checkCanOpenChat(
                                                args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
                                            ChatActivity fragment = new ChatActivity(args);
                                            NotificationCenter.getInstance()
                                                    .postNotificationName(NotificationCenter.closeChats);
                                            actionBarLayout.presentFragment(fragment, false, true, true);
                                        }
                                    } else {
                                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                                LaunchActivity.this);
                                        builder.setTitle(
                                                LocaleController.getString("AppName", R.string.AppName));
                                        if (!invite.megagroup && invite.channel
                                                || ChatObject.isChannel(invite.chat)
                                                        && !invite.chat.megagroup) {
                                            builder.setMessage(LocaleController.formatString("ChannelJoinTo",
                                                    R.string.ChannelJoinTo,
                                                    invite.chat != null ? invite.chat.title : invite.title));
                                        } else {
                                            builder.setMessage(LocaleController.formatString("JoinToGroup",
                                                    R.string.JoinToGroup,
                                                    invite.chat != null ? invite.chat.title : invite.title));
                                        }
                                        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialogInterface,
                                                            int i) {
                                                        runLinkRequest(username, group, sticker, botUser,
                                                                botChat, message, hasUrl, messageId, 1);
                                                    }
                                                });
                                        builder.setNegativeButton(
                                                LocaleController.getString("Cancel", R.string.Cancel), null);
                                        showAlertDialog(builder);
                                    }
                                } else {
                                    AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
                                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                                    if (error.text.startsWith("FLOOD_WAIT")) {
                                        builder.setMessage(
                                                LocaleController.getString("FloodWait", R.string.FloodWait));
                                    } else {
                                        builder.setMessage(LocaleController.getString(
                                                "JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
                                    }
                                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                            null);
                                    showAlertDialog(builder);
                                }
                            }
                        }
                    });
                }
            }, ConnectionsManager.RequestFlagFailOnServerErrors);
        } else if (state == 1) {
            TLRPC.TL_messages_importChatInvite req = new TLRPC.TL_messages_importChatInvite();
            req.hash = group;
            ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                @Override
                public void run(final TLObject response, final TLRPC.TL_error error) {
                    if (error == null) {
                        TLRPC.Updates updates = (TLRPC.Updates) response;
                        MessagesController.getInstance().processUpdates(updates, false);
                    }
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            if (!LaunchActivity.this.isFinishing()) {
                                try {
                                    progressDialog.dismiss();
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                if (error == null) {
                                    if (actionBarLayout != null) {
                                        TLRPC.Updates updates = (TLRPC.Updates) response;
                                        if (!updates.chats.isEmpty()) {
                                            TLRPC.Chat chat = updates.chats.get(0);
                                            chat.left = false;
                                            chat.kicked = false;
                                            MessagesController.getInstance().putUsers(updates.users, false);
                                            MessagesController.getInstance().putChats(updates.chats, false);
                                            Bundle args = new Bundle();
                                            args.putInt("chat_id", chat.id);
                                            if (mainFragmentsStack.isEmpty() || MessagesController
                                                    .checkCanOpenChat(args, mainFragmentsStack
                                                            .get(mainFragmentsStack.size() - 1))) {
                                                ChatActivity fragment = new ChatActivity(args);
                                                NotificationCenter.getInstance()
                                                        .postNotificationName(NotificationCenter.closeChats);
                                                actionBarLayout.presentFragment(fragment, false, true, true);
                                            }
                                        }
                                    }
                                } else {
                                    AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
                                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                                    if (error.text.startsWith("FLOOD_WAIT")) {
                                        builder.setMessage(
                                                LocaleController.getString("FloodWait", R.string.FloodWait));
                                    } else if (error.text.equals("USERS_TOO_MUCH")) {
                                        builder.setMessage(LocaleController.getString("JoinToGroupErrorFull",
                                                R.string.JoinToGroupErrorFull));
                                    } else {
                                        builder.setMessage(LocaleController.getString(
                                                "JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
                                    }
                                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                            null);
                                    showAlertDialog(builder);
                                }
                            }
                        }
                    });
                }
            }, ConnectionsManager.RequestFlagFailOnServerErrors);
        }
    } else if (sticker != null) {
        if (!mainFragmentsStack.isEmpty()) {
            TLRPC.TL_inputStickerSetShortName stickerset = new TLRPC.TL_inputStickerSetShortName();
            stickerset.short_name = sticker;
            mainFragmentsStack.get(mainFragmentsStack.size() - 1)
                    .showDialog(new StickersAlert(LaunchActivity.this, stickerset, null, null));
        }
        return;
    } else if (message != null) {
        Bundle args = new Bundle();
        args.putBoolean("onlySelect", true);
        DialogsActivity fragment = new DialogsActivity(args);
        fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
            @Override
            public void didSelectDialog(DialogsActivity fragment, long did, boolean param) {
                Bundle args = new Bundle();
                args.putBoolean("scrollToTopOnResume", true);
                args.putBoolean("hasUrl", hasUrl);
                int lower_part = (int) did;
                int high_id = (int) (did >> 32);
                if (lower_part != 0) {
                    if (high_id == 1) {
                        args.putInt("chat_id", lower_part);
                    } else {
                        if (lower_part > 0) {
                            args.putInt("user_id", lower_part);
                        } else if (lower_part < 0) {
                            args.putInt("chat_id", -lower_part);
                        }
                    }
                } else {
                    args.putInt("enc_id", high_id);
                }
                if (MessagesController.checkCanOpenChat(args, fragment)) {
                    NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putString("dialog_" + did, message);
                    editor.commit();
                    actionBarLayout.presentFragment(new ChatActivity(args), true, false, true);
                }
            }
        });
        presentFragment(fragment, false, true);
    }

    if (requestId != 0) {
        final int reqId = requestId;
        progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ConnectionsManager.getInstance().cancelRequest(reqId, true);
                        try {
                            dialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                    }
                });
        progressDialog.show();
    }
}

From source file:cm.aptoide.pt.MainActivity.java

private void dialogAddStore(final String url, final String username, final String password) {
    final ProgressDialog pd = new ProgressDialog(mContext);
    pd.setMessage(getString(R.string.please_wait));
    pd.show();/*w w w  . j a va 2  s . c  om*/

    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                addStore(url, username, password);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (pd.isShowing()) {
                            pd.dismiss();
                        }
                        refreshAvailableList(true);
                    }
                });

            }

        }
    }).start();
}

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

private void setLocation(final long accountId) {
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    final AsyncTask<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() {

        int serviceId;

        @Override//from w  w w  .j a v  a  2 s.  com
        protected String doInBackground(Void... none) {
            Cursor account = getContentResolver().query(Accounts.getContentUri(MyfeedleCreatePost.this),
                    new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SERVICE, Accounts.SECRET },
                    Accounts._ID + "=?", new String[] { Long.toString(accountId) }, null);
            if (account.moveToFirst()) {
                MyfeedleOAuth myfeedleOAuth;
                serviceId = account.getInt(account.getColumnIndex(Accounts.SERVICE));
                switch (serviceId) {
                case TWITTER:
                    // anonymous requests are rate limited to 150 per hour
                    // authenticated requests are rate limited to 350 per hour, so authenticate this!
                    myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET,
                            mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))),
                            mMyfeedleCrypto
                                    .Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET))));
                    return MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest(
                            new HttpGet(String.format(TWITTER_SEARCH, TWITTER_BASE_URL, mLat, mLong))));
                case FACEBOOK:
                    return MyfeedleHttpClient.httpResponse(mHttpClient,
                            new HttpGet(String.format(FACEBOOK_SEARCH, FACEBOOK_BASE_URL, mLat, mLong,
                                    Saccess_token, mMyfeedleCrypto.Decrypt(
                                            account.getString(account.getColumnIndex(Accounts.TOKEN))))));
                case FOURSQUARE:
                    return MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet(
                            String.format(FOURSQUARE_SEARCH, FOURSQUARE_BASE_URL, mLat, mLong, mMyfeedleCrypto
                                    .Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))))));
                }
            }
            account.close();
            return null;
        }

        @Override
        protected void onPostExecute(String response) {
            if (loadingDialog.isShowing())
                loadingDialog.dismiss();
            if (response != null) {
                switch (serviceId) {
                case TWITTER:
                    try {
                        JSONArray places = new JSONObject(response).getJSONObject(Sresult)
                                .getJSONArray(Splaces);
                        final String placesNames[] = new String[places.length()];
                        final String placesIds[] = new String[places.length()];
                        for (int i = 0, i2 = places.length(); i < i2; i++) {
                            JSONObject place = places.getJSONObject(i);
                            placesNames[i] = place.getString(Sfull_name);
                            placesIds[i] = place.getString(Sid);
                        }
                        mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this))
                                .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        mAccountsLocation.put(accountId, placesIds[which]);
                                        dialog.dismiss();
                                    }
                                }).setNegativeButton(android.R.string.cancel,
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.cancel();
                                            }
                                        })
                                .create();
                        mDialog.show();
                    } catch (JSONException e) {
                        Log.e(TAG, e.toString());
                    }
                    break;
                case FACEBOOK:
                    try {
                        JSONArray places = new JSONObject(response).getJSONArray(Sdata);
                        final String placesNames[] = new String[places.length()];
                        final String placesIds[] = new String[places.length()];
                        for (int i = 0, i2 = places.length(); i < i2; i++) {
                            JSONObject place = places.getJSONObject(i);
                            placesNames[i] = place.getString(Sname);
                            placesIds[i] = place.getString(Sid);
                        }
                        mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this))
                                .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        mAccountsLocation.put(accountId, placesIds[which]);
                                        dialog.dismiss();
                                    }
                                }).setNegativeButton(android.R.string.cancel,
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                dialog.cancel();
                                            }
                                        })
                                .create();
                        mDialog.show();
                    } catch (JSONException e) {
                        Log.e(TAG, e.toString());
                    }
                    break;
                case FOURSQUARE:
                    try {
                        JSONArray groups = new JSONObject(response).getJSONObject(Sresponse)
                                .getJSONArray(Sgroups);
                        for (int g = 0, g2 = groups.length(); g < g2; g++) {
                            JSONObject group = groups.getJSONObject(g);
                            if (group.getString(Sname).equals(SNearby)) {
                                JSONArray places = group.getJSONArray(Sitems);
                                final String placesNames[] = new String[places.length()];
                                final String placesIds[] = new String[places.length()];
                                for (int i = 0, i2 = places.length(); i < i2; i++) {
                                    JSONObject place = places.getJSONObject(i);
                                    placesNames[i] = place.getString(Sname);
                                    placesIds[i] = place.getString(Sid);
                                }
                                mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this))
                                        .setSingleChoiceItems(placesNames, -1,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        mAccountsLocation.put(accountId, placesIds[which]);
                                                        dialog.dismiss();
                                                    }
                                                })
                                        .setNegativeButton(android.R.string.cancel,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .create();
                                mDialog.show();
                                break;
                            }
                        }
                    } catch (JSONException e) {
                        Log.e(TAG, e.toString());
                    }
                    break;
                }
            } else {
                (Toast.makeText(MyfeedleCreatePost.this, getString(R.string.failure), Toast.LENGTH_LONG))
                        .show();
            }
        }

    };
    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();
}

From source file:cm.aptoide.pt.MainActivity.java

@Override
public boolean onContextItemSelected(final MenuItem item) {
    final ProgressDialog pd;
    switch (item.getItemId()) {
    case 0:/*w w  w . j av  a2 s . c  om*/
        pd = new ProgressDialog(mContext);
        pd.setMessage(getString(R.string.please_wait));
        pd.show();
        pd.setCancelable(false);
        new Thread(new Runnable() {

            private boolean result = false;

            @Override
            public void run() {
                try {
                    result = service.deleteStore(db, ((AdapterContextMenuInfo) item.getMenuInfo()).id);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            pd.dismiss();
                            if (result) {
                                refreshAvailableList(false);
                                installedLoader.forceLoad();
                                updatesLoader.forceLoad();
                            } else {
                                Toast toast = Toast.makeText(mContext,
                                        mContext.getString(R.string.error_delete_store), Toast.LENGTH_SHORT);
                                toast.show();
                            }

                        }
                    });
                }
            }
        }).start();
        break;
    case 1:
        pd = new ProgressDialog(mContext);
        pd.setMessage(getString(R.string.please_wait));
        pd.show();
        pd.setCancelable(false);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    service.parseServer(db,
                            db.getServer(((AdapterContextMenuInfo) item.getMenuInfo()).id, false));
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            pd.dismiss();
                            refreshAvailableList(false);
                        }
                    });

                }
            }
        }).start();

        break;
    }

    return super.onContextItemSelected(item);
}

From source file:xj.property.activity.HXBaseActivity.MainActivity.java

/**
 * ??dialog/*from  w  w w .  java2 s .c  o  m*/
 */
private void showConflictDialog() {
    isConflictDialogShow = true;
    final UserInfoDetailBean detailBean = PreferencesUtil.getLoginInfo(getApplication());
    username = detailBean.getUsername();
    password = detailBean.getPassword();
    final XJUserInfoBean bean = new XJUserInfoBean();
    bean.setInfo(detailBean);

    if (xjpushManager != null) {
        xjpushManager.unregisterLoginedPushService();
    } else {
        xjpushManager = new XJPushManager(this);
        xjpushManager.unregisterLoginedPushService();
    }

    //        boolean flag= PushManager.getInstance().unBindAlias(MainActivity.this,   PreferencesUtil.getLoginInfo(MainActivity.this).getEmobId());
    //        Log.i("onion","flag"+flag);
    XjApplication.getInstance().logout(new EMCallBack() {
        @Override
        public void onSuccess() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    refreshUI();
                    refreshNewBangBiUI();
                }
            });
        }

        @Override
        public void onError(int i, String s) {

        }

        @Override
        public void onProgress(int i, String s) {

        }
    });
    PreferencesUtil.Logout(MainActivity.this);
    if (!MainActivity.this.isFinishing()) {
        // clear up global variables
        try {
            final Dialog dialog = new Dialog(MainActivity.this, R.style.MyDialogStyle);
            dialog.setContentView(R.layout.dialog_conflict);
            TextView tv_cancle = (TextView) dialog.findViewById(R.id.tv_cancle);
            TextView tv_relogin = (TextView) dialog.findViewById(R.id.tv_relogin);
            tv_cancle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    conflictBuilder = null;
                    dialog.dismiss();
                    index = 0;
                    updateUnreadLabel();
                    startActivity(new Intent(MainActivity.this, MainActivity.class));
                    //                        finish();
                }
            });
            tv_relogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final ProgressDialog pd = new ProgressDialog(MainActivity.this,
                            ProgressDialog.THEME_HOLO_LIGHT);
                    pd.setCanceledOnTouchOutside(false);
                    pd.setCancelable(false);
                    pd.setOnCancelListener(new DialogInterface.OnCancelListener() {

                        @Override
                        public void onCancel(DialogInterface dialog) {
                            progressShow = false;
                        }
                    });
                    progressShow = true;
                    pd.setMessage("...");
                    if (pd != null && !MainActivity.this.isFinishing())
                        pd.show();
                    //???
                    // getuser((int) detailBean.getCommunityId(),detailBean.getEmobId());
                    UserUtils.reLoginUser(MainActivity.this, username, password, new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            switch (msg.what) {
                            case Config.LoginUserComplete:
                                if (progressShow)
                                    pd.dismiss();
                                dialog.dismiss();
                                startActivity(new Intent(MainActivity.this, MainActivity.class));
                                isConflict = false;

                                //                                        boolean flag = PushManager.getInstance().bindAlias(MainActivity.this, PreferencesUtil.getLoginInfo(MainActivity.this).getEmobId());
                                PushManager.getInstance().turnOnPush(MainActivity.this);

                                if (xjpushManager == null) {
                                    xjpushManager = new XJPushManager(getmContext());
                                }
                                xjpushManager.registerLoginedPushService();
                                break;
                            case Config.LoginUserFailure:
                                if (progressShow && !MainActivity.this.isFinishing()) {
                                    pd.dismiss();
                                    Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT)
                                            .show();
                                }
                                break;
                            default:
                                pd.setMessage("..");
                                break;

                            }
                        }
                    });

                    /* UserUtils.loginEMChat(MainActivity.this, username, bean, new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        switch (msg.what) {
                            case Config.LoginUserComplete:
                                if (progressShow) pd.dismiss();
                                dialog.dismiss();
                                UserUtils.appLogin(MainActivity.this,PushManager.getInstance().getClientid(MainActivity.this), PreferencesUtil.getLoginInfo(MainActivity.this).getUsername());
                                startActivity(new Intent(MainActivity.this,
                                    MainActivity.class));
                                isConflict=false;
                                boolean flag= PushManager.getInstance().bindAlias(MainActivity.this,   PreferencesUtil.getLoginInfo(MainActivity.this).getEmobId());
                            
                                PushManager.getInstance().turnOnPush(MainActivity.this);
                                break;
                            case Config.LoginUserFailure:
                                if (progressShow && !MainActivity.this.isFinishing()) {
                                    pd.dismiss();
                                    Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT).show();
                                }
                                break;
                            default:
                                pd.setMessage("..");
                                break;
                            
                        }
                    }
                     });*/
                }
            });

            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
            dialog.setCancelable(false);
            dialog.show();

            isConflict = true;
        } catch (Exception e) {
            EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage());
        }

    }
}

From source file:de.da_sense.moses.client.AvailableFragment.java

/**
 * FIXME: The ProgressDialog doesn't show up. Handles installing APK from
 * the Server.//from w ww  .ja v  a2  s  . c om
 * 
 * @param app
 *            the App to download and install
 */
protected void handleInstallApp(ExternalApplication app) {

    final ProgressDialog progressDialog = new ProgressDialog(WelcomeActivity.getInstance());

    Log.d(TAG, "progressDialog = " + progressDialog);

    final ApkDownloadManager downloader = new ApkDownloadManager(app,
            WelcomeActivity.getInstance().getApplicationContext(), // getActivity().getApplicationContext(),
            new ExecutableForObject() {
                @Override
                public void execute(final Object o) {
                    if (o instanceof Integer) {
                        WelcomeActivity.getInstance().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (totalSize == -1) {
                                    totalSize = (Integer) o / 1024;
                                    progressDialog.setMax(totalSize);
                                } else {
                                    progressDialog.incrementProgressBy(
                                            ((Integer) o / 1024) - progressDialog.getProgress());
                                }
                            }
                        });
                        /*
                         * They were : Runnable runnable = new Runnable() {
                         * Integer temporary = (Integer) o / 1024;
                         * 
                         * @Override public void run() { if (totalSize ==
                         * -1) { totalSize = temporary;
                         * progressDialog.setMax(totalSize); } else {
                         * progressDialog .incrementProgressBy( temporary -
                         * progressDialog.getProgress()); } } };
                         * getActivity().runOnUiThread(runnable);
                         */
                    }
                }
            });

    progressDialog.setTitle(getString(R.string.downloadingApp));
    progressDialog.setMessage(getString(R.string.pleaseWait));
    progressDialog.setMax(0);
    progressDialog.setProgress(0);
    progressDialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            downloader.cancel();
        }
    });

    progressDialog.setCancelable(true);
    progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (progressDialog.isShowing())
                progressDialog.cancel();
        }
    });
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    Observer observer = new Observer() {
        @Override
        public void update(Observable observable, Object data) {
            if (downloader.getState() == ApkDownloadManager.State.ERROR) {
                // error downloading
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorDownloading(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.ERROR_NO_CONNECTION) {
                // error with connection
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorNoConnection(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.FINISHED) {
                // success
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                installDownloadedApk(downloader.getDownloadedApk(), downloader.getExternalApplicationResult());
            }
        }
    };
    downloader.addObserver(observer);
    totalSize = -1;
    // progressDialog.show(); FIXME: commented out in case it throws an
    // error
    downloader.start();
}

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

/** Called when the activity is first created. */
@Override/* w  w  w  .  j a  v  a 2s  . c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_unifiednav);

    detectedAPs = (TextView) findViewById(R.id.detectedAPs);
    textFloor = (TextView) findViewById(R.id.textFloor);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    textDebug = (TextView) findViewById(R.id.textDebug);
    if (AnyplaceAPI.DEBUG_MESSAGES)
        textDebug.setVisibility(View.VISIBLE);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);

    userData = new AnyUserData();

    SimpleWifiManager.getInstance().startScan();
    sensorsMain = new SensorsMain(getApplicationContext());
    movementDetector = new MovementDetector();
    sensorsMain.addListener(movementDetector);
    sensorsStepCounter = new SensorsStepCounter(getApplicationContext(), sensorsMain);
    lpTracker = new TrackerLogicPlusIMU(movementDetector, sensorsMain, sensorsStepCounter);
    // lpTracker = new TrackerLogic(sensorsMain);
    floorSelector = new Algo1Radiomap(getApplicationContext());

    mAnyplaceCache = AnyplaceCache.getInstance(this);
    visiblePois = new VisiblePois();

    setUpMapIfNeeded();

    // setup the trackme button overlaid in the map
    btnTrackme = (ImageButton) findViewById(R.id.btnTrackme);
    btnTrackme.setImageResource(R.drawable.dark_device_access_location_off);
    isTrackingErrorBackground = true;
    btnTrackme.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final GeoPoint gpsLoc = userData.getLocationGPSorIP();
            if (gpsLoc != null) {
                AnyplaceCache mAnyplaceCache = AnyplaceCache.getInstance(UnifiedNavigationActivity.this);
                mAnyplaceCache.loadWorldBuildings(new FetchBuildingsTaskListener() {

                    @Override
                    public void onSuccess(String result, List<BuildingModel> buildings) {
                        final FetchNearBuildingsTask nearest = new FetchNearBuildingsTask();
                        nearest.run(buildings, gpsLoc.lat, gpsLoc.lng, 200);

                        if (nearest.buildings.size() > 0 && (userData.getSelectedBuildingId() == null
                                || !userData.getSelectedBuildingId().equals(nearest.buildings.get(0).buid))) {
                            floorSelector.Stop();
                            final FloorSelector floorSelectorAlgo1 = new Algo1Server(getApplicationContext());
                            final ProgressDialog floorSelectorDialog = new ProgressDialog(
                                    UnifiedNavigationActivity.this);

                            floorSelectorDialog.setIndeterminate(true);
                            floorSelectorDialog.setTitle("Detecting floor");
                            floorSelectorDialog.setMessage("Please be patient...");
                            floorSelectorDialog.setCancelable(true);
                            floorSelectorDialog.setCanceledOnTouchOutside(false);
                            floorSelectorDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface dialog) {
                                    floorSelectorAlgo1.Destoy();
                                    bypassSelectBuildingActivity(nearest.buildings.get(0), "0", false);
                                }
                            });

                            class Callback implements ErrorAnyplaceFloorListener, FloorAnyplaceFloorListener {

                                @Override
                                public void onNewFloor(String floor) {
                                    floorSelectorAlgo1.Destoy();
                                    if (floorSelectorDialog.isShowing()) {
                                        floorSelectorDialog.dismiss();
                                        bypassSelectBuildingActivity(nearest.buildings.get(0), floor, false);
                                    }
                                }

                                @Override
                                public void onFloorError(Exception ex) {
                                    floorSelectorAlgo1.Destoy();
                                    if (floorSelectorDialog.isShowing()) {
                                        floorSelectorDialog.dismiss();
                                        bypassSelectBuildingActivity(nearest.buildings.get(0), "0", false);
                                    }
                                }

                            }
                            Callback callback = new Callback();
                            floorSelectorAlgo1.addListener((FloorAnyplaceFloorListener) callback);
                            floorSelectorAlgo1.addListener((ErrorAnyplaceFloorListener) callback);

                            // Show Dialog
                            floorSelectorDialog.show();
                            floorSelectorAlgo1.Start(gpsLoc.lat, gpsLoc.lng);
                        } else {
                            focusUserLocation();

                            // Clear cancel request
                            lastFloor = null;
                            floorSelector.RunNow();
                            lpTracker.reset();
                        }
                    }

                    @Override
                    public void onErrorOrCancel(String result) {

                    }

                }, UnifiedNavigationActivity.this, false);
            } else {
                focusUserLocation();

                // Clear cancel request
                lastFloor = null;
                floorSelector.RunNow();
                lpTracker.reset();
            }

        }
    });

    btnFloorUp = (ImageButton) findViewById(R.id.btnFloorUp);
    btnFloorUp.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (!userData.isFloorSelected()) {
                Toast.makeText(getBaseContext(), "Load a map before tracking can be used!", Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            BuildingModel b = userData.getSelectedBuilding();
            if (b == null) {
                return;
            }

            if (userData.isNavBuildingSelected()) {
                // Move to start/destination poi's floor
                String floor_number;
                List<PoisNav> puids = userData.getNavPois();
                // Check start and destination floor number
                if (!puids.get(puids.size() - 1).floor_number.equals(puids.get(0).floor_number)) {
                    if (userData.getSelectedFloorNumber().equals(puids.get(puids.size() - 1).floor_number)) {
                        floor_number = puids.get(0).floor_number;
                    } else {
                        floor_number = puids.get(puids.size() - 1).floor_number;
                    }

                    FloorModel floor = b.getFloorFromNumber(floor_number);
                    if (floor != null) {
                        bypassSelectBuildingActivity(b, floor);
                        return;
                    }
                }
            }

            // Move one floor up
            int index = b.getSelectedFloorIndex();

            if (b.checkIndex(index + 1)) {
                bypassSelectBuildingActivity(b, b.getFloors().get(index + 1));
            }

        }
    });

    btnFloorDown = (ImageButton) findViewById(R.id.btnFloorDown);
    btnFloorDown.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!userData.isFloorSelected()) {
                Toast.makeText(getBaseContext(), "Load a map before tracking can be used!", Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            BuildingModel b = userData.getSelectedBuilding();
            if (b == null) {
                return;
            }

            if (userData.isNavBuildingSelected()) {
                // Move to start/destination poi's floor
                String floor_number;
                List<PoisNav> puids = userData.getNavPois();
                // Check start and destination floor number
                if (!puids.get(puids.size() - 1).floor_number.equals(puids.get(0).floor_number)) {
                    if (userData.getSelectedFloorNumber().equals(puids.get(puids.size() - 1).floor_number)) {
                        floor_number = puids.get(0).floor_number;
                    } else {
                        floor_number = puids.get(puids.size() - 1).floor_number;
                    }

                    FloorModel floor = b.getFloorFromNumber(floor_number);
                    if (floor != null) {
                        bypassSelectBuildingActivity(b, floor);
                        return;
                    }
                }
            }

            // Move one floor down
            int index = b.getSelectedFloorIndex();

            if (b.checkIndex(index - 1)) {
                bypassSelectBuildingActivity(b, b.getFloors().get(index - 1));
            }
        }

    });

    /*
     * Create a new location client, using the enclosing class to handle callbacks.
     */
    // Create the LocationRequest object
    mLocationRequest = LocationRequest.create();
    // Use high accuracy
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    // Set the update interval to 2 seconds
    mLocationRequest.setInterval(2000);
    // Set the fastest update interval to 1 second
    mLocationRequest.setFastestInterval(1000);
    mLocationClient = new LocationClient(this, this, this);
    // declare that this is the first time this Activity launched so make
    // the automatic building selection
    mAutomaticGPSBuildingSelection = true;

    // get/set settings
    PreferenceManager.setDefaultValues(this, SHARED_PREFS_ANYPLACE, MODE_PRIVATE, R.xml.preferences_anyplace,
            true);
    SharedPreferences preferences = getSharedPreferences(SHARED_PREFS_ANYPLACE, MODE_PRIVATE);
    preferences.registerOnSharedPreferenceChangeListener(this);
    lpTracker.setAlgorithm(preferences.getString("TrackingAlgorithm", "WKNN"));

    // handle the search intent
    handleIntent(getIntent());
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveWavPart2(final String finalval, final String needToRename) {
    Intent new_intent = new Intent();
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 15);
    new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval);
    sendBroadcast(new_intent);
    final ProgressDialog prog;
    prog = new ProgressDialog(TimidityActivity.this);
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override//w  ww  . jav a 2 s  . c  om
        public void onClick(DialogInterface dialog, int which) {

            dialog.dismiss();
        }
    });
    prog.setTitle("Converting to WAV");
    prog.setMessage("Converting...");
    prog.setIndeterminate(false);
    prog.setCancelable(false);
    prog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    prog.show();
    new Thread(new Runnable() {
        @Override
        public void run() {
            while (!localfinished && prog.isShowing()) {
                prog.setMax(JNIHandler.maxTime);
                prog.setProgress(JNIHandler.currTime);
                try {

                    Thread.sleep(25);
                } catch (InterruptedException e) {
                }
            }
            if (!localfinished) {
                JNIHandler.stop();
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(TimidityActivity.this, "Conversion canceled", Toast.LENGTH_SHORT).show();
                        if (!Globals.keepWav) {
                            if (new File(finalval).exists())
                                new File(finalval).delete();
                        } else {
                            fileFrag.getDir(fileFrag.currPath);
                        }
                    }
                });

            } else {
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        String trueName = finalval;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null
                                && needToRename != null) {
                            if (Globals.renameDocumentFile(TimidityActivity.this, finalval, needToRename)) {
                                trueName = needToRename;
                            } else {
                                trueName = "Error";
                            }
                        }
                        Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                        prog.dismiss();
                        fileFrag.getDir(fileFrag.currPath);
                    }
                });
            }
        }
    }).start();
}

From source file:com.sxt.superqq.activity.LoginActivity.java

/**
 * ?//w  w w.  j av  a 2  s .  c  om
 */
private void setLoginClickListener() {
    findViewById(R.id.btnLogin).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!CommonUtils.isNetWorkConnected(LoginActivity.this)) {
                Toast.makeText(LoginActivity.this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show();
                return;
            }
            currentUsername = usernameEditText.getText().toString().trim();
            currentPassword = passwordEditText.getText().toString().trim();

            /*
             * ????
             */
            if (TextUtils.isEmpty(currentUsername)) {
                Toast.makeText(LoginActivity.this, R.string.User_name_cannot_be_empty, Toast.LENGTH_SHORT)
                        .show();
                return;
            }
            if (TextUtils.isEmpty(currentPassword)) {
                Toast.makeText(LoginActivity.this, R.string.Password_cannot_be_empty, Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            //?
            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(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;
                    }

                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.setMessage(getString(R.string.list_is_for));
                        }
                    });
                    try {

                        //?
                        boolean isSuccess = loginAppServer(currentUsername, currentPassword);
                        if (!isSuccess) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(LoginActivity.this, "", 2000).show();
                                    return;
                                }
                            });
                        }
                        final String userName = SuperQQApplication.getInstance().getUserName();
                        //?
                        isSuccess = NetUtils.downloadAvatar(LoginActivity.this, userName);

                        if (SuperQQApplication.getInstance().getContacts().size() == 0) {
                            //,20userName??
                            new DownloadContactsTask(LoginActivity.this, userName, 0, 20)
                                    .execute(I.SERVER_ROOT);
                        }
                        if (!isSuccess) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(LoginActivity.this, userName + "?", 3000)
                                            .show();
                                }
                            });
                        }
                        // ** ?logout???
                        // ** manually load all local groups and
                        // conversations in case we are auto login
                        EMGroupManager.getInstance().loadAllGroups();
                        EMChatManager.getInstance().loadAllConversations();
                        //??
                        processContactsAndGroups();
                    } catch (Exception e) {
                        e.printStackTrace();
                        //?????
                        runOnUiThread(new Runnable() {
                            public void run() {
                                pd.dismiss();
                                SuperQQApplication.getInstance().logout(null);
                                Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1)
                                        .show();
                            }
                        });
                        return;
                    }
                    //?nickname ios?nick
                    boolean updatenick = EMChatManager.getInstance()
                            .updateCurrentUserNick(SuperQQApplication.currentUserNick.trim());
                    if (!updatenick) {
                        Log.e("LoginActivity", "update current user nick fail");
                    }
                    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(final int code, final String message) {
                    if (!progressShow) {
                        return;
                    }
                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.dismiss();
                            Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
            //                Intent intent = new Intent(LoginActivity.this, com.sxt.superqq.activity.AlertDialogActivity.class);
            //                intent.putExtra("editTextShow", true);
            //                intent.putExtra("titleIsCancel", true);
            //                intent.putExtra("msg", getResources().getString(R.string.please_set_the_current));
            //                intent.putExtra("edit_text", currentUsername);
            //                startActivityForResult(intent, REQUEST_CODE_SETNICK);
        }
    });
}