Search in sources :

Example 1 with SafeListener

use of com.andframe.listener.SafeListener in project AndFrameWorks by scwang90.

the class AfDialogBuilder method selectDate.

/**
 * 选择日期
 * @param title 标题
 * @param value 默认时间
 * @param listener 监听器
 */
@Override
public Dialog selectDate(CharSequence title, Date value, final OnDateSetListener listener) {
    Calendar calender = Calendar.getInstance();
    calender.setTime(value);
    int year = calender.get(Calendar.YEAR);
    int month = calender.get(Calendar.MONTH);
    int day = calender.get(Calendar.DAY_OF_MONTH);
    AlertDialog tDialog = new DatePickerDialog(mContext, new SafeListener(listener), year, month, day) {

        @Override
        public void show() {
            super.show();
            if (listener instanceof OnDateSetVerifyListener) {
                getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
                    try {
                        DatePicker picker = AfReflecter.getMemberByType(this, DatePicker.class);
                        if (picker == null) {
                            this.dismiss();
                            super.onClick(this, BUTTON_POSITIVE);
                        } else if (((OnDateSetVerifyListener) listener).onPreDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth())) {
                            this.dismiss();
                            super.onClick(this, BUTTON_POSITIVE);
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                });
            }
        }
    };
    if (title != null && title.length() > 0) {
        tDialog.setTitle(title);
    }
    tDialog.show();
    tDialog.setCancelable(true);
    return tDialog;
}
Also used : AlertDialog(android.app.AlertDialog) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) SafeListener(com.andframe.listener.SafeListener) DatePicker(android.widget.DatePicker) SuppressLint(android.annotation.SuppressLint)

Example 2 with SafeListener

use of com.andframe.listener.SafeListener in project AndFrameWorks by scwang90.

the class AfDialogBuilder method multiChoice.

/**
 * 显示一个多选对话框 (默认可取消)
 *
 * @param title         对话框标题
 * @param items         选择菜单项
 * @param checkedItems  选择结果
 * @param listener      选择监听器
 * @param lpositive     完成选择器
 */
@Override
public Dialog multiChoice(CharSequence title, CharSequence[] items, boolean[] checkedItems, OnMultiChoiceClickListener listener, OnClickListener lpositive) {
    Builder dialog = new Builder(mContext);
    if (title != null) {
        dialog.setTitle(title);
        dialog.setNegativeButton("确定", new SafeListener(lpositive));
    }
    dialog.setMultiChoiceItems(items, checkedItems, new SafeListener(listener));
    return dialog.show();
}
Also used : Builder(android.app.AlertDialog.Builder) DialogBuilder(com.andframe.api.DialogBuilder) SafeListener(com.andframe.listener.SafeListener)

Example 3 with SafeListener

use of com.andframe.listener.SafeListener in project AndFrameWorks by scwang90.

the class AfDialogBuilder method selectDateTime.

/**
 * 选择日期时间
 * @param title 标题
 * @param value 默认时间
 * @param listener 监听器
 */
@Override
public Dialog selectDateTime(final CharSequence title, final Date value, final OnDateTimeSetListener listener) {
    final Calendar calender = Calendar.getInstance();
    calender.setTime(value);
    int year = calender.get(Calendar.YEAR);
    final int month = calender.get(Calendar.MONTH);
    final int day = calender.get(Calendar.DAY_OF_MONTH);
    final AlertDialog tDialog = new DatePickerDialog(mContext, new SafeListener((view, year1, month1, day1) -> {
        int hour = calender.get(Calendar.HOUR_OF_DAY);
        int minute = calender.get(Calendar.MINUTE);
        Dialog tDialog1 = new TimePickerDialog(mContext, new SafeListener((OnTimeSetListener) (view1, hour1, minute1) -> listener.onDateTimeSet(year1, month1, day1, hour1, minute1)), hour, minute, true) {

            @Override
            public void show() {
                super.show();
                if (listener instanceof OnDateTimeSetVerifyListener) {
                    getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
                        try {
                            TimePicker picker = AfReflecter.getMemberByType(this, TimePicker.class);
                            if (picker == null) {
                                this.dismiss();
                                super.onClick(this, BUTTON_POSITIVE);
                            } else if (((OnDateTimeSetVerifyListener) listener).onPreTimeSet(picker, picker.getCurrentHour(), picker.getCurrentMinute())) {
                                this.dismiss();
                                super.onClick(this, BUTTON_POSITIVE);
                            }
                        } catch (IllegalAccessException e) {
                            e.printStackTrace();
                        }
                    });
                }
            }
        };
        ;
        if (title != null && title.length() > 0) {
            tDialog1.setTitle(title);
        }
        tDialog1.show();
        tDialog1.setCancelable(true);
    }), year, month, day) {

        @Override
        public void show() {
            super.show();
            if (listener instanceof OnDateTimeSetVerifyListener) {
                getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
                    try {
                        DatePicker picker = AfReflecter.getMemberByType(this, DatePicker.class);
                        if (picker == null) {
                            this.dismiss();
                            super.onClick(this, BUTTON_POSITIVE);
                        } else if (((OnDateTimeSetVerifyListener) listener).onPreDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth())) {
                            this.dismiss();
                            super.onClick(this, BUTTON_POSITIVE);
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                });
            }
        }
    };
    if (title != null && title.length() > 0) {
        tDialog.setTitle(title);
    }
    tDialog.show();
    tDialog.setCancelable(true);
    return tDialog;
}
Also used : AlertDialog(android.app.AlertDialog) Builder(android.app.AlertDialog.Builder) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) LinearLayout(android.widget.LinearLayout) OnClickListener(android.content.DialogInterface.OnClickListener) OnMultiChoiceClickListener(android.content.DialogInterface.OnMultiChoiceClickListener) Date(java.util.Date) Dialog(android.app.Dialog) AfDensity(com.andframe.util.android.AfDensity) DatePicker(android.widget.DatePicker) Stack(java.util.Stack) SuppressLint(android.annotation.SuppressLint) Calendar(java.util.Calendar) DatePickerDialog(android.app.DatePickerDialog) CheckBox(android.widget.CheckBox) AfActivity(com.andframe.activity.AfActivity) Handler(android.os.Handler) Looper(android.os.Looper) View(android.view.View) OnCancelListener(android.content.DialogInterface.OnCancelListener) OnShowListener(android.content.DialogInterface.OnShowListener) Build(android.os.Build) OnDateSetListener(android.app.DatePickerDialog.OnDateSetListener) TargetApi(android.annotation.TargetApi) DialogInterface(android.content.DialogInterface) OnTimeSetListener(android.app.TimePickerDialog.OnTimeSetListener) SafeListener(com.andframe.listener.SafeListener) ProgressDialog(android.app.ProgressDialog) InputType(android.text.InputType) TextUtils(android.text.TextUtils) ViewGroup(android.view.ViewGroup) AfExceptionHandler(com.andframe.exception.AfExceptionHandler) AlertDialog(android.app.AlertDialog) DialogBuilder(com.andframe.api.DialogBuilder) Gravity(android.view.Gravity) LayoutParams(android.view.ViewGroup.LayoutParams) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) com.andframe.$(com.andframe.$) RelativeLayout(android.widget.RelativeLayout) TimePicker(android.widget.TimePicker) AfReflecter(com.andframe.util.java.AfReflecter) Window(android.view.Window) EditText(android.widget.EditText) TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) SuppressLint(android.annotation.SuppressLint) TimePickerDialog(android.app.TimePickerDialog) Dialog(android.app.Dialog) DatePickerDialog(android.app.DatePickerDialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.app.AlertDialog) SafeListener(com.andframe.listener.SafeListener) DatePicker(android.widget.DatePicker)

Example 4 with SafeListener

use of com.andframe.listener.SafeListener in project AndFrameWorks by scwang90.

the class AfDialogBuilder method showDialog.

/**
 * 显示视图对话框
 *
 * @param theme     主题
 * @param iconres   对话框图标
 * @param title     显示标题
 * @param message   显示内容
 * @param positive  确认 按钮显示信息
 * @param lpositive 点击  确认 按钮 响应事件
 * @param neutral   详细 按钮显示信息
 * @param lneutral  点击  详细 按钮 响应事件
 * @param negative  按钮显示信息
 * @param lnegative 点击  拒绝 按钮 响应事件
 */
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public Dialog showDialog(int theme, int iconres, CharSequence title, CharSequence message, CharSequence negative, OnClickListener lnegative, CharSequence neutral, OnClickListener lneutral, CharSequence positive, OnClickListener lpositive) {
    Builder builder = null;
    if (theme > 0) {
        try {
            builder = new Builder(mContext, theme);
        } catch (Throwable ignored) {
        }
    }
    if (builder == null) {
        try {
            builder = new Builder(mContext);
        } catch (Throwable ex) {
            return null;
        }
    }
    builder.setTitle(title);
    builder.setMessage(message);
    if (iconres > 0) {
        builder.setIcon(iconres);
    }
    if (positive != null && positive.length() > 0) {
        builder.setPositiveButton(positive, new SafeListener(lpositive));
    }
    if (negative != null && negative.length() > 0) {
        builder.setNegativeButton(negative, new SafeListener(lnegative));
    }
    if (neutral != null && neutral.length() > 0) {
        builder.setNeutralButton(neutral, new SafeListener(lneutral));
    }
    builder.setCancelable(false);
    builder.create();
    return builder.show();
}
Also used : Builder(android.app.AlertDialog.Builder) DialogBuilder(com.andframe.api.DialogBuilder) SafeListener(com.andframe.listener.SafeListener) TargetApi(android.annotation.TargetApi)

Example 5 with SafeListener

use of com.andframe.listener.SafeListener in project AndFrameWorks by scwang90.

the class BaseMoreFooter method onViewCreated.

@Override
public void onViewCreated() {
    super.onViewCreated();
    mLayout.setOnClickListener(new SafeListener((OnCancelListener) v -> triggerLoadMore()));
}
Also used : SafeListener(com.andframe.listener.SafeListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

SafeListener (com.andframe.listener.SafeListener)11 SuppressLint (android.annotation.SuppressLint)8 Builder (android.app.AlertDialog.Builder)7 DialogBuilder (com.andframe.api.DialogBuilder)7 AlertDialog (android.app.AlertDialog)6 TargetApi (android.annotation.TargetApi)5 DatePickerDialog (android.app.DatePickerDialog)5 TimePickerDialog (android.app.TimePickerDialog)5 Calendar (java.util.Calendar)5 Dialog (android.app.Dialog)4 ProgressDialog (android.app.ProgressDialog)4 DialogInterface (android.content.DialogInterface)4 OnCancelListener (android.content.DialogInterface.OnCancelListener)4 OnClickListener (android.content.DialogInterface.OnClickListener)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 LayoutParams (android.view.ViewGroup.LayoutParams)4 CheckBox (android.widget.CheckBox)4 DatePicker (android.widget.DatePicker)4 LinearLayout (android.widget.LinearLayout)4