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