Example usage for android.app AlertDialog setIcon

List of usage examples for android.app AlertDialog setIcon

Introduction

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

Prototype

public void setIcon(Drawable icon) 

Source Link

Usage

From source file:com.tweetlanes.android.view.BaseLaneActivity.java

public void shareSelected(TwitterStatus status) {

    if (status != null) {

        final String statusUrl = status.getTwitterComStatusUrl();
        final String statusText = status.mStatus;
        final ArrayList<String> urls = Util.getUrlsInString(status.mStatus);

        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(getString(R.string.alert_share_title));
        alertDialog.setMessage(getString(R.string.alert_share_message));
        alertDialog.setIcon(AppSettings.get().getCurrentTheme() == AppSettings.Theme.Holo_Dark
                ? R.drawable.ic_action_share_dark
                : R.drawable.ic_action_share_light);
        // TODO: The order these buttons are set looks wrong, but appears correctly. Have to ensure this is consistent on other devices.
        alertDialog.setButton2(getString(R.string.share_tweet_link), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                shareText(statusUrl);//  w ww .  ja va 2  s  .com
            }
        });

        if (urls != null && urls.size() > 0) {
            alertDialog.setButton3(getString(R.string.share_tweet), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    shareText(statusText);
                }
            });

            alertDialog.setButton(getString(urls.size() == 1 ? R.string.share_link : R.string.share_first_link),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            shareText(urls.get(0));
                        }
                    });
        } else {
            alertDialog.setButton(getString(R.string.share_tweet), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    shareText(statusText);
                }
            });
        }

        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 w  w  w  . j  ava  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:com.tweetlanes.android.core.view.BaseLaneActivity.java

public void shareSelected(TwitterStatus status) {

    if (status != null) {

        App application = (App) getApplication();
        AccountDescriptor currentAccount = application.getCurrentAccount();

        String url;/*from   w  w  w .ja v a  2  s  .  c  o  m*/
        String shareText;
        if (currentAccount.getSocialNetType() == SocialNetConstant.Type.Twitter) {
            url = status.getTwitterComStatusUrl();
            shareText = getString(R.string.share_tweet_link);
        } else {
            url = status.getAdnStatusUrl();
            shareText = getString(R.string.share_tweet_post);
        }
        final String statusUrl = url;
        final String statusText = status.mStatus;
        final ArrayList<String> urls = Util.getUrlsInString(status.mStatus);

        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(getString(R.string.alert_share_title));
        alertDialog.setMessage(getString(R.string.alert_share_message));
        alertDialog.setIcon(AppSettings.get().getCurrentTheme() == AppSettings.Theme.Holo_Dark
                || AppSettings.get().getCurrentTheme() == AppSettings.Theme.Holo_Light_DarkAction
                        ? R.drawable.ic_action_share_dark
                        : R.drawable.ic_action_share_light);
        // TODO: The order these buttons are set looks wrong, but appears
        // correctly. Have to ensure this is consistent on other devices.
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.share_tweet),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        shareText(statusText);
                    }
                });

        alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, shareText,
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        shareText(statusUrl);
                    }
                });

        if (urls != null && urls.size() > 0) {
            alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
                    getString(urls.size() == 1 ? R.string.share_link : R.string.share_first_link),
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            shareText(urls.get(0));
                        }
                    });
        }

        alertDialog.show();
    }
}

From source file:com.shafiq.mytwittle.view.BaseLaneActivity.java

public void shareSelected(TwitterStatus status) {

    if (status != null) {

        final String statusUrl = status.getTwitterComStatusUrl();
        final String statusText = status.mStatus;
        final ArrayList<String> urls = Util.getUrlsInString(status.mStatus);

        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(getString(R.string.alert_share_title));
        alertDialog.setMessage(getString(R.string.alert_share_message));
        alertDialog.setIcon(AppSettings.get().getCurrentTheme() == AppSettings.Theme.Holo_Dark
                ? R.drawable.ic_action_share_dark
                : R.drawable.ic_action_share_light);
        // TODO: The order these buttons are set looks wrong, but appears
        // correctly. Have to ensure this is consistent on other devices.
        alertDialog.setButton2(getString(R.string.share_tweet_link), new DialogInterface.OnClickListener() {

            @Override/*from  www.ja  va  2s  .  c o  m*/
            public void onClick(DialogInterface dialog, int which) {
                shareText(statusUrl);
            }
        });

        if (urls != null && urls.size() > 0) {
            alertDialog.setButton3(getString(R.string.share_tweet), new DialogInterface.OnClickListener() {

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

            alertDialog.setButton(getString(urls.size() == 1 ? R.string.share_link : R.string.share_first_link),
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            shareText(urls.get(0));
                        }
                    });
        } else {
            alertDialog.setButton(getString(R.string.share_tweet), new DialogInterface.OnClickListener() {

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

        alertDialog.show();
    }
}

From source file:org.odk.collect.android.activities.GoogleDriveActivity.java

private void createAlertDialog(String message) {
    Collect.getInstance().getActivityLogger().logAction(this, "createAlertDialog", "show");

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.download_forms_result));
    alertDialog.setMessage(message);//from w w w. j a va2  s  .  co  m
    DialogInterface.OnClickListener quitListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {
            switch (i) {
            case DialogInterface.BUTTON1: // ok
                Collect.getInstance().getActivityLogger().logAction(this, "createAlertDialog", "OK");
                alertShowing = false;
                finish();
                break;
            }
        }
    };
    alertDialog.setCancelable(false);
    alertDialog.setButton(getString(R.string.ok), quitListener);
    alertDialog.setIcon(android.R.drawable.ic_dialog_info);
    alertShowing = true;
    alertMsg = message;
    alertDialog.show();
}

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

public void loadMalware(final MalwareStatus malwareStatus) {
    runOnUiThread(new Runnable() {

        @Override// w  w  w .j a  va  2 s .c  om
        public void run() {
            try {
                EnumApkMalware apkStatus = EnumApkMalware
                        .valueOf(malwareStatus.getStatus().toUpperCase(Locale.ENGLISH));
                Log.d("ApkInfoMalware-malwareStatus", malwareStatus.getStatus());
                Log.d("ApkInfoMalware-malwareReason", malwareStatus.getReason());

                switch (apkStatus) {
                case SCANNED:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.trusted));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_scanned);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View trustedView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(trustedView);
                            final AlertDialog trustedDialog = dialogBuilder.create();
                            trustedDialog.setIcon(R.drawable.badge_scanned);
                            trustedDialog.setTitle(getString(R.string.app_trusted, viewApk.getName()));
                            trustedDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) trustedView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_verified));
                            ImageView check_signature = (ImageView) trustedView
                                    .findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_yes);

                            trustedDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    trustedDialog.dismiss();
                                }
                            });
                            trustedDialog.show();
                        }
                    });
                    break;
                //             case UNKNOWN:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.unknown));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_unknown);
                //                break;
                case WARN:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.warning));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_warn);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View warnView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(warnView);
                            final AlertDialog warnDialog = dialogBuilder.create();
                            warnDialog.setIcon(R.drawable.badge_warn);
                            warnDialog.setTitle(getString(R.string.app_warning, viewApk.getName()));
                            warnDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) warnView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_not_verified));
                            ImageView check_signature = (ImageView) warnView.findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_failed);

                            warnDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    warnDialog.dismiss();
                                }
                            });
                            warnDialog.show();
                        }
                    });
                    break;
                //             case CRITICAL:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.critical));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_critical);
                //                break;
                default:
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });

}

From source file:pt.aptoide.backupapps.Aptoide.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    EnumOptionsMenu menuEntry = EnumOptionsMenu.reverseOrdinal(item.getItemId());
    Log.d("Aptoide-OptionsMenu", "menuOption: " + menuEntry + " itemid: " + item.getItemId());
    switch (menuEntry) {
    //         case MANAGE_REPO:
    //            availableAdapter.sleep();
    //            Intent manageRepo = new Intent(this, ManageRepos.class);
    //            startActivity(manageRepo);
    //            return true;

    case UNINSTALL:
        try {//from  w w  w  . j a  va  2 s.  c o  m
            serviceDataCaller.callUninstallApps(installedAdapter.getSelectedIds());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;

    case DELETE:
        //TODO improve listIds as an extended parcelable array ;) then use it as a carrier for checked hashids list
        return true;

    case DISPLAY_OPTIONS:
        if (!loadingRepos.get()) {
            //TODO refactor extract dialog management class
            LayoutInflater displayOptionsInflater = LayoutInflater.from(this);
            View displayOptions = displayOptionsInflater.inflate(R.layout.dialog_display_options, null);
            Builder dialogBuilder = new AlertDialog.Builder(theme).setView(displayOptions);
            final AlertDialog sortDialog = dialogBuilder.create();
            sortDialog.setIcon(android.R.drawable.ic_menu_sort_by_size);
            sortDialog.setTitle(getString(R.string.display_options));

            // ***********************************************************
            // Categories
            //               final RadioButton byCategory = (RadioButton) displayOptions.findViewById(R.id.by_category);
            //               final RadioButton byAll = (RadioButton) displayOptions.findViewById(R.id.by_all);
            //               if(availableByCategory){
            //                  byCategory.setChecked(true);
            //               }else{
            //                  byAll.setChecked(true);
            //               }
            //   
            //               final View spacer = displayOptions.findViewById(R.id.spacer);
            //               
            //               if(currentAppsList != EnumAppsLists.Available){
            //                  spacer.setVisibility(View.GONE);
            //                  ((RadioGroup) displayOptions.findViewById(R.id.group_show)).setVisibility(View.GONE);
            //               }

            // ***********************************************************
            // Sorting            
            final View group_sort = displayOptions.findViewById(R.id.group_sort);
            final RadioButton byAlphabetic = (RadioButton) displayOptions.findViewById(R.id.by_alphabetic);
            final RadioButton byFreshness = (RadioButton) displayOptions.findViewById(R.id.by_freshness);
            final RadioButton bySize = (RadioButton) displayOptions.findViewById(R.id.by_size);

            //               spacer.setVisibility(View.VISIBLE);
            group_sort.setVisibility(View.VISIBLE);
            switch (appsSortingPolicy) {
            case ALPHABETIC:
                byAlphabetic.setChecked(true);
                break;

            case FRESHNESS:
                byFreshness.setChecked(true);
                break;

            case SIZE:
                bySize.setChecked(true);
                break;

            default:
                break;
            }

            // ***********************************************************

            final CheckBox showSystemApps = (CheckBox) displayOptions.findViewById(R.id.show_system_apps);
            boolean showSystemAppsState = false;
            try {
                showSystemAppsState = serviceDataCaller.callGetShowSystemApps();
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            showSystemApps.setChecked(showSystemAppsState);
            final boolean storedShowSystemAppsState = showSystemAppsState;

            sortDialog.setButton(getString(R.string.done), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    //                     boolean byCategoryChanged = false;
                    EnumAppsSorting newSortingPolicy = null;

                    //                     if(byCategory.isChecked() != availableByCategory){
                    //                        byCategoryChanged = true;
                    //                        availableByCategory = byCategory.isChecked();
                    //                        setAvailableListBy(availableByCategory);
                    //                     }

                    if (showSystemApps.isChecked() != storedShowSystemAppsState) {
                        setShowSystemApps(showSystemApps.isChecked());
                    }

                    if (byAlphabetic.isChecked()) {
                        newSortingPolicy = EnumAppsSorting.ALPHABETIC;
                    } else if (byFreshness.isChecked()) {
                        newSortingPolicy = EnumAppsSorting.FRESHNESS;
                    } else if (bySize.isChecked()) {
                        newSortingPolicy = EnumAppsSorting.SIZE;
                    }
                    if (newSortingPolicy != null && newSortingPolicy != appsSortingPolicy) {
                        //                        availableAdapter.sleep();
                        appsSortingPolicy = newSortingPolicy;
                        setAppsSortingPolicy(appsSortingPolicy);
                    }

                    //                     if(byCategoryChanged){
                    //                        if(availableByCategory){
                    //                           availableAdapter.sleep();
                    //                           categoriesAdapter.resetDisplayCategories();
                    //                        }else{
                    //                           availableAdapter.resetDisplay(null);                        
                    //                        }
                    //                     }
                    sortDialog.dismiss();
                }
            });

            sortDialog.show();
        } else {
            Toast.makeText(Aptoide.this, getString(R.string.option_not_available_while_updating_repos),
                    Toast.LENGTH_SHORT).show();
        }
        return true;

    //         case SEARCH_MENU:
    //            onSearchRequested();
    //            return true;

    case UN_SELECT_ALL:
        switch (currentAppsList) {
        case RESTORE:
            if (availableAdapter.isDynamic()) {
                Toast.makeText(Aptoide.this, getString(R.string.too_many_apps_to_select_at_once),
                        Toast.LENGTH_SHORT).show();
                return true;
            }
            availableAdapter.toggleSelectAll();
            break;

        case BACKUP:
            installedAdapter.toggleSelectAll();
            break;

        default:
            break;
        }
        return true;

    case ABOUT:
        LayoutInflater aboutInflater = LayoutInflater.from(this);
        View about = aboutInflater.inflate(R.layout.about, null);
        TextView info = (TextView) about.findViewById(R.id.credits);
        info.setText(getString(R.string.credits, versionName));
        Builder aboutCreator = new AlertDialog.Builder(theme).setView(about);
        final AlertDialog aboutDialog = aboutCreator.create();
        aboutDialog.setIcon(R.drawable.icon);
        aboutDialog.setTitle(R.string.self_name);
        //            aboutDialog.setButton(getText(R.string.changelog), new DialogInterface.OnClickListener() {
        //               public void onClick(DialogInterface dialog, int   whichButton) {
        //                  Uri uri = Uri.parse(getString(R.string.changelog_url));
        //                  startActivity(new Intent( Intent.ACTION_VIEW, uri));
        //               }
        //            });
        aboutDialog.show();
        return true;

    case SETTINGS:
        //            availableAdapter.sleep();
        Intent settings = new Intent(this, Settings.class);
        startActivity(settings);
        return true;

    case LOGIN:
        //            boolean insertingRepo = false;
        //            try {
        //               insertingRepo = serviceDataCaller.callIsInsertingRepo();
        //            } catch (RemoteException e1) {
        //               // TODO Auto-generated catch block
        //               e1.printStackTrace();
        //            }
        //            if(insertingRepo){
        //               AptoideLog.d(Aptoide.this, getString(R.string.updating_repo_please_wait));
        //               Toast.makeText(getApplicationContext(), getResources().getString(R.string.updating_repo_please_wait), Toast.LENGTH_SHORT).show();
        //            }
        //            else{
        Log.d("Aptoide-Settings", "clicked set server login");
        String token = null;
        try {
            token = serviceDataCaller.callGetServerToken();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (token == null) {
            Log.d("Aptoide-Settings", "No login set");
            Intent login = new Intent(Aptoide.this, BazaarLogin.class);
            login.putExtra("InvoqueType", BazaarLogin.InvoqueType.NO_CREDENTIALS_SET.ordinal());
            startActivity(login);
            //               DialogLogin dialogLogin = new DialogLogin(Settings.this, serviceDataCaller, DialogLogin.InvoqueType.NO_CREDENTIALS_SET);
            //               loginComments.setOnDismissListener(new OnDismissListener() {
            //                  @Override
            //                  public void onDismiss(DialogInterface dialog) {
            //                     addAppVersionComment();
            //                  }
            //               });
            //               dialogLogin.show();
        } else {
            Log.d("Aptoide-Settings", "Login edit");
            Intent login = new Intent(Aptoide.this, BazaarLogin.class);
            login.putExtra("InvoqueType", BazaarLogin.InvoqueType.OVERRIDE_CREDENTIALS.ordinal());
            startActivity(login);
            //               DialogLogin dialogLogin = new DialogLogin(Settings.this, serviceDataCaller, DialogLogin.InvoqueType.OVERRIDE_CREDENTIALS);
            //               Toast.makeText(Settings.this, "Login already set", Toast.LENGTH_SHORT).show();
            //               dialogLogin.show();
        }
        //            }
        return true;

    case FOLLOW:
        new DialogFollowOnSocialNets(this, serviceDataCaller).show();
        return true;

    //         case SCHEDULED_DOWNLOADS:
    //            availableAdapter.sleep();
    //            Intent manageScheduled = new Intent(this, ManageScheduled.class);
    //            startActivity(manageScheduled);
    //            return true;

    //         case UPDATE_ALL:
    //            if(!loadingRepos.get()){
    //               AptoideLog.d(this, "Update all");
    //               try {
    //                  serviceDataCaller.callUpdateAll();
    //               } catch (RemoteException e) {
    //                  // TODO Auto-generated catch block
    //                  e.printStackTrace();
    //               }
    //            }else{
    //               Toast.makeText(Aptoide.this, "Option not available while updating stores!", Toast.LENGTH_SHORT).show();
    //            }
    //            return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Confirms user to create new directory.
 *///from w w  w.j  a  va  2 s .c  o  m
private void showNewDirectoryCreationDialog() {
    final AlertDialog dialog = Dlg.newAlertDlg(getActivity());

    View view = getLayoutInflater(null).inflate(R.layout.afc_simple_text_input_view, null);
    final EditText textFile = (EditText) view.findViewById(R.id.afc_text1);
    textFile.setHint(R.string.afc_hint_folder_name);
    textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Ui.showSoftKeyboard(v, false);
                dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });

    dialog.setView(view);
    dialog.setTitle(R.string.afc_cmd_new_folder);
    dialog.setIcon(android.R.drawable.ic_menu_add);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String name = textFile.getText().toString().trim();
                    if (!FileUtils.isFilenameValid(name)) {
                        Dlg.toast(getActivity(), getString(R.string.afc_pmsg_filename_is_invalid, name),
                                Dlg.LENGTH_SHORT);
                        return;
                    }

                    new LoadingDialog<Void, Void, Uri>(getActivity(), false) {

                        @Override
                        protected Uri doInBackground(Void... params) {
                            return getActivity().getContentResolver().insert(
                                    BaseFile.genContentUriBase(getCurrentLocation().getAuthority()).buildUpon()
                                            .appendPath(getCurrentLocation().getLastPathSegment())
                                            .appendQueryParameter(BaseFile.PARAM_NAME, name)
                                            .appendQueryParameter(BaseFile.PARAM_FILE_TYPE,
                                                    Integer.toString(BaseFile.FILE_TYPE_DIRECTORY))
                                            .build(),
                                    null);
                        }// doInBackground()

                        @Override
                        protected void onPostExecute(Uri result) {
                            super.onPostExecute(result);

                            if (result != null) {
                                Dlg.toast(getActivity(), getString(R.string.afc_msg_done), Dlg.LENGTH_SHORT);
                            } else
                                Dlg.toast(getActivity(),
                                        getString(R.string.afc_pmsg_cannot_create_folder, name),
                                        Dlg.LENGTH_SHORT);
                        }// onPostExecute()

                    }.execute();
                }// onClick()
            });
    dialog.show();
    Ui.showSoftKeyboard(textFile, true);

    final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    buttonOk.setEnabled(false);

    textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            /*
             * Do nothing.
             */
        }// onTextChanged()

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            /*
             * Do nothing.
             */
        }// beforeTextChanged()

        @Override
        public void afterTextChanged(Editable s) {
            buttonOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }// afterTextChanged()
    });
}

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

public void showAbout() {
    View aboutView = LayoutInflater.from(this).inflate(R.layout.dialog_about, null);
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this).setView(aboutView);
    final AlertDialog aboutDialog = dialogBuilder.create();
    aboutDialog.setIcon(android.R.drawable.ic_menu_help);
    aboutDialog.setTitle(getString(R.string.about));
    aboutDialog.setCancelable(true);/*from   ww  w.  j ava 2 s . c  o m*/

    WindowManager.LayoutParams params = aboutDialog.getWindow().getAttributes();
    params.width = WindowManager.LayoutParams.MATCH_PARENT;
    aboutDialog.getWindow().setAttributes(params);

    aboutDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_chlog),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Uri uri = Uri.parse(getString(R.string.change_log_url));
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                }
            });

    aboutDialog.show();
}