Blame view
GameSDKDemo/src/main/java/com/gump/game/sdk/demo/PaymentInfoSubmitFragment.java
4.98 KB
e877dd7d0
![]() |
1 |
package com.gump.game.sdk.demo; |
4a6edc661
![]() |
2 3 4 5 6 |
import android.app.AlertDialog; import android.app.Dialog; import android.os.Bundle; |
4a6edc661
![]() |
7 8 9 10 11 |
import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; |
e877dd7d0
![]() |
12 13 14 15 |
import com.google.android.material.textfield.TextInputLayout; import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; |
4a6edc661
![]() |
16 |
|
7b52014d1
![]() |
17 |
|
4a6edc661
![]() |
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
public class PaymentInfoSubmitFragment extends DialogFragment { interface OnSubmitListener { void onSubmit(Bundle payInfo); } private OnSubmitListener listener; TextInputLayout etProduct, etAmount, etCurrency, etServerId, etRoleId, etExtra; |
4a6edc661
![]() |
32 |
|
4a6edc661
![]() |
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
public static PaymentInfoSubmitFragment newInstance(OnSubmitListener listener) { PaymentInfoSubmitFragment fragment = new PaymentInfoSubmitFragment(); fragment.listener = listener; return fragment; } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_payment, null, false); etProduct = view.findViewById(R.id.product); etAmount = view.findViewById(R.id.amount); etCurrency = view.findViewById(R.id.currency); etServerId = view.findViewById(R.id.server_id); etRoleId = view.findViewById(R.id.role_id); etExtra = view.findViewById(R.id.extra); etProduct.getEditText().addTextChangedListener(new EditTextWatcher(etProduct)); etAmount.getEditText().addTextChangedListener(new EditTextWatcher(etAmount)); etCurrency.getEditText().addTextChangedListener(new EditTextWatcher(etCurrency)); etServerId.getEditText().addTextChangedListener(new EditTextWatcher(etServerId)); etRoleId.getEditText().addTextChangedListener(new EditTextWatcher(etRoleId)); etExtra.getEditText().addTextChangedListener(new EditTextWatcher(etExtra)); //设置默认值 etProduct.getEditText().setText("EV1.test.abc"); etAmount.getEditText().setText("0.99"); etCurrency.getEditText().setText("USD"); etServerId.getEditText().setText("100"); etRoleId.getEditText().setText("41080"); |
e877dd7d0
![]() |
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
view.findViewById(R.id.submit).setOnClickListener(v -> { String product = etProduct.getEditText().getText().toString(); String currency = etCurrency.getEditText().getText().toString(); String serverId = etServerId.getEditText().getText().toString(); String roleId = etRoleId.getEditText().getText().toString(); String extra = etExtra.getEditText().getText().toString(); String amount = etAmount.getEditText().getText().toString(); if (checkInput(product, amount, currency, serverId, roleId, extra)) { Bundle payInfo = new Bundle(); payInfo.putString("product", product); payInfo.putFloat("amount", Float.valueOf(amount)); payInfo.putString("extraInfo", extra); payInfo.putString("serverId", serverId); payInfo.putString("roleId", roleId); payInfo.putString("currency", currency); if (listener != null) { listener.onSubmit(payInfo); |
4a6edc661
![]() |
80 |
} |
e877dd7d0
![]() |
81 |
dismiss(); |
4a6edc661
![]() |
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
} }); AlertDialog dialog = builder.setView(view).create(); return dialog; } private boolean checkInput(String product, String amount, String currency, String serverId, String roleId, String extra) { if (TextUtils.isEmpty(product)) { etProduct.setError("product is empty"); return false; } if (TextUtils.isEmpty(currency)) { etCurrency.setError("currency is empty"); return false; } if (TextUtils.isEmpty(serverId)) { etServerId.setError("serverId is empty"); return false; } if (TextUtils.isEmpty(roleId)) { etRoleId.setError("roleId is empty"); return false; } if (TextUtils.isEmpty(extra)) { etExtra.setError("extra is empty"); return false; } if (TextUtils.isEmpty(amount)) { etAmount.setError("amount is empty"); return false; } return true; } class EditTextWatcher implements TextWatcher { private TextInputLayout editText; public EditTextWatcher(TextInputLayout editText) { this.editText = editText; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { editText.setError(null); } @Override public void afterTextChanged(Editable s) { } } } |