Search in sources :

Example 1 with OnShowListener

use of android.content.DialogInterface.OnShowListener in project bitcoin-wallet by bitcoin-wallet.

the class RestoreWalletFromExternalDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final View view = LayoutInflater.from(activity).inflate(R.layout.restore_wallet_from_external_dialog, null);
    passwordView = (EditText) view.findViewById(R.id.import_keys_from_content_dialog_password);
    showView = (CheckBox) view.findViewById(R.id.import_keys_from_content_dialog_show);
    replaceWarningView = view.findViewById(R.id.restore_wallet_from_content_dialog_replace_warning);
    final DialogBuilder builder = new DialogBuilder(activity);
    builder.setTitle(R.string.import_keys_dialog_title);
    builder.setView(view);
    builder.setPositiveButton(R.string.import_keys_dialog_button_import, new OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            final String password = passwordView.getText().toString().trim();
            // get rid of it asap
            passwordView.setText(null);
            handleRestore(password);
        }
    });
    builder.setNegativeButton(R.string.button_cancel, new OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            // get rid of it asap
            passwordView.setText(null);
            activity.finish();
        }
    });
    builder.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(final DialogInterface dialog) {
            // get rid of it asap
            passwordView.setText(null);
            activity.finish();
        }
    });
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(final DialogInterface d) {
            final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(passwordView, dialog) {

                @Override
                protected boolean hasFile() {
                    return true;
                }
            };
            passwordView.addTextChangedListener(dialogButtonEnabler);
            RestoreWalletFromExternalDialogFragment.this.dialog = dialog;
            updateView();
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) View(android.view.View) OnShowListener(android.content.DialogInterface.OnShowListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 2 with OnShowListener

use of android.content.DialogInterface.OnShowListener in project packages_apps_Contacts by AOKP.

the class LabeledEditorView method createCustomDialog.

/**
 * Prepare dialog for entering a custom label. The input value is trimmed: white spaces before
 * and after the input text is removed.
 * <p>
 * If the final value is empty, this change request is ignored;
 * no empty text is allowed in any custom label.
 */
private Dialog createCustomDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    final LayoutInflater layoutInflater = LayoutInflater.from(builder.getContext());
    builder.setTitle(R.string.customLabelPickerTitle);
    final View view = layoutInflater.inflate(R.layout.contact_editor_label_name_dialog, null);
    final EditText editText = (EditText) view.findViewById(R.id.custom_dialog_content);
    editText.setInputType(INPUT_TYPE_CUSTOM);
    editText.setSaveEnabled(true);
    builder.setView(view);
    editText.requestFocus();
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String customText = editText.getText().toString().trim();
            if (ContactsUtils.isGraphic(customText)) {
                final List<EditType> allTypes = RawContactModifier.getValidTypes(mState, mKind, null, true, null, true);
                mType = null;
                for (EditType editType : allTypes) {
                    if (editType.customColumn != null) {
                        mType = editType;
                        break;
                    }
                }
                if (mType == null)
                    return;
                mEntry.put(mKind.typeColumn, mType.rawValue);
                mEntry.put(mType.customColumn, customText);
                rebuildLabel();
                requestFocusForFirstEditField();
                onLabelRebuilt();
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            updateCustomDialogOkButtonState(dialog, editText);
        }
    });
    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            updateCustomDialogOkButtonState(dialog, editText);
        }
    });
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) View(android.view.View) DialogShowingView(com.android.contacts.util.DialogManager.DialogShowingView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) OnShowListener(android.content.DialogInterface.OnShowListener) EditType(com.android.contacts.common.model.account.AccountType.EditType) LayoutInflater(android.view.LayoutInflater) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) List(java.util.List)

Example 3 with OnShowListener

use of android.content.DialogInterface.OnShowListener in project Android-DialogFragments by wada811.

the class AbstractDialogFragment method setOnShowListener.

protected void setOnShowListener(Dialog dialog) {
    useOnShowListener = true;
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            bindShowListener();
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) OnShowListener(android.content.DialogInterface.OnShowListener)

Example 4 with OnShowListener

use of android.content.DialogInterface.OnShowListener in project Osmand by osmandapp.

the class IntermediatePointsDialog method applySortTargets.

private static void applySortTargets(AlertDialog dlg, final Activity activity, final List<TargetPoint> intermediates, final TIntArrayList originalPositions, final ArrayAdapter<TargetPoint> listadapter, final ProgressBar pb, final TextView textInfo) {
    dlg.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    new AsyncTask<Void, Void, int[]>() {

                        protected void onPreExecute() {
                            pb.setVisibility(View.VISIBLE);
                            textInfo.setVisibility(View.VISIBLE);
                        }

                        protected int[] doInBackground(Void[] params) {
                            OsmandApplication app = (OsmandApplication) activity.getApplication();
                            Location cll = app.getLocationProvider().getLastKnownLocation();
                            ArrayList<TargetPoint> lt = new ArrayList<TargetPoint>(intermediates);
                            TargetPoint start;
                            if (cll != null) {
                                LatLon ll = new LatLon(cll.getLatitude(), cll.getLongitude());
                                start = TargetPoint.create(ll, null);
                            } else if (app.getTargetPointsHelper().getPointToStart() != null) {
                                TargetPoint ps = app.getTargetPointsHelper().getPointToStart();
                                LatLon ll = new LatLon(ps.getLatitude(), ps.getLongitude());
                                start = TargetPoint.create(ll, null);
                            // } else if(activity instanceof MapActivity) {
                            // LatLon ll = new LatLon(((MapActivity) activity).getMapView().getLatitude(), ((MapActivity) activity).getMapView().getLongitude());
                            // start = TargetPoint.create(ll, null);
                            } else {
                                start = lt.get(0);
                            }
                            TargetPoint end = lt.remove(lt.size() - 1);
                            ArrayList<LatLon> al = new ArrayList<LatLon>();
                            for (TargetPoint p : lt) {
                                al.add(p.point);
                            }
                            return new TspAnt().readGraph(al, start.point, end.point).solve();
                        }

                        protected void onPostExecute(int[] result) {
                            pb.setVisibility(View.GONE);
                            List<TargetPoint> alocs = new ArrayList<TargetPoint>();
                            TIntArrayList newOriginalPositions = new TIntArrayList();
                            for (int i = 0; i < result.length; i++) {
                                if (result[i] > 0) {
                                    TargetPoint loc = intermediates.get(result[i] - 1);
                                    alocs.add(loc);
                                    newOriginalPositions.add(originalPositions.get(intermediates.indexOf(loc)));
                                }
                            }
                            intermediates.clear();
                            intermediates.addAll(alocs);
                            originalPositions.clear();
                            originalPositions.addAll(newOriginalPositions);
                            listadapter.notifyDataSetChanged();
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
                }
            });
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TspAnt(net.osmand.TspAnt) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OnShowListener(android.content.DialogInterface.OnShowListener) TIntArrayList(gnu.trove.list.array.TIntArrayList) LatLon(net.osmand.data.LatLon) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Location(net.osmand.Location)

Example 5 with OnShowListener

use of android.content.DialogInterface.OnShowListener 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)

Aggregations

DialogInterface (android.content.DialogInterface)13 OnShowListener (android.content.DialogInterface.OnShowListener)13 AlertDialog (android.app.AlertDialog)10 View (android.view.View)8 OnCancelListener (android.content.DialogInterface.OnCancelListener)5 EditText (android.widget.EditText)5 TextView (android.widget.TextView)5 OnClickListener (android.content.DialogInterface.OnClickListener)4 Editable (android.text.Editable)4 TextWatcher (android.text.TextWatcher)4 Dialog (android.app.Dialog)3 Context (android.content.Context)3 Handler (android.os.Handler)3 LayoutInflater (android.view.LayoutInflater)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