Search in sources :

Example 81 with Builder

use of android.app.AlertDialog.Builder in project PocketMaps by junjunguo.

the class MessageDialog method createMsg.

private static Builder createMsg(final Activity activity, final String prefName, int msgId, final boolean dontShowAgain) {
    final Builder adb = new Builder(activity);
    LayoutInflater adbInflater = LayoutInflater.from(activity);
    View view = adbInflater.inflate(R.layout.app_message, null);
    final CheckBox checkbox = (CheckBox) view.findViewById(R.id.msgCheckbox);
    if (!dontShowAgain) {
        checkbox.setVisibility(View.INVISIBLE);
    }
    adb.setView(view);
    adb.setTitle(R.string.settings);
    adb.setMessage(msgId);
    adb.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            if (dontShowAgain) {
                SharedPreferences settings = activity.getSharedPreferences("DontShowAgain", 0);
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean(prefName, checkbox.isChecked());
                editor.commit();
            }
            dialog.cancel();
        }
    });
    return adb;
}
Also used : DialogInterface(android.content.DialogInterface) SharedPreferences(android.content.SharedPreferences) CheckBox(android.widget.CheckBox) Builder(android.app.AlertDialog.Builder) LayoutInflater(android.view.LayoutInflater) View(android.view.View)

Example 82 with Builder

use of android.app.AlertDialog.Builder in project AndFrameWorks by scwang90.

the class AfExceptionHandler method doShowDialog.

public static synchronized void doShowDialog(Context activity, String title, String msg, Callback callback, Looper looper, String id) {
    if (mDialogMap.containsKey(id)) {
        return;
    }
    final String tid = id;
    final String ttitle = title;
    final String tmsg = msg;
    final Callback tcallback = callback;
    final Looper tLooper = looper;
    final Builder dialog = new Builder(activity);
    new Thread(() -> {
        try {
            Looper.prepare();
            mDialogMap.put(tid, ttitle);
            dialog.setTitle(ttitle);
            dialog.setCancelable(false);
            dialog.setMessage(tmsg);
            dialog.setNeutralButton("我知道了", (dialog1, which) -> {
                dialog1.dismiss();
                mDialogMap.remove(tid);
                if (tLooper != null && tcallback != null) {
                    new Handler(tLooper, tcallback).sendMessage(Message.obtain());
                } else if (tcallback != null) {
                    tcallback.handleMessage(Message.obtain());
                }
                Handler handler = new Handler() {

                    @Override
                    public void handleMessage(Message msg1) {
                        Looper looper1 = Looper.myLooper();
                        if (looper1 != null) {
                            looper1.quit();
                        }
                    }
                };
                handler.sendMessageDelayed(Message.obtain(), 300);
            });
            dialog.show();
            Looper.loop();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }) {
    }.start();
}
Also used : Builder(android.app.AlertDialog.Builder) Context(android.content.Context) AfDurableCacher(com.andframe.caches.AfDurableCacher) AfDateFormat(com.andframe.util.java.AfDateFormat) Exceptional(com.andframe.model.Exceptional) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) Date(java.util.Date) FileWriter(java.io.FileWriter) AfDispatcher(com.andframe.task.AfDispatcher) HashMap(java.util.HashMap) DisplayMetrics(android.util.DisplayMetrics) AfDateGuid(com.andframe.util.java.AfDateGuid) Message(android.os.Message) com.andframe.$(com.andframe.$) Handler(android.os.Handler) Looper(android.os.Looper) Callback(android.os.Handler.Callback) AfReflecter(com.andframe.util.java.AfReflecter) Activity(android.app.Activity) AfApp(com.andframe.application.AfApp) Resources(android.content.res.Resources) Looper(android.os.Looper) Callback(android.os.Handler.Callback) Message(android.os.Message) Builder(android.app.AlertDialog.Builder) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) Handler(android.os.Handler)

Example 83 with Builder

use of android.app.AlertDialog.Builder in project AndFrameWorks by scwang90.

the class AfDialogBuilder method inputText.

/**
 * 弹出一个文本输入框
 *
 * @param title    标题
 * @param defaul   默认值
 * @param type     android.text.InputType
 * @param listener 监听器
 */
@Override
public Dialog inputText(CharSequence title, final CharSequence defaul, int type, final InputTextListener listener) {
    final EditText input = new EditText(mContext);
    final int defaullength = defaul != null ? defaul.length() : 0;
    input.setText(defaul);
    input.clearFocus();
    input.setInputType(type);
    final CharSequence oKey = "确定";
    final CharSequence msgKey = "$inputText$";
    OnClickListener cancleListener = (dialog, which) -> {
        AfSoftKeyboard.hideSoftKeyboard(input);
        if (listener instanceof InputTextCancelable) {
            ((InputTextCancelable) listener).onInputTextCancel(input);
        }
        if (dialog != null) {
            dialog.dismiss();
        }
    };
    final OnClickListener okListener = (dialog, which) -> {
        if (listener.onInputTextComfirm(input, input.getText().toString())) {
            AfSoftKeyboard.hideSoftKeyboard(input);
            if (dialog != null) {
                dialog.dismiss();
            }
        }
    };
    final OnShowListener showListener = dialog -> {
        AfSoftKeyboard.showSoftkeyboard(input);
        if (defaullength > 3 && defaul.toString().matches("[^.]+\\.[a-zA-Z]\\w{1,3}")) {
            input.setSelection(0, defaul.toString().lastIndexOf('.'));
        } else {
            input.setSelection(0, defaullength);
        }
    };
    if (mBuildNative) {
        Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(input);
        builder.setCancelable(false);
        builder.setTitle(title);
        builder.setPositiveButton("确定", new SafeListener());
        builder.setNegativeButton("取消", cancleListener);
        final AlertDialog dialog = builder.create();
        dialog.setOnShowListener(showListener);
        dialog.show();
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> new SafeListener(okListener).onClick(dialog, 0));
        return dialog;
    } else {
        final Dialog dialog = showDialog(title, msgKey, oKey, okListener, "取消", cancleListener);
        new Handler(Looper.getMainLooper()).postDelayed(() -> {
            FindTextViewWithText builderHelper = FindTextViewWithText.invoke((ViewGroup) dialog.getWindow().getDecorView(), msgKey);
            if (builderHelper != null) {
                builderHelper.parent.removeViewAt(builderHelper.index);
                builderHelper.parent.addView(input, builderHelper.index, builderHelper.textView.getLayoutParams());
                showListener.onShow(dialog);
                builderHelper = FindTextViewWithText.invoke((ViewGroup) dialog.getWindow().getDecorView(), oKey);
                if (builderHelper != null) {
                    builderHelper.textView.setOnClickListener(v -> new SafeListener(okListener).onClick(dialog, 0));
                }
            }
        }, mBuildDelayed);
        return dialog;
    }
}
Also used : EditText(android.widget.EditText) 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) AlertDialog(android.app.AlertDialog) ViewGroup(android.view.ViewGroup) Builder(android.app.AlertDialog.Builder) DialogBuilder(com.andframe.api.DialogBuilder) Handler(android.os.Handler) AfExceptionHandler(com.andframe.exception.AfExceptionHandler) SuppressLint(android.annotation.SuppressLint) OnShowListener(android.content.DialogInterface.OnShowListener) TimePickerDialog(android.app.TimePickerDialog) Dialog(android.app.Dialog) DatePickerDialog(android.app.DatePickerDialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) SafeListener(com.andframe.listener.SafeListener)

Example 84 with Builder

use of android.app.AlertDialog.Builder in project AndFrameWorks by scwang90.

the class AfDialogBuilder method showViewDialog.

/**
 * 显示视图对话框
 *
 * @param theme     主题
 * @param iconres   对话框图标
 * @param title     显示标题
 * @param view      显示内容
 * @param positive  确认 按钮显示信息
 * @param lpositive 点击  确认 按钮 响应事件
 * @param neutral   详细 按钮显示信息
 * @param lneutral  点击  详细 按钮 响应事件
 * @param negative  按钮显示信息
 * @param lnegative 点击  拒绝 按钮 响应事件
 */
@Override
@SuppressLint("NewApi")
public Dialog showViewDialog(int theme, int iconres, CharSequence title, View view, 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);
    RelativeLayout.LayoutParams lp;
    lp = new RelativeLayout.LayoutParams(AfActivity.LP_WC, AfActivity.LP_WC);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    RelativeLayout layout = new RelativeLayout(mContext);
    layout.addView(view, lp);
    builder.setView(layout);
    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) RelativeLayout(android.widget.RelativeLayout) SafeListener(com.andframe.listener.SafeListener) SuppressLint(android.annotation.SuppressLint)

Example 85 with Builder

use of android.app.AlertDialog.Builder in project AndFrameWorks by scwang90.

the class AfDialogBuilder method inputLines.

/**
 * 弹出一个文本输入框
 *
 * @param title    标题
 * @param defaul   默认值
 * @param type     android.text.InputType
 * @param listener 监听器
 */
@Override
public Dialog inputLines(CharSequence title, final CharSequence defaul, int type, final InputTextListener listener) {
    final EditText input = new EditText(mContext);
    final int defaullength = defaul != null ? defaul.length() : 0;
    input.setText(defaul);
    input.clearFocus();
    input.setInputType(type | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    input.setGravity(Gravity.TOP);
    input.setSingleLine(false);
    input.setHorizontallyScrolling(false);
    input.setMinHeight(AfDensity.dp2px(100));
    final CharSequence oKey = "确定";
    final CharSequence msgKey = "$inputLines$";
    OnClickListener cancleListener = (dialog, which) -> {
        AfSoftKeyboard.hideSoftKeyboard(input);
        if (listener instanceof InputTextCancelable) {
            ((InputTextCancelable) listener).onInputTextCancel(input);
        }
        if (dialog != null) {
            dialog.dismiss();
        }
    };
    final OnClickListener okListener = (dialog, which) -> {
        if (listener.onInputTextComfirm(input, input.getText().toString())) {
            AfSoftKeyboard.hideSoftKeyboard(input);
            if (dialog != null) {
                dialog.dismiss();
            }
        }
    };
    final OnShowListener showListener = dialog -> {
        AfSoftKeyboard.showSoftkeyboard(input);
        if (defaullength > 3 && defaul.toString().matches("[^.]+\\.[a-zA-Z]\\w{1,3}")) {
            input.setSelection(0, defaul.toString().lastIndexOf('.'));
        } else {
            input.setSelection(0, defaullength);
        }
    };
    if (mBuildNative) {
        Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(input);
        builder.setCancelable(false);
        builder.setTitle(title);
        builder.setPositiveButton("确定", new SafeListener());
        builder.setNegativeButton("取消", cancleListener);
        final AlertDialog dialog = builder.create();
        dialog.setOnShowListener(showListener);
        dialog.show();
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> new SafeListener(okListener).onClick(dialog, 0));
        return dialog;
    } else {
        final Dialog dialog = showDialog(title, msgKey, oKey, okListener, "取消", cancleListener);
        new Handler(Looper.getMainLooper()).postDelayed(() -> {
            FindTextViewWithText builderHelper = FindTextViewWithText.invoke((ViewGroup) dialog.getWindow().getDecorView(), msgKey);
            if (builderHelper != null) {
                builderHelper.parent.removeViewAt(builderHelper.index);
                builderHelper.parent.addView(input, builderHelper.index, builderHelper.textView.getLayoutParams());
                showListener.onShow(dialog);
                builderHelper = FindTextViewWithText.invoke((ViewGroup) dialog.getWindow().getDecorView(), oKey);
                if (builderHelper != null) {
                    builderHelper.textView.setOnClickListener(v -> new SafeListener(okListener).onClick(dialog, 0));
                }
            }
        }, mBuildDelayed);
        return dialog;
    }
}
Also used : EditText(android.widget.EditText) 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) AlertDialog(android.app.AlertDialog) ViewGroup(android.view.ViewGroup) Builder(android.app.AlertDialog.Builder) DialogBuilder(com.andframe.api.DialogBuilder) Handler(android.os.Handler) AfExceptionHandler(com.andframe.exception.AfExceptionHandler) SuppressLint(android.annotation.SuppressLint) OnShowListener(android.content.DialogInterface.OnShowListener) TimePickerDialog(android.app.TimePickerDialog) Dialog(android.app.Dialog) DatePickerDialog(android.app.DatePickerDialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) SafeListener(com.andframe.listener.SafeListener)

Aggregations

Builder (android.app.AlertDialog.Builder)112 DialogInterface (android.content.DialogInterface)64 AlertDialog (android.app.AlertDialog)42 Intent (android.content.Intent)29 View (android.view.View)28 TextView (android.widget.TextView)25 OnClickListener (android.content.DialogInterface.OnClickListener)21 SuppressLint (android.annotation.SuppressLint)16 ArrayList (java.util.ArrayList)15 OnClickListener (android.view.View.OnClickListener)13 ImageView (android.widget.ImageView)13 Context (android.content.Context)12 AlertDialog (android.support.v7.app.AlertDialog)12 List (java.util.List)12 Bundle (android.os.Bundle)11 RelativeLayout (android.widget.RelativeLayout)10 Point (android.graphics.Point)9 ExpandableListView (android.widget.ExpandableListView)9 ImageButton (android.widget.ImageButton)7 EditText (android.widget.EditText)6