Example usage for android.app ProgressDialog getContext

List of usage examples for android.app ProgressDialog getContext

Introduction

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

Prototype

public final @NonNull Context getContext() 

Source Link

Document

Retrieve the Context this Dialog is running in.

Usage

From source file:Main.java

/**
 * Method to dismiss progress dialog.//from  w  w  w . ja  v a 2  s .  c om
 */
public static void dismissProgress(ProgressDialog mProgressDialog) {
    if (mProgressDialog != null && mProgressDialog.isShowing() && mProgressDialog.getContext() != null) {
        try {
            mProgressDialog.dismiss();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:br.com.indigo.android.facebook.SocialFacebook.java

public void commentPost(final Activity activity, final String postId, final NewObjectListener listener) {

    if (!mFacebook.isSessionValid()) {
        login(activity, new SimpleRequestListener() {

            public void onComplete() {
                commentPost(activity, postId, listener);
            }/*from   ww  w  .j a  v a2s  .  c o m*/

            public void onFail(Throwable thr) {
                listener.onFail(thr);
            }

            public void onCancel() {
                listener.onCancel();
            }
        });
    } else {

        final FbTextDialog dialog = new FbTextDialog(activity);
        dialog.setDialogListener(new DialogListener() {

            public void onComplete(Bundle values) {

                final ProgressDialog spinner = new ProgressDialog(activity);
                spinner.setMessage(spinner.getContext().getString(R.string.loading));
                spinner.setCancelable(false);
                spinner.show();

                facebookRequest(activity, postId + "/comments", values, "POST", true, new RequestAdapter() {

                    public void onFail(Throwable thr, Object state) {
                        listener.onFail(thr);
                        spinner.dismiss();
                        dialog.dismiss();
                    }

                    public void onComplete(JSONObject jsonResponse, Object state) {
                        listener.onComplete(jsonResponse.optString("id"));
                        spinner.dismiss();
                        dialog.dismiss();
                    }

                    public void onCancel() {
                        listener.onCancel();
                        spinner.dismiss();
                        dialog.dismiss();
                    }
                });
            }

            public void onFacebookError(FacebookError e) {
                listener.onFail(e);
            }

            public void onError(DialogError e) {
                listener.onFail(e);
            }

            public void onCancel() {
                listener.onCancel();
            }
        });

        dialog.show();
    }
}

From source file:br.com.indigo.android.facebook.SocialFacebook.java

public void publish(final Activity activity, final FbSimplePost post, final String pageId,
        final NewObjectListener listener) {

    if (!mFacebook.isSessionValid()) {

        login(activity, new SimpleRequestListener() {

            public void onFail(Throwable thr) {
                listener.onFail(thr);// ww w.  j  a v a  2 s . com
            }

            public void onCancel() {
                listener.onCancel();
            }

            public void onComplete() {
                publish(activity, post, pageId, listener);
            }
        });
    } else {

        final FbTextDialog dialog = new FbTextDialog(activity);
        dialog.setTitle(R.string.dialog_post_to_wall_title);
        dialog.setPlaceHolder(R.string.dialog_post_to_wall_placeholder);

        dialog.setDialogListener(new DialogListener() {

            public void onComplete(Bundle values) {

                final ProgressDialog spinner = new ProgressDialog(activity);
                spinner.setMessage(spinner.getContext().getString(R.string.loading));
                spinner.setCancelable(false);
                spinner.show();

                Bundle params = paramsForPost(post);
                params.putAll(values);

                facebookRequest(activity, pageId + "/feed", params, "POST", true, new RequestAdapter() {

                    public void onFail(Throwable thr, Object state) {
                        listener.onFail(thr);
                        spinner.dismiss();
                        dialog.dismiss();
                    }

                    public void onComplete(JSONObject jsonResponse, Object state) {
                        listener.onComplete(jsonResponse.optString("id"));
                        spinner.dismiss();
                        dialog.dismiss();
                    }

                    public void onCancel() {
                        listener.onCancel();
                        spinner.dismiss();
                        dialog.dismiss();
                    }
                });
            }

            public void onFacebookError(FacebookError e) {
                listener.onFail(e);
            }

            public void onError(DialogError e) {
                listener.onFail(e);
            }

            public void onCancel() {
                listener.onCancel();
            }
        });

        dialog.show();
    }
}

From source file:ch.kanti_baden.pu_marc_14b.traffictimewaste.SORT_TYPE.java

private void setupRecyclerViewAsync(@NonNull final ViewGroup viewGroup) {
    final ProgressDialog progressDialog = ProgressDialog.show(this,
            getResources().getString(R.string.progress_loading_posts),
            getResources().getString(R.string.progress_please_wait), true, false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    DatabaseLink.DatabaseListener listener = new DatabaseLink.DatabaseListener() {
        @Override//ww w  .j  a  v  a  2 s . c o m
        void onGetResponse(String str) {
            final Post[] posts;
            try {
                JSONObject json = new JSONObject(str);
                posts = DatabaseLink.parseJson(json);
            } catch (JSONException e) {
                onError("JSON is invalid. Error: " + e.getMessage() + ", JSON: " + str);
                return;
            }

            if (progressDialog.isShowing())
                progressDialog.dismiss();

            final Post[] sortedPosts = sortPosts(posts);

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // Inflate layout post_list
                    View rootView = View.inflate(PostListActivity.this, R.layout.post_list, null);
                    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.post_list);

                    // Setup refresh action
                    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) rootView
                            .findViewById(R.id.swipe_refresh);
                    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                        @Override
                        public void onRefresh() {
                            recreate();
                        }
                    });

                    // Set adapter with posts
                    recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(sortedPosts));

                    // Add to ViewGroup
                    viewGroup.addView(rootView);
                }
            });
        }

        @Override
        void onError(String error) {
            if (progressDialog.isShowing())
                progressDialog.dismiss();

            new AlertDialog.Builder(progressDialog.getContext()).setTitle("Error").setMessage(error).show();
        }
    };

    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction()))
        DatabaseLink.instance.getPostsWithTag(listener, intent.getStringExtra(SearchManager.QUERY));
    else
        DatabaseLink.instance.getAllPosts(listener);
    Log.v("TrafficTimeWaste", "Querying db...");
}