diff --git a/GameSDKDemo/build.gradle b/GameSDKDemo/build.gradle
index 4d9217b..dd05d23 100644
--- a/GameSDKDemo/build.gradle
+++ b/GameSDKDemo/build.gradle
@@ -36,7 +36,7 @@ repositories {
}
android {
- compileSdkVersion 27
+ compileSdkVersion 28
buildToolsVersion '28.0.3'
signingConfigs {
@@ -71,8 +71,8 @@ android {
abortOnError false
}
compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_7
- targetCompatibility JavaVersion.VERSION_1_7
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
}
applicationVariants.all {
variant ->
@@ -85,12 +85,15 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
- implementation 'com.android.support:support-v4:27.1.1'
+// implementation 'com.android.support:support-v4:27.1.1'
+ implementation 'androidx.appcompat:appcompat:1.1.0'
+ implementation 'androidx.fragment:fragment:1.1.0'
+ implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
- implementation 'com.android.support:appcompat-v7:27.1.1'
- implementation 'com.android.support:design:27.1.1'
+// implementation 'com.android.support:appcompat-v7:27.1.1'
+// implementation 'com.android.support:design:27.1.1'
// implementation project(':GameSDK')
// implementation project(':IAP5Helper')
- implementation 'com.gumptech.sdk:GameSDK:4.7.8'
-// implementation 'com.gumptech.sdk:SamsungIAP:5.1.1'
+ implementation 'com.gumptech.sdk:GameSDK:4.8.0'
+// implementation 'com.gump.game.sdk:SamsungIAP:5.1.1'
}
diff --git a/GameSDKDemo/proguard-rules.pro b/GameSDKDemo/proguard-rules.pro
index 145067f..154b80b 100644
--- a/GameSDKDemo/proguard-rules.pro
+++ b/GameSDKDemo/proguard-rules.pro
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
-# in D:\DevTools\android-com.gumptech.sdk-windows/tools/proguard/proguard-android.txt
+# in D:\DevTools\android-gump.gamee.sdk-windows/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
diff --git a/GameSDKDemo/src/androidTest/java/com/gump/game/sdk/demo/ApplicationTest.java b/GameSDKDemo/src/androidTest/java/com/gump/game/sdk/demo/ApplicationTest.java
new file mode 100644
index 0000000..6f0831e
--- /dev/null
+++ b/GameSDKDemo/src/androidTest/java/com/gump/game/sdk/demo/ApplicationTest.java
@@ -0,0 +1,13 @@
+package com.gump.game.sdk.demo;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+/**
+ * Testing Fundamentals
+ */
+public class ApplicationTest extends ApplicationTestCase {
+ public ApplicationTest() {
+ super(Application.class);
+ }
+}
\ No newline at end of file
diff --git a/GameSDKDemo/src/androidTest/java/com/gumptech/sdk/demo/ApplicationTest.java b/GameSDKDemo/src/androidTest/java/com/gumptech/sdk/demo/ApplicationTest.java
deleted file mode 100644
index 9e9221f..0000000
--- a/GameSDKDemo/src/androidTest/java/com/gumptech/sdk/demo/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gumptech.sdk.demo;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase {
- public ApplicationTest() {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/GameSDKDemo/src/main/AndroidManifest.xml b/GameSDKDemo/src/main/AndroidManifest.xml
index d201237..800f5c7 100644
--- a/GameSDKDemo/src/main/AndroidManifest.xml
+++ b/GameSDKDemo/src/main/AndroidManifest.xml
@@ -1,5 +1,5 @@
+ package="com.gump.game.sdk.demo">
@@ -17,7 +17,7 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
{
+ if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0)
+ GameSDK.login(MainActivity.this);
+ else
+ GameSDK.logout(MainActivity.this);
+ });
+ btnCheckState.setOnClickListener(v -> {
+ GameSDK.iapUsable(MainActivity.this, serverId, roleId, usable -> {
+ btnIap.setEnabled(usable);
+ btnPay.setEnabled(!usable);
+ });
+ });
+ btnPay = findViewById(R.id.pay);
+ btnPay.setOnClickListener(v -> {
+ PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.pay(MainActivity.this, payInfo, MainActivity.this));
+ submitFragment.show(getSupportFragmentManager(), "pay");
+ });
+ btnIap = findViewById(R.id.iap);
+ btnIap.setOnClickListener(v -> {
+ PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.iap(MainActivity.this, payInfo, MainActivity.this));
+ submitFragment.show(getSupportFragmentManager(), "iap");
+ });
+
+
+ Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage());
+
+ GameSDK.getSettings().setDebug(false);
+ /**
+ * 设置是否打印debug日志
+ */
+ GameSDK.getSettings().enableDebugLogging(true);
+ /**
+ * 设置启用facebook登录
+ */
+ GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB);
+
+ /**
+ * 设置启用google登录
+ */
+ GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE);
+
+ /**
+ * 设置启用Line登录
+ */
+ GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE);
+
+
+ /**
+ * 设置用户登录状态监听器
+ */
+
+ GameSDK.setUserStateListener(new LoginStateListener() {
+ @Override
+ public void onLoginSuccess(GumpUser user) {
+ btnCheckState.setEnabled(true);
+ gumpUser = user;
+ String userType = null;
+ switch (user.getAccountType()) {
+ case GumpPreference.ACCOUNT_TYPE_FB:
+ userType = "Facebook登录";
+ String fbToken = FBAccessToken.getCurrentAccessToken().getToken();
+ Log.d(TAG, "FBAccessToken:" + fbToken);
+ break;
+ case GumpPreference.ACCOUNT_TYPE_QUICK_REG:
+ userType = "快速登录";
+ break;
+ case GumpPreference.ACCOUNT_TYPE_REG:
+ userType = "gump注册用户";
+ break;
+ case GumpPreference.ACCOUNT_TYPE_GOOGLE:
+ userType = "google 登录";
+ break;
+ case GumpPreference.ACCOUNT_TYPE_LINE:
+ userType = "Line登录";
+ break;
+ }
+ userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey()
+ .getToken());
+ btnLoginOrLogout.setText("Logout");
+ btnLoginOrLogout.setTag(1);
+ }
+
+ @Override
+ public void onLoginFailed(int code, String msg) {
+ userInfo.setText(msg);
+ Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onLoginCanceled() {
+ Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onLogout() {
+ btnLoginOrLogout.setText("Login");
+ btnLoginOrLogout.setTag(0);
+ userInfo.setText("User is logout");
+ }
+
+ @Override
+ public void onPermissionDenied(String[] deniedPermissions) {
+ StringBuilder sb = new StringBuilder();
+ for (String s : deniedPermissions) {
+ sb.append(s);
+ sb.append(",");
+ }
+ Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show();
+ }
+ });
+ /**
+ * 初始化sdk
+ */
+ GameSDK.init(getApplicationContext(), appId);
+
+ tvVersion.setText("SDK Version:" + GameSDK.getVersion());
+
+ }
+
+ private void checkRisk() {
+ GameSDK.inspectRiskLevel(this, isRisk -> Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk"));
+ }
+
+ @Override
+ public void onPurchaseCompleted() {
+ Log.i(TAG, "purchase completed");
+ }
+
+ @Override
+ public void onPurchaseError(int code, String msg) {
+ Log.i(TAG, "purchase error:"+code+","+msg);
+ }
+
+ @Override
+ public void onPurchaseCanceled() {
+ Log.i(TAG, "purchase canceled");
+ }
+
+
+}
diff --git a/GameSDKDemo/src/main/java/com/gump/game/sdk/demo/PaymentInfoSubmitFragment.java b/GameSDKDemo/src/main/java/com/gump/game/sdk/demo/PaymentInfoSubmitFragment.java
new file mode 100644
index 0000000..e4a6d40
--- /dev/null
+++ b/GameSDKDemo/src/main/java/com/gump/game/sdk/demo/PaymentInfoSubmitFragment.java
@@ -0,0 +1,142 @@
+package com.gump.game.sdk.demo;
+
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import com.google.android.material.textfield.TextInputLayout;
+
+import androidx.annotation.NonNull;
+import androidx.fragment.app.DialogFragment;
+
+
+public class PaymentInfoSubmitFragment extends DialogFragment {
+
+ interface OnSubmitListener {
+ void onSubmit(Bundle payInfo);
+ }
+
+ private OnSubmitListener listener;
+
+ TextInputLayout etProduct,
+ etAmount,
+ etCurrency,
+ etServerId,
+ etRoleId,
+ etExtra;
+
+
+
+ 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");
+ 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);
+ }
+ dismiss();
+ }
+ });
+ 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) {
+
+ }
+ }
+}
diff --git a/GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java b/GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
deleted file mode 100644
index df67cb5..0000000
--- a/GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
+++ /dev/null
@@ -1,266 +0,0 @@
-package com.gumptech.sdk.demo;
-
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.gumptech.sdk.GumpPreference;
-import com.gumptech.sdk.GumpSDK;
-import com.gumptech.sdk.PaymentVersion;
-import com.gumptech.sdk.SDKSettings;
-import com.gumptech.sdk.bean.GumpUser;
-import com.gumptech.sdk.bean.PurchaseResult;
-import com.gumptech.sdk.callback.InitializeCallback;
-import com.gumptech.sdk.callback.LoginStateListener;
-import com.gumptech.sdk.callback.PurchaseCallback;
-import com.gumptech.sdk.callback.ResultCallback;
-import com.gumptech.sdk.passport.fb.FBAccessToken;
-
-import java.util.Locale;
-
-public class MainActivity extends AppCompatActivity implements PurchaseCallback {
-
- private static final String TAG = "MainActivity";
-
- private TextView tvVersion;
- private TextView userInfo;
-
- private Button btnLoginOrLogout;
- private Button btnInit;
- private Button btnCheckState;
- private Button btnPay;
- private Button btnIap;
-
- private String appId = "100";
- private String appKey = "f899139df5e1059396431415e770c6dd";
- private GumpUser gumpUser;
-
- /**
- * 测试数据
- */
- String serverId = "100";
- String roleId = "41080";
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- tvVersion = findViewById(R.id.version);
- userInfo = findViewById(R.id.user_info);
- btnLoginOrLogout = findViewById(R.id.login_or_logout);
- btnInit = findViewById(R.id.init);
- btnCheckState = findViewById(R.id.check_state);
- btnLoginOrLogout.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0)
- GumpSDK.start(MainActivity.this);
- else
- GumpSDK.logout(MainActivity.this);
- }
- });
- btnInit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- btnInit.setEnabled(false);
- GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() {
- @Override
- public void initComplete(int result) {
- if (result == GumpSDK.CODE.OK) {
- btnLoginOrLogout.setEnabled(true);
- userInfo.setText("initialization has finished");
- } else {
- btnInit.setEnabled(true);
- userInfo.setText("initialization has error");
- }
- }
- });
- }
- });
- btnCheckState.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-// btnCheckState.setEnabled(false);
- GumpSDK.shouldUseCoPay(MainActivity.this, serverId, roleId, new ResultCallback() {
- @Override
- public void onResult(boolean isRisk) {
- btnIap.setEnabled(isRisk);
- btnPay.setEnabled(isRisk);
- }
- });
- }
- });
- btnPay = findViewById(R.id.pay);
- btnPay.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() {
- @Override
- public void onSubmit(Bundle payInfo) {
- GumpSDK.pay(MainActivity.this, payInfo, MainActivity.this);
- }
- });
- submitFragment.show(getSupportFragmentManager(), "pay");
- }
- });
- btnIap = findViewById(R.id.iap);
- btnIap.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() {
- @Override
- public void onSubmit(Bundle payInfo) {
- GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this);
- }
- });
- submitFragment.show(getSupportFragmentManager(), "iap");
- }
- });
-
-
- Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage());
-
- GumpSDK.getSettings().setDebug(false);
- /**
- * 设置是否打印debug日志
- */
- GumpSDK.getSettings().enableDebugLogging(true);
- /**
- * 设置启用facebook登录
- */
- GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB);
-
- /**
- * 设置启用google登录
- */
- GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE);
-
- /**
- * 设置启用Line登录
- */
- GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE);
-
- /**
- * 设置支付版本
- */
- GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4);
-
- /**
- * 设置用户登录状态监听器
- */
-
- GumpSDK.setUserStateListener(new LoginStateListener() {
- @Override
- public void onLoginSuccess(GumpUser user) {
- btnCheckState.setEnabled(true);
- gumpUser = user;
- String userType = null;
- switch (user.getAccountType()) {
- case GumpPreference.ACCOUNT_TYPE_FB:
- userType = "Facebook登录";
- String fbToken = FBAccessToken.getCurrentAccessToken().getToken();
- Log.d(TAG, "FBAccessToken:" + fbToken);
- break;
- case GumpPreference.ACCOUNT_TYPE_QUICK_REG:
- userType = "快速登录";
- break;
- case GumpPreference.ACCOUNT_TYPE_REG:
- userType = "gump注册用户";
- break;
- case GumpPreference.ACCOUNT_TYPE_GOOGLE:
- userType = "google 登录";
- break;
- case GumpPreference.ACCOUNT_TYPE_LINE:
- userType = "Line登录";
- break;
- }
- userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey()
- .getToken());
- btnLoginOrLogout.setText("Logout");
- btnLoginOrLogout.setTag(1);
- }
-
- @Override
- public void onLoginFailed(int code, String msg) {
- userInfo.setText(msg);
- Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onLoginCanceled() {
- Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onLogout() {
- btnLoginOrLogout.setText("Login");
- btnLoginOrLogout.setTag(0);
- userInfo.setText("User is logout");
- }
-
- @Override
- public void onPermissionDenied(String[] deniedPermissions) {
- StringBuilder sb = new StringBuilder();
- for (String s : deniedPermissions) {
- sb.append(s);
- sb.append(",");
- }
- Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show();
- }
- });
- /**
- * 初始化sdk
- */
- GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() {
- @Override
- public void initComplete(int result) {
- if (result == GumpSDK.CODE.OK) {
- btnLoginOrLogout.setEnabled(true);
- userInfo.setText("initialization has finished");
-
- //checkRisk();
- } else {
- btnInit.setEnabled(true);
- userInfo.setText("initialization has error");
- }
- }
- });
-
- tvVersion.setText("SDK Version:" + GumpSDK.getVersion());
-
- }
-
- private void checkRisk() {
- GumpSDK.checkRisk(this, new ResultCallback() {
- @Override
- public void onResult(boolean isRisk) {
- Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk");
- }
- });
- }
-
- @Override
- public void onPurchaseCompleted(PurchaseResult result) {
- Log.i(TAG, "purchase completed");
- }
-
- @Override
- public void onPurchaseError(int code, String msg) {
- Log.i(TAG, "purchase error:"+code+","+msg);
- }
-
- @Override
- public void onPurchaseCanceled() {
- Log.i(TAG, "purchase canceled");
- }
-
-
-}
diff --git a/GameSDKDemo/src/main/java/com/gumptech/sdk/demo/PaymentInfoSubmitFragment.java b/GameSDKDemo/src/main/java/com/gumptech/sdk/demo/PaymentInfoSubmitFragment.java
deleted file mode 100644
index ab05d43..0000000
--- a/GameSDKDemo/src/main/java/com/gumptech/sdk/demo/PaymentInfoSubmitFragment.java
+++ /dev/null
@@ -1,144 +0,0 @@
-package com.gumptech.sdk.demo;
-
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.design.widget.TextInputLayout;
-import android.support.v4.app.DialogFragment;
-import android.text.Editable;
-import android.text.TextUtils;
-import android.text.TextWatcher;
-import android.view.LayoutInflater;
-import android.view.View;
-
-
-
-public class PaymentInfoSubmitFragment extends DialogFragment {
-
- interface OnSubmitListener {
- void onSubmit(Bundle payInfo);
- }
-
- private OnSubmitListener listener;
-
- TextInputLayout etProduct,
- etAmount,
- etCurrency,
- etServerId,
- etRoleId,
- etExtra;
-
-
-
- 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");
- view.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View 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);
- }
- dismiss();
- }
- }
- });
- 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) {
-
- }
- }
-}
diff --git a/GameSDKDemo/src/main/res/layout/activity_main.xml b/GameSDKDemo/src/main/res/layout/activity_main.xml
index 98ec4a6..8e6ac43 100644
--- a/GameSDKDemo/src/main/res/layout/activity_main.xml
+++ b/GameSDKDemo/src/main/res/layout/activity_main.xml
@@ -19,19 +19,10 @@
android:textColor="@android:color/black"/>
-
-