Blame view
GameSDKDemo/src/main/java/com/gumptech/sdk/demo/MainActivity.java
6.78 KB
d6bc71fcb
![]() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
package com.gumptech.sdk.demo; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.text.ClipboardManager; 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
![]() |
15 |
import com.gumptech.sdk.PaymentVersion; |
d6bc71fcb
![]() |
16 17 18 19 20 |
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
![]() |
21 |
import com.gumptech.sdk.callback.ResultCallback; |
41d220c11
![]() |
22 |
import com.gumptech.sdk.passport.fb.FBAccessToken; |
d6bc71fcb
![]() |
23 |
|
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; |
41d220c11
![]() |
32 33 |
private String appId = "10022"; private String appKey = "93a27b0bd99bac3e68a440b48aa421ab"; |
d6bc71fcb
![]() |
34 |
private String sessionKey; |
064eb2054
![]() |
35 |
|
d6bc71fcb
![]() |
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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(); |
d6bc71fcb
![]() |
58 59 60 61 |
payInfo.putString("product", "test2"); payInfo.putFloat("amount", 0.1f); payInfo.putString("extraInfo", "This is demo!"); payInfo.putString("serverId", "100"); |
064eb2054
![]() |
62 |
payInfo.putString("roleId","100123"); |
d6bc71fcb
![]() |
63 64 65 66 |
payInfo.putString("sessionKey", sessionKey); GumpSDK.pay(MainActivity.this, payInfo, MainActivity.this); } }); |
064eb2054
![]() |
67 68 69 70 71 72 73 74 75 76 77 78 |
findViewById(R.id.iap).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle payInfo = new Bundle(); payInfo.putString("product", "gp_skuId"); payInfo.putFloat("amount", 0.1f); payInfo.putString("extraInfo", "This is demo!"); payInfo.putString("serverId", "100"); payInfo.putString("roleId","100123"); GumpSDK.iap(MainActivity.this, payInfo, MainActivity.this); } }); |
d6bc71fcb
![]() |
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
/** * 设置否是打印debug日志 */ GumpSDK.getSettings().enableDebugLogging(true); /** * 设置是否启用facebook登录 */ GumpSDK.getSettings().setFBEnable(true); /** * 设置是否启用Vk登录 */ GumpSDK.getSettings().setVKEnable(false); /** * 设置屏幕方向 */ GumpSDK.getSettings().setScreenLandscape(true); |
656f5f9fd
![]() |
95 96 97 98 99 |
/** * 设置支付版本 */ GumpSDK.getSettings().setPaymentVersion(PaymentVersion.V4); |
d6bc71fcb
![]() |
100 101 102 |
/** * 设置用户登录状态监听器 */ |
064eb2054
![]() |
103 |
|
d6bc71fcb
![]() |
104 105 106 |
GumpSDK.setUserStateListener(new LoginStateListener() { @Override public void onLoginSuccess(GumpUser user) { |
064eb2054
![]() |
107 108 |
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(user.getSessionKey()); |
d6bc71fcb
![]() |
109 |
sessionKey = user.getSessionKey(); |
064eb2054
![]() |
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
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; |
d6bc71fcb
![]() |
126 |
} |
064eb2054
![]() |
127 128 129 |
userInfo.setText(" Userid:" + user.getUid() + " accountType:(" + user.getAccountType() + ") " + userType + " sessionKey:" + user.getSessionKey()); |
d6bc71fcb
![]() |
130 131 132 133 134 |
btnLoginOrLogout.setText("Logout"); btnLoginOrLogout.setTag(1); } @Override |
064eb2054
![]() |
135 |
public void onLoginFailed(int code, String msg) { |
d6bc71fcb
![]() |
136 |
userInfo.setText(msg); |
064eb2054
![]() |
137 |
Toast.makeText(MainActivity.this, "Login failed:code=" + code + ",message=" + msg, Toast.LENGTH_SHORT).show(); |
d6bc71fcb
![]() |
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
} @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"); } }); /** * 初始化sdk */ GumpSDK.init(getApplicationContext(), appId, appKey, "1000", new InitializeCallback() { @Override public void initComplete(int result) { if (result == GumpSDK.CODE.OK) { btnLoginOrLogout.setEnabled(true); |
7a5aadf06
![]() |
160 161 |
//checkRisk(); |
d6bc71fcb
![]() |
162 163 164 165 166 |
} } }); tvVersion.setText("SDK Version:" + GumpSDK.getVersion()); |
064eb2054
![]() |
167 |
|
d6bc71fcb
![]() |
168 |
} |
7a5aadf06
![]() |
169 170 171 172 173 174 175 176 |
private void checkRisk(){ GumpSDK.checkRisk(this, new ResultCallback() { @Override public void onResult(boolean isRisk) { Log.i(TAG,isRisk?"There is some risks":"Nothing is risk"); } }); } |
d6bc71fcb
![]() |
177 178 |
@Override public void onPurchaseCompleted(PurchaseResult result) { |
064eb2054
![]() |
179 |
Log.i(TAG, "purchase completed"); |
d6bc71fcb
![]() |
180 181 182 183 |
} @Override public void onPurchaseError(int code, String msg) { |
064eb2054
![]() |
184 |
Log.i(TAG, "purchase error"); |
d6bc71fcb
![]() |
185 186 187 188 |
} @Override public void onPurchaseCanceled() { |
064eb2054
![]() |
189 |
Log.i(TAG, "purchase canceled"); |
d6bc71fcb
![]() |
190 |
} |
064eb2054
![]() |
191 |
|
d6bc71fcb
![]() |
192 |
} |