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