Java Code Examples for android.support.v7.app.AlertDialog.setView()

The following are Jave code examples for showing how to use setView() of the android.support.v7.app.AlertDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Material-File-Picker   File: FilePicker.java   Source Code and License Vote up 8 votes
/**
 * This method creates and display file picker dialog
 */
private void show() {
    if (ActivityCompat.checkSelfPermission(mActivity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(mActivity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                STORAGE_PERMISSIONS);
        return;
    }

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mActivity);
    final AlertDialog alertdialog = alertBuilder.create();
    mPickerViewModel.setAlertDialog(alertdialog);

    PickerDialogBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mActivity),
            R.layout.picker_dialog, null, false);
    binding.setVariable(BR.viewModel, mPickerViewModel);

    alertdialog.setView(binding.getRoot());
    alertdialog.show();
}
 
Example 2
Project: updateUtils   File: UpdateAgent.java   Source Code and License Vote up 5 votes
@Override
public void onPrompt(UpdateAgent agent) {
    final UpdateInfo info = agent.getInfo();
    String size = Formatter.formatShortFileSize(mContext, info.size);
    String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);

    final AlertDialog dialog = new AlertDialog.Builder(mContext).create();

    dialog.setTitle("应用更新");
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);


    float density = mContext.getResources().getDisplayMetrics().density;
    TextView tv = new TextView(mContext);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setVerticalScrollBarEnabled(true);
    tv.setTextSize(14);
    tv.setMaxHeight((int) (250 * density));

    dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);


    DialogInterface.OnClickListener listener = new OnPromptClick(agent, true);

    if (info.isForce) {
        tv.setText("您需要更新应用才能继续使用\n\n" + content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
    } else {
        tv.setText(content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
        if (info.isIgnorable) {
            dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
        }
    }
    dialog.show();
}
 
Example 3
Project: BackendDrivenMenu   File: MainActivity.java   Source Code and License Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.about) {
        final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(getString(R.string.about_title));
        ImageView iv = new ImageView(this);
        int p = G.dpToPx(this, 10);
        iv.setPadding(p, G.dpToPx(this, 20), p, p);
        iv.setImageDrawable(logo);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                visitWeb();
                alertDialog.hide();
            }
        });
        alertDialog.setView(iv);
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.visit_web), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                visitWeb();
            }
        });
        alertDialog.setCancelable(true);
        alertDialog.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 4
Project: GitHub   File: UpdateAgent.java   Source Code and License Vote up 4 votes
@Override
public void prompt(IUpdateAgent agent) {
    if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
        return;
    }
    final UpdateInfo info = agent.getInfo();
    String size = Formatter.formatShortFileSize(mContext, info.size);
    String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);

    final AlertDialog dialog = new AlertDialog.Builder(mContext).create();

    dialog.setTitle("应用更新");
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);


    float density = mContext.getResources().getDisplayMetrics().density;
    TextView tv = new TextView(mContext);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setVerticalScrollBarEnabled(true);
    tv.setTextSize(14);
    tv.setMaxHeight((int) (250 * density));

    dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);


    DialogInterface.OnClickListener listener = new DefaultPromptClickListener(agent, true);

    if (info.isForce) {
        tv.setText("您需要更新应用才能继续使用\n\n" + content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
    } else {
        tv.setText(content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
        if (info.isIgnorable) {
            dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
        }
    }
    dialog.show();
}
 
Example 5
Project: update-master   File: UpdateAgent.java   Source Code and License Vote up 4 votes
@Override
public void prompt(IUpdateAgent agent) {
    if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
        return;
    }
    final UpdateInfo info = agent.getInfo();
    String size = Formatter.formatShortFileSize(mContext, info.size);
    String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);

    final AlertDialog dialog = new AlertDialog.Builder(mContext).create();

    dialog.setTitle("应用更新");
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);


    float density = mContext.getResources().getDisplayMetrics().density;
    TextView tv = new TextView(mContext);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setVerticalScrollBarEnabled(true);
    tv.setTextSize(14);
    tv.setMaxHeight((int) (250 * density));

    dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);


    DialogInterface.OnClickListener listener = new DefaultPromptClickListener(agent, true);

    if (info.isForce) {
        tv.setText("您需要更新应用才能继续使用\n\n" + content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
    } else {
        tv.setText(content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
        if (info.isIgnorable) {
            dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
        }
    }
    dialog.show();
}
 
Example 6
Project: Material-Calendar-View   File: DatePicker.java   Source Code and License Vote up 4 votes
public DatePicker show() {
    LayoutInflater layoutInflater = LayoutInflater.from(mContext);
    final View view = layoutInflater.inflate(R.layout.date_picker_dialog, null);

    if(mCalendarProperties.getPagesColor() != 0){
        view.setBackgroundColor(mCalendarProperties.getPagesColor());
    }

    mCancelButton = (AppCompatButton) view.findViewById(R.id.negative_button);
    mOkButton = (AppCompatButton) view.findViewById(R.id.positive_button);
    mTodayButton = (AppCompatButton) view.findViewById(R.id.today_button);

    setTodayButtonVisibility();
    setDialogButtonsColors();
    setOkButtonState(mCalendarProperties.getCalendarType() == CalendarView.ONE_DAY_PICKER);
    mCalendarProperties.setOnSelectionAbilityListener(this::setOkButtonState);

    CalendarView calendarView = new CalendarView(mContext, mCalendarProperties);

    FrameLayout calendarContainer = (FrameLayout) view.findViewById(R.id.calendarContainer);
    calendarContainer.addView(calendarView);

    Optional.ofNullable(mCalendarProperties.getCalendar()).ifPresent(calendar -> {
        try {
            calendarView.setDate(calendar);
        } catch (OutOfDateRangeException exception) {
            exception.printStackTrace();
        }
    });

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
    final AlertDialog alertdialog = alertBuilder.create();
    alertdialog.setView(view);

    mCancelButton.setOnClickListener(v -> alertdialog.cancel());

    mOkButton.setOnClickListener(v -> {
        alertdialog.cancel();
        mCalendarProperties.getOnSelectDateListener().onSelect(calendarView.getSelectedDates());
    });

    mTodayButton.setOnClickListener(v -> calendarView.showCurrentMonthPage());

    alertdialog.show();

    return this;
}
 
Example 7
Project: SimpleDialogFragments   File: CustomViewDialog.java   Source Code and License Vote up 4 votes
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);

    layoutInflater = dialog.getLayoutInflater();

    View content = onCreateContentView(savedInstanceState);

    // Intermediate view with custom message TextView
    View intermediate = inflate(R.layout.simpledialogfragment_custom_view);
    TextView textView = (TextView) intermediate.findViewById(R.id.customMessage);
    View topSpacer = intermediate.findViewById(R.id.textSpacerNoTitle);
    ViewGroup container = (ViewGroup) intermediate.findViewById(R.id.customView);
    container.addView(content);

    dialog.setView(intermediate);


    String msg = getArgString(MESSAGE);
    if (msg != null) {
        CharSequence message;
        if (getArguments().getBoolean(HTML)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                message = Html.fromHtml(msg, 0);
            } else {
                //noinspection deprecation
                message = Html.fromHtml(msg);
            }
        } else {
            message = msg;
        }
        textView.setText(message);

    } else {
        textView.setVisibility(View.GONE);
    }
    dialog.setMessage(null);

    topSpacer.setVisibility(getArgString(TITLE) == null && msg != null ? View.VISIBLE : View.GONE);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pressPositiveButton();
                }
            });
            onDialogShown();

        }
    });

    return dialog;
}