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;
}
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();
}
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;
}
}
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();
}
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;
}
}
Aggregations