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:org.telegram.ui.PrivacySettingsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("PrivacySettings", R.string.PrivacySettings));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//w w  w .  ja  v a2 s .  c  om
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    listAdapter = new ListAdapter(context);

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

    ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDrawSelectorOnTop(true);
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i == blockedRow) {
                presentFragment(new BlockedUsersActivity());
            } else if (i == sessionsRow) {
                presentFragment(new SessionsActivity());
            } else if (i == deleteAccountRow) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("DeleteAccountTitle", R.string.DeleteAccountTitle));
                builder.setItems(
                        new CharSequence[] { LocaleController.formatPluralString("Months", 1),
                                LocaleController.formatPluralString("Months", 3),
                                LocaleController.formatPluralString("Months", 6),
                                LocaleController.formatPluralString("Years", 1) },
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                int value = 0;
                                if (which == 0) {
                                    value = 30;
                                } else if (which == 1) {
                                    value = 90;
                                } else if (which == 2) {
                                    value = 182;
                                } else if (which == 3) {
                                    value = 365;
                                }
                                final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
                                progressDialog
                                        .setMessage(LocaleController.getString("Loading", R.string.Loading));
                                progressDialog.setCanceledOnTouchOutside(false);
                                progressDialog.setCancelable(false);
                                progressDialog.show();

                                final TLRPC.TL_account_setAccountTTL req = new TLRPC.TL_account_setAccountTTL();
                                req.ttl = new TLRPC.TL_accountDaysTTL();
                                req.ttl.days = value;
                                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() {
                                                try {
                                                    progressDialog.dismiss();
                                                } catch (Exception e) {
                                                    FileLog.e("tmessages", e);
                                                }
                                                if (response instanceof TLRPC.TL_boolTrue) {
                                                    ContactsController.getInstance()
                                                            .setDeleteAccountTTL(req.ttl.days);
                                                    listAdapter.notifyDataSetChanged();
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i == lastSeenRow) {
                presentFragment(new PrivacyControlActivity(false));
            } else if (i == groupsRow) {
                presentFragment(new PrivacyControlActivity(true));
            } else if (i == passwordRow) {
                presentFragment(new TwoStepVerificationActivity(0));
            } else if (i == passcodeRow) {
                if (UserConfig.passcodeHash.length() > 0) {
                    presentFragment(new PasscodeActivity(2));
                } else {
                    presentFragment(new PasscodeActivity(0));
                }
            } else if (i == secretWebpageRow) {
                if (MessagesController.getInstance().secretWebpagePreview == 1) {
                    MessagesController.getInstance().secretWebpagePreview = 0;
                } else {
                    MessagesController.getInstance().secretWebpagePreview = 1;
                }
                ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
                        .edit().putInt("secretWebpage2", MessagesController.getInstance().secretWebpagePreview)
                        .commit();
                if (view instanceof TextCheckCell) {
                    ((TextCheckCell) view)
                            .setChecked(MessagesController.getInstance().secretWebpagePreview == 1);
                }
            }
        }
    });

    return fragmentView;
}

From source file:com.app.uafeed.activity.EditFeedActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from  w ww  .j av a  2 s  .com*/
        return true;
    case R.id.menu_add_filter: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null);

        new AlertDialog.Builder(this) //
                .setTitle(R.string.filter_add_title) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText()
                                .toString();
                        if (filterText.length() != 0) {
                            String feedId = getIntent().getData().getLastPathSegment();

                            ContentValues values = new ContentValues();
                            values.put(FilterColumns.FILTER_TEXT, filterText);
                            values.put(FilterColumns.IS_REGEX,
                                    ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked());
                            values.put(FilterColumns.IS_APPLIED_TO_TITLE,
                                    ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked());

                            ContentResolver cr = getContentResolver();
                            cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values);
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                    }
                }).show();
        return true;
    }
    case R.id.menu_search_feed: {
        final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null);
        final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText);
        if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME)
                && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) {
            searchText.setText(mUrlEditText.getText());
        }
        final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup);

        new AlertDialog.Builder(EditFeedActivity.this) //
                .setIcon(R.drawable.action_search) //
                .setTitle(R.string.feed_search) //
                .setView(dialogView) //
                .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        if (searchText.getText().length() > 0) {
                            String tmp = searchText.getText().toString();
                            try {
                                tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8);
                            } catch (UnsupportedEncodingException ignored) {
                            }
                            final String text = tmp;

                            switch (radioGroup.getCheckedRadioButtonId()) {
                            case R.id.byWebSearch:
                                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) {
                                                return new GetFeedSearchResultsLoader(EditFeedActivity.this,
                                                        text);
                                            }

                                            @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) {
                                                                    mNameEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_TITLE));
                                                                    mUrlEditText.setText(data.get(which)
                                                                            .get(FEED_SEARCH_URL));
                                                                }
                                                            });
                                                    builder.show();
                                                }
                                            }

                                            @Override
                                            public void onLoaderReset(
                                                    Loader<ArrayList<HashMap<String, String>>> loader) {
                                            }
                                        });
                                break;

                            case R.id.byTopic:
                                mUrlEditText.setText("http://www.faroo.com/api?q=" + text
                                        + "&start=1&length=10&l=en&src=news&f=rss");
                                break;

                            case R.id.byYoutube:
                                mUrlEditText.setText("http://www.youtube.com/rss/user/"
                                        + text.replaceAll("\\+", "") + "/videos.rss");
                                break;
                            }
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, null).show();
        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.money.manager.ex.sync.SyncManager.java

public void invokeSyncService(String action) {
    // Validation.
    String remoteFile = getRemotePath();
    // We need a value in remote file name preferences.
    if (TextUtils.isEmpty(remoteFile))
        return;//from w  w  w  .  j ava2  s. c o  m

    // Action

    ProgressDialog progressDialog = null;
    // Create progress dialog only if called from the UI.
    if ((getContext() instanceof Activity)) {
        //progress dialog shown only when downloading an updated db file.
        progressDialog = new ProgressDialog(getContext());
        progressDialog.setCancelable(false);
        progressDialog.setMessage(getContext().getString(R.string.syncProgress));
        progressDialog.setIndeterminate(true);
        //            progressDialog.show();
    }
    Messenger messenger = null;
    if (getContext() instanceof Activity) {
        // Messenger handles received messages from the sync service. Can run only in a looper thread.
        messenger = new Messenger(new SyncServiceMessageHandler(getContext(), progressDialog, remoteFile));
    }

    String localFile = getDatabases().getCurrent().localPath;

    Intent syncServiceIntent = IntentFactory.getSyncServiceIntent(getContext(), action, localFile, remoteFile,
            messenger);
    // start service
    getContext().startService(syncServiceIntent);

    // Reset any other scheduled uploads as the current operation will modify the files.
    abortScheduledUpload();

    // The messages from the service are received via messenger.
}

From source file:org.telegram.ui.PrivacyControlActivity.java

private void applyCurrentPrivacySettings() {
    TLRPC.TL_account_setPrivacy req = new TLRPC.TL_account_setPrivacy();
    if (isGroup) {
        req.key = new TLRPC.TL_inputPrivacyKeyChatInvite();
    } else {/*  w w w .  j  av a2 s.  c om*/
        req.key = new TLRPC.TL_inputPrivacyKeyStatusTimestamp();
    }
    if (currentType != 0 && currentPlus.size() > 0) {
        TLRPC.TL_inputPrivacyValueAllowUsers rule = new TLRPC.TL_inputPrivacyValueAllowUsers();
        for (int a = 0; a < currentPlus.size(); a++) {
            TLRPC.User user = MessagesController.getInstance().getUser(currentPlus.get(a));
            if (user != null) {
                TLRPC.InputUser inputUser = MessagesController.getInputUser(user);
                if (inputUser != null) {
                    rule.users.add(inputUser);
                }
            }
        }
        req.rules.add(rule);
    }
    if (currentType != 1 && currentMinus.size() > 0) {
        TLRPC.TL_inputPrivacyValueDisallowUsers rule = new TLRPC.TL_inputPrivacyValueDisallowUsers();
        for (int a = 0; a < currentMinus.size(); a++) {
            TLRPC.User user = MessagesController.getInstance().getUser(currentMinus.get(a));
            if (user != null) {
                TLRPC.InputUser inputUser = MessagesController.getInputUser(user);
                if (inputUser != null) {
                    rule.users.add(inputUser);
                }
            }
        }
        req.rules.add(rule);
    }
    if (currentType == 0) {
        req.rules.add(new TLRPC.TL_inputPrivacyValueAllowAll());
    } else if (currentType == 1) {
        req.rules.add(new TLRPC.TL_inputPrivacyValueDisallowAll());
    } else if (currentType == 2) {
        req.rules.add(new TLRPC.TL_inputPrivacyValueAllowContacts());
    }
    ProgressDialog progressDialog = null;
    if (getParentActivity() != null) {
        progressDialog = new ProgressDialog(getParentActivity());
        progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.setCancelable(false);
        progressDialog.show();
    }
    final ProgressDialog progressDialogFinal = progressDialog;
    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() {
                    try {
                        if (progressDialogFinal != null) {
                            progressDialogFinal.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                    if (error == null) {
                        finishFragment();
                        TLRPC.TL_account_privacyRules rules = (TLRPC.TL_account_privacyRules) response;
                        MessagesController.getInstance().putUsers(rules.users, false);
                        ContactsController.getInstance().setPrivacyRules(rules.rules, isGroup);
                    } else {
                        showErrorAlert();
                    }
                }
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}

From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java

/**
 * Export data./* ww w.  j a  v a 2  s.com*/
 * 
 * @param descr
 *            description of the exported rule set
 * @param fn
 *            one of the predefined file names from {@link DataProvider}.
 */
private void exportData(final String descr, final String fn) {
    if (descr == null) {
        final EditText et = new EditText(this);
        Builder builder = new Builder(this);
        builder.setView(et);
        builder.setCancelable(true);
        builder.setTitle(R.string.export_rules_descr);
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                Preferences.this.exportData(et.getText().toString(), fn);
            }
        });
        builder.show();
    } else {
        final ProgressDialog d = new ProgressDialog(this);
        d.setIndeterminate(true);
        d.setMessage(this.getString(R.string.export_progr));
        d.setCancelable(false);
        d.show();

        // run task in background
        final AsyncTask<Void, Void, String> task = // .
                new AsyncTask<Void, Void, String>() {
                    @Override
                    protected String doInBackground(final Void... params) {
                        if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                            return DataProvider.backupRuleSet(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                            return DataProvider.backupLogs(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                            return DataProvider.backupNumGroups(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                            return DataProvider.backupHourGroups(Preferences.this, descr);
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(final String result) {
                        Log.d(TAG, "export:\n" + result);
                        System.out.println("\n" + result);
                        d.dismiss();
                        if (result != null && result.length() > 0) {
                            Uri uri = null;
                            int resChooser = -1;
                            if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                                uri = DataProvider.EXPORT_RULESET_URI;
                                resChooser = R.string.export_rules_;
                            } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                                uri = DataProvider.EXPORT_LOGS_URI;
                                resChooser = R.string.export_logs_;
                            } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_NUMGROUPS_URI;
                                resChooser = R.string.export_numgroups_;
                            } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_HOURGROUPS_URI;
                                resChooser = R.string.export_hourgroups_;
                            }
                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType(DataProvider.EXPORT_MIMETYPE);
                            intent.putExtra(Intent.EXTRA_STREAM, uri);
                            intent.putExtra(Intent.EXTRA_SUBJECT, // .
                                    "Call Meter 3G export");
                            intent.addCategory(Intent.CATEGORY_DEFAULT);

                            try {
                                final File d = Environment.getExternalStorageDirectory();
                                final File f = new File(d, DataProvider.PACKAGE + File.separator + fn);
                                f.mkdirs();
                                if (f.exists()) {
                                    f.delete();
                                }
                                f.createNewFile();
                                FileWriter fw = new FileWriter(f);
                                fw.append(result);
                                fw.close();
                                // call an exporting app with the uri to the
                                // preferences
                                Preferences.this.startActivity(
                                        Intent.createChooser(intent, Preferences.this.getString(resChooser)));
                            } catch (IOException e) {
                                Log.e(TAG, "error writing export file", e);
                                Toast.makeText(Preferences.this, R.string.err_export_write, Toast.LENGTH_LONG)
                                        .show();
                            }
                        }
                    }
                };
        task.execute((Void) null);
    }
}

From source file:net.sylvek.sharemyposition.ShareMyPosition.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    default:/*from w  w  w  . j av  a2s. c o  m*/
        return super.onCreateDialog(id);
    case MAP_DLG:
        final View sharedMapView = LayoutInflater.from(this).inflate(R.layout.sharedmap, null);
        final FrameLayout map = (FrameLayout) sharedMapView.findViewById(R.id.sharedmap);
        map.addView(this.sharedMap);
        final CheckBox latlonAddress = (CheckBox) sharedMapView.findViewById(R.id.add_lat_lon_location);
        final CheckBox geocodeAddress = (CheckBox) sharedMapView.findViewById(R.id.add_address_location);
        final RadioButton nourl = (RadioButton) sharedMapView.findViewById(R.id.add_no_url_location);
        final RadioButton url = (RadioButton) sharedMapView.findViewById(R.id.add_url_location);
        final RadioButton gmap = (RadioButton) sharedMapView.findViewById(R.id.add_native_location);
        final EditText body = (EditText) sharedMapView.findViewById(R.id.body);
        final ToggleButton track = (ToggleButton) sharedMapView.findViewById(R.id.add_track_location);

        latlonAddress.setChecked(pref.getBoolean(PREF_LAT_LON_CHECKED, true));
        geocodeAddress.setChecked(pref.getBoolean(PREF_ADDRESS_CHECKED, true));
        final boolean isUrl = pref.getBoolean(PREF_URL_CHECKED, true);
        final boolean isGmap = pref.getBoolean(PREF_GMAP_CHECKED, false);
        url.setChecked(isUrl);
        gmap.setChecked(isGmap);
        nourl.setChecked(!isUrl && !isGmap);
        body.setText(pref.getString(PREF_BODY_DEFAULT, getString(R.string.body)));
        track.setChecked(pref.getBoolean(PREF_TRACK_CHECKED, false));

        if (track.isChecked()) {
            latlonAddress.setEnabled(false);
            latlonAddress.setChecked(false);
            geocodeAddress.setEnabled(false);
            geocodeAddress.setChecked(false);
            url.setEnabled(false);
            url.setChecked(true);
            gmap.setEnabled(false);
            gmap.setChecked(false);
            nourl.setEnabled(false);
            nourl.setChecked(false);
        }

        track.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                latlonAddress.setEnabled(!isChecked);
                latlonAddress.setChecked(!isChecked);
                geocodeAddress.setEnabled(!isChecked);
                geocodeAddress.setChecked(!isChecked);
                url.setEnabled(!isChecked);
                url.setChecked(true);
                gmap.setEnabled(!isChecked);
                gmap.setChecked(!isChecked);
                nourl.setEnabled(!isChecked);
                nourl.setChecked(!isChecked);
            }
        });

        return new AlertDialog.Builder(this).setTitle(R.string.app_name).setView(sharedMapView)
                .setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface arg0) {
                        finish();
                    }
                }).setNeutralButton(R.string.options, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        /* needed to display neutral button */
                    }
                }).setPositiveButton(R.string.share_it, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        final boolean isLatLong = ((CheckBox) sharedMapView
                                .findViewById(R.id.add_lat_lon_location)).isChecked();
                        final boolean isGeocodeAddress = ((CheckBox) sharedMapView
                                .findViewById(R.id.add_address_location)).isChecked();
                        final boolean isUrl = ((RadioButton) sharedMapView.findViewById(R.id.add_url_location))
                                .isChecked();
                        final boolean isGmap = ((RadioButton) sharedMapView
                                .findViewById(R.id.add_native_location)).isChecked();
                        final EditText body = (EditText) sharedMapView.findViewById(R.id.body);
                        final boolean isTracked = ((ToggleButton) sharedMapView
                                .findViewById(R.id.add_track_location)).isChecked();
                        final String uuid = UUID.randomUUID().toString();

                        pref.edit().putBoolean(PREF_LAT_LON_CHECKED, isLatLong)
                                .putBoolean(PREF_ADDRESS_CHECKED, isGeocodeAddress)
                                .putBoolean(PREF_URL_CHECKED, isUrl).putBoolean(PREF_GMAP_CHECKED, isGmap)
                                .putString(PREF_BODY_DEFAULT, body.getText().toString())
                                .putBoolean(PREF_TRACK_CHECKED, isTracked).commit();

                        final Intent t = new Intent(Intent.ACTION_SEND);
                        t.setType("text/plain");
                        t.addCategory(Intent.CATEGORY_DEFAULT);
                        final Intent share = Intent.createChooser(t, getString(R.string.app_name));
                        final GeoPoint p = sharedMap.getMapCenter();

                        final String text = body.getText().toString();
                        share(p.getLatitude(), p.getLongitude(), t, share, text, isGeocodeAddress, isUrl,
                                isGmap, isLatLong, isTracked, uuid);
                    }
                }).create();
    case PROGRESS_DLG:
        final ProgressDialog dlg = new ProgressDialog(this);
        dlg.setTitle(getText(R.string.app_name));
        dlg.setMessage(getText(R.string.progression_desc));
        dlg.setIndeterminate(true);
        dlg.setCancelable(true);
        dlg.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        return dlg;
    case PROVIDERS_DLG:
        return new AlertDialog.Builder(this).setTitle(R.string.app_name).setCancelable(false)
                .setIcon(android.R.drawable.ic_menu_help).setMessage(R.string.providers_needed)
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }

                }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent gpsProperty = new Intent(
                                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(gpsProperty);
                    }
                }).create();
    }
}

From source file:fm.smart.r1.ItemActivity.java

public void addToList(final String item_id) {
    final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
    myOtherProgressDialog.setTitle("Please Wait ...");
    myOtherProgressDialog.setMessage("Adding item to study goal ...");
    myOtherProgressDialog.setIndeterminate(true);
    myOtherProgressDialog.setCancelable(true);

    final Thread add = new Thread() {
        public void run() {
            ItemActivity.add_item_result = new AddItemResult(
                    Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, null));

            myOtherProgressDialog.dismiss();
            ItemActivity.this.runOnUiThread(new Thread() {
                public void run() {
                    final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                    dialog.setTitle(ItemActivity.add_item_result.getTitle());
                    dialog.setMessage(ItemActivity.add_item_result.getMessage());
                    ItemActivity.add_item_result = null;
                    dialog.setButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }//from  ww  w .jav  a2  s  .c o  m
                    });

                    dialog.show();
                }
            });

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

From source file:org.namelessrom.devicecontrol.appmanager.AppDetailsActivity.java

private void uninstall() {
    // try via native package manager api
    AppHelper.uninstallPackage(mPm, mAppItem.getPackageName());

    // build our command
    final StringBuilder sb = new StringBuilder();

    sb.append(String.format("pm uninstall %s;", mAppItem.getPackageName()));

    if (mAppItem.isSystemApp()) {
        sb.append("busybox mount -o rw,remount /system;");
    }/*  w w w.j  av a 2  s  . co m*/

    sb.append(String.format("rm -rf %s;", mAppItem.getApplicationInfo().publicSourceDir));
    sb.append(String.format("rm -rf %s;", mAppItem.getApplicationInfo().sourceDir));
    sb.append(String.format("rm -rf %s;", mAppItem.getApplicationInfo().dataDir));

    if (mAppItem.isSystemApp()) {
        sb.append("busybox mount -o ro,remount /system;");
    }

    final String cmd = sb.toString();
    Logger.v(this, cmd);

    // create the dialog (will not be shown for a long amount of time though)
    final ProgressDialog dialog;
    dialog = new ProgressDialog(this);
    dialog.setTitle(R.string.uninstalling);
    dialog.setMessage(getString(R.string.applying_wait));
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setCancelable(false);

    new AsyncTask<Void, Void, Void>() {

        @Override
        protected void onPreExecute() {
            dialog.show();
        }

        @Override
        protected Void doInBackground(Void... voids) {
            Utils.runRootCommand(cmd, true);
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            dialog.dismiss();
            Toast.makeText(AppDetailsActivity.this, getString(R.string.uninstall_success, mAppItem.getLabel()),
                    Toast.LENGTH_SHORT).show();
            mAppItem = null;
            finish();

        }
    }.execute();
}

From source file:com.money.manager.ex.MainActivity.java

public void startServiceSyncDropbox() {
    if (mDropboxHelper != null && mDropboxHelper.isLinked()) {
        Intent service = new Intent(getApplicationContext(), DropboxServiceIntent.class);
        service.setAction(DropboxServiceIntent.INTENT_ACTION_SYNC);
        service.putExtra(DropboxServiceIntent.INTENT_EXTRA_LOCAL_FILE,
                MoneyManagerApplication.getDatabasePath(this.getApplicationContext()));
        service.putExtra(DropboxServiceIntent.INTENT_EXTRA_REMOTE_FILE, mDropboxHelper.getLinkedRemoteFile());
        //progress dialog
        final ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);
        progressDialog.setMessage(getString(R.string.dropbox_syncProgress));
        progressDialog.setIndeterminate(true);
        progressDialog.show();/*from   w w w  . j a  va2s . c  o  m*/
        //create a messenger
        Messenger messenger = new Messenger(new Handler() {
            @Override
            public void handleMessage(Message msg) {
                if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_NOT_CHANGE) {
                    // close dialog
                    if (progressDialog != null && progressDialog.isShowing())
                        progressDialog.hide();

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.dropbox_database_is_synchronized,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_START_DOWNLOAD) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.dropbox_download_is_starting,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_DOWNLOAD) {
                    // close dialog
                    if (progressDialog != null && progressDialog.isShowing())
                        progressDialog.hide();
                    // reload fragment
                    reloadAllFragment();
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_START_UPLOAD) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.dropbox_upload_is_starting,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_UPLOAD) {
                    // close dialog
                    if (progressDialog != null && progressDialog.isShowing())
                        progressDialog.hide();

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.upload_file_to_dropbox_complete,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                }
            }
        });
        service.putExtra(DropboxServiceIntent.INTENT_EXTRA_MESSENGER, messenger);

        this.startService(service);
    }
}

From source file:com.einzig.ipst2.activities.MainActivity.java

/**
 * Wrapper function for parseEmailWork./*w  w  w . ja v a  2  s  .c  o  m*/
 * <p>
 * Builds the progress dialog for, then calls parseEmailWork
 * </p>
 *
 * @see MainActivity#parseEmailWork(Account, ProgressDialog)
 */
private void parseEmail() {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        Logger.d("IS MAIN THREAD?!");
    }
    final Account account = getAccount();
    if (account != null) {
        final ProgressDialog dialog = new ProgressDialog(this, ThemeHelper.getDialogTheme(this));
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setIndeterminate(true);
        dialog.setTitle(getString(R.string.searching_email));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
        new Thread() {
            public void run() {
                parseEmailWork(account, dialog);
            }
        }.start();
        //getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        //getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
}