Example usage for android.app AlertDialog.Builder setCustomTitle

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

Introduction

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

Prototype

public void setCustomTitle(View customTitleView) 

Source Link

Usage

From source file:Main.java

public static void showOkDialog(String title, String msg, Activity act) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(act);
    if (title != null) {

        TextView dialogTitle = new TextView(act);
        dialogTitle.setText(title);//from   www .j  ava 2 s .c  o  m
        dialogTitle.setPadding(10, 10, 10, 10);
        dialogTitle.setGravity(Gravity.CENTER);
        dialogTitle.setTextColor(Color.WHITE);
        dialogTitle.setTextSize(20);
        dialog.setCustomTitle(dialogTitle);

    }
    if (msg != null) {
        dialog.setMessage(msg);
    }
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });
    AlertDialog dlg = dialog.show();
    TextView messageText = (TextView) dlg.findViewById(android.R.id.message);
    messageText.setGravity(Gravity.CENTER);

}

From source file:ua.naiksoftware.chars.Sender.java

@Override
protected void onPreExecute() {
    Log.d(tag, "onPreExecute begin");

    ProgressBar progressBar = new ProgressBar(EngineActivity.CONTEXT);
    progressBar.setIndeterminate(true);/*from  w w w  . ja va 2  s.co  m*/

    AlertDialog.Builder builder = new AlertDialog.Builder(EngineActivity.CONTEXT);
    builder.setCustomTitle(progressBar);
    builder.setIcon(android.R.drawable.ic_menu_upload);
    builder.setMessage(R.string.send_record);
    builder.setCancelable(false);
    dialog = builder.create();
    dialog.show();
    Log.d(tag, "onPreExecute end");
}

From source file:com.javielinux.dialogs.CreateDefaultColumnsUserDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    userId = getArguments().getLong("user_id");

    userEntity = new Entity("users", userId);

    CharSequence[] choices = new CharSequence[3];
    choices[0] = getString(R.string.timeline);
    choices[1] = getString(R.string.mentions);
    choices[2] = getString(R.string.direct_messages);

    final boolean[] isChoices = new boolean[] { true, true, true };

    LinearLayout llTitle = new LinearLayout(getActivity());
    llTitle.setOrientation(LinearLayout.VERTICAL);
    final CheckBox boxInvite = new CheckBox(getActivity());
    boxInvite.setText(R.string.follow_tweettopics);
    boxInvite.setChecked(true);//  w ww.  j a  va  2  s  . com
    llTitle.addView(boxInvite);
    TextView txtTitle = new TextView(getActivity());
    txtTitle.setText(R.string.create_columns);
    txtTitle.setTextSize(25);
    llTitle.addView(txtTitle);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setCustomTitle(llTitle);
    builder.setMultiChoiceItems(choices, isChoices, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            isChoices[whichButton] = isChecked;
        }
    });
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // choices
            int count = DataFramework.getInstance().getEntityListCount("columns", "") + 1;
            if (isChoices[0]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_TIMELINE);
                Entity timeline = new Entity("columns");
                timeline.setValue("description", type.getString("description"));
                timeline.setValue("type_id", type);
                timeline.setValue("position", count);
                timeline.setValue("user_id", userEntity.getId());
                timeline.save();
                count++;
            }
            if (isChoices[1]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_MENTIONS);
                Entity mentions = new Entity("columns");
                mentions.setValue("description", type.getString("description"));
                mentions.setValue("type_id", type);
                mentions.setValue("position", count);
                mentions.setValue("user_id", userEntity.getId());
                mentions.save();
                count++;
            }
            if (isChoices[2]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_DIRECT_MESSAGES);
                Entity dms = new Entity("columns");
                dms.setValue("description", type.getString("description"));
                dms.setValue("type_id", type);
                dms.setValue("position", count);
                dms.setValue("user_id", userEntity.getId());
                dms.save();
            }

            ((TweetTopicsActivity) getActivity()).refreshColumns();

            // create friend
            if (boxInvite.isChecked()) {
                Utils.showMessage(getActivity(), getActivity().getString(R.string.thanks));
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            ConnectionManager.getInstance().getTwitter(userEntity.getId())
                                    .createFriendship("tweettopics_app");
                        } catch (TwitterException e1) {
                            e1.printStackTrace();
                        } catch (IllegalArgumentException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }

    });

    return builder.create();

}

From source file:de.tobiasbielefeld.solitaire.dialogs.DialogWon.java

@Override
@NonNull//from  w  w  w. j  a v a  2  s. co m
public Dialog onCreateDialog(Bundle savedState) {
    final GameManager gameManager = (GameManager) getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialog_won, null);

    builder.setCustomTitle(view).setItems(R.array.won_menu, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // "which" argument contains index of selected item
            switch (which) {
            case 0:
                gameLogic.newGame();
                break;
            case 1:
                gameLogic.redeal();
                break;
            case 2:
                if (gameManager.hasLoaded) {
                    timer.save();
                    gameLogic.setWonAndReloaded();
                    gameLogic.save();
                }

                gameManager.finish();
                break;
            }
        }
    }).setNegativeButton(R.string.game_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            //just cancel
        }
    });

    LinearLayout layoutScores = (LinearLayout) view.findViewById(R.id.dialog_won_layout_scores);

    //only show the calculation of the score if bonus is enabled
    if (currentGame.isBonusEnabled()) {
        layoutScores.setVisibility(View.VISIBLE);
        TextView text1 = (TextView) view.findViewById(R.id.dialog_won_text1);
        TextView text2 = (TextView) view.findViewById(R.id.dialog_won_text2);
        TextView text3 = (TextView) view.findViewById(R.id.dialog_won_text3);

        score = (savedState != null && savedState.containsKey(KEY_SCORE)) ? savedState.getLong(KEY_SCORE)
                : scores.getPreBonus();
        bonus = (savedState != null && savedState.containsKey(KEY_BONUS)) ? savedState.getLong(KEY_BONUS)
                : scores.getBonus();
        total = (savedState != null && savedState.containsKey(KEY_TOTAL)) ? savedState.getLong(KEY_TOTAL)
                : scores.getScore();

        text1.setText(
                String.format(Locale.getDefault(), getContext().getString(R.string.dialog_win_score), score));
        text2.setText(
                String.format(Locale.getDefault(), getContext().getString(R.string.dialog_win_bonus), bonus));
        text3.setText(
                String.format(Locale.getDefault(), getContext().getString(R.string.dialog_win_total), total));
    } else {
        layoutScores.setVisibility(View.GONE);
    }

    return applyFlags(builder.create());
}

From source file:com.sean.takeastand.ui.MainActivity.java

private void showPauseSettingsDialog() {
    LayoutInflater inflater = getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View dialogView = inflater.inflate(R.layout.dialog_pause, null);
    TextView title = new TextView(this);
    title.setPadding(50, 50, 50, 50);//  w  w  w.j  av a 2 s .  c o m
    title.setTextSize(22);
    title.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
    title.setText(getResources().getString(R.string.select_pause_type));
    builder.setCustomTitle(title);
    String[] valueSet = new String[pauseTimes.length];
    for (int i = 0; i < pauseTimes.length; i++) {
        valueSet[i] = Integer.toString(pauseTimes[i]);
    }
    builder.setView(dialogView);
    final NumberPicker npPause = (NumberPicker) dialogView.findViewById(R.id.pauseNumberPicker);
    npPause.setDisplayedValues(valueSet);
    npPause.setMinValue(0);
    npPause.setMaxValue(valueSet.length - 1);
    npPause.setWrapSelectorWheel(false);
    int initialValue = Utils.getDefaultPauseAmount(this);
    for (int i = 0; i < pauseTimes.length; i++) {
        if (initialValue == pauseTimes[i]) {
            initialValue = i;
        }
    }
    npPause.setValue(initialValue);
    builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            //getValue returns the index number, so need to do some math to correct correct
            //actual value
            setDefaultPauseAmount(pauseTimes[npPause.getValue()]);
            int currentStatus = Utils.getImageStatus(MainActivity.this);
            if (currentStatus == Constants.NON_SCHEDULE_ALARM_RUNNING
                    || currentStatus == Constants.NON_SCHEDULE_STOOD_UP
                    || currentStatus == Constants.NON_SCHEDULE_TIME_TO_STAND) {
                pauseUnscheduled();
            } else {
                pauseSchedule();
                sendAnalyticsEvent("Paused");
            }
            dialogInterface.dismiss();
        }
    });
    builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            mPausePlay.setIcon(getResources().getDrawable(R.drawable.ic_action_pause));
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java

private void clickedOnUserBrick(final UserBrick clickedBrick, View view) {
    final Context context = getActivity();

    final List<CharSequence> items = new ArrayList<CharSequence>();

    items.add(context.getText(R.string.brick_context_dialog_add_to_script));

    items.add(context.getText(R.string.brick_context_dialog_edit_brick));

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

    boolean drawingCacheEnabled = view.isDrawingCacheEnabled();
    view.setDrawingCacheEnabled(true);//w  w  w . j a  v  a2s  . com
    view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);
    view.buildDrawingCache(true);

    if (view.getDrawingCache() != null) {
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(drawingCacheEnabled);

        ImageView imageView = getGlowingBorder(bitmap);
        builder.setCustomTitle(imageView);
    }

    builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            CharSequence clickedItemText = items.get(item);
            if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_add_to_script))) {
                addBrickToScript(clickedBrick);
            } else if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_edit_brick))) {
                launchBrickScriptActivityOnBrick(context, clickedBrick);
            }
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:hku.fyp14017.blencode.ui.fragment.AddBrickFragment.java

private void clickedOnUserBrick(final UserBrick clickedBrick, View view) {
    final Context context = getActivity();

    final List<CharSequence> items = new ArrayList<CharSequence>();

    items.add(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_add_to_script));

    items.add(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_edit_brick));

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

    boolean drawingCacheEnabled = view.isDrawingCacheEnabled();
    view.setDrawingCacheEnabled(true);/* ww  w  .  j  a v a2  s .c om*/
    view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);
    view.buildDrawingCache(true);

    if (view.getDrawingCache() != null) {
        Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
        view.setDrawingCacheEnabled(drawingCacheEnabled);

        ImageView imageView = getGlowingBorder(bitmap);
        builder.setCustomTitle(imageView);
    }

    builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            CharSequence clickedItemText = items.get(item);
            if (clickedItemText.equals(
                    context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_add_to_script))) {
                addBrickToScript(clickedBrick);
            } else if (clickedItemText
                    .equals(context.getText(hku.fyp14017.blencode.R.string.brick_context_dialog_edit_brick))) {
                launchBrickScriptActivityOnBrick(context, clickedBrick);
            }

        }

    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:com.example.drugsformarinemammals.ViewPager_Pinnipeds.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);/*from   w ww.  j  a v a 2  s .c om*/
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("");
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}

From source file:r2b.apps.view.base.BaseDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    iconRes = getArguments().getInt(ICON_RES_KEY, 0);
    title = getArguments().getString(TITLE_KEY);
    text = getArguments().getString(TEXT_KEY);
    isCancelable = getArguments().getBoolean(IS_CANCELABLE_KEY, true);
    customTitleViewRes = getArguments().getInt(CUSTOM_TITLE_VIEW_RES_KEY, 0);
    viewRes = getArguments().getInt(VIEW_RES_KEY, 0);
    positiveButonTextRes = getArguments().getInt(POSITIVE_BUTTON_TEXT_RES, 0);
    negativeButonTextRes = getArguments().getInt(NEGATIVE_BUTTON_TEXT_RES, 0);
    neutralButonTextRes = getArguments().getInt(NEUTRAL_BUTTON_TEXT_RES, 0);
    listArrayRes = getArguments().getInt(LIST_ARRAY_RES, 0);
    singleChoiceListArrayRes = getArguments().getInt(SINGLE_CHOICE_LIST_ARRAY_RES, 0);
    singleChoiceDefaultSelected = getArguments().getInt(SINGLE_CHOICE_DEFAULT_SELECTED, -1);
    multiChoiceListArrayRes = getArguments().getInt(MULTI_CHOICE_LIST_ARRAY_RES, 0);
    multiChoiceDefaultSelected = getArguments().getBooleanArray(MULTI_CHOICE_DEFAULT_SELECTED);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final ArrayList<Integer> selectedItems = new ArrayList<Integer>();

    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    if (iconRes != 0) {
        builder.setIcon(iconRes);//  w  ww .jav  a 2s.  co  m
    }

    if (title != null) {
        builder.setTitle(title);
    }

    if (text != null && multiChoiceListArrayRes == 0 && singleChoiceListArrayRes == 0 && listArrayRes == 0) {
        builder.setMessage(text);
    }

    builder.setCancelable(isCancelable);

    if (customTitleViewRes != 0) {
        builder.setCustomTitle(inflater.inflate(customTitleViewRes, null)); // TODO NULL OR this, activity??
    }

    if (viewRes != 0) {
        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(inflater.inflate(viewRes, null));
    }

    if (positiveButonTextRes != 0) {
        builder.setPositiveButton(positiveButonTextRes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                if (multiChoiceListArrayRes == 0) {
                    // Send the positive button event back to the host activity
                    dialogListener.onDialogPositiveClick(BaseDialog.this);
                } else {
                    // Send the positive items selected to the host activity
                    dialogListener.onSelectedItems(BaseDialog.this, selectedItems);
                }

            }
        });
    }

    if (negativeButonTextRes != 0) {
        builder.setNegativeButton(negativeButonTextRes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                // Send the negative button event back to the host activity
                dialogListener.onDialogNegativeClick(BaseDialog.this);
            }
        });
    }

    if (neutralButonTextRes != 0) {
        builder.setNeutralButton(neutralButonTextRes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                // Send the neutral button event back to the host activity
                dialogListener.onDialogNeutralClick(BaseDialog.this);
            }
        });
    }

    if (listArrayRes != 0) {
        builder.setItems(listArrayRes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // The 'which' argument contains the index position of the selected item
                dialogListener.onItemClick(BaseDialog.this, which);
            }
        });
    }

    if (singleChoiceListArrayRes != 0) {
        // Specify the list array, the items to be selected by default (-1 for none),
        // and the listener through which to receive callbacks when item is selected
        builder.setSingleChoiceItems(singleChoiceListArrayRes, singleChoiceDefaultSelected,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // The 'which' argument contains the index position of the selected item
                        dialogListener.onItemClick(BaseDialog.this, which);
                    }
                });
    }

    if (multiChoiceListArrayRes != 0) {
        // Specify the list array, the items to be selected by default (null for none),
        // and the listener through which to receive callbacks when items are selected
        builder.setMultiChoiceItems(multiChoiceListArrayRes, multiChoiceDefaultSelected,
                new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                        if (isChecked) {
                            // If the user checked the item, add it to the selected items
                            selectedItems.add(which);
                        } else if (selectedItems.contains(which)) {
                            // Else, if the item is already in the array, remove it
                            selectedItems.remove(Integer.valueOf(which));
                        }
                    }
                });
    }

    return builder.create();
}

From source file:com.example.drugsformarinemammals.Combined_Search.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);//from ww  w  . ja v  a  2s  .c o m
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText(messageTitle);
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}