Blame view
GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
9.4 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 |
|
1a7b48163
![]() |
36 37 |
private String appId = "100"; private String appKey = "f899139df5e1059396431415e770c6dd"; |
c4a5d1b80
![]() |
38 |
private GumpUser gumpUser; |
d6bc71fcb
![]() |
39 |
|
4a6edc661
![]() |
40 41 42 43 44 |
/** * 测试数据 */ String serverId = "100"; String roleId = "41080"; |
4a6edc661
![]() |
45 |
|
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 |
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); |
1a7b48163
![]() |
93 |
btnPay.setEnabled(isRisk); |
4a6edc661
![]() |
94 95 96 97 98 99 |
} }); } }); 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 |
PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { @Override public void onSubmit(Bundle payInfo) { GumpSDK.pay(MainActivity.this, payInfo, MainActivity.this); } }); |
4a6edc661
![]() |
109 |
submitFragment.show(getSupportFragmentManager(), "pay"); |
d6bc71fcb
![]() |
110 111 |
} }); |
4a6edc661
![]() |
112 113 |
btnIap = findViewById(R.id.iap); btnIap.setOnClickListener(new View.OnClickListener() { |
064eb2054
![]() |
114 115 |
@Override public void onClick(View v) { |
4a6edc661
![]() |
116 117 118 119 120 121 122 |
PaymentInfoSubmitFragment submitFragment = PaymentInfoSubmitFragment.newInstance(new PaymentInfoSubmitFragment.OnSubmitListener() { @Override public void onSubmit(Bundle payInfo) { GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); } }); submitFragment.show(getSupportFragmentManager(), "iap"); |
064eb2054
![]() |
123 124 |
} }); |
6a217e5ca
![]() |
125 |
|
472513368
![]() |
126 |
|
057d4c203
![]() |
127 |
Log.i("DEMO", "country:" + Locale.getDefault().getCountry() + ",language:" + Locale.getDefault().getLanguage()); |
6a217e5ca
![]() |
128 |
GumpSDK.getSettings().setDebug(false); |
d6bc71fcb
![]() |
129 |
/** |
057d4c203
![]() |
130 |
* 设置是否打印debug日志 |
d6bc71fcb
![]() |
131 132 133 |
*/ GumpSDK.getSettings().enableDebugLogging(true); /** |
43932caac
![]() |
134 |
* 设置启用facebook登录 |
d6bc71fcb
![]() |
135 |
*/ |
43932caac
![]() |
136 |
GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_FB); |
43932caac
![]() |
137 138 139 140 141 142 143 144 145 146 |
/** * 设置启用google登录 */ GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_GOOGLE); /** * 设置启用Line登录 */ GumpSDK.getSettings().requestThirdSupport(SDKSettings.THIRD_SUPPORT_LINE); |
656f5f9fd
![]() |
147 148 149 150 151 |
/** * 设置支付版本 */ GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); |
d6bc71fcb
![]() |
152 153 154 |
/** * 设置用户登录状态监听器 */ |
064eb2054
![]() |
155 |
|
d6bc71fcb
![]() |
156 157 158 |
GumpSDK.setUserStateListener(new LoginStateListener() { @Override public void onLoginSuccess(GumpUser user) { |
4a6edc661
![]() |
159 |
btnCheckState.setEnabled(true); |
c4a5d1b80
![]() |
160 |
gumpUser = user; |
064eb2054
![]() |
161 162 163 164 165 166 167 168 169 170 171 172 173 |
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
![]() |
174 175 176 |
case GumpPreference.ACCOUNT_TYPE_GOOGLE: userType = "google 登录"; break; |
43932caac
![]() |
177 178 179 |
case GumpPreference.ACCOUNT_TYPE_LINE: userType = "Line登录"; break; |
d6bc71fcb
![]() |
180 |
} |
472513368
![]() |
181 182 183 184 |
userInfo.setText(" Userid:" + user.getUid() + " accountType:(" + user.getAccountType() + ") " + userType + " sessionKey:" + user.getSessionKey() .getToken()); |
d6bc71fcb
![]() |
185 186 187 188 189 |
btnLoginOrLogout.setText("Logout"); btnLoginOrLogout.setTag(1); } @Override |
064eb2054
![]() |
190 |
public void onLoginFailed(int code, String msg) { |
d6bc71fcb
![]() |
191 |
userInfo.setText(msg); |
064eb2054
![]() |
192 |
Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); |
d6bc71fcb
![]() |
193 194 195 196 197 198 199 200 201 202 203 204 205 |
} @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
![]() |
206 207 |
@Override |
057d4c203
![]() |
208 209 210 211 212 213 214 |
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
![]() |
215 |
} |
d6bc71fcb
![]() |
216 217 218 219 220 221 222 223 224 |
}); /** * 初始化sdk */ GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { @Override public void initComplete(int result) { if (result == GumpSDK.CODE.OK) { btnLoginOrLogout.setEnabled(true); |
d42a06680
![]() |
225 |
userInfo.setText("initialization has finished"); |
4a6edc661
![]() |
226 |
|
7a5aadf06
![]() |
227 |
//checkRisk(); |
d42a06680
![]() |
228 229 230 |
} else { btnInit.setEnabled(true); userInfo.setText("initialization has error"); |
d6bc71fcb
![]() |
231 232 233 234 235 |
} } }); tvVersion.setText("SDK Version:" + GumpSDK.getVersion()); |
064eb2054
![]() |
236 |
|
d6bc71fcb
![]() |
237 |
} |
43932caac
![]() |
238 |
private void checkRisk() { |
7a5aadf06
![]() |
239 240 241 |
GumpSDK.checkRisk(this, new ResultCallback() { @Override public void onResult(boolean isRisk) { |
43932caac
![]() |
242 |
Log.i(TAG, isRisk ? "There is some risks" : "Nothing is risk"); |
7a5aadf06
![]() |
243 244 245 |
} }); } |
d6bc71fcb
![]() |
246 247 |
@Override public void onPurchaseCompleted(PurchaseResult result) { |
064eb2054
![]() |
248 |
Log.i(TAG, "purchase completed"); |
d6bc71fcb
![]() |
249 250 251 252 |
} @Override public void onPurchaseError(int code, String msg) { |
7b52014d1
![]() |
253 |
Log.i(TAG, "purchase error:"+code+","+msg); |
d6bc71fcb
![]() |
254 255 256 257 |
} @Override public void onPurchaseCanceled() { |
064eb2054
![]() |
258 |
Log.i(TAG, "purchase canceled"); |
d6bc71fcb
![]() |
259 |
} |
064eb2054
![]() |
260 |
|
d6bc71fcb
![]() |
261 |
} |