Example usage for android.app ProgressDialog cancel

List of usage examples for android.app ProgressDialog cancel

Introduction

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

Prototype

@Override
public void cancel() 

Source Link

Document

Cancel the dialog.

Usage

From source file:Main.java

private static void hideProgressDialog(ProgressDialog aDialog) {
    if (null != aDialog) {
        aDialog.cancel();
        aDialog = null;/*from   w w w  .java 2  s.  c o m*/
    }
}

From source file:org.dash.wallet.integration.uphold.ui.UpholdAccountActivity.java

private void loadUserBalance() {
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    loadingDialog.setIndeterminate(true);
    loadingDialog.setCancelable(false);//  ww  w . jav a  2 s .com
    loadingDialog.setMessage(getString(R.string.loading));
    loadingDialog.show();

    UpholdClient.getInstance().getDashBalance(new UpholdClient.Callback<BigDecimal>() {
        @Override
        public void onSuccess(BigDecimal data) {
            balance = data;
            balanceView.setAmount(Coin.parseCoin(balance.toString()));
            loadingDialog.cancel();
        }

        @Override
        public void onError(Exception e, boolean otpRequired) {
            loadingDialog.cancel();
            showErrorAlert();
        }
    });
}

From source file:org.tigase.mobile.roster.ContactEditActivity.java

protected void updateItem() {
    final BareJID jid = BareJID.bareJIDInstance(jabberIdEdit.getText().toString());
    final String name = nameEdit.getText().toString();
    final ArrayList<String> g = new ArrayList<String>();
    int p = groupEdit.getSelectedItemPosition();
    if (p > 0) {
        g.add(groups.get(p));/*from   w  w w  .j ava2 s.  c  o m*/
    }

    if (jid == null || jid.toString().length() == 0) {
        WarningDialog.showWarning(ContactEditActivity.this, R.string.contact_edit_wrn_jid_cant_be_empty);
        return;
    }

    if (jid.getLocalpart() == null || jid.getDomain() == null) {
        WarningDialog.showWarning(ContactEditActivity.this, R.string.contact_edit_wrn_wrong_jid);
        return;
    }

    if (name == null || name.length() == 0) {
        WarningDialog.showWarning(ContactEditActivity.this, R.string.contact_edit_wrn_name_cant_be_empty);
        return;
    }

    final ProgressDialog dialog = ProgressDialog.show(ContactEditActivity.this, "",
            getResources().getString(R.string.contact_edit_info_updating), true);
    Runnable r = new Runnable() {

        @Override
        public void run() {

            try {
                jaxmpp.getRoster().add(jid, name, g, new AsyncCallback() {

                    @Override
                    public void onError(Stanza responseStanza, ErrorCondition error) throws JaxmppException {
                        dialog.cancel();
                        if (error == null)
                            WarningDialog.showWarning(ContactEditActivity.this,
                                    R.string.contact_edit_wrn_unkown);
                        else
                            WarningDialog.showWarning(ContactEditActivity.this, error.name());
                    }

                    @Override
                    public void onSuccess(Stanza responseStanza) throws JaxmppException {
                        if (requestAuth.getVisibility() == View.VISIBLE && requestAuth.isChecked()) {
                            jaxmpp.getModule(PresenceModule.class).subscribe(JID.jidInstance(jid));
                        }
                        dialog.cancel();
                        finish();
                    }

                    @Override
                    public void onTimeout() throws JaxmppException {
                        dialog.cancel();
                        WarningDialog.showWarning(ContactEditActivity.this, R.string.contact_edit_wrn_timeout);
                    }
                });
            } catch (JaxmppException e) {
                dialog.cancel();
                Log.e(TAG, "Can't add buddy", e);
                WarningDialog.showWarning(ContactEditActivity.this, e.getMessage());
            }
        }
    };

    (new Thread(r)).start();

}

From source file:org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment.java

/**
 * Creates dialog//from  ww w .  j  av  a 2 s.c o m
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    ProgressDialog dialog = new ProgressDialog(activity);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);

    String message = getArguments().getString(ARG_MESSAGE);
    int style = getArguments().getInt(ARG_STYLE);
    boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE);

    dialog.setMessage(message);
    dialog.setProgressStyle(style);

    if (cancelable) {
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, activity.getString(R.string.progress_cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
    }

    // Disable the back button
    OnKeyListener keyListener = new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                return true;
            }
            return false;
        }

    };
    dialog.setOnKeyListener(keyListener);

    return dialog;
}

From source file:be.ac.ucl.lfsab1509.llncampus.UCLouvain.java

/**
 * Launch the download of the courses list and store them in the database.
 * // w ww. j  ava2s. c om
 * @param context
 *          Application context.
 * @param username
 *          UCL global user identifier.
 * @param password
 *          UCL password.
 * @param end
 *          Runnable to be executed at the end of the download.
 * @param mHandler
 *          Handler to manage messages and threads.
 *          
 */
public static void downloadCoursesFromUCLouvain(final LLNCampusActivity context, final String username,
        final String password, final Runnable end, final Handler mHandler) {
    Time t = new Time();
    t.setToNow();
    int year = t.year;
    // A new academic year begin in September (8th month on 0-based count).
    if (t.month < 8) {
        year--;
    }
    final int academicYear = year;

    mHandler.post(new Runnable() {

        public void run() {

            final ProgressDialog mProgress = new ProgressDialog(context);
            mProgress.setCancelable(false);
            mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgress.setMax(100);
            mProgress.setMessage(context.getString(R.string.connection));
            mProgress.show();

            new Thread(new Runnable() {
                /**
                 * Set the progress to the value n and show the message nextStep
                 * @param n
                 *          The progress value.
                 * @param nextStep
                 *          The message to show (indicate the next step to be processed).
                 */
                public void progress(final int n, final String nextStep) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            mProgress.setProgress(n);
                            mProgress.setMessage(nextStep);
                        }
                    });
                    Log.d("UCLouvain", nextStep);
                }

                /**
                 * Notify to the user an error.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void sendError(String msg) {
                    notify(context.getString(R.string.error) + " :" + msg);
                    mProgress.cancel();
                }

                /**
                 * Notify to the user a message.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void notify(final String msg) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            context.notify(msg);
                        }
                    });
                }

                public void run() {
                    progress(0, context.getString(R.string.connection_ucl));
                    UCLouvain uclouvain = new UCLouvain(username, password);

                    progress(20, context.getString(R.string.fetch_info));
                    ArrayList<Offer> offers = uclouvain.getOffers(academicYear);

                    if (offers == null || offers.isEmpty()) {
                        sendError(context.getString(R.string.error_academic_year) + academicYear);
                        return;
                    }

                    int i = 40;
                    ArrayList<Course> courses = new ArrayList<Course>();
                    for (Offer o : offers) {
                        progress(i, context.getString(R.string.get_courses) + o.getOfferName());
                        ArrayList<Course> offerCourses = uclouvain.getCourses(o);
                        if (offerCourses != null && !offerCourses.isEmpty()) {
                            courses.addAll(offerCourses);
                        } else {
                            Log.e("CoursListEditActivity", "Error : No course for offer [" + o.getOfferCode()
                                    + "] " + o.getOfferName());
                        }
                        i += (int) (30. / offers.size());
                    }

                    if (courses.isEmpty()) {
                        sendError(context.getString(R.string.courses_empty));
                        return;
                    }

                    // Remove old courses.
                    progress(70, context.getString(R.string.cleaning_db));
                    LLNCampus.getDatabase().delete("Courses", "", null);
                    LLNCampus.getDatabase().delete("Horaire", "", null);

                    // Add new data.
                    i = 80;
                    for (Course c : courses) {
                        progress(i, context.getString(R.string.add_courses_db));
                        ContentValues cv = new ContentValues();
                        cv.put("CODE", c.getCourseCode());
                        cv.put("NAME", c.getCoursName());

                        LLNCampus.getDatabase().insert("Courses", cv);
                        i += (int) (20. / courses.size());
                    }

                    progress(100, context.getString(R.string.end));
                    mProgress.cancel();
                    mHandler.post(end);
                }
            }).start();
        }
    });
}

From source file:org.openremote.android.console.AppSettingsActivity.java

private void retrieveCertificate() {
    final Button doneButton = (Button) findViewById(R.id.setting_done);
    doneButton.setEnabled(false);/*w w  w . j av  a  2  s .c o  m*/
    final ProgressDialog dialog = ProgressDialog.show(this, "Fetching certificate",
            "Busy fetching certificate");

    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            doneButton.setEnabled(true);
            dialog.cancel();
            switch (msg.what) {
            case -1:
                ViewHelper.showAlertViewWithTitle(AppSettingsActivity.this, "Connection error",
                        "Can't connect to the server.");
                break;
            case 0:
                startMain();
                break;
            case 1:
                ViewHelper.showAlertViewWithTitle(AppSettingsActivity.this, "No access",
                        "You don't have access.\nPlease ask the administrator for permission.");
                break;
            case 2:
                ViewHelper.showAlertViewWithTitle(AppSettingsActivity.this, "No access",
                        "You don't have access.\nYour certificate is invalid.");
                break;
            case 3:
                ViewHelper.showAlertViewWithTitle(AppSettingsActivity.this, "No access",
                        "You don't have access.\nYour certificate expired.");
                break;
            }
        }
    };

    ORKeyStore.getInstance(getApplicationContext())
            .checkCertificateChain(AppSettingsModel.getCurrentServer(getApplicationContext()), handler);
}

From source file:de.baumann.hhsmoodle.helper.helper_main.java

public static void onClose(final Activity activity) {
    PreferenceManager.setDefaultValues(activity, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
    final ProgressDialog progressDialog;

    if (sharedPref.getBoolean("backup_aut", false)) {

        try {//from   w  w w.jav  a  2  s .c o m
            helper_security.encryptBackup(activity, "/bookmarks_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/courses_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/notes_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/random_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/subject_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/schedule_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/todo_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }

        progressDialog = new ProgressDialog(activity);
        progressDialog.setMessage(activity.getString(R.string.app_close));
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.show();

        new Handler().postDelayed(new Runnable() {
            public void run() {
                sharedPref.edit().putString("loadURL", "").apply();
                helper_security.encryptDatabases(activity);
                if (progressDialog.isShowing()) {
                    progressDialog.cancel();
                }
                activity.finishAffinity();
            }
        }, 1500);

    } else {
        sharedPref.edit().putString("loadURL", "").apply();
        helper_security.encryptDatabases(activity);
        activity.finishAffinity();
    }
}

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  w  w.ja va 2s. co  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:edu.cwru.apo.Directory.java

private void loadTable() {
    ProgressDialog progDialog = ProgressDialog.show(this, "Loading", "Please Wait", false);
    userTable.removeAllViews();/*  www.  j  a v  a  2  s .  c o m*/
    Cursor results = database.query("phoneDB", new String[] { "first", "last", "_id", "phone" }, null, null,
            null, null, "first");
    String rowText = "";
    TableRow row;
    TextView text;
    if (!results.moveToFirst())
        return;
    while (!results.isAfterLast()) {
        String phoneNumber = removeNonDigits(results.getString(3));
        if (!(phoneNumber == null || phoneNumber.trim().equals("") || phoneNumber.trim().equals("null"))) {
            rowText = results.getString(0) + " " + results.getString(1) + " [" + results.getString(2) + "]";
            row = new TableRow(this);
            text = new TextView(this);
            row.setPadding(0, 5, 0, 5);
            text.setClickable(true);
            text.setOnClickListener(this);
            //text.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            text.setText(rowText);
            userTable.addView(row);
            row.addView(text);
        }
        results.moveToNext();
    }
    progDialog.cancel();
}

From source file:com.juick.android.UserCenterActivity.java

private void enableJAM(final Runnable then) {
    if (!MainActivity.isJAMServiceRunning(UserCenterActivity.this)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);/*from ww  w  . j  a v  a 2 s .  c om*/
        builder.setMessage(R.string.JAMNotEnabledEnable);
        builder.setTitle(getString(R.string.JuickAdvancedFunctionality));
        builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(UserCenterActivity.this);
                sp.edit().putBoolean("enableJAMessaging", true).commit();
                MainActivity.toggleJAMessaging(UserCenterActivity.this, true);
                final ProgressDialog pd = new ProgressDialog(UserCenterActivity.this);
                dialog.cancel();
                pd.setIndeterminate(true);
                pd.setMessage(getString(R.string.WaitingForService));
                final Thread thread = new Thread() {
                    @Override
                    public void run() {
                        while (true) {
                            try {
                                JAMService instance = JAMService.instance;
                                if (instance != null) {
                                    JAXMPPClient client = instance.client;
                                    if (client != null && client.loggedIn) {
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                pd.cancel();
                                                then.run();
                                            }
                                        });
                                    }
                                }
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                                break;
                            }
                        }
                        super.run(); //To change body of overridden methods use File | Settings | File Templates.
                    }
                };
                thread.start();
                pd.setCancelable(true);
                pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        thread.interrupt();
                    }
                });
                pd.show();
            }
        });
        builder.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();
    } else {
        then.run();
    }
    return;
}