Example usage for android.app ProgressDialog show

List of usage examples for android.app ProgressDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:ablgroup.daily2.authentification.AuthentificationFragment.java

private void signIn(String email, String password) {
    Log.d(TAG, "signIn:" + email);
    if (!validateForm()) {
        return;//ww w . j  ava 2s  .  c  o  m
    }

    final ProgressDialog pd = new ProgressDialog(AuthentificationFragment.this);
    pd.setMessage("loading");
    pd.show();

    // [START sign_in_with_email]
    mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this,
            new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithEmail:failed", task.getException());
                        Toast.makeText(AuthentificationFragment.this, R.string.auth_failed, Toast.LENGTH_SHORT)
                                .show();
                    }

                    // [START_EXCLUDE]
                    if (!task.isSuccessful()) {
                        mStatusTextView.setText(R.string.auth_failed);
                    }
                    pd.hide();
                    // [END_EXCLUDE]
                }
            });
    // [END sign_in_with_email]
}

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

public void reg(final String username, final String pwd) {
    if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(pwd)) {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setMessage("...");
        pd.show();
        new Thread(new Runnable() {
            public void run() {
                try {
                    // sdk
                    EMChatManager.getInstance().createAccountOnServer(username, pwd);
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!RegisterActivity.this.isFinishing())
                                pd.dismiss();
                            RequestParams params = new RequestParams();
                            params.add("user", username);
                            if (DemoApplication.getInstance().getlastloc() != null) {
                                double Latitude = DemoApplication.getInstance().getlastloc().getLatitude();
                                double Longitude = DemoApplication.getInstance().getlastloc().getLongitude();
                                String adr = DemoApplication.getInstance().getlastloc().getAddrStr();
                                params.add("jiedao", adr);
                            }//ww w.ja  v a2  s  .c om
                            HttpRestClient.get(Constant.REGISTER_URL_HUIZHI, params,
                                    new BaseJsonHttpResponseHandler() {

                                        @Override
                                        public void onSuccess(int statusCode, Header[] headers,
                                                String rawJsonResponse, Object response) {
                                            // TODO Auto-generated method stub
                                            Log.d("login_res_json" + rawJsonResponse);

                                            if (CommonUtils.isNullOrEmpty(rawJsonResponse)) {
                                                Toast.makeText(getApplicationContext(),
                                                        "?,?", 0).show();
                                                return;
                                            }
                                            Map<String, Object> lm = JsonToMapList.getMap(rawJsonResponse);

                                            if (lm.get("status").toString() != null
                                                    && lm.get("status").toString().equals("yes")) {
                                                Map<String, Object> result = JsonToMapList
                                                        .getMap(lm.get("result").toString());
                                                String resultStr = "status:" + lm.get("status") + "\n"
                                                        + "message:" + lm.get("message") + "\n" + "result:"
                                                        + lm.get("result") + "\n";

                                                Log.d("login_res_obj" + resultStr);

                                                pd.dismiss();
                                                // ???
                                                //                                 DemoApplication.getInstance().setUserName(username);
                                                DemoApplication.getInstance().setUser(username);
                                                Toast.makeText(getApplicationContext(), "?", 0)
                                                        .show();
                                                finish();
                                            } else {
                                                Toast.makeText(getApplicationContext(),
                                                        lm.get("message").toString(), 0).show();
                                                pd.dismiss();
                                            }

                                        }

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

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

                                    });

                        }
                    });
                } catch (final Exception e) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!RegisterActivity.this.isFinishing())
                                pd.dismiss();
                            if (e != null && e.getMessage() != null) {
                                String errorMsg = e.getMessage();
                                if (errorMsg.indexOf("EMNetworkUnconnectedException") != -1) {
                                    Toast.makeText(getApplicationContext(), "?",
                                            0).show();
                                } else if (errorMsg.indexOf("conflict") != -1) {
                                    //????
                                    Toast.makeText(getApplicationContext(), "??", 0)
                                            .show();
                                } else if (errorMsg.indexOf("not support the capital letters") != -1) {
                                    Toast.makeText(getApplicationContext(), "??????",
                                            0).show();
                                } else {
                                    Toast.makeText(getApplicationContext(), ": " + e.getMessage(),
                                            1).show();
                                }

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

    }
}

From source file:com.imalu.alyou.activity.FriendlistFragment.java

/**
 * ?/*from ww w  . j  av  a  2 s  .  c o m*/
 * 
 * @param toDeleteUser
 */
public void deleteContact(final HXUser tobeDeleteUser) {
    final ProgressDialog pd = new ProgressDialog(getActivity());
    pd.setMessage("...");
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    //      new Thread(new Runnable() {
    //         public void run() {
    //            try {
    //               //EMContactManager.getInstance().deleteContact(tobeDeleteUser.getUsername());
    //               // db?
    //               UserDao dao = new UserDao(getActivity());
    //               dao.deleteContact(tobeDeleteUser.getUsername());
    //               AlUApplication.getInstance().getContactList().remove(tobeDeleteUser.getUsername());
    //               getActivity().runOnUiThread(new Runnable() {
    //                  public void run() {
    //                     pd.dismiss();
    ////                     adapter.remove(tobeDeleteUser);
    //                     adapter.notifyDataSetChanged();
    //
    //                  }
    //               });
    //            } catch (final Exception e) {
    //               getActivity().runOnUiThread(new Runnable() {
    //                  public void run() {
    //                     pd.dismiss();
    //                     Toast.makeText(getActivity(), ": " + e.getMessage(), 1).show();
    //                  }
    //               });
    //
    //            }
    //
    //         }
    //      }).start();

}

From source file:com.imalu.alyou.activity.FriendlistFragment.java

/**
 * user???//ww  w.j  a  v a  2 s. c om
 */
private void moveToBlacklist(final String username) {
    final ProgressDialog pd = new ProgressDialog(getActivity());
    pd.setMessage("???...");
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            //try {
            //???
            //EMContactManager.getInstance().addUserToBlackList(username,false);
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    pd.dismiss();
                    Toast.makeText(getActivity(), "????", 0).show();
                    //refresh();
                }
            });
            //} 
            //            catch (EaseMobException e) {
            //               e.printStackTrace();
            //               getActivity().runOnUiThread(new Runnable() {
            //                  public void run() {
            //                     pd.dismiss();
            //                     Toast.makeText(getActivity(), "???", 0).show();
            //                  }
            //               });
            //            }
        }
    }).start();

}

From source file:com.easemob.chatuidemo.adapter.NewFriendsMsgAdapter.java

/**
 * ???//from  w w w . j a  v a2 s .  com
 *
 * @param button
 * @param username
 */
public void acceptInvitation(final Button button, final InviteMessage msg) {
    final ProgressDialog pd = new ProgressDialog(context);
    String str1 = context.getResources().getString(R.string.Are_agree_with);
    final String str2 = context.getResources().getString(R.string.Has_agreed_to);
    final String str3 = context.getResources().getString(R.string.Agree_with_failure);
    pd.setMessage(str1);
    pd.setCanceledOnTouchOutside(false);
    pd.show();

    RequestQueue requestQueue = Volley.newRequestQueue(context);

    requestQueue.start();

    requestQueue.add(new AutoLoginRequest(context, Request.Method.POST, Model.PathLoad,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    pd.dismiss();
                    button.setText(str2);
                    msg.setStatus(InviteMesageStatus.AGREED);
                    // db
                    ContentValues values = new ContentValues();
                    values.put(InviteMessgeDao.COLUMN_NAME_STATUS, msg.getStatus().ordinal());
                    messgeDao.updateMessage(msg.getId(), values);
                    button.setBackgroundDrawable(null);
                    button.setEnabled(false);

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(context, str3 + error.getMessage(), 1).show();

                }
            }) {
        @Override
        protected void setParams(Map<String, String> params) {
            if (msg.getGroupId() == null) {//???
                params.put("sys", "msg");
                params.put("ctrl", "msger");
                params.put("action", "add_friend");
                params.put("friend_name", msg.getFrom());
            } else //??
            {
                params.put("sys", "msg");
                params.put("ctrl", "msger");
                params.put("action", "agree_group");
                params.put("stranger", msg.getFrom());
                params.put("group_sn", msg.getGroupId());
            }

        }
    });
}

From source file:org.xbmc.android.remote.presentation.controller.AbstractController.java

public void onWrongConnectionState(int state, final INotifiableManager manager, final Command<?> source) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    switch (state) {
    case WifiHelper.WIFI_STATE_DISABLED:
        builder.setTitle("Wifi disabled");
        builder.setMessage("This host is Wifi only. Should I activate Wifi?");
        builder.setNeutralButton("Activate Wifi", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                final ProgressDialog pd = new ProgressDialog(mActivity);
                pd.setCancelable(true);//  w ww  .ja v a 2 s  . c o m
                pd.setTitle("Activating Wifi");
                pd.setMessage("Please wait while Wifi is activated.");
                pd.show();
                (new Thread() {
                    public void run() {
                        final WifiHelper helper = WifiHelper.getInstance(mActivity);
                        helper.enableWifi(true);
                        int wait = 0;
                        while (wait <= MAX_WAIT_FOR_WIFI * 1000
                                && helper.getWifiState() != WifiHelper.WIFI_STATE_ENABLED) {
                            try {
                                sleep(500);
                                wait += 500;
                            } catch (InterruptedException e) {
                            }
                        }
                        manager.retryAll();
                        pd.cancel();
                        mDialogShowing = false;

                    }
                }).start();
            }
        });
        showDialog(builder);
        break;
    case WifiHelper.WIFI_STATE_ENABLED:
        final Host host = HostFactory.host;
        final WifiHelper helper = WifiHelper.getInstance(mActivity);
        final String msg;
        if (host != null && host.access_point != null && !host.access_point.equals("")) {
            helper.connect(host);
            msg = "Connecting to " + host.access_point + ". Please wait";
        } else {
            msg = "Waiting for Wifi to connect to your LAN.";
        }
        final ProgressDialog pd = new ProgressDialog(mActivity);
        pd.setCancelable(true);
        pd.setTitle("Connecting");
        pd.setMessage(msg);
        mWaitForWifi = new Thread() {
            public void run() {
                mDialogShowing = true;
                pd.show();
                (new Thread() {
                    public void run() {
                        int wait = 0;
                        while (wait <= MAX_WAIT_FOR_WIFI * 1000
                                && helper.getWifiState() != WifiHelper.WIFI_STATE_CONNECTED) {
                            try {
                                sleep(500);
                                wait += 500;
                            } catch (InterruptedException e) {
                            }
                        }
                        pd.cancel();
                        mDialogShowing = false;
                    }
                }).start();
                pd.setOnDismissListener(new OnDismissListener() {
                    public void onDismiss(DialogInterface dialog) {
                        if (helper.getWifiState() != WifiHelper.WIFI_STATE_CONNECTED) {
                            builder.setTitle("Wifi doesn't seem to connect");
                            builder.setMessage(
                                    "You can open the Wifi settings or wait " + MAX_WAIT_FOR_WIFI + " seconds");
                            builder.setNeutralButton("Wifi Settings", new OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    mDialogShowing = false;
                                    mActivity.startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
                                }
                            });
                            builder.setCancelable(true);
                            builder.setNegativeButton("Wait", new OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    mDialogShowing = false;
                                    mActivity.runOnUiThread(mWaitForWifi); //had to make the Thread a field because of this line
                                }
                            });

                            mActivity.runOnUiThread(new Runnable() {
                                public void run() {
                                    final AlertDialog alert = builder.create();
                                    try {
                                        if (!mDialogShowing) {
                                            alert.show();
                                            mDialogShowing = true;
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                        }
                    }

                });
            }
        };
        mActivity.runOnUiThread(mWaitForWifi);
    }

}

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

/**
 * ?/*from   www.ja v a 2s .co m*/
 * 
 */
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();
    new Thread(new Runnable() {
        public void run() {
            try {
                EMContactManager.getInstance().deleteContact(tobeDeleteUser.getUsername());
                // db?
                UserDao dao = new UserDao(getActivity());
                dao.deleteContact(tobeDeleteUser.getUsername());
                ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList()
                        .remove(tobeDeleteUser.getUsername());
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        adapter.remove(tobeDeleteUser);
                        adapter.notifyDataSetChanged();

                    }
                });
            } catch (final Exception e) {
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st2 + e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });

            }

        }
    }).start();

}

From source file:com.zigvine.zagriculture.UIActivity.java

private void manualUpdateCheck() {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setMessage("");
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    MainApp.getInstance().startCheck(new UpdateCheckListener() {
        @Override/*from   w w  w  .  jav  a2s. com*/
        public void onCheckedOver(int result) {
            pd.dismiss();
            if (result == MainApp.CHECKED_NO_NEED) {
                UI.toast("?");
            } else if (result == MainApp.UNCHECKED) {
                UI.toast("");
            }
        }
    }, true);
}

From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from ww  w  .  ja v a2  s. c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    if (view != null)
        return view;

    view = inflater.inflate(R.layout.webview, container, false);
    assert view != null;

    final WebView webView = (WebView) view.findViewById(R.id.webView);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);

    final ProgressDialog progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage(getResources().getString(R.string.loading));

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress < 100) {
                progressDialog.setProgress(newProgress);
                progressDialog.show();
            } else {
                progressDialog.hide();
            }
        }
    });

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, @NotNull SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @SuppressWarnings("ConstantConditions")
        @Override
        public void onReceivedHttpAuthRequest(WebView view, @NotNull HttpAuthHandler handler, String host,
                String realm) {
            FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity());
            String url = currentServer.getUrl();
            String alternativeUrl = trimToNull(currentServer.getAlternateUrl());
            try {

                String fhemUrlHost = new URL(url).getHost();
                String alternativeUrlHost = alternativeUrl == null ? null : new URL(alternativeUrl).getHost();
                String username = currentServer.getUsername();
                String password = currentServer.getPassword();

                if (host.startsWith(fhemUrlHost)
                        || (alternativeUrlHost != null && host.startsWith(alternativeUrlHost))) {
                    handler.proceed(username, password);
                } else {
                    handler.cancel();

                    Intent intent = new Intent(Actions.SHOW_TOAST);
                    intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_authentication);
                    getActivity().sendBroadcast(intent);
                }

            } catch (MalformedURLException e) {
                Intent intent = new Intent(Actions.SHOW_TOAST);
                intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection);
                getActivity().sendBroadcast(intent);
                LOG.error("malformed URL: " + url, e);

                handler.cancel();
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if ("about:blank".equalsIgnoreCase(url)) {
                Optional<String> alternativeUrl = getAlternateLoadUrl();
                if (alternativeUrl.isPresent()) {
                    webView.loadUrl(alternativeUrl.get());
                }
            } else {
                onPageLoadFinishedCallback(view, url);
            }
        }
    });

    return view;
}

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

/**
 * //from   w w  w  .j  a  v a  2s  .co 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) {

        }
    });
}