Example usage for android.app AlertDialog.Builder setIcon

List of usage examples for android.app AlertDialog.Builder setIcon

Introduction

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

Prototype

public void setIcon(Drawable icon) 

Source Link

Usage

From source file:com.ywesee.amiko.MainActivity.java

private void showDownloadAlert(int install_type) {
    // Display message box asking people whether they want to download the DB from the ywesee server.
    AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
    alert.setIcon(R.drawable.desitin_new);
    if (Constants.appLanguage().equals("de")) {
        alert.setTitle("Medikamentendatenbank");
        String message = "AmiKo wurde installiert.";
        if (install_type == 1)
            message = "Ihre Datenbank ist lter als 30 Tage.";
        alert.setMessage(//from  w w w. j ava2 s . com
                message + " Empfehlung: Laden Sie jetzt die tagesaktuelle Datenbank runter (ca. 50 MB). "
                        + "Sie knnen die Daten tglich aktualisieren, falls Sie wnschen.");
    } else if (Constants.appLanguage().equals("fr")) {
        alert.setTitle("Banque de donnes des mdicaments");
        String message = "L'installation de la nouvelle version de CoMed s'est droule.";
        if (install_type == 1)
            message = "Votre banque de donnes est age plus de 30 jours.";
        alert.setMessage(message + " Vous avez tout intrt de mettre  jour "
                + "votre banque de donnes (env. 50 MB). D'ailleurs vous pouvez utiliser le download  tout moment si vous dsirez.");
    }
    String yes = "Ja";
    String no = "Nein";
    if (Constants.appLanguage().equals("fr")) {
        yes = "Oui";
        no = "Non";
    }
    alert.setPositiveButton(yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            if (!mUpdateInProgress)
                requestPermissionAndDownloadUpdates();
        }
    });
    alert.setNegativeButton(no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Do nothing...
        }
    });
    alert.show();
}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

protected void exportContent(final String narrativeId, final boolean isTemplate) {
    if (MediaPhone.DIRECTORY_TEMP == null) {
        UIUtilities.showToast(MediaPhoneActivity.this, R.string.export_missing_directory, true);
        return;//from  ww w. java  2s .com
    }
    if (IOUtilities.isInternalPath(MediaPhone.DIRECTORY_TEMP.getAbsolutePath())) {
        UIUtilities.showToast(MediaPhoneActivity.this, R.string.export_potential_problem, true);
    }

    // important to keep awake to export because we only have one chance to display the export options
    // after creating mov or smil file (will be cancelled on screen unlock; Android is weird)
    // TODO: move to a better (e.g. notification bar) method of exporting?
    UIUtilities.acquireKeepScreenOn(getWindow());

    final CharSequence[] items = { getString(R.string.export_mov), getString(R.string.export_html),
            getString(R.string.export_smil, getString(R.string.app_name)) };

    AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this);
    builder.setTitle(R.string.export_narrative_title);
    // builder.setMessage(R.string.send_narrative_hint); //breaks dialog
    builder.setIcon(android.R.drawable.ic_dialog_info);
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            ContentResolver contentResolver = getContentResolver();

            NarrativeItem thisNarrative;
            if (isTemplate) {
                thisNarrative = NarrativesManager.findTemplateByInternalId(contentResolver, narrativeId);
            } else {
                thisNarrative = NarrativesManager.findNarrativeByInternalId(contentResolver, narrativeId);
            }
            final ArrayList<FrameMediaContainer> contentList = thisNarrative.getContentList(contentResolver);

            // random name to counter repeat sending name issues
            String exportId = MediaPhoneProvider.getNewInternalId().substring(0, 8);
            final String exportName = String.format(Locale.ENGLISH, "%s-%s",
                    getString(R.string.app_name).replaceAll("[^a-zA-Z0-9]+", "-").toLowerCase(Locale.ENGLISH),
                    exportId);

            Resources res = getResources();
            final Map<Integer, Object> settings = new Hashtable<Integer, Object>();
            settings.put(MediaUtilities.KEY_AUDIO_RESOURCE_ID, R.raw.ic_audio_playback);

            // some output settings (TODO: make sure HTML version respects these)
            settings.put(MediaUtilities.KEY_BACKGROUND_COLOUR, res.getColor(R.color.export_background));
            settings.put(MediaUtilities.KEY_TEXT_COLOUR_NO_IMAGE, res.getColor(R.color.export_text_no_image));
            settings.put(MediaUtilities.KEY_TEXT_COLOUR_WITH_IMAGE,
                    res.getColor(R.color.export_text_with_image));
            settings.put(MediaUtilities.KEY_TEXT_BACKGROUND_COLOUR,
                    res.getColor(R.color.export_text_background));
            // TODO: do we want to do getDimensionPixelSize for export?
            settings.put(MediaUtilities.KEY_TEXT_SPACING,
                    res.getDimensionPixelSize(R.dimen.export_icon_text_padding));
            settings.put(MediaUtilities.KEY_TEXT_CORNER_RADIUS,
                    res.getDimensionPixelSize(R.dimen.export_icon_text_corner_radius));
            settings.put(MediaUtilities.KEY_TEXT_BACKGROUND_SPAN_WIDTH,
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB);
            settings.put(MediaUtilities.KEY_MAX_TEXT_FONT_SIZE,
                    res.getDimensionPixelSize(R.dimen.export_maximum_text_size));
            settings.put(MediaUtilities.KEY_MAX_TEXT_CHARACTERS_PER_LINE,
                    res.getInteger(R.integer.export_maximum_text_characters_per_line));
            settings.put(MediaUtilities.KEY_MAX_TEXT_HEIGHT_WITH_IMAGE,
                    res.getDimensionPixelSize(R.dimen.export_maximum_text_height_with_image));

            if (contentList != null && contentList.size() > 0) {
                switch (item) {
                case 0:
                    settings.put(MediaUtilities.KEY_OUTPUT_WIDTH, res.getInteger(R.integer.export_mov_width));
                    settings.put(MediaUtilities.KEY_OUTPUT_HEIGHT, res.getInteger(R.integer.export_mov_height));
                    settings.put(MediaUtilities.KEY_IMAGE_QUALITY,
                            res.getInteger(R.integer.camera_jpeg_save_quality));

                    // all image files are compatible - we just convert to JPEG when writing the movie,
                    // but we need to check for incompatible audio that we can't convert to PCM
                    boolean incompatibleAudio = false;
                    for (FrameMediaContainer frame : contentList) {
                        for (String audioPath : frame.mAudioPaths) {
                            if (!AndroidUtilities.arrayContains(MediaUtilities.MOV_AUDIO_FILE_EXTENSIONS,
                                    IOUtilities.getFileExtension(audioPath))) {
                                incompatibleAudio = true;
                                break;
                            }
                        }
                        if (incompatibleAudio) {
                            break;
                        }
                    }

                    if (incompatibleAudio) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this);
                        builder.setTitle(android.R.string.dialog_alert_title);
                        builder.setMessage(R.string.mov_export_mov_incompatible);
                        builder.setIcon(android.R.drawable.ic_dialog_alert);
                        builder.setNegativeButton(android.R.string.cancel, null);
                        builder.setPositiveButton(R.string.button_continue,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        exportMovie(settings, exportName, contentList);
                                    }
                                });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        exportMovie(settings, exportName, contentList);
                    }
                    break;

                case 1:
                    settings.put(MediaUtilities.KEY_OUTPUT_WIDTH, res.getInteger(R.integer.export_html_width));
                    settings.put(MediaUtilities.KEY_OUTPUT_HEIGHT,
                            res.getInteger(R.integer.export_html_height));
                    runExportNarrativesTask(new BackgroundRunnable() {
                        private int mTaskResult = 0;

                        @Override
                        public int getTaskId() {
                            return mTaskResult;
                        }

                        @Override
                        public boolean getShowDialog() {
                            return true;
                        }

                        @Override
                        public void run() {
                            ArrayList<Uri> filesToSend = HTMLUtilities.generateNarrativeHTML(getResources(),
                                    new File(MediaPhone.DIRECTORY_TEMP,
                                            exportName + MediaUtilities.HTML_FILE_EXTENSION),
                                    contentList, settings);

                            if (filesToSend == null || filesToSend.size() <= 0) {
                                mTaskResult = R.id.export_creation_failed;
                            } else {
                                sendFiles(filesToSend);
                            }
                        }
                    });
                    break;

                case 2:
                    settings.put(MediaUtilities.KEY_OUTPUT_WIDTH, res.getInteger(R.integer.export_smil_width));
                    settings.put(MediaUtilities.KEY_OUTPUT_HEIGHT,
                            res.getInteger(R.integer.export_smil_height));
                    settings.put(MediaUtilities.KEY_PLAYER_BAR_ADJUSTMENT,
                            res.getInteger(R.integer.export_smil_player_bar_adjustment));
                    runExportNarrativesTask(new BackgroundRunnable() {
                        private int mTaskResult = 0;

                        @Override
                        public int getTaskId() {
                            return mTaskResult;
                        }

                        @Override
                        public boolean getShowDialog() {
                            return true;
                        }

                        @Override
                        public void run() {
                            ArrayList<Uri> filesToSend = SMILUtilities.generateNarrativeSMIL(getResources(),
                                    new File(MediaPhone.DIRECTORY_TEMP,
                                            exportName + MediaUtilities.SMIL_FILE_EXTENSION),
                                    contentList, settings);

                            if (filesToSend == null || filesToSend.size() <= 0) {
                                mTaskResult = R.id.export_creation_failed;
                            } else {
                                sendFiles(filesToSend);
                            }
                        }
                    });
                    break;
                }
            } else {
                UIUtilities.showToast(MediaPhoneActivity.this,
                        (isTemplate ? R.string.export_template_failed : R.string.export_narrative_failed));
            }
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Display "change connector" menu.//from   w  w  w .  j a  va 2s .com
 */
private void changeConnectorMenu() {
    Log.d(TAG, "changeConnectorMenu()");
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(android.R.drawable.ic_menu_share);
    builder.setTitle(R.string.change_connector_);
    final ConnectorLabel[] items = this.getConnectorMenuItems(true /*isIncludePseudoConnectors*/);
    final int l = items.length;

    if (l == 0) {
        Toast.makeText(this, R.string.log_noreadyconnector, Toast.LENGTH_LONG).show();

    } else if (l == 1) {
        this.saveSelectedConnector(items[0].getConnector(), items[0].getSubConnector());

    } else if (l == 2) {
        // Find actual connector, pick the other one from css
        ConnectorLabel newSelected;
        if (prefsConnectorSpec == null || prefsSubConnectorSpec == null) {
            newSelected = items[0];

        } else if (prefsConnectorSpec.getPackage().equals(items[0].getConnector().getPackage())
                && prefsSubConnectorSpec.getID().equals(items[0].getSubConnector().getID())) {
            newSelected = items[1];

        } else {
            newSelected = items[0];
        }
        this.saveSelectedConnector(newSelected.getConnector(), newSelected.getSubConnector());
        Toast.makeText(this, this.getString(R.string.connectors_switch) + " " + newSelected.getName(),
                Toast.LENGTH_SHORT).show();
    } else {
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(final DialogInterface d, final int idx) {
                WebSMS.this.saveSelectedConnector(items[idx].getConnector(), items[idx].getSubConnector());
            }
        });
        builder.create().show();
    }
}

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

private void optionChangelog() {
    WebView webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            int userId = Util.getUserId(Process.myUid());
            Version currentVersion = new Version(Util.getSelfVersionName(ActivityMain.this));
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingChangelog, currentVersion.toString());
        }/* w w  w .j a  v  a  2 s .c  om*/
    });
    webview.loadUrl("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md");

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(R.string.menu_changelog);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(webview);
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final FragmentActivity activity = getActivity();
    mMessenger = getArguments().getParcelable(ARG_MESSENGER);

    final long[] keyRingRowIds = getArguments().getLongArray(ARG_DELETE_KEY_RING_ROW_IDS);

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    //Setup custom View to display in AlertDialog
    LayoutInflater inflater = activity.getLayoutInflater();
    mInflateView = inflater.inflate(R.layout.view_key_delete_fragment, null);
    builder.setView(mInflateView);/*  w ww  .  ja va2s.  c o m*/

    mDeleteSecretKeyView = (LinearLayout) mInflateView.findViewById(R.id.deleteSecretKeyView);
    mMainMessage = (TextView) mInflateView.findViewById(R.id.mainMessage);
    mCheckDeleteSecret = (CheckBox) mInflateView.findViewById(R.id.checkDeleteSecret);

    builder.setTitle(R.string.warning);

    //If only a single key has been selected
    if (keyRingRowIds.length == 1) {
        Uri dataUri;
        ArrayList<Long> publicKeyRings; //Any one will do
        mIsSingleSelection = true;

        long selectedRow = keyRingRowIds[0];
        long keyType;
        publicKeyRings = ProviderHelper.getPublicKeyRingsRowIds(activity);

        if (publicKeyRings.contains(selectedRow)) {
            //TODO Should be a better method to do this other than getting all the KeyRings
            dataUri = KeychainContract.KeyRings.buildPublicKeyRingsUri(String.valueOf(selectedRow));
            keyType = Id.type.public_key;
        } else {
            dataUri = KeychainContract.KeyRings.buildSecretKeyRingsUri(String.valueOf(selectedRow));
            keyType = Id.type.secret_key;
        }

        String userId = ProviderHelper.getUserId(activity, dataUri);
        // Hide the Checkbox and TextView since this is a single selection, user will be
        // notified through message
        mDeleteSecretKeyView.setVisibility(View.GONE);
        // Set message depending on which key it is.
        mMainMessage.setText(getString(keyType == Id.type.secret_key ? R.string.secret_key_deletion_confirmation
                : R.string.public_key_deletetion_confirmation, userId));

    } else {
        mDeleteSecretKeyView.setVisibility(View.VISIBLE);
        mMainMessage.setText(R.string.key_deletion_confirmation_multi);
    }

    builder.setIcon(R.drawable.ic_dialog_alert_holo_light);
    builder.setPositiveButton(R.string.btn_delete, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Uri queryUri = KeychainContract.KeyRings.buildUnifiedKeyRingsUri();
            String[] projection = new String[] { KeychainContract.KeyRings.MASTER_KEY_ID, // 0
                    KeychainContract.KeyRings.TYPE // 1
            };

            // make selection with all entries where _ID is one of the given row ids
            String selection = KeychainDatabase.Tables.KEY_RINGS + "." + KeychainContract.KeyRings._ID + " IN(";
            String selectionIDs = "";
            for (int i = 0; i < keyRingRowIds.length; i++) {
                selectionIDs += "'" + String.valueOf(keyRingRowIds[i]) + "'";
                if (i + 1 < keyRingRowIds.length) {
                    selectionIDs += ",";
                }
            }
            selection += selectionIDs + ")";

            Cursor cursor = activity.getContentResolver().query(queryUri, projection, selection, null, null);

            long masterKeyId;
            long keyType;
            boolean isSuccessfullyDeleted;
            try {
                isSuccessfullyDeleted = false;
                while (cursor != null && cursor.moveToNext()) {
                    masterKeyId = cursor.getLong(0);
                    keyType = cursor.getLong(1);

                    Log.d(Constants.TAG, "masterKeyId: " + masterKeyId + ", keyType:"
                            + (keyType == KeychainContract.KeyTypes.PUBLIC ? "Public" : "Private"));

                    if (keyType == KeychainContract.KeyTypes.SECRET) {
                        if (mCheckDeleteSecret.isChecked() || mIsSingleSelection) {
                            ProviderHelper.deleteUnifiedKeyRing(activity, String.valueOf(masterKeyId), true);
                        }
                    } else {
                        ProviderHelper.deleteUnifiedKeyRing(activity, String.valueOf(masterKeyId), false);
                    }
                }

                //Check if the selected rows have actually been deleted
                cursor = activity.getContentResolver().query(queryUri, projection, selection, null, null);
                if (cursor == null || cursor.getCount() == 0 || !mCheckDeleteSecret.isChecked()) {
                    isSuccessfullyDeleted = true;
                }

            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }

            dismiss();

            if (isSuccessfullyDeleted) {
                sendMessageToHandler(MESSAGE_OKAY, null);
            } else {
                sendMessageToHandler(MESSAGE_ERROR, null);
            }
        }

    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dismiss();
        }
    });
    return builder.create();
}

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);/*  w  ww .j a  v  a2s. c om*/
        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: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   ww w .  j  a  v a2  s.c  o  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:ac.robinson.mediaphone.MediaPhoneActivity.java

public void processIncomingFiles(Message msg) {

    // deal with messages from the BluetoothObserver
    Bundle fileData = msg.peekData();//from  w  w  w.  j  av  a 2  s  . co  m
    if (fileData == null) {
        return; // error - no parameters passed
    }

    String importedFileName = fileData.getString(MediaUtilities.KEY_FILE_NAME);
    if (importedFileName == null) {
        if (msg.what == MediaUtilities.MSG_IMPORT_SERVICE_REGISTERED) {
            onBluetoothServiceRegistered();
        }
        return; // error - no filename
    }

    // get the imported file object
    final File importedFile = new File(importedFileName);
    if (!importedFile.canRead() || !importedFile.canWrite()) {
        if (MediaPhone.IMPORT_DELETE_AFTER_IMPORTING) {
            importedFile.delete(); // error - probably won't work, but might
            // as well try; doesn't throw, so is okay
        }
        return;
    }

    final int messageType = msg.what;
    switch (messageType) {
    case MediaUtilities.MSG_RECEIVED_IMPORT_FILE:
        UIUtilities.showToast(MediaPhoneActivity.this, R.string.import_starting);
        break;

    case MediaUtilities.MSG_RECEIVED_SMIL_FILE:
    case MediaUtilities.MSG_RECEIVED_HTML_FILE:
    case MediaUtilities.MSG_RECEIVED_MOV_FILE:
        if (MediaPhone.IMPORT_CONFIRM_IMPORTING) {
            if (MediaPhoneActivity.this.isFinishing()) {
                if (!(MediaPhoneActivity.this instanceof NarrativeBrowserActivity)) {
                    // TODO: send a delayed message to the next task? (can't from NarrativeBrowser - app exit)
                }
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(MediaPhoneActivity.this);
                builder.setTitle(R.string.import_file_confirmation);
                // fake that we're using the SMIL file if we're actually using .sync.jpg
                builder.setMessage(getString(R.string.import_file_hint,
                        importedFile.getName().replace(MediaUtilities.SYNC_FILE_EXTENSION, "")
                                .replace(MediaUtilities.SMIL_FILE_EXTENSION, "")));
                builder.setIcon(android.R.drawable.ic_dialog_info);
                builder.setNegativeButton(R.string.import_not_now, null);
                builder.setPositiveButton(R.string.import_file, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        importFiles(messageType, importedFile);
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            }
        } else {
            importFiles(messageType, importedFile);
        }
        break;
    }
}

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

private void optionSubmit() {
    if (ActivityShare.registerDevice(this)) {
        int[] uid = (mAppAdapter == null ? new int[0]
                : mAppAdapter.getSelectedOrVisibleUid(AppListAdapter.cSelectAppNone));
        if (uid.length == 0) {
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setMessage(R.string.msg_select);
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setPositiveButton(getString(android.R.string.ok),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }/* w  ww  . j  a  v  a 2 s.co  m*/
                    });
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        } else if (uid.length <= ActivityShare.cSubmitLimit) {
            if (mAppAdapter != null) {
                Intent intent = new Intent(ActivityShare.ACTION_SUBMIT);
                intent.putExtra(ActivityShare.cInteractive, true);
                intent.putExtra(ActivityShare.cUidList, uid);
                startActivity(intent);
            }
        } else {
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setMessage(getString(R.string.msg_limit, ActivityShare.cSubmitLimit + 1));
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setPositiveButton(getString(android.R.string.ok),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.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);/*  w  ww .  j a va 2  s.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();
}