Blame view

InlandSDKDemo/src/com/gump/inland/sdk/demo/MainActivity.java 3.99 KB
83715f60d   赵康   add inlandSDKRelease
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  package com.gump.inland.sdk.demo;
  
  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 com.gump.inland.gamesdk.InlandSDK;
  import com.gump.inland.gamesdk.InlandSDKCallback;
  import com.gump.inland.gamesdk.InlandSDKException;
  import com.gump.inland.gamesdk.bean.GumpUser;
  import com.gump.inland.gamesdk.bean.PayRequest;
  import com.gump.inland.gamesdk.callback.PurchaseCallback;
  import com.gump.inland.gamesdk.passport.Passport;
83715f60d   赵康   add inlandSDKRelease
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  import com.ninjaonline.R;
  
  public class MainActivity extends Activity {
  
  	private static final String TAG = "MainActivity";
  	private TextView tvSDKInfo;
  	private TextView tvUserInfo;
  	private TextView tvPurchaseResult;
  	private Button btnLogin;
  	private Button btnPay;
  
  	@Override
  	protected void onCreate(Bundle savedInstanceState) {
  		super.onCreate(savedInstanceState);
  		setContentView(R.layout.activity_main);
  		tvSDKInfo = (TextView) findViewById(R.id.sdk_info);
  		tvUserInfo = (TextView) findViewById(R.id.user_info);
  		tvPurchaseResult = (TextView) findViewById(R.id.purchase_result);
  		btnLogin = (Button) findViewById(R.id.login);
  		btnPay = (Button) findViewById(R.id.purchase);
  
  		Log.d(TAG, "MainActivity onCreate");
1b1227b3b   赵康   更新银联sdk到3.1.0,解决a...
40
  		InlandSDK.setIsDebugEnable(false);
2a5af05fa   赵康   release 1.0.3
41
42
  		InlandSDK.setScreenLandscape(true);
  		InlandSDK.initializeSDK("10000", "dkfjgljdlgjldjgl");
83715f60d   赵康   add inlandSDKRelease
43
44
45
46
  		Passport.getInstance().registerCallback(new InlandSDKCallback<GumpUser>() {
  
  			@Override
  			public void onSuccess(GumpUser result) {
e0ca8afd8   赵康   release1.0.0
47
  				Log.d(TAG, "gumpUser:" + result.toString());
83715f60d   赵康   add inlandSDKRelease
48
49
50
51
52
53
54
  				btnLogin.setVisibility(View.GONE);
  				tvUserInfo.setText(formatUserInfo(result));
  				btnPay.setVisibility(View.VISIBLE);
  			}
  
  			@Override
  			public void onError(InlandSDKException error) {
e0ca8afd8   赵康   release1.0.0
55
  				Log.d(TAG, "login error:" + error.getMessage());
83715f60d   赵康   add inlandSDKRelease
56
57
58
59
  			}
  
  			@Override
  			public void onCancel() {
e0ca8afd8   赵康   release1.0.0
60
  				Log.d(TAG, "login be canceled");
83715f60d   赵康   add inlandSDKRelease
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  			}
  		});
  
  		tvSDKInfo.setText(getSDKInfo());
  		btnLogin.setOnClickListener(new View.OnClickListener() {
  
  			@Override
  			public void onClick(View v) {
  				Passport.getInstance().login(MainActivity.this);
  			}
  		});
  		btnPay.setOnClickListener(new View.OnClickListener() {
  
  			@Override
  			public void onClick(View v) {
  				PayRequest payRequest = new PayRequest();
  				payRequest.setPrice(1);
  				payRequest.setProduct("玄冥剑");
1b1227b3b   赵康   更新银联sdk到3.1.0,解决a...
79
  				payRequest.setExtOrder("p100201508311731");
83715f60d   赵康   add inlandSDKRelease
80
81
82
83
84
  				payRequest.setGumpUid(Passport.getInstance().getGumpUser().getUid());
  				InlandSDK.purchase(MainActivity.this, payRequest, new PurchaseCallback() {
  
  					@Override
  					public void onPurchaseError(Exception e) {
e0ca8afd8   赵康   release1.0.0
85
  						Log.w(TAG, "purchase error:" + e.getMessage());
83715f60d   赵康   add inlandSDKRelease
86
87
88
89
90
  						tvPurchaseResult.setText("purchase occured an error:" + e.getMessage());
  					}
  
  					@Override
  					public void onPurchaseSuccess(String gumpTransId, String extOrder) {
e0ca8afd8   赵康   release1.0.0
91
  						Log.d(TAG, "purchase success:" + gumpTransId + ",extorder:" + extOrder);
83715f60d   赵康   add inlandSDKRelease
92
93
94
95
96
  						tvPurchaseResult.setText("purchase " + gumpTransId + " success,extorder:" + extOrder);
  					}
  
  					@Override
  					public void onPurchaseCanceled() {
e0ca8afd8   赵康   release1.0.0
97
  						Log.d(TAG, "purchase be canceled");
83715f60d   赵康   add inlandSDKRelease
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  						tvPurchaseResult.setText("purchase be canceled");
  					}
  				});
  			}
  		});
  	}
  
  	@Override
  	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  		if (!InlandSDK.onActivityResult(requestCode, resultCode, data))
  			super.onActivityResult(requestCode, resultCode, data);
  	}
  
  	private String getSDKInfo() {
  		StringBuilder str = new StringBuilder();
  		str.append("SDK version:");
  		str.append(InlandSDK.getVersion());
  		str.append("
  appId:");
  		str.append(InlandSDK.getAppId());
  		str.append("
  appKey:");
  		str.append(InlandSDK.getAppKey());
  		return str.toString();
  	}
  
  	private String formatUserInfo(GumpUser user) {
  		StringBuilder str = new StringBuilder();
  		str.append("Logined User information:
  ");
  		str.append("userId:" + user.getUid());
  		str.append("
  acccountType:" + user.getAccountType());
  		str.append("
  sessionKey:" + user.getSessionKey());
  		return str.toString();
  	}
  }