Example usage for android.app ProgressDialog setCancelable

List of usage examples for android.app ProgressDialog setCancelable

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:fm.smart.r1.activity.CreateExampleActivity.java

public void onClick(View v) {
    EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence);
    EditText translationInput = (EditText) findViewById(R.id.create_example_translation);
    EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration);
    EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration);
    final String example = exampleInput.getText().toString();
    final String translation = translationInput.getText().toString();
    if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) {
        Toast t = Toast.makeText(this, "Example and translation are required fields", 150);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();//w  w  w.  j a  v a 2  s. c o m
    } else {
        final String example_language_code = Utils.LANGUAGE_MAP.get(example_language);
        final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language);
        final String example_transliteration = exampleTransliterationInput.getText().toString();
        final String translation_transliteration = translationTransliterationInput.getText().toString();

        if (Main.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid
            // navigation
            // back to this?
            LoginActivity.return_to = CreateExampleActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("list_id", list_id);
            LoginActivity.params.put("item_id", item_id);
            LoginActivity.params.put("example", example);
            LoginActivity.params.put("translation", translation);
            LoginActivity.params.put("example_language", example_language);
            LoginActivity.params.put("translation_language", translation_language);
            LoginActivity.params.put("example_transliteration", example_transliteration);
            LoginActivity.params.put("translation_transliteration", translation_transliteration);
            startActivity(intent);
        } else {

            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Creating Example ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread create_example = new Thread() {
                public void run() {
                    // TODO make this interruptable .../*if
                    // (!this.isInterrupted())*/
                    try {
                        // TODO failures here could derail all ...
                        CreateExampleActivity.add_item_list_result = ItemActivity.addItemToList(list_id,
                                item_id, CreateExampleActivity.this);
                        CreateExampleActivity.create_example_result = createExample(example,
                                example_language_code, example_transliteration, translation,
                                translation_language_code, translation_transliteration, item_id, list_id);
                        CreateExampleActivity.add_sentence_list_result = ItemActivity.addSentenceToList(
                                CreateExampleActivity.create_example_result.http_response, item_id, list_id,
                                CreateExampleActivity.this);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    myOtherProgressDialog.dismiss();

                }
            };
            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    create_example.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    create_example.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            myOtherProgressDialog.show();
            create_example.start();
        }
    }
}

From source file:com.jwetherell.quick_response_code.EncoderActivity.java

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    com.ranorex.android.RanorexAndroidAutomation.Hook(this);
    // Get text views
    textoSsid = (TextView) findViewById(R.id.ssid);
    textoPassword = (TextView) findViewById(R.id.password);
    descripcion = (TextView) findViewById(R.id.descripcion);
    icon = (ImageView) findViewById(R.id.icon);
    //textoCifrado = (TextView) findViewById(R.id.cifrado);

    settings = getSharedPreferences(MainActivity.PREFS, 0);

    // if(settings.contains("connected_wifi_5ghz") && settings.getBoolean("connected_wifi_5ghz", false))
    //      descripcion.setText("");

    final ProgressDialog dialog = new ProgressDialog(EncoderActivity.this);

    dialog.setMessage("Generando Qr...");
    dialog.show();/* w ww .  j a v  a  2s .  co m*/
    dialog.setCancelable(false);

    try {

        if (settings.contains("ssid") && settings.contains("password1")) {
            // Get ssid, psk and encrypted of settings.

            if (!getIntent().getBooleanExtra("is_5ghz", false)) // Network 2.4 GHz.
            {
                cifradoSettings = settings.getString("cifrado", "WPA");
                ssidSettings = settings.getString("ssid", "");
                pskSettings = settings.getString("password1", "");
                if (settings.contains("connected_wifi_5ghz")
                        && !settings.getBoolean("connected_wifi_5ghz", false)
                        || !settings.contains("connected_wifi_5ghz")) {
                    descripcion.setVisibility(View.VISIBLE);
                }
            } else // Network 5 GHz.
            {
                cifradoSettings = settings.getString("cifrado5ghz", "WPA");
                ssidSettings = settings.getString("ssid5ghz", "");
                pskSettings = settings.getString("password5ghz", "");
                icon.setImageResource(R.drawable.wifiplus120);
                ((TextView) findViewById(R.id.textView1)).setText("WifiPlus");
                if (settings.contains("connected_wifi_5ghz")
                        && settings.getBoolean("connected_wifi_5ghz", false)) {
                    descripcion.setVisibility(View.VISIBLE);
                }
            }

            ssidFull = ssidSettings;
            pskFull = pskSettings;

            if (cifradoSettings.contains("WPA")) {
                cifradoQR = "WPA";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;";
            } else if (cifradoSettings.contains("abierta")) {
                cifradoQR = "nopass";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";;";
            } else if (cifradoSettings.contains("WEP")) {
                cifradoQR = "WEP";
                string = "WIFI:T:" + cifradoQR + ";S:" + ssidSettings + ";P:" + pskSettings + ";;";
            }

            // Update texts
            textoSsid.setText(ssidSettings);

            try {
                if (pskSettings.length() > 39)
                    pskSettings = ellipsis(pskSettings, 39);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (pskSettings.equalsIgnoreCase("sin password") || pskSettings.equalsIgnoreCase(""))
                pskSettings = "Sin password";

            textoPassword.setText(pskSettings);

        }

    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Could not encode barcode", e);
    }

    new AsyncTask<String, Integer, Bitmap>() {

        @Override
        protected Bitmap doInBackground(String... params) {
            QRCodeEncoder qrCodeEncoder = null;
            // This assumes the view is full screen, which is a good assumption
            WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
            Display display = manager.getDefaultDisplay();
            int width = display.getWidth();
            int height = display.getHeight();
            int smallerDimension = width < height ? width : height;
            smallerDimension = smallerDimension * 7 / 8;

            try {
                qrCodeEncoder = new QRCodeEncoder(string, null, Contents.Type.TEXT,
                        BarcodeFormat.QR_CODE.toString(), smallerDimension);
                Hashtable hints = new Hashtable();
                hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
                QRCodeWriter qrcw = new QRCodeWriter();
                BitMatrix matrix = qrcw.encode(string, BarcodeFormat.QR_CODE, width, height, hints);
                bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                for (int y = 0; y < matrix.getHeight(); y++) {
                    for (int x = 0; x < matrix.getWidth(); x++) {
                        if (!matrix.get(x, y))
                            bm.setPixel(x, y, Color.WHITE);
                        else
                            bm.setPixel(x, y, Color.BLACK);
                    }
                }
            } catch (WriterException we) {
                we.printStackTrace();
                Log.e(TAG, "Could not encode barcode", we);
            }

            return bm;
        }

        protected void onPostExecute(Bitmap bitmap) {
            if (bitmap != null) {
                viewCode = (ImageView) findViewById(R.id.image_view);
                viewCode.setImageBitmap(bitmap);//bitmap);
                dialog.dismiss();
            } else {
                Toast.makeText(EncoderActivity.this, "Problema al generar Qr", Toast.LENGTH_LONG).show();
            }
        }
    }.execute();

    if (bm != null) {
        dialog.dismiss();
    }

}

From source file:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java

/**
 * Create the underlying dialog/*from  www.j  a  v  a 2  s  . com*/
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    ProgressDialog dialog = new ProgressDialog(getActivity());
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(false);

    int msg = getArguments().getInt("title");
    if (msg != 0)
        dialog.setMessage(getActivity().getString(msg));
    final boolean isIndet = getArguments().getBoolean("isIndeterminate");
    dialog.setIndeterminate(isIndet);
    if (isIndet) {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    }

    // We can't use "this.requestUpdateProgress()" because getDialog() will still return null
    if (!isIndet) {
        dialog.setMax(mMax);
        dialog.setProgress(mProgress);
        if (mMessage != null)
            dialog.setMessage(mMessage);
        setDialogNumberFormat(dialog);
    }

    return dialog;
}

From source file:com.kncwallet.wallet.ui.SendingAddressesFragment.java

private void handleReloadContacts() {
    final Context context = activity;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String phoneNumber = activity.getWalletApplication().GetPhoneNumber();

    final ProgressDialog progressDialog = new ProgressDialog(context);
    progressDialog.setTitle(R.string.contacts_lookup_refresh_title);
    progressDialog.setMessage(getString(R.string.contacts_lookup_refresh_message));
    progressDialog.setCancelable(false);
    progressDialog.show();/*from w w w. j  a  v  a  2s  . com*/

    KnCDialog.fixDialogDivider(progressDialog);

    new ContactsDownloader(context, prefs, phoneNumber, new ContactsDownloader.ContactsDownloaderListener() {
        @Override
        public void onSuccess(int newContacts) {
            progressDialog.dismiss();
            if (newContacts > 0) {
                Toast.makeText(context, getString(R.string.contacts_lookup_contacts_added, "" + newContacts),
                        Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(context, R.string.contacts_lookup_success, Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onError(String message) {
            progressDialog.dismiss();
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
    }).doContactsLookup();
}

From source file:net.mypapit.mobile.callsignview.MainActivity.java

public ProgressDialog progressDialog() {

    ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(getResources().getString(R.string.progress_dialog));
    dialog.setTitle(getResources().getString(R.string.progress_title));
    dialog.setCancelable(false);
    dialog.setIndeterminate(true);/*w w  w .jav  a  2  s  .  com*/
    dialog.show();

    return dialog;

}

From source file:edu.mit.media.funf.funfohmage.OhmageLoginActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = super.onCreateDialog(id);
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    switch (id) {
    case DIALOG_FIRST_RUN:
        dialogBuilder.setTitle(R.string.eula_title).setMessage(R.string.eula_text).setCancelable(false)
                .setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() {
                    @Override// w  ww . j  a  v a2 s  .  c o  m
                    public void onClick(DialogInterface dialog, int which) {
                        mPreferencesHelper.setFirstRun(false);
                    }
                }).setNegativeButton(R.string.eula_cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        OhmageLoginActivity.this.finish();
                    }
                });
        dialog = dialogBuilder.create();
        break;

    case DIALOG_LOGIN_ERROR:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_invalid_password)
                .setCancelable(true).setPositiveButton(R.string.ok, null)
        /*.setNeutralButton("Help", new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(LoginActivity.this, HelpActivity.class));
                //put extras for specific help on login error
             }
          })*/;
        //add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_USER_DISABLED:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_account_disabled)
                .setCancelable(true).setPositiveButton(R.string.ok, null)
        /*.setNeutralButton("Help", new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(LoginActivity.this, HelpActivity.class));
                //put extras for specific help on login error
             }
          })*/;
        //add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_NETWORK_ERROR:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_network_error)
                .setCancelable(true).setPositiveButton(R.string.ok, null)
        /*.setNeutralButton("Help", new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(LoginActivity.this, HelpActivity.class));
                //put extras for specific help on http error
             }
          })*/;
        //add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_INTERNAL_ERROR:
        dialogBuilder.setTitle(R.string.login_error).setMessage(R.string.login_server_error).setCancelable(true)
                .setPositiveButton(R.string.ok, null)
        /*.setNeutralButton("Help", new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(LoginActivity.this, HelpActivity.class));
                //put extras for specific help on http error
             }
          })*/;
        //add button for contact
        dialog = dialogBuilder.create();
        break;

    case DIALOG_LOGIN_PROGRESS: {
        ProgressDialog pDialog = new ProgressDialog(this);
        pDialog.setMessage(getString(R.string.login_authenticating, getString(R.string.server_name)));
        pDialog.setCancelable(false);
        //pDialog.setIndeterminate(true);
        dialog = pDialog;
        break;
    }
    case DIALOG_DOWNLOADING_CAMPAIGNS: {
        ProgressDialog pDialog = new ProgressDialog(this);
        pDialog.setMessage(getString(R.string.login_download_campaign));
        pDialog.setCancelable(false);
        //pDialog.setIndeterminate(true);
        dialog = pDialog;
        break;
    }
    }

    return dialog;
}

From source file:com.slp.rss_api.activity.EditFeedActivity.java

public void onClickOk(View view) {
    // only in insert mode

    final String name = mNameEditText.getText().toString().trim();
    final String urlOrSearch = mUrlEditText.getText().toString().trim();
    if (urlOrSearch.isEmpty()) {
        Toast.makeText(this, R.string.error_feed_error, Toast.LENGTH_SHORT).show();
    }/*from   w w w. j a  va  2 s  . co m*/

    if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) {
        final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this);
        pd.setMessage(getString(R.string.loading));
        pd.setCancelable(true);
        pd.setIndeterminate(true);
        pd.show();

        getLoaderManager().restartLoader(1, null,
                new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() {

                    @Override
                    public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int id, Bundle args) {
                        String encodedSearchText = urlOrSearch;
                        try {
                            encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8);
                        } catch (UnsupportedEncodingException ignored) {
                        }

                        return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText);
                    }

                    @Override
                    public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> loader,
                            final ArrayList<HashMap<String, String>> data) {
                        pd.cancel();

                        if (data == null) {
                            Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                        } else if (data.isEmpty()) {
                            Toast.makeText(EditFeedActivity.this, R.string.no_result, Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(EditFeedActivity.this);
                            builder.setTitle(R.string.feed_search);

                            // create the grid item mapping
                            String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC };
                            int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

                            // fill in the grid_item layout
                            SimpleAdapter adapter = new SimpleAdapter(EditFeedActivity.this, data,
                                    R.layout.item_search_result, from, to);
                            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    FeedDataContentProvider.addFeed(EditFeedActivity.this,
                                            data.get(which).get(FEED_SEARCH_URL),
                                            name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name,
                                            mRetrieveFulltextCb.isChecked());

                                    setResult(RESULT_OK);
                                    finish();
                                }
                            });
                            builder.show();
                        }
                    }

                    @Override
                    public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) {
                    }
                });
    } else {
        FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name,
                mRetrieveFulltextCb.isChecked());

        setResult(RESULT_OK);
        finish();
    }
}

From source file:ack.me.truconnectandroiddemo.MainActivity.java

private void initialiseListviewListener(ListView listView) {
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//  w w  w. j a v a 2s  .  c  o m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mCurrentDeviceName = mDeviceList.get(position);

            if (!mConnecting) {
                mConnecting = true;

                stopScan();
                Log.d(TAG, "Connecting to BLE device " + mCurrentDeviceName);
                mTruconnectManager.connect(mCurrentDeviceName);

                final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
                String title = getString(R.string.progress_title);
                String msg = getString(R.string.progress_message);
                dialog.setIndeterminate(true);//Dont know how long connection could take.....
                dialog.setCancelable(true);

                mConnectProgressDialog = dialog.show(view.getContext(), title, msg);
                mConnectProgressDialog.setCancelable(true);
                mConnectProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        dialogInterface.dismiss();
                    }
                });

            }
        }
    });
}

From source file:com.ubuntuone.android.files.activity.StoreActivity.java

/**
 * Builds a "logging in" progress dialog. If user cancels, the activity
 * finishes./*  w  ww .jav  a  2  s . co  m*/
 * 
 * @return a dialog indicating logging in
 */
private Dialog buildLoggingInDialog() {
    final ProgressDialog dialog = buildSimpleProgressDialog(R.string.progress_signing_in);
    dialog.setOnCancelListener(new OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            if (mLoginTask != null) {
                mLoginTask.cancel(true);
            }
        }
    });
    dialog.setCancelable(true);
    return dialog;
}

From source file:com.doplgangr.secrecy.views.VaultsListFragment.java

void add() {
    final View dialogView = View.inflate(context, R.layout.new_credentials, null);
    final EditText password = new EditText(context);
    password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    new AlertDialog.Builder(context).setTitle(getString(R.string.Vault__new)).setView(dialogView)
            .setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String name = ((EditText) dialogView.findViewById(R.id.newName)).getText().toString();
                    String password = ((EditText) dialogView.findViewById(R.id.stealth_keycode)).getText()
                            .toString();
                    String Confirmpassword = ((EditText) dialogView.findViewById(R.id.confirmPassword))
                            .getText().toString();
                    File directory = new File(Storage.getRoot().getAbsolutePath() + "/" + name);
                    if (!password.equals(Confirmpassword) || "".equals(password))
                        passwordWrong();
                    else if (directory.mkdirs()) {
                        // Create vault to initialize the vault header
                        ProgressDialog progress = new ProgressDialog(context);
                        progress.setIndeterminate(true);
                        progress.setMessage(getString(R.string.Vault__initializing));
                        progress.setCancelable(false);
                        progress.show();
                        createVaultInBackground(name, password, directory, dialog, progress);
                    } else
                        failedtocreate();

                }/*from  w  w w .j a  v  a 2s .co  m*/
            }).setNegativeButton(getString(R.string.CANCEL), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                }
            }).show();
}