Search in sources :

Example 6 with OnShowListener

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

the class MaintenanceDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final View view = LayoutInflater.from(activity).inflate(R.layout.maintenance_dialog, null);
    Coin value = Coin.ZERO;
    Coin fee = Coin.ZERO;
    for (final Transaction tx : determineMaintenanceTransactions()) {
        value = value.add(tx.getValueSentFromMe(wallet));
        fee = fee.add(tx.getFee());
    }
    final TextView messageView = (TextView) view.findViewById(R.id.maintenance_dialog_message);
    final MonetaryFormat format = application.getConfiguration().getFormat();
    messageView.setText(getString(R.string.maintenance_dialog_message, format.format(value), format.format(fee)));
    passwordGroup = view.findViewById(R.id.maintenance_dialog_password_group);
    passwordView = (EditText) view.findViewById(R.id.maintenance_dialog_password);
    passwordView.setText(null);
    badPasswordView = view.findViewById(R.id.maintenance_dialog_bad_password);
    final DialogBuilder builder = new DialogBuilder(activity);
    builder.setTitle(R.string.maintenance_dialog_title);
    builder.setView(view);
    // dummies, just to make buttons show
    builder.setPositiveButton(R.string.maintenance_dialog_button_move, null);
    builder.setNegativeButton(R.string.button_dismiss, null);
    builder.setCancelable(false);
    final AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(final DialogInterface d) {
            positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
            positiveButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    log.info("user decided to do maintenance");
                    handleGo();
                }
            });
            negativeButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    log.info("user decided to dismiss");
                    dismissAllowingStateLoss();
                }
            });
            passwordView.addTextChangedListener(textWatcher);
            MaintenanceDialogFragment.this.dialog = dialog;
            updateView();
        }
    });
    log.info("showing maintenance dialog");
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) Coin(org.bitcoinj.core.Coin) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) Transaction(org.bitcoinj.core.Transaction) DialogInterface(android.content.DialogInterface) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) View(android.view.View) TextView(android.widget.TextView) OnShowListener(android.content.DialogInterface.OnShowListener)

Example 7 with OnShowListener

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

the class RaiseFeeDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final View view = LayoutInflater.from(activity).inflate(R.layout.raise_fee_dialog, null);
    messageView = (TextView) view.findViewById(R.id.raise_fee_dialog_message);
    passwordGroup = view.findViewById(R.id.raise_fee_dialog_password_group);
    passwordView = (EditText) view.findViewById(R.id.raise_fee_dialog_password);
    passwordView.setText(null);
    badPasswordView = view.findViewById(R.id.raise_fee_dialog_bad_password);
    final DialogBuilder builder = new DialogBuilder(activity);
    builder.setTitle(R.string.raise_fee_dialog_title);
    builder.setView(view);
    // dummies, just to make buttons show
    builder.setPositiveButton(R.string.raise_fee_dialog_button_raise, null);
    builder.setNegativeButton(R.string.button_dismiss, null);
    builder.setCancelable(false);
    final AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(final DialogInterface d) {
            positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
            positiveButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    handleGo();
                }
            });
            negativeButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    dismissAllowingStateLoss();
                }
            });
            passwordView.addTextChangedListener(textWatcher);
            RaiseFeeDialogFragment.this.dialog = dialog;
            updateView();
        }
    });
    log.info("showing raise fee dialog");
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.view.View.OnClickListener) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) View(android.view.View) TextView(android.widget.TextView) OnShowListener(android.content.DialogInterface.OnShowListener)

Example 8 with OnShowListener

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

the class EncryptKeysDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final View view = LayoutInflater.from(activity).inflate(R.layout.encrypt_keys_dialog, null);
    oldPasswordGroup = view.findViewById(R.id.encrypt_keys_dialog_password_old_group);
    oldPasswordView = (EditText) view.findViewById(R.id.encrypt_keys_dialog_password_old);
    oldPasswordView.setText(null);
    newPasswordView = (EditText) view.findViewById(R.id.encrypt_keys_dialog_password_new);
    newPasswordView.setText(null);
    badPasswordView = view.findViewById(R.id.encrypt_keys_dialog_bad_password);
    passwordStrengthView = (TextView) view.findViewById(R.id.encrypt_keys_dialog_password_strength);
    showView = (CheckBox) view.findViewById(R.id.encrypt_keys_dialog_show);
    final DialogBuilder builder = new DialogBuilder(activity);
    builder.setTitle(R.string.encrypt_keys_dialog_title);
    builder.setView(view);
    // dummies, just to make buttons show
    builder.setPositiveButton(R.string.button_ok, null);
    builder.setNegativeButton(R.string.button_cancel, null);
    builder.setCancelable(false);
    final AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(final DialogInterface d) {
            positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    handleGo();
                }
            });
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    dismissAllowingStateLoss();
                }
            });
            oldPasswordView.addTextChangedListener(textWatcher);
            newPasswordView.addTextChangedListener(textWatcher);
            showView = (CheckBox) dialog.findViewById(R.id.encrypt_keys_dialog_show);
            showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(newPasswordView, oldPasswordView));
            showView.setChecked(true);
            EncryptKeysDialogFragment.this.dialog = dialog;
            updateView();
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) CheckBox(android.widget.CheckBox) View(android.view.View) TextView(android.widget.TextView) OnShowListener(android.content.DialogInterface.OnShowListener)

Example 9 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 10 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)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