Blame view
android/GameSDKSample/src/com/gumptech/loginsdk/sample/MainActivity.java
3.24 KB
|
7bb951594
|
1 2 3 4 5 6 7 8 9 10 |
package com.gumptech.loginsdk.sample; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; |
|
7bb951594
|
11 12 13 |
import com.gumptech.sdk.GumpSDK;
public class MainActivity extends Activity implements GumpSDK.Callback {
|
|
3b0b01ef6
|
14 |
private TextView tvVersion; |
|
7bb951594
|
15 |
private TextView userInfo; |
|
3b0b01ef6
|
16 |
private Button btnLoginOrLogout; |
|
508fb0528
|
17 18 |
private String appId = "10009"; |
|
7bb951594
|
19 20 21 22 23 |
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
|
|
3b0b01ef6
|
24 |
tvVersion = (TextView) findViewById(R.id.version); |
|
7bb951594
|
25 |
userInfo = (TextView) findViewById(R.id.user_info); |
|
3b0b01ef6
|
26 27 |
btnLoginOrLogout = (Button) findViewById(R.id.login_or_logout);
btnLoginOrLogout.setOnClickListener(new View.OnClickListener() {
|
|
7bb951594
|
28 29 30 |
@Override
public void onClick(View v) {
|
|
3b0b01ef6
|
31 32 33 |
if (btnLoginOrLogout.getTag() == null || (Integer) btnLoginOrLogout.getTag() == 0) GumpSDK.start(MainActivity.this); else |
|
7bb951594
|
34 35 36 |
GumpSDK.logout(MainActivity.this, MainActivity.this); } }); |
|
7bb951594
|
37 38 39 40 41 42 43 44 45 |
findViewById(R.id.pay).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle payInfo = new Bundle();
payInfo.putString("nick", "thi");
payInfo.putString("product", "元宝");
payInfo.putFloat("amount", 0.0f);
payInfo.putString("extraInfo", "This is demo!");
|
|
e4307bd08
|
46 47 |
payInfo.putString("serverId", "B4003");
payInfo.putString("roleId", "10010");
|
|
7bb951594
|
48 |
GumpSDK.pay(MainActivity.this, payInfo); |
|
e4307bd08
|
49 |
} |
|
7bb951594
|
50 |
}); |
|
508fb0528
|
51 |
GumpSDK.init(getApplicationContext(), appId, "483d8df877b31405c1e8fe4247f02d86", "301596413332339", "1000"); |
|
3b0b01ef6
|
52 |
tvVersion.setText("SDK Version:" + GumpSDK.getVersion());
|
|
7bb951594
|
53 54 55 56 57 58 59 60 |
GumpSDK.start(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("Main", "activity requestCode:" + requestCode + ",resultCode:" + resultCode);
if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
|
|
c51a6fd5c
|
61 |
String uid = data.getStringExtra("userId");
|
|
7bb951594
|
62 63 |
int accountType = data.getIntExtra("accountType", -1);
String sessionkey = data.getStringExtra("sessionKey");
|
|
3b0b01ef6
|
64 65 66 67 68 |
userInfo.setText(" userid:" + uid + "
accountType:" + accountType + "
sessionKey:" + sessionkey);
btnLoginOrLogout.setText("Logout");
btnLoginOrLogout.setTag(1);
|
|
7bb951594
|
69 70 71 |
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show();
}
|
|
7bb951594
|
72 73 74 75 |
} else if (requestCode == GumpSDK.PAY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
int code = data.getIntExtra("code", -1);
String msg = data.getStringExtra("msg");
|
|
508fb0528
|
76 |
String orderId = data.getStringExtra("orderId");
|
|
7bb951594
|
77 78 79 80 81 82 83 84 85 86 87 |
String extraInfo = data.getStringExtra("extraInfo");
Toast.makeText(this, "pay result: " + code + "," + msg + ",orderId:" + orderId + ",extraInfo:" + extraInfo, Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onLogout() {
|
|
3b0b01ef6
|
88 89 90 91 |
btnLoginOrLogout.setText("Login");
btnLoginOrLogout.setTag(0);
userInfo.append("
User is logout");
|
|
7bb951594
|
92 93 94 |
} } |