Example usage for android.app AlertDialog show

List of usage examples for android.app AlertDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionSort() {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.sort, null);
    final RadioGroup rgSMode = (RadioGroup) view.findViewById(R.id.rgSMode);
    final CheckBox cbSInvert = (CheckBox) view.findViewById(R.id.cbSInvert);

    // Initialise controls
    switch (mSortMode) {
    case SORT_BY_NAME:
        rgSMode.check(R.id.rbSName);/*  ww  w . ja v  a  2  s  . co m*/
        break;
    case SORT_BY_UID:
        rgSMode.check(R.id.rbSUid);
        break;
    case SORT_BY_INSTALL_TIME:
        rgSMode.check(R.id.rbSInstalled);
        break;
    case SORT_BY_UPDATE_TIME:
        rgSMode.check(R.id.rbSUpdated);
        break;
    case SORT_BY_MODIFY_TIME:
        rgSMode.check(R.id.rbSModified);
        break;
    case SORT_BY_STATE:
        rgSMode.check(R.id.rbSState);
        break;
    }
    cbSInvert.setChecked(mSortInvert);

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
    alertDialogBuilder.setTitle(R.string.menu_sort);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(ActivityMain.this.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (rgSMode.getCheckedRadioButtonId()) {
                    case R.id.rbSName:
                        mSortMode = SORT_BY_NAME;
                        break;
                    case R.id.rbSUid:
                        mSortMode = SORT_BY_UID;
                        break;
                    case R.id.rbSInstalled:
                        mSortMode = SORT_BY_INSTALL_TIME;
                        break;
                    case R.id.rbSUpdated:
                        mSortMode = SORT_BY_UPDATE_TIME;
                        break;
                    case R.id.rbSModified:
                        mSortMode = SORT_BY_MODIFY_TIME;
                        break;
                    case R.id.rbSState:
                        mSortMode = SORT_BY_STATE;
                        break;
                    }
                    mSortInvert = cbSInvert.isChecked();

                    int userId = Util.getUserId(Process.myUid());
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortMode,
                            Integer.toString(mSortMode));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortInverted,
                            Boolean.toString(mSortInvert));

                    applySort();
                }
            });
    alertDialogBuilder.setNegativeButton(ActivityMain.this.getString(android.R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:ar.rulosoft.mimanganu.PreferencesFragment.java

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.fragment_preferences);
    ColorListDialogPref primaryColor = (ColorListDialogPref) getPreferenceManager().findPreference("primario");
    primaryColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override/*from ww w.jav a2  s  . c  om*/
        public boolean onPreferenceChange(Preference preference, Object o) {
            ((MainActivity) getActivity()).setColorToBars();
            return false;
        }
    });
    PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("account");
    ServerBase[] servers = ServerBase.getServers(getContext());
    for (final ServerBase sb : servers) {
        if (sb.needLogin()) {
            SwitchPreferenceCompat preference = new SwitchPreferenceCompat(getContext());
            preference.setTitle(sb.getServerName());
            preference.setSelectable(true);
            preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    new LoginDialog(getContext(), sb).show();
                    return false;
                }
            });
            preferenceGroup.addPreference(preference);
        }
    }

    /** Once, create necessary Data */
    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
    final String current_filepath = prefs.getString("directorio",
            Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/";

    /** This enables to hide downloaded images from gallery, just a toggle */
    final SwitchPreferenceCompat cBoxPref = (SwitchPreferenceCompat) getPreferenceManager()
            .findPreference("mostrar_en_galeria");
    cBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean have_noMedia = (Boolean) newValue;

            if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
                File mimaFolder = new File(current_filepath, ".nomedia");

                if (have_noMedia) {
                    try {
                        mimaFolder.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    if (mimaFolder.exists()) {
                        mimaFolder.delete();
                    }
                }
            }

            return true;
        }
    });

    /** Set summary for Reader preference + seamless chapter transitions summary **/
    // true: Paged Reader; false: Continuous Reader
    Boolean readType = prefs.getBoolean("reader_type", false);
    Preference reader_type = getPreferenceManager().findPreference("reader_type");
    Preference seamlessChapterTransitionsPref = getPreferenceManager()
            .findPreference("seamless_chapter_transitions");
    if (readType) {
        reader_type.setTitle(getString(R.string.paged_reader));
        seamlessChapterTransitionsPref
                .setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle));
    } else {
        reader_type.setTitle(getString(R.string.continuous_reader));
        seamlessChapterTransitionsPref
                .setSummary(getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle));
    }
    final SwitchPreferenceCompat readerTypePref = (SwitchPreferenceCompat) getPreferenceManager()
            .findPreference("reader_type");
    readerTypePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Boolean readType = prefs.getBoolean("reader_type", false);
            Preference reader_type = getPreferenceManager().findPreference("reader_type");
            Preference seamlessChapterTransitions = getPreferenceManager()
                    .findPreference("seamless_chapter_transitions");
            if (!readType) {
                reader_type.setTitle(getString(R.string.paged_reader));
                seamlessChapterTransitions
                        .setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle));
            } else {
                reader_type.setTitle(getString(R.string.continuous_reader));
                seamlessChapterTransitions.setSummary(
                        getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle));
            }
            return true;
        }
    });

    /** enable / disable seamless_chapter_transitions_delete_read depending on the state of seamless_chapter_transitions **/
    Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager()
            .findPreference("seamless_chapter_transitions_delete_read");
    if (prefs.getBoolean("seamless_chapter_transitions", false)) {
        seamlessChapterTransitionsDeleteReadPreference.setEnabled(true);
    } else {
        seamlessChapterTransitionsDeleteReadPreference.setEnabled(false);
    }
    final SwitchPreferenceCompat seamlessChapterTransitionsSPC = (SwitchPreferenceCompat) getPreferenceManager()
            .findPreference("seamless_chapter_transitions");
    seamlessChapterTransitionsSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager()
                    .findPreference("seamless_chapter_transitions_delete_read");
            if (!prefs.getBoolean("seamless_chapter_transitions", false)) {
                seamlessChapterTransitionsDeleteReadPreference.setEnabled(true);
            } else {
                seamlessChapterTransitionsDeleteReadPreference.setEnabled(false);

                SharedPreferences.Editor prefEdit = prefs.edit();
                prefEdit.putBoolean("seamless_chapter_transitions_delete_read", false);
                prefEdit.apply();
            }
            return true;
        }
    });
    Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path");
    /** enable / disable auto_import_path depending on the state of auto_import **/
    if (prefs.getBoolean("auto_import", false)) {
        autoImportPath.setEnabled(true);
    } else {
        autoImportPath.setEnabled(false);
    }
    final SwitchPreferenceCompat autoImportSPC = (SwitchPreferenceCompat) getPreferenceManager()
            .findPreference("auto_import");
    autoImportSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path");
            if (!prefs.getBoolean("auto_import", false)) {
                autoImportPath.setEnabled(true);
            } else {
                autoImportPath.setEnabled(false);
            }
            return true;
        }
    });

    /** This sets the download threads (parallel downloads) */
    final SeekBarCustomPreference listPreferenceDT = (SeekBarCustomPreference) getPreferenceManager()
            .findPreference("download_threads");
    listPreferenceDT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int threads = (int) newValue;
            int antes = DownloadPoolService.SLOTS;
            DownloadPoolService.SLOTS = threads;
            if (DownloadPoolService.actual != null)
                DownloadPoolService.actual.slots += (threads - antes);
            return true;
        }
    });

    /** This sets the maximum number of errors to tolerate */
    final SeekBarCustomPreference listPrefET = (SeekBarCustomPreference) getPreferenceManager()
            .findPreference("error_tolerancia");
    listPrefET.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            ChapterDownload.MAX_ERRORS = (int) newValue;
            return true;
        }
    });

    /** This sets the number of retries to fetch images */
    SeekBarCustomPreference listPrefRT = (SeekBarCustomPreference) getPreferenceManager()
            .findPreference("reintentos");
    listPrefRT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SingleDownload.RETRY = (int) newValue;
            return true;
        }
    });

    /** This sets the Update Interval of the mangas (i.e. once per week) */
    final ListPreference listPrefCU = (ListPreference) getPreferenceManager().findPreference("update_interval");
    listPrefCU.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            long time = Long.parseLong((String) newValue);
            if (time > 0) {
                AlarmReceiver.setAlarms(getActivity().getApplicationContext(),
                        System.currentTimeMillis() + time, time);
            } else {
                AlarmReceiver.stopAlarms(getActivity().getApplicationContext());
            }

            if (time < 0)
                MainActivity.coldStart = false;

            return true;
        }
    });

    /** This is for Custom language selection */
    final ListPreference listPrefBatotoLang = (ListPreference) getPreferenceManager()
            .findPreference("batoto_lang_selection");
    listPrefBatotoLang.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.equals("Custom")) {
                LayoutInflater inflater = (LayoutInflater) getContext()
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View rootView = inflater.inflate(R.layout.batoto_custom_lang_dialog, null);
                final EditText CustomLang = (EditText) rootView.findViewById(R.id.txtCustomLang);
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
                dialogBuilder.setTitle("Custom language");
                dialogBuilder.setView(rootView);
                dialogBuilder.setPositiveButton("Ok", null);
                dialogBuilder.setNegativeButton("Cancel", null);
                AlertDialog dialog = dialogBuilder.create();
                dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                    @Override
                    public void onShow(final DialogInterface dialog) {
                        Button accept = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                        accept.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                prefs.edit().putString("batoto_custom_lang", CustomLang.getText().toString())
                                        .apply();
                                Util.getInstance().toast(getContext(),
                                        "Custom Language: " + CustomLang.getText().toString());
                                dialog.dismiss();
                            }
                        });
                        Button cancel = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
                        cancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                dialog.dismiss();
                            }
                        });
                    }
                });
                dialog.show();
            }

            return true;
        }
    });

    /** This sets the Version Number, that's all */
    final Preference prefAbout = getPreferenceManager().findPreference("about_text");
    prefAbout.setSummary("v" + BuildConfig.VERSION_NAME);

    /** This will check how much storage is taken by the mangas */
    new calcStorage().execute(current_filepath);

    final Preference prefLicense = getPreferenceManager().findPreference("license_view");
    prefLicense.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            ((MainActivity) getActivity()).replaceFragment(new LicenseFragment(), "licence_fragment");
            return false;
        }
    });

    final SwitchPreferenceCompat onlyWifiUpdateSwitch = (SwitchPreferenceCompat) getPreferenceManager()
            .findPreference("update_only_wifi");

    SwitchPreferenceCompat onlyWifiSwitch = (SwitchPreferenceCompat) getPreferenceManager()
            .findPreference("only_wifi");
    onlyWifiSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            NetworkUtilsAndReceiver.ONLY_WIFI = (Boolean) o;
            NetworkUtilsAndReceiver.connectionStatus = NetworkUtilsAndReceiver.ConnectionStatus.UNCHECKED;
            onlyWifiUpdateSwitch.setEnabled(!(Boolean) o);
            return true;
        }
    });

    if (onlyWifiSwitch.isChecked()) {
        onlyWifiUpdateSwitch.setEnabled(false);
    } else {
        onlyWifiUpdateSwitch.setEnabled(true);
    }

    final SeekBarCustomPreference seekBarConnectionTimeout = (SeekBarCustomPreference) getPreferenceManager()
            .findPreference("connection_timeout");
    seekBarConnectionTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Navigator.connectionTimeout = Integer.parseInt(prefs.getString("connection_timeout", "10"));
            return true;
        }
    });

    final SeekBarCustomPreference seekBarWriteTimeout = (SeekBarCustomPreference) getPreferenceManager()
            .findPreference("write_timeout");
    seekBarWriteTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Navigator.writeTimeout = Integer.parseInt(prefs.getString("write_timeout", "10"));
            return true;
        }
    });

    final SeekBarCustomPreference seekBarReadTimeout = (SeekBarCustomPreference) getPreferenceManager()
            .findPreference("read_timeout");
    seekBarReadTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Navigator.readTimeout = Integer.parseInt(prefs.getString("read_timeout", "30"));
            return true;
        }
    });

    Preference gridColumnsPref = getPreferenceManager().findPreference("grid_columns");
    if (prefs.getBoolean("grid_columns_automatic_detection", true)) {
        gridColumnsPref.setEnabled(false);
    } else {
        gridColumnsPref.setEnabled(true);
    }
    final SwitchPreferenceCompat gridColumnsAutomaticDetectionSPC = (SwitchPreferenceCompat) getPreferenceManager()
            .findPreference("grid_columns_automatic_detection");
    gridColumnsAutomaticDetectionSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
            Preference gridColumns = getPreferenceManager().findPreference("grid_columns");
            if (prefs.getBoolean("grid_columns_automatic_detection", true)) {
                gridColumns.setEnabled(true);
            } else {
                gridColumns.setEnabled(false);
            }
            return true;
        }
    });

    final Preference prefClearCache = getPreferenceManager().findPreference("clear_cache");
    prefClearCache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference clearCache = getPreferenceManager().findPreference("clear_cache");
            clearCache.setEnabled(false);
            Thread t0 = new Thread(new Runnable() {
                @Override
                public void run() {
                    new FileCache(getActivity()).clearCache();
                }
            });

            Thread t1 = new Thread(new Runnable() {
                @Override
                public void run() {
                    Util.getInstance().createNotificationWithProgressbar(getContext(), 69,
                            getString(R.string.deleting_empty_directories), "");
                    Util.getInstance().deleteEmptyDirectoriesRecursive(new File(current_filepath));
                    Util.getInstance().cancelNotification(69);
                }
            });

            t0.start();
            t1.start();
            return true;
        }
    });

    final Preference prefResetServersToDefaults = getPreferenceManager()
            .findPreference("reset_server_list_to_defaults");
    prefResetServersToDefaults.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference resetServerListToDefaults = getPreferenceManager()
                    .findPreference("reset_server_list_to_defaults");
            resetServerListToDefaults.setEnabled(false);
            prefs.edit().putString("unused_servers", "").apply();
            return true;
        }
    });

    final Preference prefVacuumDatabase = getPreferenceManager().findPreference("vacuum_database");
    prefVacuumDatabase.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Preference vacuumDatabase = getPreferenceManager().findPreference("vacuum_database");
            vacuumDatabase.setEnabled(false);
            Thread t0 = new Thread(new Runnable() {
                @Override
                public void run() {
                    Util.getInstance().createNotificationWithProgressbar(getContext(), 70,
                            getString(R.string.vacuum_database_notification_text), "");
                    Database.vacuumDatabase(getContext());
                    Util.getInstance().cancelNotification(70);
                }
            });
            t0.start();
            return true;
        }
    });

    setFirstRunDefaults();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionTemplate() {
    final int userId = Util.getUserId(Process.myUid());

    // Build view
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.template, null);
    final Spinner spTemplate = (Spinner) view.findViewById(R.id.spTemplate);
    Button btnRename = (Button) view.findViewById(R.id.btnRename);
    ExpandableListView elvTemplate = (ExpandableListView) view.findViewById(R.id.elvTemplate);

    // Template selector
    final SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0",
            getString(R.string.title_default));
    spAdapter.add(defaultName);/*from  w ww  . jav  a 2 s .co  m*/
    for (int i = 1; i <= 4; i++) {
        String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i),
                getString(R.string.title_alternate) + " " + i);
        spAdapter.add(alternateName);
    }
    spTemplate.setAdapter(spAdapter);

    // Template definition
    final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry);
    elvTemplate.setAdapter(templateAdapter);
    elvTemplate.setGroupIndicator(null);

    spTemplate.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            templateAdapter.notifyDataSetChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            templateAdapter.notifyDataSetChanged();
        }
    });

    btnRename.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Util.hasProLicense(ActivityMain.this) == null) {
                // Redirect to pro page
                Util.viewUri(ActivityMain.this, cProUri);
                return;
            }

            final int templateId = spTemplate.getSelectedItemPosition();
            if (templateId == AdapterView.INVALID_POSITION)
                return;

            AlertDialog.Builder dlgRename = new AlertDialog.Builder(spTemplate.getContext());
            dlgRename.setTitle(R.string.title_rename);

            final String original = (templateId == 0 ? getString(R.string.title_default)
                    : getString(R.string.title_alternate) + " " + templateId);
            dlgRename.setMessage(original);

            final EditText input = new EditText(spTemplate.getContext());
            dlgRename.setView(input);

            dlgRename.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String name = input.getText().toString();
                    if (TextUtils.isEmpty(name)) {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                null);
                        name = original;
                    } else {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                name);
                    }
                    spAdapter.remove(spAdapter.getItem(templateId));
                    spAdapter.insert(name, templateId);
                    spAdapter.notifyDataSetChanged();
                }
            });

            dlgRename.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }
            });

            dlgRename.create().show();
        }
    });

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(R.string.menu_template);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(getString(R.string.msg_done), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
        }
    });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:cm.aptoide.pt.ManageRepo.java

private void editRepo(final String repo) {
    LayoutInflater li = LayoutInflater.from(this);
    View view = li.inflate(R.layout.addrepo, null);
    Builder p = new AlertDialog.Builder(this).setView(view);
    final AlertDialog alrt = p.create();
    final EditText uri = (EditText) view.findViewById(R.id.edit_uri);
    uri.setText(repo);//from   ww w .ja v a  2 s .co m

    final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
    final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);
    final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
    sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                sec_user.setEnabled(true);
                sec_pwd.setEnabled(true);
            } else {
                sec_user.setEnabled(false);
                sec_pwd.setEnabled(false);
            }
        }
    });

    String[] logins = null;
    logins = db.getLogin(repo);
    if (logins != null) {
        sec.setChecked(true);
        sec_user.setText(logins[0]);
        sec_pwd.setText(logins[1]);
    } else {
        sec.setChecked(false);
    }

    alrt.setIcon(android.R.drawable.ic_menu_add);
    alrt.setTitle("Edit repository");
    alrt.setButton("Done", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String new_repo = uri.getText().toString();
            db.updateServer(repo, new_repo);
            if (sec.isChecked()) {
                db.addLogin(sec_user.getText().toString(), sec_pwd.getText().toString(), new_repo);
            } else {
                db.disableLogin(new_repo);
            }
            change = true;
            redraw();
        }
    });

    alrt.setButton2("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    alert2.dismiss();
    alrt.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionFilter() {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.filters, null);
    final CheckBox cbFUsed = (CheckBox) view.findViewById(R.id.cbFUsed);
    final CheckBox cbFInternet = (CheckBox) view.findViewById(R.id.cbFInternet);
    final CheckBox cbFPermission = (CheckBox) view.findViewById(R.id.cbFPermission);
    final CheckBox cbFRestriction = (CheckBox) view.findViewById(R.id.cbFRestriction);
    final CheckBox cbFRestrictionNot = (CheckBox) view.findViewById(R.id.cbFRestrictionNot);
    final CheckBox cbFOnDemand = (CheckBox) view.findViewById(R.id.cbFOnDemand);
    final CheckBox cbFOnDemandNot = (CheckBox) view.findViewById(R.id.cbFOnDemandNot);
    final CheckBox cbFUser = (CheckBox) view.findViewById(R.id.cbFUser);
    final CheckBox cbFSystem = (CheckBox) view.findViewById(R.id.cbFSystem);
    final Button btnDefault = (Button) view.findViewById(R.id.btnDefault);

    // Get settings
    final int userId = Util.getUserId(Process.myUid());
    boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false);
    boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false);
    boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true);
    boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false);
    boolean fRestrictionNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestrictionNot,
            false);//from  www .  j  ava  2s .c o  m
    boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false);
    boolean fOnDemandNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemandNot, false);
    boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true);
    boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false);

    boolean ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true);

    // Setup checkboxes
    cbFUsed.setChecked(fUsed);
    cbFInternet.setChecked(fInternet);
    cbFPermission.setChecked(fPermission);
    cbFRestriction.setChecked(fRestriction);
    cbFRestrictionNot.setChecked(fRestrictionNot);
    cbFOnDemand.setChecked(fOnDemand && ondemand);
    cbFOnDemandNot.setChecked(fOnDemandNot && ondemand);
    cbFUser.setChecked(fUser);
    cbFSystem.setChecked(fSystem);

    cbFRestrictionNot.setEnabled(fRestriction);

    cbFOnDemand.setEnabled(ondemand);
    cbFOnDemandNot.setEnabled(fOnDemand && ondemand);

    // Manage user/system filter exclusivity
    OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (buttonView == cbFUser) {
                if (isChecked)
                    cbFSystem.setChecked(false);
            } else if (buttonView == cbFSystem) {
                if (isChecked)
                    cbFUser.setChecked(false);
            } else if (buttonView == cbFRestriction)
                cbFRestrictionNot.setEnabled(cbFRestriction.isChecked());
            else if (buttonView == cbFOnDemand)
                cbFOnDemandNot.setEnabled(cbFOnDemand.isChecked());
        }
    };
    cbFUser.setOnCheckedChangeListener(checkListener);
    cbFSystem.setOnCheckedChangeListener(checkListener);
    cbFRestriction.setOnCheckedChangeListener(checkListener);
    cbFOnDemand.setOnCheckedChangeListener(checkListener);

    // Clear button
    btnDefault.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            cbFUsed.setChecked(false);
            cbFInternet.setChecked(false);
            cbFPermission.setChecked(true);
            cbFRestriction.setChecked(false);
            cbFRestrictionNot.setChecked(false);
            cbFOnDemand.setChecked(false);
            cbFOnDemandNot.setChecked(false);
            cbFUser.setChecked(true);
            cbFSystem.setChecked(false);
        }
    });

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
    alertDialogBuilder.setTitle(R.string.menu_filter);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(ActivityMain.this.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFUsed,
                            Boolean.toString(cbFUsed.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFInternet,
                            Boolean.toString(cbFInternet.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFRestriction,
                            Boolean.toString(cbFRestriction.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFRestrictionNot,
                            Boolean.toString(cbFRestrictionNot.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFPermission,
                            Boolean.toString(cbFPermission.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFOnDemand,
                            Boolean.toString(cbFOnDemand.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFOnDemandNot,
                            Boolean.toString(cbFOnDemandNot.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFUser,
                            Boolean.toString(cbFUser.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFSystem,
                            Boolean.toString(cbFSystem.isChecked()));

                    invalidateOptionsMenu();
                    applyFilter();
                }
            });
    alertDialogBuilder.setNegativeButton(ActivityMain.this.getString(android.R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Deletes the item represented by this fragment
 * @param item The item to delete//from w ww  . java2 s  . c o  m
 */
private void deleteItem(final Item item) {
    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.delete)
            .setIcon(android.R.drawable.ic_delete)
            .setMessage(getActivity().getString(R.string.confirm_delete_action, mItem.name))
            .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final BaseApplication application = (BaseApplication) getActivity().getApplication();
                    application.getOneDriveClient().getDrive().getItems(item.id).buildRequest()
                            .delete(new DefaultCallback<Void>(application) {
                                @Override
                                public void success(final Void response) {
                                    Toast.makeText(getActivity(),
                                            application.getString(R.string.deleted_this_item, item.name),
                                            Toast.LENGTH_LONG).show();
                                    getActivity().onBackPressed();
                                }
                            });
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:com.df.app.carCheck.VehicleInfoLayout.java

/**
 * //from   w  ww  . j av a  2  s  . co m
 */
private void selectCarManually() {
    View view = LayoutInflater.from(rootView.getContext()).inflate(R.layout.vehicle_model_select, null);

    TextView title = (TextView) view.findViewById(R.id.title);
    title.setText(R.string.select_model);

    initModelSelectEdits(view);

    AlertDialog dialog = new AlertDialog.Builder(rootView.getContext()).setView(view)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // ?Spinner?
                    if (lastCountryIndex == 0 || lastBrandIndex == 0 || lastManufacturerIndex == 0
                            || lastSeriesIndex == 0 || lastModelIndex == 0) {
                        Toast.makeText(rootView.getContext(), "", Toast.LENGTH_SHORT)
                                .show();

                        return;
                    }

                    Country country = vehicleModel.countries.get(lastCountryIndex - 1);
                    Brand brand = country.brands.get(lastBrandIndex - 1);
                    Manufacturer manufacturer = brand.manufacturers.get(lastManufacturerIndex - 1);
                    Series series = manufacturer.serieses.get(lastSeriesIndex - 1);
                    Model model = series.models.get(lastModelIndex - 1);

                    mCarSettings.setCountry(country);
                    mCarSettings.setBrand(brand);
                    mCarSettings.setManufacturer(manufacturer);
                    mCarSettings.setSeries(series);
                    mCarSettings.setModel(model);

                    // ?seriesIdmodelId????  config:powerWindows,powerSeats...
                    getCarSettingsFromServer(series.id + "," + model.id);
                }
            }).setNegativeButton(R.string.cancel, null).create();

    dialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;//from   w  w w. j a va  2s . c om

    // Import license file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()))
        if (Util.importProLicense(new File(getIntent().getData().getPath())) != null)
            Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show();

    // Set layout
    setContentView(R.layout.mainlist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // Set sub title
    if (Util.hasProLicense(this) != null)
        getSupportActionBar().setSubtitle(R.string.menu_pro);

    // Annotate
    Meta.annotate(this.getResources());

    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(
            PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));

    // Build spinner adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spAdapter.addAll(listRestrictionName);

    // Handle info
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onClick(View view) {
            int position = spRestriction.getSelectedItemPosition();
            if (position != AdapterView.INVALID_POSITION) {
                String query = (position == 0 ? "restrictions"
                        : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position
                                - 1]);

                WebView webview = new WebView(ActivityMain.this);
                webview.getSettings().setUserAgentString("Mozilla/5.0");
                // needed for hashtag
                webview.getSettings().setJavaScriptEnabled(true);
                webview.loadUrl("https://github.com/M66B/XPrivacy#" + query);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
                alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem());
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setView(webview);
                alertDialogBuilder.setCancelable(true);
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    // Setup category spinner
    spRestriction = (Spinner) findViewById(R.id.spRestriction);
    spRestriction.setAdapter(spAdapter);
    spRestriction.setOnItemSelectedListener(this);
    int pos = getSelectedCategory(userId);
    spRestriction.setSelection(pos);

    // Setup sort
    mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0"));
    mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false);

    // Start task to get app list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, (Object) null);

    // Check environment
    Requirements.check(this);

    // Licensing
    checkLicense();

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_ADDED);
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    boolean showChangelog = true;

    // First run
    if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) {
        showChangelog = false;
        optionAbout();
    }

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) {
        showChangelog = false;
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Legacy
    if (!PrivacyManager.cVersion3) {
        long now = new Date().getTime();
        String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null);
        if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) {
            showChangelog = false;
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now));

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setMessage(R.string.title_update_legacy);
            alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Util.viewUri(ActivityMain.this,
                            Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3"));
                }
            });
            alertDialogBuilder.setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    });

            // Show dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }

    // Show changelog
    if (showChangelog) {
        String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null);
        Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion);
        Version currentVersion = new Version(Util.getSelfVersionName(this));
        if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0)
            optionChangelog();
    }
}

From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Selected menu item id: " + String.valueOf(item.getItemId()));
    }//from w w w  . j  av a 2  s .c o m
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View v;
    ListViewHolder viewHolder;
    AdapterView.AdapterContextMenuInfo contextInfo;
    String app_name;
    final String package_name;
    switch (item.getItemId()) {
    case R.id.btnUncheckAll:

        builder.setTitle(R.string.dialog_confirm_title);
        builder.setMessage(getString(R.string.dialog_uncheck_message));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                if (lvPackages == null || lvPackages.getAdapter() == null
                        || ((packageAdapter) lvPackages.getAdapter()).selected == null) {
                    //something went wrong
                    return;
                }
                ((packageAdapter) lvPackages.getAdapter()).selected.clear();
                lvPackages.invalidateViews();
            }
        });
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                //do nothing!
            }
        });
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.show();

        return true;
    case R.id.btnSave:
        finish();
        return true;
    case R.id.btnDonate:
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(Constants.DONATION_URL));
        startActivity(i);
        return true;
    case R.id.btnSettings:
        Intent settings = new Intent(this, SettingsActivity.class);
        startActivity(settings);
        return true;
    case R.id.btnRename:
        contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        int position = contextInfo.position;
        long id = contextInfo.id;
        // the child view who's info we're viewing (should be equal to v)
        v = contextInfo.targetView;
        app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString();
        viewHolder = (ListViewHolder) v.getTag();
        if (viewHolder == null || viewHolder.chkEnabled == null) {
            //failure
            return true;
        }
        package_name = (String) viewHolder.chkEnabled.getTag();
        builder.setTitle(R.string.dialog_title_rename_notification);
        final EditText input = new EditText(this);
        input.setHint(app_name);
        builder.setView(input);
        builder.setPositiveButton(R.string.confirm, null);
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //do nothing
            }
        });
        final AlertDialog d = builder.create();
        d.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
                if (b != null) {
                    b.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //can't be nothing
                            if (input.getText().length() > 0) {
                                if (Constants.IS_LOGGABLE) {
                                    Log.i(Constants.LOG_TAG,
                                            "Adding rename for " + package_name + " to " + input.getText());
                                }
                                JSONObject rename = new JSONObject();
                                try {
                                    rename.put("pkg", package_name);
                                    rename.put("to", input.getText());
                                    arrayRenames.put(rename);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged();

                                d.dismiss();
                            } else {
                                input.setText(R.string.error_cant_be_blank);
                            }

                        }
                    });
                }
            }
        });

        d.show();

        return true;
    case R.id.btnRemoveRename:
        contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        // the child view who's info we're viewing (should be equal to v)
        v = contextInfo.targetView;
        app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString();
        viewHolder = (ListViewHolder) v.getTag();
        if (viewHolder == null || viewHolder.chkEnabled == null) {
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Viewholder is null or chkEnabled is null");
            }
            //failure
            return true;
        }
        package_name = (String) viewHolder.chkEnabled.getTag();
        builder.setTitle(
                getString(R.string.dialog_title_remove_rename) + app_name + " (" + package_name + ")?");
        builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Before remove is: " + String.valueOf(arrayRenames.length()));
                }
                JSONArray tmp = new JSONArray();
                try {
                    for (int i = 0; i < arrayRenames.length(); i++) {
                        if (!arrayRenames.getJSONObject(i).getString("pkg").equalsIgnoreCase(package_name)) {
                            tmp.put(arrayRenames.getJSONObject(i));
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                arrayRenames = tmp;
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "After remove is: " + String.valueOf(arrayRenames.length()));
                }
                ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged();
            }
        });
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //do nothing
            }
        });
        builder.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.zen.androidhtmleditor.AHEActivity.java

public void disconnect() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Disconnect?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    //newfile.setEnabled(false);
                    //newfolder.setEnabled(false);
                    hsv.setVisibility(View.GONE);
                    //Button button2 = (Button)findViewById(R.id.button2);
                    //button2.setVisibility(View.GONE);

                    Button button1 = (Button) findViewById(R.id.button1);
                    button1.setVisibility(View.VISIBLE);
                    Button button3 = (Button) findViewById(R.id.button3);
                    button3.setVisibility(View.VISIBLE);
                    Button disconnect_button = (Button) findViewById(R.id.disconnect_button);
                    disconnect_button.setVisibility(View.GONE);

                    //   ImageView logo = (ImageView)findViewById(R.id.logo);
                    //   logo.setVisibility(View.VISIBLE);

                    ScrollView frontLayout = (ScrollView) findViewById(R.id.front);
                    frontLayout.setVisibility(View.VISIBLE);

                    Button backButton = (Button) findViewById(R.id.backButton);
                    backButton.setVisibility(View.GONE);
                    arrayAdapter.clear();
                    arrayAdapter.notifyDataSetChanged();
                    TextView pathInfo = (TextView) findViewById(R.id.path);
                    pathInfo.setText("");
                    folderPath = "";
                    //new MyFetchTask("zenstudio.com.au", "zenstudi", ".-x$%Wmd5b#C","folder",folderPath).execute();
                    connectedTo = -1;/*from w  w w .  j ava2 s . c om*/
                    SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putInt("connectedTo", connectedTo);
                    editor.commit();

                    Toast.makeText(AHEActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });

    AlertDialog alert = builder.create();
    alert.show();

}