use of android.content.DialogInterface.OnShowListener 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;
}
}
use of android.content.DialogInterface.OnShowListener in project android_packages_apps_Dialer by LineageOS.
the class MigrateBlockedNumbersDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.migrate_blocked_numbers_dialog_title).setMessage(R.string.migrate_blocked_numbers_dialog_message).setPositiveButton(R.string.migrate_blocked_numbers_dialog_allow_button, null).setNegativeButton(R.string.migrate_blocked_numbers_dialog_cancel_button, null).create();
// The Dialog's buttons aren't available until show is called, so an OnShowListener
// is used to set the positive button callback.
dialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
final AlertDialog alertDialog = (AlertDialog) dialog;
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(newPositiveButtonOnClickListener(alertDialog));
}
});
return dialog;
}
use of android.content.DialogInterface.OnShowListener in project android_packages_apps_Dialer by LineageOS.
the class CreateCustomSmsDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = View.inflate(builder.getContext(), R.layout.fragment_custom_sms_dialog, null);
editText = (EditText) view.findViewById(R.id.custom_sms_input);
if (savedInstanceState != null) {
editText.setText(savedInstanceState.getCharSequence(ARG_ENTERED_TEXT));
}
builder.setCancelable(true).setView(view).setPositiveButton(R.string.call_incoming_custom_message_send, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
FragmentUtils.getParentUnsafe(CreateCustomSmsDialogFragment.this, CreateCustomSmsHolder.class).customSmsCreated(editText.getText().toString().trim());
dismiss();
}
}).setNegativeButton(R.string.call_incoming_custom_message_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dismiss();
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
dismiss();
}
}).setTitle(R.string.call_incoming_respond_via_sms_custom_message);
final AlertDialog customMessagePopup = builder.create();
customMessagePopup.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
((AlertDialog) dialogInterface).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
});
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
Button sendButton = customMessagePopup.getButton(DialogInterface.BUTTON_POSITIVE);
sendButton.setEnabled(editable != null && editable.toString().trim().length() != 0);
}
});
customMessagePopup.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
customMessagePopup.getWindow().addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
return customMessagePopup;
}
use of android.content.DialogInterface.OnShowListener in project android_packages_apps_Dialer by MoKee.
the class MigrateBlockedNumbersDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.migrate_blocked_numbers_dialog_title).setMessage(R.string.migrate_blocked_numbers_dialog_message).setPositiveButton(R.string.migrate_blocked_numbers_dialog_allow_button, null).setNegativeButton(R.string.migrate_blocked_numbers_dialog_cancel_button, null).create();
// The Dialog's buttons aren't available until show is called, so an OnShowListener
// is used to set the positive button callback.
dialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
final AlertDialog alertDialog = (AlertDialog) dialog;
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(newPositiveButtonOnClickListener(alertDialog));
}
});
return dialog;
}
use of android.content.DialogInterface.OnShowListener in project android_packages_apps_Gallery2 by LineageOS.
the class BookmarkerInfo method showResumeDialog.
private void showResumeDialog(Context context, final BookmarkerInfo bookmark) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.resume_playing_title);
builder.setMessage(String.format(context.getString(R.string.resume_playing_message), GalleryUtils.formatDuration(context, bookmark.mBookmark / 1000)));
builder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
onCompletion();
}
});
builder.setPositiveButton(R.string.resume_playing_resume, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// here try to seek for bookmark
mVideoCanSeek = true;
doStartVideo(true, bookmark.mBookmark, bookmark.mDuration);
}
});
builder.setNegativeButton(R.string.resume_playing_restart, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
doStartVideo(true, 0, bookmark.mDuration);
}
});
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(DialogInterface arg0) {
mIsShowResumingDialog = true;
}
});
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface arg0) {
mIsShowResumingDialog = false;
}
});
dialog.show();
}
Aggregations