Commit e877dd7d0274d46936c3cb5a3b94cfbfd0408799
1 parent
1f96df5c37
Exists in
master
重构版本4.8.0\
Showing 14 changed files with 430 additions and 519 deletions Inline Diff
- GameSDKDemo/build.gradle
- GameSDKDemo/proguard-rules.pro
- GameSDKDemo/src/androidTest/java/com/gump/game/sdk/demo/ApplicationTest.java
- GameSDKDemo/src/androidTest/java/com/gumptech/sdk/demo/ApplicationTest.java
- GameSDKDemo/src/main/AndroidManifest.xml
- GameSDKDemo/src/main/java/com/gump/game/sdk/demo/MainActivity.java
- GameSDKDemo/src/main/java/com/gump/game/sdk/demo/PaymentInfoSubmitFragment.java
- GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
- GameSDKDemo/src/main/java/com/gumptech/sdk/demo/PaymentInfoSubmitFragment.java
- GameSDKDemo/src/main/res/layout/activity_main.xml
- GameSDKDemo/src/main/res/layout/fragment_payment.xml
- GameSDKDemo/src/test/java/com/gump/game/sdk/demo/ExampleUnitTest.java
- GameSDKDemo/src/test/java/com/gumptech/sdk/demo/ExampleUnitTest.java
- README.md
GameSDKDemo/build.gradle
1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
2 | 2 | ||
3 | /*The config for internal testing,you could ignore it | 3 | /*The config for internal testing,you could ignore it |
4 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 | 4 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 |
5 | * --start-- | 5 | * --start-- |
6 | */ | 6 | */ |
7 | def keystorePSW = '' | 7 | def keystorePSW = '' |
8 | def keystoreAlias = '' | 8 | def keystoreAlias = '' |
9 | def keystoreAliasPSW = '' | 9 | def keystoreAliasPSW = '' |
10 | // default keystore file, PLZ config file path in local.properties | 10 | // default keystore file, PLZ config file path in local.properties |
11 | def keyfile = file('s.keystore.temp') | 11 | def keyfile = file('s.keystore.temp') |
12 | 12 | ||
13 | Properties properties = new Properties() | 13 | Properties properties = new Properties() |
14 | // local.properties file in the root director | 14 | // local.properties file in the root director |
15 | properties.load(project.file('local.properties').newDataInputStream()) | 15 | properties.load(project.file('local.properties').newDataInputStream()) |
16 | def keystoreFilepath = properties.getProperty("keystore.path") | 16 | def keystoreFilepath = properties.getProperty("keystore.path") |
17 | 17 | ||
18 | if (keystoreFilepath) { | 18 | if (keystoreFilepath) { |
19 | keystorePSW = properties.getProperty("keystore.password") | 19 | keystorePSW = properties.getProperty("keystore.password") |
20 | keystoreAlias = properties.getProperty("keystore.alias") | 20 | keystoreAlias = properties.getProperty("keystore.alias") |
21 | keystoreAliasPSW = properties.getProperty("keystore.key_passwd") | 21 | keystoreAliasPSW = properties.getProperty("keystore.key_passwd") |
22 | keyfile = file(keystoreFilepath) | 22 | keyfile = file(keystoreFilepath) |
23 | } | 23 | } |
24 | /* | 24 | /* |
25 | * The config for internal testing,you could ignore it | 25 | * The config for internal testing,you could ignore it |
26 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 | 26 | * gump内部测试使用,你可以自行配置,或者直接删除这部分内容 |
27 | * --end-- | 27 | * --end-- |
28 | */ | 28 | */ |
29 | 29 | ||
30 | repositories { | 30 | repositories { |
31 | maven { | 31 | maven { |
32 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" | 32 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" |
33 | } | 33 | } |
34 | jcenter() | 34 | jcenter() |
35 | google() | 35 | google() |
36 | } | 36 | } |
37 | 37 | ||
38 | android { | 38 | android { |
39 | compileSdkVersion 27 | 39 | compileSdkVersion 28 |
40 | buildToolsVersion '28.0.3' | 40 | buildToolsVersion '28.0.3' |
41 | 41 | ||
42 | signingConfigs { | 42 | signingConfigs { |
43 | release { | 43 | release { |
44 | storeFile keyfile | 44 | storeFile keyfile |
45 | storePassword keystorePSW | 45 | storePassword keystorePSW |
46 | keyPassword keystoreAliasPSW | 46 | keyPassword keystoreAliasPSW |
47 | keyAlias keystoreAlias | 47 | keyAlias keystoreAlias |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | defaultConfig { | 51 | defaultConfig { |
52 | minSdkVersion 14 | 52 | minSdkVersion 14 |
53 | targetSdkVersion 27 | 53 | targetSdkVersion 27 |
54 | applicationId "mx.she.rd4" | 54 | applicationId "mx.she.rd4" |
55 | versionCode 6 | 55 | versionCode 6 |
56 | versionName "1.4" | 56 | versionName "1.4" |
57 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | 57 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
58 | signingConfig signingConfigs.release | 58 | signingConfig signingConfigs.release |
59 | } | 59 | } |
60 | buildTypes { | 60 | buildTypes { |
61 | release { | 61 | release { |
62 | minifyEnabled false | 62 | minifyEnabled false |
63 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | 63 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
64 | zipAlignEnabled true | 64 | zipAlignEnabled true |
65 | } | 65 | } |
66 | debug { | 66 | debug { |
67 | signingConfig signingConfigs.release | 67 | signingConfig signingConfigs.release |
68 | } | 68 | } |
69 | } | 69 | } |
70 | lintOptions { | 70 | lintOptions { |
71 | abortOnError false | 71 | abortOnError false |
72 | } | 72 | } |
73 | compileOptions { | 73 | compileOptions { |
74 | sourceCompatibility JavaVersion.VERSION_1_7 | 74 | sourceCompatibility JavaVersion.VERSION_1_8 |
75 | targetCompatibility JavaVersion.VERSION_1_7 | 75 | targetCompatibility JavaVersion.VERSION_1_8 |
76 | } | 76 | } |
77 | applicationVariants.all { | 77 | applicationVariants.all { |
78 | variant -> | 78 | variant -> |
79 | variant.outputs.all { | 79 | variant.outputs.all { |
80 | outputFileName = "GameSDKDemo-" + variant.name + defaultConfig.versionName + ".apk" | 80 | outputFileName = "GameSDKDemo-" + variant.name + defaultConfig.versionName + ".apk" |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | } | 84 | } |
85 | 85 | ||
86 | dependencies { | 86 | dependencies { |
87 | implementation fileTree(include: ['*.jar'], dir: 'libs') | 87 | implementation fileTree(include: ['*.jar'], dir: 'libs') |
88 | implementation 'com.android.support:support-v4:27.1.1' | 88 | // implementation 'com.android.support:support-v4:27.1.1' |
89 | implementation 'androidx.appcompat:appcompat:1.1.0' | ||
90 | implementation 'androidx.fragment:fragment:1.1.0' | ||
91 | implementation 'com.google.android.material:material:1.0.0' | ||
89 | testImplementation 'junit:junit:4.12' | 92 | testImplementation 'junit:junit:4.12' |
90 | implementation 'com.android.support:appcompat-v7:27.1.1' | 93 | // implementation 'com.android.support:appcompat-v7:27.1.1' |
91 | implementation 'com.android.support:design:27.1.1' | 94 | // implementation 'com.android.support:design:27.1.1' |
92 | // implementation project(':GameSDK') | 95 | // implementation project(':GameSDK') |
93 | // implementation project(':IAP5Helper') | 96 | // implementation project(':IAP5Helper') |
94 | implementation 'com.gumptech.sdk:GameSDK:4.7.8' | 97 | implementation 'com.gumptech.sdk:GameSDK:4.8.0' |
95 | // implementation 'com.gumptech.sdk:SamsungIAP:5.1.1' | 98 | // implementation 'com.gump.game.sdk:SamsungIAP:5.1.1' |
96 | } | 99 | } |
97 | 100 |
GameSDKDemo/proguard-rules.pro
1 | # Add project specific ProGuard rules here. | 1 | # Add project specific ProGuard rules here. |
2 | # By default, the flags in this file are appended to flags specified | 2 | # By default, the flags in this file are appended to flags specified |
3 | # in D:\DevTools\android-com.gumptech.sdk-windows/tools/proguard/proguard-android.txt | 3 | # in D:\DevTools\android-gump.gamee.sdk-windows/tools/proguard/proguard-android.txt |
4 | # You can edit the include path and order by changing the proguardFiles | 4 | # You can edit the include path and order by changing the proguardFiles |
5 | # directive in build.gradle. | 5 | # directive in build.gradle. |
6 | # | 6 | # |
7 | # For more details, see | 7 | # For more details, see |
8 | # http://developer.android.com/guide/developing/tools/proguard.html | 8 | # http://developer.android.com/guide/developing/tools/proguard.html |
9 | 9 | ||
10 | # Add any project specific keep options here: | 10 | # Add any project specific keep options here: |
11 | 11 | ||
12 | # If your project uses WebView with JS, uncomment the following | 12 | # If your project uses WebView with JS, uncomment the following |
13 | # and specify the fully qualified class name to the JavaScript interface | 13 | # and specify the fully qualified class name to the JavaScript interface |
14 | # class: | 14 | # class: |
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { |
16 | # public *; | 16 | # public *; |
17 | #} | 17 | #} |
18 | 18 |
GameSDKDemo/src/androidTest/java/com/gump/game/sdk/demo/ApplicationTest.java
File was created | 1 | package com.gump.game.sdk.demo; | |
2 | |||
3 | import android.app.Application; | ||
4 | import android.test.ApplicationTestCase; | ||
5 | |||
6 | /** | ||
7 | * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
8 | */ | ||
9 | public class ApplicationTest extends ApplicationTestCase<Application> { | ||
10 | public ApplicationTest() { | ||
11 | super(Application.class); | ||
12 | } | ||
13 | } |
GameSDKDemo/src/androidTest/java/com/gumptech/sdk/demo/ApplicationTest.java
1 | package com.gumptech.sdk.demo; | File was deleted | |
2 | |||
3 | import android.app.Application; | ||
4 | import android.test.ApplicationTestCase; | ||
5 | |||
6 | /** | ||
7 | * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
8 | */ | ||
9 | public class ApplicationTest extends ApplicationTestCase<Application> { | ||
10 | public ApplicationTest() { | ||
11 | super(Application.class); | ||
12 | } | ||
13 | } |
GameSDKDemo/src/main/AndroidManifest.xml
1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 1 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
2 | package="com.gumptech.sdk.demo"> | 2 | package="com.gump.game.sdk.demo"> |
3 | 3 | ||
4 | 4 | ||
5 | <uses-permission android:name="android.permission.INTERNET"/> | 5 | <uses-permission android:name="android.permission.INTERNET"/> |
6 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | 6 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> |
7 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 7 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
8 | <!-- Danger Level permission--> | 8 | <!-- Danger Level permission--> |
9 | 9 | ||
10 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | 10 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> |
11 | <uses-permission android:name="com.android.vending.BILLING"/> | 11 | <uses-permission android:name="com.android.vending.BILLING"/> |
12 | <!--samgung iap need this permission--> | 12 | <!--samgung iap need this permission--> |
13 | <uses-permission android:name="com.samsung.android.iap.permission.BILLING"/> | 13 | <uses-permission android:name="com.samsung.android.iap.permission.BILLING"/> |
14 | 14 | ||
15 | <application | 15 | <application |
16 | android:allowBackup="true" | 16 | android:allowBackup="true" |
17 | android:icon="@drawable/ic_launcher" | 17 | android:icon="@drawable/ic_launcher" |
18 | android:label="@string/app_name"> | 18 | android:label="@string/app_name"> |
19 | <activity | 19 | <activity |
20 | android:name="com.gumptech.sdk.demo.MainActivity" | 20 | android:name="com.gump.game.sdk.demo.MainActivity" |
21 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 21 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
22 | android:label="@string/app_name" | 22 | android:label="@string/app_name" |
23 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" | 23 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" |
24 | android:screenOrientation="portrait"> | 24 | android:screenOrientation="portrait"> |
25 | <intent-filter> | 25 | <intent-filter> |
26 | <action android:name="android.intent.action.MAIN"/> | 26 | <action android:name="android.intent.action.MAIN"/> |
27 | 27 | ||
28 | <category android:name="android.intent.category.LAUNCHER"/> | 28 | <category android:name="android.intent.category.LAUNCHER"/> |
29 | </intent-filter> | 29 | </intent-filter> |
30 | </activity> | 30 | </activity> |
31 | <activity | 31 | <activity |
32 | android:name="com.gumptech.sdk.ContainerActivity" | 32 | android:name="com.gump.game.sdk.PassportActivity" |
33 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 33 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
34 | android:launchMode="singleTask" | 34 | android:launchMode="singleTask" |
35 | android:theme="@style/Theme.Orange" | 35 | android:theme="@style/Theme.Pink" |
36 | android:screenOrientation="behind" | 36 | android:screenOrientation="behind" |
37 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> | 37 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> |
38 | </activity> | 38 | </activity> |
39 | <activity | 39 | <activity |
40 | android:name="com.gumptech.sdk.PaymentActivity" | 40 | android:name="com.gump.game.sdk.RechargeActivity" |
41 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 41 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
42 | android:launchMode="singleTask" | 42 | android:launchMode="singleTask" |
43 | android:screenOrientation="behind" | 43 | android:screenOrientation="behind" |
44 | android:theme="@style/Theme.Translucent"> | 44 | android:theme="@style/Theme.Translucent"> |
45 | <intent-filter> | 45 | <intent-filter> |
46 | <category android:name="android.intent.category.DEFAULT"/> | 46 | <category android:name="android.intent.category.DEFAULT"/> |
47 | 47 | ||
48 | <action android:name="android.intent.action.VIEW"/> | 48 | <action android:name="android.intent.action.VIEW"/> |
49 | 49 | ||
50 | <category android:name="android.intent.category.BROWSABLE"/> | 50 | <category android:name="android.intent.category.BROWSABLE"/> |
51 | 51 | ||
52 | <data | 52 | <data |
53 | android:host="com.gump.sdk" | 53 | android:host="com.gump.sdk" |
54 | android:scheme="gump100"/> | 54 | android:scheme="gump100"/> |
55 | </intent-filter> | 55 | </intent-filter> |
56 | </activity> | 56 | </activity> |
57 | 57 | ||
58 | </application> | 58 | </application> |
59 | 59 | ||
60 | 60 | ||
61 | </manifest> | 61 | </manifest> |
62 | 62 |
GameSDKDemo/src/main/java/com/gump/game/sdk/demo/MainActivity.java
File was created | 1 | package com.gump.game.sdk.demo; | |
2 | |||
3 | import android.os.Bundle; | ||
4 | import android.util.Log; | ||
5 | import android.widget.Button; | ||
6 | import android.widget.TextView; | ||
7 | import android.widget.Toast; | ||
8 | |||
9 | import com.gump.game.sdk.GameSDK; | ||
10 | import com.gump.game.sdk.GumpPreference; | ||
11 | import com.gump.game.sdk.SDKSettings; | ||
12 | import com.gump.game.sdk.bean.GumpUser; | ||
13 | import com.gump.game.sdk.callback.LoginStateListener; | ||
14 | import com.gump.game.sdk.callback.RechargeCallback; | ||
15 | import com.gump.game.sdk.passport.fb.FBAccessToken; | ||
16 | |||
17 | import java.util.Locale; | ||
18 | |||
19 | import androidx.appcompat.app.AppCompatActivity; | ||
20 | |||
21 | public class MainActivity extends AppCompatActivity implements RechargeCallback { | ||
22 | |||
23 | private static final String TAG = "MainActivity"; | ||
24 | |||
25 | private TextView tvVersion; | ||
26 | private TextView userInfo; | ||
27 | |||
28 | private Button btnLoginOrLogout; | ||
29 | private Button btnCheckState; | ||
30 | private Button btnPay; | ||
31 | private Button btnIap; | ||
32 | |||
33 | private String appId = "100"; | ||
34 | private String appKey = "f899139df5e1059396431415e770c6dd"; | ||
35 | private GumpUser gumpUser; | ||
36 | |||
37 | /** | ||
38 | * 测试数据 | ||
39 | */ | ||
40 | String serverId = "100"; | ||
41 | String roleId = "41080"; | ||
42 | |||
43 | |||
44 | @Override | ||
45 | protected void onCreate(Bundle savedInstanceState) { | ||
46 | super.onCreate(savedInstanceState); | ||
47 | setContentView(R.layout.activity_main); | ||
48 | |||
49 | tvVersion = findViewById(R.id.version); | ||
50 | userInfo = findViewById(R.id.user_info); | ||
51 | btnLoginOrLogout = findViewById(R.id.login_or_logout); | ||
52 | btnCheckState = findViewById(R.id.check_state); | ||
53 | btnLoginOrLogout.setOnClickListener(v -> { | ||
54 | if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0) | ||
55 | GameSDK.login(MainActivity.this); | ||
56 | else | ||
57 | GameSDK.logout(MainActivity.this); | ||
58 | }); | ||
59 | btnCheckState.setOnClickListener(v -> { | ||
60 | GameSDK.iapUsable(MainActivity.this, serverId, roleId, usable -> { | ||
61 | btnIap.setEnabled(usable); | ||
62 | btnPay.setEnabled(!usable); | ||
63 | }); | ||
64 | }); | ||
65 | btnPay = findViewById(R.id.pay); | ||
66 | btnPay.setOnClickListener(v -> { | ||
67 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.pay(MainActivity.this, payInfo, MainActivity.this)); | ||
68 | submitFragment.show(getSupportFragmentManager(), "pay"); | ||
69 | }); | ||
70 | btnIap = findViewById(R.id.iap); | ||
71 | btnIap.setOnClickListener(v -> { | ||
72 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(payInfo -> GameSDK.iap(MainActivity.this, payInfo, MainActivity.this)); | ||
73 | submitFragment.show(getSupportFragmentManager(), "iap"); | ||
74 | }); | ||
75 | |||
76 | |||
77 | Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); | ||
78 | |||
79 | GameSDK.getSettings().setDebug(false); | ||
80 | /** | ||
81 | * 设置是否打印debug日志 | ||
82 | */ | ||
83 | GameSDK.getSettings().enableDebugLogging(true); | ||
84 | /** | ||
85 | * 设置启用facebook登录 | ||
86 | */ | ||
87 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); | ||
88 | |||
89 | /** | ||
90 | * 设置启用google登录 | ||
91 | */ | ||
92 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); | ||
93 | |||
94 | /** | ||
95 | * 设置启用Line登录 | ||
96 | */ | ||
97 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); | ||
98 | |||
99 | |||
100 | /** | ||
101 | * 设置用户登录状态监听器 | ||
102 | */ | ||
103 | |||
104 | GameSDK.setUserStateListener(new LoginStateListener() { | ||
105 | @Override | ||
106 | public void onLoginSuccess(GumpUser user) { | ||
107 | btnCheckState.setEnabled(true); | ||
108 | gumpUser = user; | ||
109 | String userType = null; | ||
110 | switch (user.getAccountType()) { | ||
111 | case GumpPreference.ACCOUNT_TYPE_FB: | ||
112 | userType = "Facebook登录"; | ||
113 | String fbToken = FBAccessToken.getCurrentAccessToken().getToken(); | ||
114 | Log.d(TAG, "FBAccessToken:" + fbToken); | ||
115 | break; | ||
116 | case GumpPreference.ACCOUNT_TYPE_QUICK_REG: | ||
117 | userType = "快速登录"; | ||
118 | break; | ||
119 | case GumpPreference.ACCOUNT_TYPE_REG: | ||
120 | userType = "gump注册用户"; | ||
121 | break; | ||
122 | case GumpPreference.ACCOUNT_TYPE_GOOGLE: | ||
123 | userType = "google 登录"; | ||
124 | break; | ||
125 | case GumpPreference.ACCOUNT_TYPE_LINE: | ||
126 | userType = "Line登录"; | ||
127 | break; | ||
128 | } | ||
129 | userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey() | ||
130 | .getToken()); | ||
131 | btnLoginOrLogout.setText("Logout"); | ||
132 | btnLoginOrLogout.setTag(1); | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public void onLoginFailed(int code, String msg) { | ||
137 | userInfo.setText(msg); | ||
138 | Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); | ||
139 | } | ||
140 | |||
141 | @Override | ||
142 | public void onLoginCanceled() { | ||
143 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | ||
144 | } | ||
145 | |||
146 | @Override | ||
147 | public void onLogout() { | ||
148 | btnLoginOrLogout.setText("Login"); | ||
149 | btnLoginOrLogout.setTag(0); | ||
150 | userInfo.setText("User is logout"); | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public void onPermissionDenied(String[] deniedPermissions) { | ||
155 | StringBuilder sb = new StringBuilder(); | ||
156 | for (String s : deniedPermissions) { | ||
157 | sb.append(s); | ||
158 | sb.append(","); | ||
159 | } | ||
160 | Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show(); | ||
161 | } | ||
162 | }); | ||
163 | /** | ||
164 | * 初始化sdk | ||
165 | */ | ||
166 | GameSDK.init(getApplicationContext(), appId); | ||
167 | |||
168 | tvVersion.setText("SDK Version:" + GameSDK.getVersion()); | ||
169 | |||
170 | } | ||
171 | |||
172 | private void checkRisk() { | ||
173 | GameSDK.inspectRiskLevel(this, isRisk -> Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk")); | ||
174 | } | ||
175 | |||
176 | @Override | ||
177 | public void onPurchaseCompleted() { | ||
178 | Log.i(TAG, "purchase completed"); | ||
179 | } | ||
180 | |||
181 | @Override | ||
182 | public void onPurchaseError(int code, String msg) { | ||
183 | Log.i(TAG, "purchase error:"+code+","+msg); | ||
184 | } | ||
185 | |||
186 | @Override | ||
187 | public void onPurchaseCanceled() { | ||
188 | Log.i(TAG, "purchase canceled"); | ||
189 | } | ||
190 | |||
191 | |||
192 | } | ||
193 |
GameSDKDemo/src/main/java/com/gump/game/sdk/demo/PaymentInfoSubmitFragment.java
File was created | 1 | package com.gump.game.sdk.demo; | |
2 | |||
3 | |||
4 | import android.app.AlertDialog; | ||
5 | import android.app.Dialog; | ||
6 | import android.os.Bundle; | ||
7 | import android.text.Editable; | ||
8 | import android.text.TextUtils; | ||
9 | import android.text.TextWatcher; | ||
10 | import android.view.LayoutInflater; | ||
11 | import android.view.View; | ||
12 | |||
13 | import com.google.android.material.textfield.TextInputLayout; | ||
14 | |||
15 | import androidx.annotation.NonNull; | ||
16 | import androidx.fragment.app.DialogFragment; | ||
17 | |||
18 | |||
19 | public class PaymentInfoSubmitFragment extends DialogFragment { | ||
20 | |||
21 | interface OnSubmitListener { | ||
22 | void onSubmit(Bundle payInfo); | ||
23 | } | ||
24 | |||
25 | private OnSubmitListener listener; | ||
26 | |||
27 | TextInputLayout etProduct, | ||
28 | etAmount, | ||
29 | etCurrency, | ||
30 | etServerId, | ||
31 | etRoleId, | ||
32 | etExtra; | ||
33 | |||
34 | |||
35 | |||
36 | public static PaymentInfoSubmitFragment newInstance(OnSubmitListener listener) { | ||
37 | PaymentInfoSubmitFragment fragment = new PaymentInfoSubmitFragment(); | ||
38 | fragment.listener = listener; | ||
39 | return fragment; | ||
40 | } | ||
41 | |||
42 | @NonNull | ||
43 | @Override | ||
44 | public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
45 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | ||
46 | View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_payment, null, false); | ||
47 | etProduct = view.findViewById(R.id.product); | ||
48 | etAmount = view.findViewById(R.id.amount); | ||
49 | etCurrency = view.findViewById(R.id.currency); | ||
50 | etServerId = view.findViewById(R.id.server_id); | ||
51 | etRoleId = view.findViewById(R.id.role_id); | ||
52 | etExtra = view.findViewById(R.id.extra); | ||
53 | etProduct.getEditText().addTextChangedListener(new EditTextWatcher(etProduct)); | ||
54 | etAmount.getEditText().addTextChangedListener(new EditTextWatcher(etAmount)); | ||
55 | etCurrency.getEditText().addTextChangedListener(new EditTextWatcher(etCurrency)); | ||
56 | etServerId.getEditText().addTextChangedListener(new EditTextWatcher(etServerId)); | ||
57 | etRoleId.getEditText().addTextChangedListener(new EditTextWatcher(etRoleId)); | ||
58 | etExtra.getEditText().addTextChangedListener(new EditTextWatcher(etExtra)); | ||
59 | //设置默认值 | ||
60 | etProduct.getEditText().setText("EV1.test.abc"); | ||
61 | etAmount.getEditText().setText("0.99"); | ||
62 | etCurrency.getEditText().setText("USD"); | ||
63 | etServerId.getEditText().setText("100"); | ||
64 | etRoleId.getEditText().setText("41080"); | ||
65 | view.findViewById(R.id.submit).setOnClickListener(v -> { | ||
66 | String product = etProduct.getEditText().getText().toString(); | ||
67 | String currency = etCurrency.getEditText().getText().toString(); | ||
68 | String serverId = etServerId.getEditText().getText().toString(); | ||
69 | String roleId = etRoleId.getEditText().getText().toString(); | ||
70 | String extra = etExtra.getEditText().getText().toString(); | ||
71 | String amount = etAmount.getEditText().getText().toString(); | ||
72 | if (checkInput(product, amount, currency, serverId, roleId, extra)) { | ||
73 | Bundle payInfo = new Bundle(); | ||
74 | payInfo.putString("product", product); | ||
75 | payInfo.putFloat("amount", Float.valueOf(amount)); | ||
76 | payInfo.putString("extraInfo", extra); | ||
77 | payInfo.putString("serverId", serverId); | ||
78 | payInfo.putString("roleId", roleId); | ||
79 | payInfo.putString("currency", currency); | ||
80 | if (listener != null) { | ||
81 | listener.onSubmit(payInfo); | ||
82 | } | ||
83 | dismiss(); | ||
84 | } | ||
85 | }); | ||
86 | AlertDialog dialog = builder.setView(view).create(); | ||
87 | return dialog; | ||
88 | } | ||
89 | |||
90 | |||
91 | private boolean checkInput(String product, String amount, String currency, String serverId, String roleId, String extra) { | ||
92 | if (TextUtils.isEmpty(product)) { | ||
93 | etProduct.setError("product is empty"); | ||
94 | return false; | ||
95 | } | ||
96 | if (TextUtils.isEmpty(currency)) { | ||
97 | etCurrency.setError("currency is empty"); | ||
98 | return false; | ||
99 | } | ||
100 | if (TextUtils.isEmpty(serverId)) { | ||
101 | etServerId.setError("serverId is empty"); | ||
102 | return false; | ||
103 | } | ||
104 | if (TextUtils.isEmpty(roleId)) { | ||
105 | etRoleId.setError("roleId is empty"); | ||
106 | return false; | ||
107 | } | ||
108 | if (TextUtils.isEmpty(extra)) { | ||
109 | etExtra.setError("extra is empty"); | ||
110 | return false; | ||
111 | } | ||
112 | if (TextUtils.isEmpty(amount)) { | ||
113 | etAmount.setError("amount is empty"); | ||
114 | return false; | ||
115 | } | ||
116 | return true; | ||
117 | } | ||
118 | |||
119 | class EditTextWatcher implements TextWatcher { | ||
120 | |||
121 | private TextInputLayout editText; | ||
122 | |||
123 | public EditTextWatcher(TextInputLayout editText) { | ||
124 | this.editText = editText; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||
129 | |||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public void onTextChanged(CharSequence s, int start, int before, int count) { | ||
134 | editText.setError(null); | ||
135 | } | ||
136 | |||
137 | @Override | ||
138 | public void afterTextChanged(Editable s) { | ||
139 | |||
140 | } | ||
141 | } | ||
142 | } | ||
143 |
GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
1 | package com.gumptech.sdk.demo; | File was deleted | |
2 | |||
3 | import android.os.Bundle; | ||
4 | import android.support.v7.app.AppCompatActivity; | ||
5 | import android.util.Log; | ||
6 | import android.view.View; | ||
7 | import android.widget.Button; | ||
8 | import android.widget.TextView; | ||
9 | import android.widget.Toast; | ||
10 | |||
11 | import com.gumptech.sdk.GumpPreference; | ||
12 | import com.gumptech.sdk.GumpSDK; | ||
13 | import com.gumptech.sdk.PaymentVersion; | ||
14 | import com.gumptech.sdk.SDKSettings; | ||
15 | import com.gumptech.sdk.bean.GumpUser; | ||
16 | import com.gumptech.sdk.bean.PurchaseResult; | ||
17 | import com.gumptech.sdk.callback.InitializeCallback; | ||
18 | import com.gumptech.sdk.callback.LoginStateListener; | ||
19 | import com.gumptech.sdk.callback.PurchaseCallback; | ||
20 | import com.gumptech.sdk.callback.ResultCallback; | ||
21 | import com.gumptech.sdk.passport.fb.FBAccessToken; | ||
22 | |||
23 | import java.util.Locale; | ||
24 | |||
25 | public class MainActivity extends AppCompatActivity implements PurchaseCallback { | ||
26 | |||
27 | private static final String TAG = "MainActivity"; | ||
28 | |||
29 | private TextView tvVersion; | ||
30 | private TextView userInfo; | ||
31 | |||
32 | private Button btnLoginOrLogout; | ||
33 | private Button btnInit; | ||
34 | private Button btnCheckState; | ||
35 | private Button btnPay; | ||
36 | private Button btnIap; | ||
37 | |||
38 | private String appId = "100"; | ||
39 | private String appKey = "f899139df5e1059396431415e770c6dd"; | ||
40 | private GumpUser gumpUser; | ||
41 | |||
42 | /** | ||
43 | * 测试数据 | ||
44 | */ | ||
45 | String serverId = "100"; | ||
46 | String roleId = "41080"; | ||
47 | |||
48 | |||
49 | @Override | ||
50 | protected void onCreate(Bundle savedInstanceState) { | ||
51 | super.onCreate(savedInstanceState); | ||
52 | setContentView(R.layout.activity_main); | ||
53 | |||
54 | tvVersion = findViewById(R.id.version); | ||
55 | userInfo = findViewById(R.id.user_info); | ||
56 | btnLoginOrLogout = findViewById(R.id.login_or_logout); | ||
57 | btnInit = findViewById(R.id.init); | ||
58 | btnCheckState = findViewById(R.id.check_state); | ||
59 | btnLoginOrLogout.setOnClickListener(new View.OnClickListener() { | ||
60 | |||
61 | @Override | ||
62 | public void onClick(View v) { | ||
63 | if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0) | ||
64 | GumpSDK.start(MainActivity.this); | ||
65 | else | ||
66 | GumpSDK.logout(MainActivity.this); | ||
67 | } | ||
68 | }); | ||
69 | btnInit.setOnClickListener(new View.OnClickListener() { | ||
70 | @Override | ||
71 | public void onClick(View v) { | ||
72 | btnInit.setEnabled(false); | ||
73 | GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { | ||
74 | @Override | ||
75 | public void initComplete(int result) { | ||
76 | if (result == GumpSDK.CODE.OK) { | ||
77 | btnLoginOrLogout.setEnabled(true); | ||
78 | userInfo.setText("initialization has finished"); | ||
79 | } else { | ||
80 | btnInit.setEnabled(true); | ||
81 | userInfo.setText("initialization has error"); | ||
82 | } | ||
83 | } | ||
84 | }); | ||
85 | } | ||
86 | }); | ||
87 | btnCheckState.setOnClickListener(new View.OnClickListener() { | ||
88 | @Override | ||
89 | public void onClick(View v) { | ||
90 | // btnCheckState.setEnabled(false); | ||
91 | GumpSDK.shouldUseCoPay(MainActivity.this, serverId, roleId, new ResultCallback() { | ||
92 | @Override | ||
93 | public void onResult(boolean isRisk) { | ||
94 | btnIap.setEnabled(isRisk); | ||
95 | btnPay.setEnabled(isRisk); | ||
96 | } | ||
97 | }); | ||
98 | } | ||
99 | }); | ||
100 | btnPay = findViewById(R.id.pay); | ||
101 | btnPay.setOnClickListener(new View.OnClickListener() { | ||
102 | |||
103 | @Override | ||
104 | public void onClick(View v) { | ||
105 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { | ||
106 | @Override | ||
107 | public void onSubmit(Bundle payInfo) { | ||
108 | GumpSDK.pay(MainActivity.this, payInfo, MainActivity.this); | ||
109 | } | ||
110 | }); | ||
111 | submitFragment.show(getSupportFragmentManager(), "pay"); | ||
112 | } | ||
113 | }); | ||
114 | btnIap = findViewById(R.id.iap); | ||
115 | btnIap.setOnClickListener(new View.OnClickListener() { | ||
116 | @Override | ||
117 | public void onClick(View v) { | ||
118 | PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { | ||
119 | @Override | ||
120 | public void onSubmit(Bundle payInfo) { | ||
121 | GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); | ||
122 | } | ||
123 | }); | ||
124 | submitFragment.show(getSupportFragmentManager(), "iap"); | ||
125 | } | ||
126 | }); | ||
127 | |||
128 | |||
129 | Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); | ||
130 | |||
131 | GumpSDK.getSettings().setDebug(false); | ||
132 | /** | ||
133 | * 设置是否打印debug日志 | ||
134 | */ | ||
135 | GumpSDK.getSettings().enableDebugLogging(true); | ||
136 | /** | ||
137 | * 设置启用facebook登录 | ||
138 | */ | ||
139 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); | ||
140 | |||
141 | /** | ||
142 | * 设置启用google登录 | ||
143 | */ | ||
144 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); | ||
145 | |||
146 | /** | ||
147 | * 设置启用Line登录 | ||
148 | */ | ||
149 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); | ||
150 | |||
151 | /** | ||
152 | * 设置支付版本 | ||
153 | */ | ||
154 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); | ||
155 | |||
156 | /** | ||
157 | * 设置用户登录状态监听器 | ||
158 | */ | ||
159 | |||
160 | GumpSDK.setUserStateListener(new LoginStateListener() { | ||
161 | @Override | ||
162 | public void onLoginSuccess(GumpUser user) { | ||
163 | btnCheckState.setEnabled(true); | ||
164 | gumpUser = user; | ||
165 | String userType = null; | ||
166 | switch (user.getAccountType()) { | ||
167 | case GumpPreference.ACCOUNT_TYPE_FB: | ||
168 | userType = "Facebook登录"; | ||
169 | String fbToken = FBAccessToken.getCurrentAccessToken().getToken(); | ||
170 | Log.d(TAG, "FBAccessToken:" + fbToken); | ||
171 | break; | ||
172 | case GumpPreference.ACCOUNT_TYPE_QUICK_REG: | ||
173 | userType = "快速登录"; | ||
174 | break; | ||
175 | case GumpPreference.ACCOUNT_TYPE_REG: | ||
176 | userType = "gump注册用户"; | ||
177 | break; | ||
178 | case GumpPreference.ACCOUNT_TYPE_GOOGLE: | ||
179 | userType = "google 登录"; | ||
180 | break; | ||
181 | case GumpPreference.ACCOUNT_TYPE_LINE: | ||
182 | userType = "Line登录"; | ||
183 | break; | ||
184 | } | ||
185 | userInfo.setText(" Userid:" + user.getUid() + "\n accountType:(" + user.getAccountType() + ") " + userType + "\n sessionKey:" + user.getSessionKey() | ||
186 | .getToken()); | ||
187 | btnLoginOrLogout.setText("Logout"); | ||
188 | btnLoginOrLogout.setTag(1); | ||
189 | } | ||
190 | |||
191 | @Override | ||
192 | public void onLoginFailed(int code, String msg) { | ||
193 | userInfo.setText(msg); | ||
194 | Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); | ||
195 | } | ||
196 | |||
197 | @Override | ||
198 | public void onLoginCanceled() { | ||
199 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | ||
200 | } | ||
201 | |||
202 | @Override | ||
203 | public void onLogout() { | ||
204 | btnLoginOrLogout.setText("Login"); | ||
205 | btnLoginOrLogout.setTag(0); | ||
206 | userInfo.setText("User is logout"); | ||
207 | } | ||
208 | |||
209 | @Override | ||
210 | public void onPermissionDenied(String[] deniedPermissions) { | ||
211 | StringBuilder sb = new StringBuilder(); | ||
212 | for (String s : deniedPermissions) { | ||
213 | sb.append(s); | ||
214 | sb.append(","); | ||
215 | } | ||
216 | Toast.makeText(MainActivity.this, "Permission denied:" + sb.toString(), Toast.LENGTH_SHORT).show(); | ||
217 | } | ||
218 | }); | ||
219 | /** | ||
220 | * 初始化sdk | ||
221 | */ | ||
222 | GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { | ||
223 | @Override | ||
224 | public void initComplete(int result) { | ||
225 | if (result == GumpSDK.CODE.OK) { | ||
226 | btnLoginOrLogout.setEnabled(true); | ||
227 | userInfo.setText("initialization has finished"); | ||
228 | |||
229 | //checkRisk(); | ||
230 | } else { | ||
231 | btnInit.setEnabled(true); | ||
232 | userInfo.setText("initialization has error"); | ||
233 | } | ||
234 | } | ||
235 | }); | ||
236 | |||
237 | tvVersion.setText("SDK Version:" + GumpSDK.getVersion()); | ||
238 | |||
239 | } | ||
240 | |||
241 | private void checkRisk() { | ||
242 | GumpSDK.checkRisk(this, new ResultCallback() { | ||
243 | @Override | ||
244 | public void onResult(boolean isRisk) { | ||
245 | Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk"); | ||
246 | } | ||
247 | }); | ||
248 | } | ||
249 | |||
250 | @Override | ||
251 | public void onPurchaseCompleted(PurchaseResult result) { | ||
252 | Log.i(TAG, "purchase completed"); | ||
253 | } | ||
254 | |||
255 | @Override | ||
256 | public void onPurchaseError(int code, String msg) { | ||
257 | Log.i(TAG, "purchase error:"+code+","+msg); | ||
258 | } | ||
259 | |||
260 | @Override | ||
261 | public void onPurchaseCanceled() { | ||
262 | Log.i(TAG, "purchase canceled"); | ||
263 | } | ||
264 | |||
265 | |||
266 | } | ||
267 | 1 | package com.gumptech.sdk.demo; |
GameSDKDemo/src/main/java/com/gumptech/sdk/demo/PaymentInfoSubmitFragment.java
1 | package com.gumptech.sdk.demo; | File was deleted | |
2 | |||
3 | |||
4 | import android.app.AlertDialog; | ||
5 | import android.app.Dialog; | ||
6 | import android.os.Bundle; | ||
7 | import android.support.annotation.NonNull; | ||
8 | import android.support.design.widget.TextInputLayout; | ||
9 | import android.support.v4.app.DialogFragment; | ||
10 | import android.text.Editable; | ||
11 | import android.text.TextUtils; | ||
12 | import android.text.TextWatcher; | ||
13 | import android.view.LayoutInflater; | ||
14 | import android.view.View; | ||
15 | |||
16 | |||
17 | |||
18 | public class PaymentInfoSubmitFragment extends DialogFragment { | ||
19 | |||
20 | interface OnSubmitListener { | ||
21 | void onSubmit(Bundle payInfo); | ||
22 | } | ||
23 | |||
24 | private OnSubmitListener listener; | ||
25 | |||
26 | TextInputLayout etProduct, | ||
27 | etAmount, | ||
28 | etCurrency, | ||
29 | etServerId, | ||
30 | etRoleId, | ||
31 | etExtra; | ||
32 | |||
33 | |||
34 | |||
35 | public static PaymentInfoSubmitFragment newInstance(OnSubmitListener listener) { | ||
36 | PaymentInfoSubmitFragment fragment = new PaymentInfoSubmitFragment(); | ||
37 | fragment.listener = listener; | ||
38 | return fragment; | ||
39 | } | ||
40 | |||
41 | @NonNull | ||
42 | @Override | ||
43 | public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
44 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | ||
45 | View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_payment, null, false); | ||
46 | etProduct = view.findViewById(R.id.product); | ||
47 | etAmount = view.findViewById(R.id.amount); | ||
48 | etCurrency = view.findViewById(R.id.currency); | ||
49 | etServerId = view.findViewById(R.id.server_id); | ||
50 | etRoleId = view.findViewById(R.id.role_id); | ||
51 | etExtra = view.findViewById(R.id.extra); | ||
52 | etProduct.getEditText().addTextChangedListener(new EditTextWatcher(etProduct)); | ||
53 | etAmount.getEditText().addTextChangedListener(new EditTextWatcher(etAmount)); | ||
54 | etCurrency.getEditText().addTextChangedListener(new EditTextWatcher(etCurrency)); | ||
55 | etServerId.getEditText().addTextChangedListener(new EditTextWatcher(etServerId)); | ||
56 | etRoleId.getEditText().addTextChangedListener(new EditTextWatcher(etRoleId)); | ||
57 | etExtra.getEditText().addTextChangedListener(new EditTextWatcher(etExtra)); | ||
58 | //设置默认值 | ||
59 | etProduct.getEditText().setText("EV1.test.abc"); | ||
60 | etAmount.getEditText().setText("0.99"); | ||
61 | etCurrency.getEditText().setText("USD"); | ||
62 | etServerId.getEditText().setText("100"); | ||
63 | etRoleId.getEditText().setText("41080"); | ||
64 | view.findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() { | ||
65 | @Override | ||
66 | public void onClick(View v) { | ||
67 | String product = etProduct.getEditText().getText().toString(); | ||
68 | String currency = etCurrency.getEditText().getText().toString(); | ||
69 | String serverId = etServerId.getEditText().getText().toString(); | ||
70 | String roleId = etRoleId.getEditText().getText().toString(); | ||
71 | String extra = etExtra.getEditText().getText().toString(); | ||
72 | String amount = etAmount.getEditText().getText().toString(); | ||
73 | if (checkInput(product, amount, currency, serverId, roleId, extra)) { | ||
74 | Bundle payInfo = new Bundle(); | ||
75 | payInfo.putString("product", product); | ||
76 | payInfo.putFloat("amount", Float.valueOf(amount)); | ||
77 | payInfo.putString("extraInfo", extra); | ||
78 | payInfo.putString("serverId", serverId); | ||
79 | payInfo.putString("roleId", roleId); | ||
80 | payInfo.putString("currency", currency); | ||
81 | if (listener != null) { | ||
82 | listener.onSubmit(payInfo); | ||
83 | } | ||
84 | dismiss(); | ||
85 | } | ||
86 | } | ||
87 | }); | ||
88 | AlertDialog dialog = builder.setView(view).create(); | ||
89 | return dialog; | ||
90 | } | ||
91 | |||
92 | |||
93 | private boolean checkInput(String product, String amount, String currency, String serverId, String roleId, String extra) { | ||
94 | if (TextUtils.isEmpty(product)) { | ||
95 | etProduct.setError("product is empty"); | ||
96 | return false; | ||
97 | } | ||
98 | if (TextUtils.isEmpty(currency)) { | ||
99 | etCurrency.setError("currency is empty"); | ||
100 | return false; | ||
101 | } | ||
102 | if (TextUtils.isEmpty(serverId)) { | ||
103 | etServerId.setError("serverId is empty"); | ||
104 | return false; | ||
105 | } | ||
106 | if (TextUtils.isEmpty(roleId)) { | ||
107 | etRoleId.setError("roleId is empty"); | ||
108 | return false; | ||
109 | } | ||
110 | if (TextUtils.isEmpty(extra)) { | ||
111 | etExtra.setError("extra is empty"); | ||
112 | return false; | ||
113 | } | ||
114 | if (TextUtils.isEmpty(amount)) { | ||
115 | etAmount.setError("amount is empty"); | ||
116 | return false; | ||
117 | } | ||
118 | return true; | ||
119 | } | ||
120 | |||
121 | class EditTextWatcher implements TextWatcher { | ||
122 | |||
123 | private TextInputLayout editText; | ||
124 | |||
125 | public EditTextWatcher(TextInputLayout editText) { | ||
126 | this.editText = editText; | ||
127 | } | ||
128 | |||
129 | @Override | ||
130 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { | ||
131 | |||
132 | } | ||
133 | |||
134 | @Override | ||
135 | public void onTextChanged(CharSequence s, int start, int before, int count) { | ||
136 | editText.setError(null); | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public void afterTextChanged(Editable s) { | ||
141 | |||
142 | } | ||
143 | } | ||
144 | } | ||
145 | 1 | package com.gumptech.sdk.demo; |
GameSDKDemo/src/main/res/layout/activity_main.xml
1 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | 1 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
2 | android:layout_width="match_parent" | 2 | android:layout_width="match_parent" |
3 | android:layout_height="match_parent" | 3 | android:layout_height="match_parent" |
4 | android:background="@android:color/white" | 4 | android:background="@android:color/white" |
5 | android:fitsSystemWindows="true" | 5 | android:fitsSystemWindows="true" |
6 | android:orientation="vertical"> | 6 | android:orientation="vertical"> |
7 | 7 | ||
8 | <TextView | 8 | <TextView |
9 | android:id="@+id/version" | 9 | android:id="@+id/version" |
10 | android:layout_width="wrap_content" | 10 | android:layout_width="wrap_content" |
11 | android:layout_height="wrap_content" | 11 | android:layout_height="wrap_content" |
12 | android:layout_gravity="center_horizontal" | 12 | android:layout_gravity="center_horizontal" |
13 | android:textColor="@color/black_text"/> | 13 | android:textColor="@color/black_text"/> |
14 | 14 | ||
15 | <TextView | 15 | <TextView |
16 | android:id="@+id/user_info" | 16 | android:id="@+id/user_info" |
17 | android:layout_width="match_parent" | 17 | android:layout_width="match_parent" |
18 | android:layout_height="wrap_content" | 18 | android:layout_height="wrap_content" |
19 | android:textColor="@android:color/black"/> | 19 | android:textColor="@android:color/black"/> |
20 | 20 | ||
21 | <Button | 21 | <Button |
22 | android:id="@+id/init" | ||
23 | android:layout_width="match_parent" | ||
24 | android:layout_height="wrap_content" | ||
25 | android:backgroundTint="@color/g_color" | ||
26 | android:enabled="false" | ||
27 | android:text="@string/init"/> | ||
28 | |||
29 | <Button | ||
30 | android:id="@+id/login_or_logout" | 22 | android:id="@+id/login_or_logout" |
31 | android:layout_width="match_parent" | 23 | android:layout_width="match_parent" |
32 | android:layout_height="wrap_content" | 24 | android:layout_height="wrap_content" |
33 | android:backgroundTint="@color/g_color" | 25 | android:backgroundTint="@color/g_color" |
34 | android:enabled="false" | ||
35 | android:text="@string/login"/> | 26 | android:text="@string/login"/> |
36 | 27 | ||
37 | <Button | 28 | <Button |
38 | android:id="@+id/check_state" | 29 | android:id="@+id/check_state" |
39 | android:layout_width="match_parent" | 30 | android:layout_width="match_parent" |
40 | android:layout_height="wrap_content" | 31 | android:layout_height="wrap_content" |
41 | android:backgroundTint="@color/g_color" | 32 | android:backgroundTint="@color/g_color" |
42 | android:enabled="false" | 33 | android:enabled="false" |
43 | android:text="@string/check"/> | 34 | android:text="@string/check"/> |
44 | 35 | ||
45 | <Button | 36 | <Button |
46 | android:id="@+id/iap" | 37 | android:id="@+id/iap" |
47 | android:layout_width="match_parent" | 38 | android:layout_width="match_parent" |
48 | android:layout_height="wrap_content" | 39 | android:layout_height="wrap_content" |
49 | android:backgroundTint="@color/g_color" | 40 | android:backgroundTint="@color/g_color" |
50 | android:enabled="false" | 41 | android:enabled="false" |
51 | android:text="@string/iap"/> | 42 | android:text="@string/iap"/> |
52 | 43 | ||
53 | <Button | 44 | <Button |
54 | android:id="@+id/pay" | 45 | android:id="@+id/pay" |
55 | android:layout_width="match_parent" | 46 | android:layout_width="match_parent" |
56 | android:layout_height="wrap_content" | 47 | android:layout_height="wrap_content" |
57 | android:backgroundTint="@color/g_color" | 48 | android:backgroundTint="@color/g_color" |
58 | android:enabled="false" | 49 | android:enabled="false" |
59 | android:text="@string/pay"/> | 50 | android:text="@string/pay"/> |
60 | 51 | ||
61 | 52 | ||
62 | </LinearLayout> | 53 | </LinearLayout> |
GameSDKDemo/src/main/res/layout/fragment_payment.xml
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
3 | xmlns:app="http://schemas.android.com/apk/res-auto" | 3 | xmlns:app="http://schemas.android.com/apk/res-auto" |
4 | xmlns:tools="http://schemas.android.com/tools" | 4 | xmlns:tools="http://schemas.android.com/tools" |
5 | android:layout_width="match_parent" | 5 | android:layout_width="match_parent" |
6 | android:layout_height="match_parent" | 6 | android:layout_height="match_parent" |
7 | android:orientation="vertical" | 7 | android:orientation="vertical" |
8 | tools:context=".PaymentInfoSubmitFragment"> | 8 | tools:context=".PaymentInfoSubmitFragment"> |
9 | 9 | ||
10 | <android.support.design.widget.TextInputLayout | 10 | <com.google.android.material.textfield.TextInputLayout |
11 | android:id="@+id/product" | 11 | android:id="@+id/product" |
12 | android:layout_width="match_parent" | 12 | android:layout_width="match_parent" |
13 | android:layout_height="wrap_content"> | 13 | android:layout_height="wrap_content"> |
14 | 14 | ||
15 | <EditText | 15 | <EditText |
16 | android:layout_width="match_parent" | 16 | android:layout_width="match_parent" |
17 | android:layout_height="wrap_content" | 17 | android:layout_height="wrap_content" |
18 | android:hint="@string/hint_product" | 18 | android:hint="@string/hint_product" /> |
19 | /> | 19 | </com.google.android.material.textfield.TextInputLayout> |
20 | </android.support.design.widget.TextInputLayout> | ||
21 | 20 | ||
22 | <android.support.design.widget.TextInputLayout | 21 | <com.google.android.material.textfield.TextInputLayout |
23 | android:id="@+id/amount" | 22 | android:id="@+id/amount" |
24 | android:layout_width="match_parent" | 23 | android:layout_width="match_parent" |
25 | android:layout_height="wrap_content"> | 24 | android:layout_height="wrap_content"> |
26 | 25 | ||
27 | <EditText | 26 | <EditText |
28 | android:layout_width="match_parent" | 27 | android:layout_width="match_parent" |
29 | android:layout_height="wrap_content" | 28 | android:layout_height="wrap_content" |
30 | android:hint="@string/hint_amount" | 29 | android:hint="@string/hint_amount" |
31 | android:inputType="numberDecimal"/> | 30 | android:inputType="numberDecimal" /> |
32 | </android.support.design.widget.TextInputLayout> | 31 | </com.google.android.material.textfield.TextInputLayout> |
33 | 32 | ||
34 | <android.support.design.widget.TextInputLayout | 33 | <com.google.android.material.textfield.TextInputLayout |
35 | android:id="@+id/currency" | 34 | android:id="@+id/currency" |
36 | android:layout_width="match_parent" | 35 | android:layout_width="match_parent" |
37 | android:layout_height="wrap_content"> | 36 | android:layout_height="wrap_content"> |
38 | 37 | ||
39 | <EditText | 38 | <EditText |
40 | |||
41 | android:layout_width="match_parent" | 39 | android:layout_width="match_parent" |
42 | android:layout_height="wrap_content" | 40 | android:layout_height="wrap_content" |
43 | android:hint="@string/hint_currency"/> | 41 | android:hint="@string/hint_currency" /> |
44 | </android.support.design.widget.TextInputLayout> | 42 | </com.google.android.material.textfield.TextInputLayout> |
45 | 43 | ||
46 | <android.support.design.widget.TextInputLayout | 44 | <com.google.android.material.textfield.TextInputLayout |
47 | android:id="@+id/server_id" | 45 | android:id="@+id/server_id" |
48 | android:layout_width="match_parent" | 46 | android:layout_width="match_parent" |
49 | android:layout_height="wrap_content"> | 47 | android:layout_height="wrap_content"> |
50 | 48 | ||
51 | <EditText | 49 | <EditText |
52 | 50 | ||
53 | android:layout_width="match_parent" | 51 | android:layout_width="match_parent" |
54 | android:layout_height="wrap_content" | 52 | android:layout_height="wrap_content" |
55 | android:hint="@string/hint_server_id"/> | 53 | android:hint="@string/hint_server_id" /> |
56 | </android.support.design.widget.TextInputLayout> | 54 | </com.google.android.material.textfield.TextInputLayout> |
57 | 55 | ||
58 | <android.support.design.widget.TextInputLayout | 56 | <com.google.android.material.textfield.TextInputLayout |
59 | android:id="@+id/role_id" | 57 | android:id="@+id/role_id" |
60 | android:layout_width="match_parent" | 58 | android:layout_width="match_parent" |
61 | android:layout_height="wrap_content"> | 59 | android:layout_height="wrap_content"> |
62 | 60 | ||
63 | <EditText | 61 | <EditText |
64 | 62 | ||
65 | android:layout_width="match_parent" | 63 | android:layout_width="match_parent" |
66 | android:layout_height="wrap_content" | 64 | android:layout_height="wrap_content" |
67 | android:hint="@string/hint_role_id"/> | 65 | android:hint="@string/hint_role_id" /> |
68 | </android.support.design.widget.TextInputLayout> | 66 | </com.google.android.material.textfield.TextInputLayout> |
69 | 67 | ||
70 | <android.support.design.widget.TextInputLayout | 68 | <com.google.android.material.textfield.TextInputLayout |
71 | android:id="@+id/extra" | 69 | android:id="@+id/extra" |
72 | android:layout_width="match_parent" | 70 | android:layout_width="match_parent" |
73 | android:layout_height="wrap_content"> | 71 | android:layout_height="wrap_content"> |
74 | 72 | ||
75 | <EditText | 73 | <EditText |
76 | 74 | ||
77 | android:layout_width="match_parent" | 75 | android:layout_width="match_parent" |
78 | android:layout_height="wrap_content" | 76 | android:layout_height="wrap_content" |
79 | android:hint="@string/hint_extra"/> | 77 | android:hint="@string/hint_extra" /> |
80 | </android.support.design.widget.TextInputLayout> | 78 | </com.google.android.material.textfield.TextInputLayout> |
81 | 79 | ||
82 | <Button | 80 | <Button |
83 | android:id="@+id/submit" | 81 | android:id="@+id/submit" |
84 | android:layout_width="match_parent" | 82 | android:layout_width="match_parent" |
85 | android:layout_height="wrap_content" | 83 | android:layout_height="wrap_content" |
86 | android:text="@string/go_pay"/> | 84 | android:text="@string/go_pay" /> |
87 | 85 | ||
88 | 86 | ||
89 | </LinearLayout> | 87 | </LinearLayout> |
GameSDKDemo/src/test/java/com/gump/game/sdk/demo/ExampleUnitTest.java
File was created | 1 | package com.gump.game.sdk.demo; | |
2 | |||
3 | import org.junit.Test; | ||
4 | |||
5 | import static org.junit.Assert.*; | ||
6 | |||
7 | /** | ||
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. | ||
9 | */ | ||
10 | public class ExampleUnitTest { | ||
11 | @Test | ||
12 | public void addition_isCorrect() throws Exception { | ||
13 | assertEquals(4, 2 + 2); | ||
14 | } | ||
15 | } |
GameSDKDemo/src/test/java/com/gumptech/sdk/demo/ExampleUnitTest.java
1 | package com.gumptech.sdk.demo; | File was deleted | |
2 | |||
3 | import org.junit.Test; | ||
4 | |||
5 | import static org.junit.Assert.*; | ||
6 | |||
7 | /** | ||
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. | ||
9 | */ | ||
10 | public class ExampleUnitTest { | ||
11 | @Test | ||
12 | public void addition_isCorrect() throws Exception { | ||
13 | assertEquals(4, 2 + 2); | ||
14 | } | ||
15 | } |
README.md
1 | # Gump SDK 4 for Android接入文档 | 1 | # Gump SDK 4 for Android接入文档 |
2 | 2 | ||
3 | 3 | ||
4 | V4.7.8 | 4 | V4.8.0 |
5 | 2019年12月20日 | 5 | 2020年01月15日 |
6 | 6 | ||
7 | 7 | ||
8 | ## 版本概述 | 8 | ## 版本概述 |
9 | 9 | ||
10 | 此版本为使用AndroidStudio开发的版本,一改eclipse的工程依赖方式,使用aar的方式提供sdk接入包,除功能外,相对上一版本没有继承关系,请按此文档描述接入. | 10 | 此版本为使用AndroidStudio开发的版本,使用aar的方式提供sdk接入包,并使用gradle在线依赖方式,aar内别不包含依赖包,请按此文档描述接入. |
11 | 11 | ||
12 | 此SDK适用android4.0以上系统. | 12 | 此SDK适用android4.0以上系统. |
13 | 13 | ||
14 | ## 第一章 接入指南 | 14 | ## 第一章 接入指南 |
15 | ### 1.依赖导入 | 15 | ### 1.依赖导入 |
16 | 配置gradle,以下为必须项 | 16 | 配置gradle,以下为必须项 |
17 | 17 | ||
18 | repositories{ | 18 | repositories{ |
19 | maven{ | 19 | maven{ |
20 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" | 20 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" |
21 | } | 21 | } |
22 | } | 22 | } |
23 | dependencies { | 23 | dependencies { |
24 | implementation 'com.gumptech.sdk:GameSDK:4.7.8' | 24 | implementation 'com.gumptech.sdk:GameSDK:4.8.0' |
25 | 25 | ||
26 | } | 26 | } |
27 | 27 | ||
28 | 28 | ||
29 | ### 2.修改AndroidManifest.xml文件 | 29 | ### 2.修改AndroidManifest.xml文件 |
30 | 首先添加必要的权限,如下所示: | 30 | 首先添加必要的权限,如下所示: |
31 | 31 | ||
32 | <uses-permission android:name="android.permission.INTERNET" /> | 32 | <uses-permission android:name="android.permission.INTERNET" /> |
33 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | 33 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
34 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 34 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
35 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | 35 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> |
36 | <uses-permission android:name="com.android.vending.BILLING" /> | 36 | <uses-permission android:name="com.android.vending.BILLING" /> |
37 | 37 | ||
38 | 其次注册相应的Activity,具体如下: | 38 | 其次注册相应的Activity,具体如下: |
39 | 39 | ||
40 | <activity | 40 | <activity |
41 | android:name="com.gumptech.sdk.ContainerActivity" | 41 | android:name="com.gump.game.sdk.PassportActivity" |
42 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 42 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
43 | android:launchMode="singleTask" | 43 | android:launchMode="singleTask" |
44 | android:theme="@style/Theme.Origin" //登录界面的主题,可选项:Theme.Origin\Theme.Orange\Theme.Blue | 44 | android:theme="@style/Theme.Origin" //登录界面的主题,可选项:Theme.Origin\Theme.Orange\Theme.Blue\Theme.Pink |
45 | android:screenOrientation="behind" | 45 | android:screenOrientation="behind" |
46 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> | 46 | android:windowSoftInputMode="stateAlwaysHidden|adjustPan"> |
47 | </activity> | 47 | </activity> |
48 | <activity | 48 | <activity |
49 | android:name="com.gumptech.sdk.PaymentActivity" | 49 | android:name="com.gump.game.sdk.RechargeActivity" |
50 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 50 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
51 | android:launchMode="singleTask" | 51 | android:launchMode="singleTask" |
52 | android:screenOrientation="behind" | 52 | android:screenOrientation="behind" |
53 | android:theme="@style/Theme.Translucent" > | 53 | android:theme="@style/Theme.Translucent" > |
54 | <intent-filter> | 54 | <intent-filter> |
55 | <category android:name="android.intent.category.DEFAULT" /> | 55 | <category android:name="android.intent.category.DEFAULT" /> |
56 | <action android:name="android.intent.action.VIEW" /> | 56 | <action android:name="android.intent.action.VIEW" /> |
57 | <category android:name="android.intent.category.BROWSABLE" /> | 57 | <category android:name="android.intent.category.BROWSABLE" /> |
58 | <data | 58 | <data |
59 | android:host="com.gump.sdk" | 59 | android:host="com.gump.sdk" |
60 | android:scheme="gump+游戏的appId" /> | 60 | android:scheme="gump+游戏的appId" /> |
61 | </intent-filter> | 61 | </intent-filter> |
62 | </activity> | 62 | </activity> |
63 | 63 | ||
64 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 | 64 | ### 3.向Gump平台索要游戏ID(AppID),完成代码接入 |
65 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 | 65 | 正式开始接入逻辑代码前,先介绍下一些附加设置,以方便代码接入 |
66 | 66 | ||
67 | *是否打印debug日志 | 67 | *是否打印debug日志 |
68 | 68 | ||
69 | GumpSDK.getSettings().enableDebugLogging(true); | 69 | GameSDK.getSettings().enableDebugLogging(true); |
70 | 70 | ||
71 | *设置需要启用的第三方登录,参数可选类型见第二章:[第三方登录平台](http://repository.gumptech.com:81/document/gamesdk4-android/blob/master/IntegrationGuide.md#1-third_plat) 字段说明 | 71 | *设置需要启用的第三方登录,参数可选类型见第二章:[第三方登录平台](http://repository.gumptech.com:81/document/gamesdk4-android/blob/master/IntegrationGuide.md#1-third_plat) 字段说明 |
72 | 72 | ||
73 | GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_*); | 73 | GameSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_*); |
74 | 74 | ||
75 | *若要使用V4版支付请设置 | ||
76 | 75 | ||
77 | GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); | 76 | #### 1.调用GameSDK前需要执行初始化。 |
78 | |||
79 | #### 1.调用GumpSDK前需要执行初始化。 | ||
80 | 77 | ||
81 | 若不需要分渠道 | 78 | 若不需要分渠道 |
82 | 79 | ||
83 | GumpSDK.init(Context,Appid, Appkey,InitializeCallback); | 80 | GameSDK.init(Context,Appid); |
84 | 如果需要定义渠道,必须使用如下方法 | 81 | 如果需要定义渠道,必须使用如下方法 |
85 | 82 | ||
86 | GumpSDK.init(Context,Appid, Appkey,ChannelId,InitializeCallback); | 83 | GameSDK.init(Context,Appid,ChannelId); |
87 | 84 | ||
88 | InitializeCallback为初始化回调接口,此接口只有一个回调方法initComplete(int result) result标识是否初始化成功,当result等于GumpSDK.CODE.OK时为成功,其他为失败 | ||
89 | 85 | ||
90 | #### 2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数 | 86 | #### 2.调用GameSDK的登录方法,将执行登录流程,需要一个Activity实例作参数 |
91 | 87 | ||
92 | GumpSDK.start(Activity); | 88 | GameSDK.login(Activity); |
93 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: | 89 | 在此之前,开发者需要注册用户状态监听以接受用户的登录/登出通知,通常如下: |
94 | 90 | ||
95 | GumpSDK.setUserStateListener(new LoginStateListener() { | 91 | GameSDK.setUserStateListener(new LoginStateListener() { |
96 | @Override | 92 | @Override |
97 | public void onLoginSuccess(GumpUser gumpUser) { | 93 | public void onLoginSuccess(GumpUser gumpUser) { |
98 | //登录成功,用户信息包含在GumpUser对象里 | 94 | //登录成功,用户信息包含在GumpUser对象里 |
99 | } | 95 | } |
100 | 96 | ||
101 | @Override | 97 | @Override |
102 | public void onLoginFailed(int code, String msg) { | 98 | public void onLoginFailed(int code, String msg) { |
103 | //登录出错,根据错误码和信息判断错误类型 | 99 | //登录出错,根据错误码和信息判断错误类型 |
104 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); | 100 | Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show(); |
105 | } | 101 | } |
106 | 102 | ||
107 | @Override | 103 | @Override |
108 | public void onLoginCanceled() { | 104 | public void onLoginCanceled() { |
109 | //用户取消登录 | 105 | //用户取消登录 |
110 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); | 106 | Toast.makeText(MainActivity.this, "operate be canceled", Toast.LENGTH_SHORT).show(); |
111 | } | 107 | } |
112 | 108 | ||
113 | @Override | 109 | @Override |
114 | public void onLogout() { | 110 | public void onLogout() { |
115 | //用户登出 | 111 | //用户登出 |
116 | 112 | ||
117 | } | 113 | } |
118 | @Override | 114 | @Override |
119 | public void onPermissionDenied(String[] deniedPermissions) { | 115 | public void onPermissionDenied(String[] deniedPermissions) { |
120 | //用户未授予权限,参数为没有获取的权限 | 116 | //用户未授予权限,参数为没有获取的权限 |
121 | } | 117 | } |
122 | }); | 118 | }); |
123 | 119 | ||
124 | 如上成功登录后收到的GumpUser对象包含以下信息 | 120 | 如上成功登录后收到的GumpUser对象包含以下信息 |
125 | 121 | ||
126 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! | 122 | gumpUser.getUid();//获取用户的userid,此Id标识唯一用户! |
127 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 | 123 | gumpUser.getAccountType();//用户类型,此类型数据可从GumpPreference常量获取 |
128 | gumpUser.getSessionKey();//登录的sessionKey对象,获取sessionKey字符串请使用此对象的getToken()方法 | 124 | gumpUser.getSessionKey();//登录的sessionKey对象,获取sessionKey字符串请使用此对象的getToken()方法 |
129 | 125 | ||
130 | #### 3.支付功能 | 126 | #### 3.支付功能 |
131 | 调用支付前需先获取支付状态,根据状态调用支付方法 | 127 | 调用支付前需先判断支付状态,根据状态调用支付方法 |
132 | 128 | ||
133 | GumpSDK.shouldUseCoPay(Activity, serverId, roleId, new ResultCallback() { | 129 | GameSDK.iapUsable(Activity, serverId, roleId, new ResultCallback() { |
134 | @Override | 130 | @Override |
135 | public void onResult(boolean result) { | 131 | public void onResult(boolean result) { |
136 | if(result){ | 132 | if(result){ |
137 | //调用GumpSDK.iap | 133 | //调用GameSDK.iap |
138 | }else{ | 134 | }else{ |
139 | //调用GumpSDK.pay | 135 | //调用GameSDK.pay |
140 | } | 136 | } |
141 | } | 137 | } |
142 | }); | 138 | }); |
143 | 139 | ||
144 | 1)调用GumpSDK.pay | 140 | 1)调用GameSDK.pay |
145 | 141 | ||
146 | Bundle payInfo = new Bundle(); | 142 | Bundle payInfo = new Bundle(); |
147 | payInfo.putString("product", "元宝"); | 143 | payInfo.putString("product", "元宝"); |
148 | payInfo.putFloat("amount", 40.0f); | 144 | payInfo.putFloat("amount", 40.0f); |
149 | payInfo.putString("extraInfo", "This is demo!"); | 145 | payInfo.putString("extraInfo", "This is demo!"); |
150 | payInfo.putString("serverId", "B4003"); | 146 | payInfo.putString("serverId", "B4003"); |
151 | payInfo.putString("roleId", "10010"); | 147 | payInfo.putString("roleId", "10010"); |
152 | payInfo.putString("currency","currency"); | 148 | payInfo.putString("currency","currency"); |
153 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); | 149 | GumpSDK.pay(MainActivity.this, payInfo,PurchaseCallback); |
154 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,所有字段必须全部包含 | 150 | 调用pay方法时,必须穿入一个bundle对象,包含如上字段,所有字段必须全部包含 |
155 | 151 | ||
156 | 152 | ||
157 | 2)IAP支付 | 153 | 2)IAP支付 |
158 | 154 | ||
159 | Bundle payInfo = new Bundle(); | 155 | Bundle payInfo = new Bundle(); |
160 | payInfo.putString("product", "gp_skuId"); | 156 | payInfo.putString("product", "gp_skuId"); |
161 | payInfo.putFloat("amount", 0.1f); | 157 | payInfo.putFloat("amount", 0.1f); |
162 | payInfo.putString("extraInfo", "This is demo!"); | 158 | payInfo.putString("extraInfo", "This is demo!"); |
163 | payInfo.putString("serverId", "100"); | 159 | payInfo.putString("serverId", "100"); |
164 | payInfo.putString("roleId","100123"); | 160 | payInfo.putString("roleId","100123"); |
165 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); | 161 | GumpSDK.iap(MainActivity.this, payInfo, PurchaseCallback); |
166 | 162 | ||
167 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 163 | 3)PurchaseCallback为支付状态回调接口,此接口含有3个方法 |
168 | 164 | ||
169 | @Override | 165 | @Override |
170 | public void onPurchaseCompleted(PurchaseResult result) { | 166 | public void onPurchaseCompleted() { |
171 | Log.i(TAG,"purchase completed"); | 167 | Log.i(TAG,"purchase completed"); |
172 | } | 168 | } |
173 | 169 | ||
174 | @Override | 170 | @Override |
175 | public void onPurchaseError(int code, String msg) { | 171 | public void onPurchaseError(int code, String msg) { |
176 | Log.i(TAG,"purchase error"); | 172 | Log.i(TAG,"purchase error"); |
177 | } | 173 | } |
178 | 174 | ||
179 | @Override | 175 | @Override |
180 | public void onPurchaseCanceled() { | 176 | public void onPurchaseCanceled() { |
181 | Log.i(TAG,"purchase canceled"); | 177 | Log.i(TAG,"purchase canceled"); |
182 | } | 178 | } |
183 | 179 | ||
184 | #### 4.注销登录 | 180 | #### 4.注销登录 |
185 | 181 | ||
186 | GumpSDK.logout(Activity); | 182 | GameSDK.logout(Activity); |
187 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 | 183 | 当此方法调用后,用户退出登录,并会通过LoginStateListener接口通知调用程序!为了便于用户切换登录账户,请在游戏内提供用户注销的触发按钮 |
188 | #### 5.运营开关接口,若需要接入,会有我方运营人员提出需求,否则不需要接入(若对此接口不知所云,即可认为不需要接入,请自行忽略) | 184 | #### 5.运营开关接口,若需要接入,会有我方运营人员提出需求,否则不需要接入(若对此接口不知所云,即可认为不需要接入,请自行忽略) |
189 | 185 | ||
190 | GumpSDK.checkRisk(this, new ResultCallback() { | 186 | GameSDK.inspectRiskLevel(this, new ResultCallback() { |
191 | @Override | 187 | @Override |
192 | public void onResult(boolean result) { | 188 | public void onResult(boolean result) { |
193 | Log.i(TAG,result?"There is some risks":"Nothing is risk"); | 189 | Log.i(TAG,result?"There is some risks":"Nothing is risk"); |
194 | } | 190 | } |
195 | }); | 191 | }); |
196 | 192 | ||
197 | ## 第二章 常量字段与代码 | 193 | ## 第二章 常量字段与代码 |
198 | ### 1.第三方登录平台(third_plat) | 194 | ### 1.第三方登录平台(third_plat) |
199 | | 常量字段 | 说明 | | 195 | | 常量字段 | 说明 | |
200 | |--------------------------------|--------------| | 196 | |--------------------------------|--------------| |
201 | |SDKSettings.THIRD_SUPPORT_FB | Facebook登录 | | 197 | |SDKSettings.THIRD_SUPPORT_FB | Facebook登录 | |
202 | |SDKSettings.THIRD_SUPPORT_GOOGLE| Google登录 | | 198 | |SDKSettings.THIRD_SUPPORT_GOOGLE| Google登录 | |
203 | |SDKSettings.THIRD_SUPPORT_LINE | Line登录 | | 199 | |SDKSettings.THIRD_SUPPORT_LINE | Line登录 | |
204 | 200 | ||
205 | ### 2.登录账户类型 | 201 | ### 2.登录账户类型 |
206 | | 常量字段 | 说明 | | 202 | | 常量字段 | 说明 | |
207 | |-------------------------------------|--------------| | 203 | |-------------------------------------|--------------| |
208 | |GumpPreference.ACCOUNT_TYPE_FB | Facebook用户 | | 204 | |GumpPreference.ACCOUNT_TYPE_FB | Facebook用户 | |
209 | |GumpPreference.ACCOUNT_TYPE_REG | Gump注册用户 | | 205 | |GumpPreference.ACCOUNT_TYPE_REG | Gump注册用户 | |
210 | |GumpPreference.ACCOUNT_TYPE_QUICK_REG| 游客 | | 206 | |GumpPreference.ACCOUNT_TYPE_QUICK_REG| 游客 | |
211 | |GumpPreference.ACCOUNT_TYPE_GOOGLE | Google用户 | | 207 | |GumpPreference.ACCOUNT_TYPE_GOOGLE | Google用户 | |
212 | |GumpPreference.ACCOUNT_TYPE_LINE | Line用户 | | 208 | |GumpPreference.ACCOUNT_TYPE_LINE | Line用户 | |
213 | 209 | ||
214 | 210 | ||
215 | 211 | ||
216 | ## 第三章 常见问题 | 212 | ## 第三章 常见问题 |
217 | ### 问题1: 如何避免混淆对SDK的影响? | 213 | ### 问题1: 如何避免混淆对SDK的影响? |
218 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 214 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
219 | 类,导致SDK无法正常工作,解决方法如下: | 215 | 类,导致SDK无法正常工作,解决方法如下: |
220 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | 216 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 |
221 | 217 | ||
222 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable | 218 | -keepattributes *Annotation*,InnerClasses,SourceFile,LineNumberTable |
223 | -keep public class * extends android.app.Service | 219 | -keep public class * extends android.app.Service |
224 | -keep public class com.google.vending.licensing.ILicensingService | 220 | -keep public class com.google.vending.licensing.ILicensingService |
225 | -keep public class com.android.vending.licensing.ILicensingService | 221 | -keep public class com.android.vending.licensing.ILicensingService |
226 | -keep class com.gumptech.sdk.view.* {*;} | 222 | -keep class com.gump.game.sdk.view.* {*;} |
227 | -keep class com.gumptech.sdk.web.* {*;} | 223 | -keep class com.gump.game.sdk.web.* {*;} |
228 | -keep class com.gumptech.sdk.bridge.impl.*{*;} | ||
229 | 224 | ||
230 | 225 | ||
231 | 使得混淆的时候不会影响SDK的命名空间。 | 226 | 使得混淆的时候不会影响SDK的命名空间。 |