Blame view
GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
10.3 KB
d6bc71fcb
![]() |
1 |
package com.gumptech.sdk.demo; |
d6bc71fcb
![]() |
2 |
import android.os.Bundle; |
4a6edc661
![]() |
3 |
import android.support.v7.app.AppCompatActivity; |
d6bc71fcb
![]() |
4 5 6 7 8 9 10 11 |
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; |
656f5f9fd
![]() |
12 |
import com.gumptech.sdk.PaymentVersion; |
43932caac
![]() |
13 |
import com.gumptech.sdk.SDKSettings; |
d6bc71fcb
![]() |
14 15 16 17 18 |
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; |
7a5aadf06
![]() |
19 |
import com.gumptech.sdk.callback.ResultCallback; |
41d220c11
![]() |
20 |
import com.gumptech.sdk.passport.fb.FBAccessToken; |
d6bc71fcb
![]() |
21 |
|
057d4c203
![]() |
22 |
import java.util.Locale; |
4a6edc661
![]() |
23 |
public class MainActivity extends AppCompatActivity implements PurchaseCallback { |
d6bc71fcb
![]() |
24 25 26 27 28 29 30 |
private static final String TAG = "MainActivity"; private TextView tvVersion; private TextView userInfo; private Button btnLoginOrLogout; |
d42a06680
![]() |
31 |
private Button btnInit; |
4a6edc661
![]() |
32 33 34 |
private Button btnCheckState; private Button btnPay; private Button btnIap; |
d6bc71fcb
![]() |
35 |
|
43932caac
![]() |
36 37 |
private String appId = "100"; private String appKey = "f899139df5e1059396431415e770c6dd"; |
c4a5d1b80
![]() |
38 |
private GumpUser gumpUser; |
d6bc71fcb
![]() |
39 |
|
4a6edc661
![]() |
40 41 42 43 44 45 |
/** * 测试数据 */ String serverId = "100"; String roleId = "41080"; String product = "test"; |
064eb2054
![]() |
46 |
|
d6bc71fcb
![]() |
47 48 49 50 |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); |
969c0010c
![]() |
51 |
|
057d4c203
![]() |
52 53 54 |
tvVersion = findViewById(R.id.version); userInfo = findViewById(R.id.user_info); btnLoginOrLogout = findViewById(R.id.login_or_logout); |
d42a06680
![]() |
55 |
btnInit = findViewById(R.id.init); |
4a6edc661
![]() |
56 |
btnCheckState = findViewById(R.id.check_state); |
d6bc71fcb
![]() |
57 58 59 60 61 62 63 64 65 66 |
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); } }); |
d42a06680
![]() |
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
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"); } } }); } }); |
4a6edc661
![]() |
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
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() { |
d6bc71fcb
![]() |
100 101 102 |
@Override public void onClick(View v) { |
4a6edc661
![]() |
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { @Override public void onSubmit(Bundle payInfo) { GumpSDK.pay(MainActivity.this, payInfo, MainActivity.this); } }); // Bundle payInfo = new Bundle(); // payInfo.putString("product", "test"); // payInfo.putFloat("amount", 0.1f); // payInfo.putString("extraInfo", "This is demo!"); // payInfo.putString("serverId", "s1"); // payInfo.putString("roleId", "100123"); // payInfo.putString("currency", "THB"); submitFragment.show(getSupportFragmentManager(), "pay"); |
d6bc71fcb
![]() |
117 118 |
} }); |
4a6edc661
![]() |
119 120 |
btnIap = findViewById(R.id.iap); btnIap.setOnClickListener(new View.OnClickListener() { |
064eb2054
![]() |
121 122 |
@Override public void onClick(View v) { |
4a6edc661
![]() |
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { @Override public void onSubmit(Bundle payInfo) { GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); } }); submitFragment.show(getSupportFragmentManager(), "iap"); // Bundle payInfo = new Bundle(); // payInfo.putString("product", "dwe"); // payInfo.putFloat("amount", 0.1f); // payInfo.putString("extraInfo", "This is demo!"); // payInfo.putString("serverId", serverId); // payInfo.putString("roleId", "100123"); // payInfo.putString("currency", "THB"); // GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); |
064eb2054
![]() |
138 139 |
} }); |
6a217e5ca
![]() |
140 |
|
472513368
![]() |
141 |
|
057d4c203
![]() |
142 |
Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); |
6a217e5ca
![]() |
143 |
GumpSDK.getSettings().setDebug(false); |
d6bc71fcb
![]() |
144 |
/** |
057d4c203
![]() |
145 |
* 设置是否打印debug日志 |
d6bc71fcb
![]() |
146 147 148 |
*/ GumpSDK.getSettings().enableDebugLogging(true); /** |
43932caac
![]() |
149 |
* 设置启用facebook登录 |
d6bc71fcb
![]() |
150 |
*/ |
43932caac
![]() |
151 |
GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); |
43932caac
![]() |
152 153 154 155 156 157 158 159 160 161 |
/** * 设置启用google登录 */ GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); /** * 设置启用Line登录 */ GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); |
656f5f9fd
![]() |
162 163 164 165 166 |
/** * 设置支付版本 */ GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); |
d6bc71fcb
![]() |
167 168 169 |
/** * 设置用户登录状态监听器 */ |
064eb2054
![]() |
170 |
|
d6bc71fcb
![]() |
171 172 173 |
GumpSDK.setUserStateListener(new LoginStateListener() { @Override public void onLoginSuccess(GumpUser user) { |
4a6edc661
![]() |
174 |
btnCheckState.setEnabled(true); |
c4a5d1b80
![]() |
175 |
gumpUser = user; |
064eb2054
![]() |
176 177 178 179 180 181 182 183 184 185 186 187 188 |
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; |
adab52895
![]() |
189 190 191 |
case GumpPreference.ACCOUNT_TYPE_GOOGLE: userType = "google 登录"; break; |
43932caac
![]() |
192 193 194 |
case GumpPreference.ACCOUNT_TYPE_LINE: userType = "Line登录"; break; |
d6bc71fcb
![]() |
195 |
} |
472513368
![]() |
196 197 198 199 |
userInfo.setText(" Userid:" + user.getUid() + " accountType:(" + user.getAccountType() + ") " + userType + " sessionKey:" + user.getSessionKey() .getToken()); |
d6bc71fcb
![]() |
200 201 202 203 204 |
btnLoginOrLogout.setText("Logout"); btnLoginOrLogout.setTag(1); } @Override |
064eb2054
![]() |
205 |
public void onLoginFailed(int code, String msg) { |
d6bc71fcb
![]() |
206 |
userInfo.setText(msg); |
064eb2054
![]() |
207 |
Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); |
d6bc71fcb
![]() |
208 209 210 211 212 213 214 215 216 217 218 219 220 |
} @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"); } |
6a217e5ca
![]() |
221 222 |
@Override |
057d4c203
![]() |
223 224 225 226 227 228 229 |
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(); |
6a217e5ca
![]() |
230 |
} |
d6bc71fcb
![]() |
231 232 233 234 235 236 237 238 239 |
}); /** * 初始化sdk */ GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { @Override public void initComplete(int result) { if (result == GumpSDK.CODE.OK) { btnLoginOrLogout.setEnabled(true); |
d42a06680
![]() |
240 |
userInfo.setText("initialization has finished"); |
4a6edc661
![]() |
241 |
|
7a5aadf06
![]() |
242 |
//checkRisk(); |
d42a06680
![]() |
243 244 245 |
} else { btnInit.setEnabled(true); userInfo.setText("initialization has error"); |
d6bc71fcb
![]() |
246 247 248 249 250 |
} } }); tvVersion.setText("SDK Version:" + GumpSDK.getVersion()); |
064eb2054
![]() |
251 |
|
d6bc71fcb
![]() |
252 |
} |
43932caac
![]() |
253 |
private void checkRisk() { |
7a5aadf06
![]() |
254 255 256 |
GumpSDK.checkRisk(this, new ResultCallback() { @Override public void onResult(boolean isRisk) { |
43932caac
![]() |
257 |
Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk"); |
7a5aadf06
![]() |
258 259 260 |
} }); } |
d6bc71fcb
![]() |
261 262 |
@Override public void onPurchaseCompleted(PurchaseResult result) { |
064eb2054
![]() |
263 |
Log.i(TAG, "purchase completed"); |
d6bc71fcb
![]() |
264 265 266 267 |
} @Override public void onPurchaseError(int code, String msg) { |
064eb2054
![]() |
268 |
Log.i(TAG, "purchase error"); |
d6bc71fcb
![]() |
269 270 271 272 |
} @Override public void onPurchaseCanceled() { |
064eb2054
![]() |
273 |
Log.i(TAG, "purchase canceled"); |
d6bc71fcb
![]() |
274 |
} |
064eb2054
![]() |
275 |
|
d6bc71fcb
![]() |
276 |
} |