Search in sources :

Example 11 with OnShowListener

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;
    }
}
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 12 with OnShowListener

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;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnShowListener(android.content.DialogInterface.OnShowListener)

Example 13 with OnShowListener

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;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) View(android.view.View) OnShowListener(android.content.DialogInterface.OnShowListener) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnCancelListener(android.content.DialogInterface.OnCancelListener) NonNull(android.support.annotation.NonNull)

Example 14 with OnShowListener

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;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnShowListener(android.content.DialogInterface.OnShowListener)

Example 15 with OnShowListener

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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) OnClickListener(android.content.DialogInterface.OnClickListener) OnShowListener(android.content.DialogInterface.OnShowListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

DialogInterface (android.content.DialogInterface)17 OnShowListener (android.content.DialogInterface.OnShowListener)17 AlertDialog (android.app.AlertDialog)14 View (android.view.View)12 TextView (android.widget.TextView)9 OnCancelListener (android.content.DialogInterface.OnCancelListener)6 OnClickListener (android.content.DialogInterface.OnClickListener)5 DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)5 EditText (android.widget.EditText)4 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)3 OnClickListener (android.view.View.OnClickListener)3 ViewGroup (android.view.ViewGroup)3 CheckBox (android.widget.CheckBox)3 SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 Builder (android.app.AlertDialog.Builder)2 DatePickerDialog (android.app.DatePickerDialog)2 OnDateSetListener (android.app.DatePickerDialog.OnDateSetListener)2 Dialog (android.app.Dialog)2