Blame view

InlandSDKDemo/src/com/gump/inland/sdk/demo/MainActivity.java 4.06 KB
83715f60d   赵康   add inlandSDKRelease
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  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;
  import com.gump.inland.gamesdk.utils.Logger;
  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");
  		InlandSDK.setIsDebugEnable(true);
  		InlandSDK.setScreenLandscape(false);
126455baa   赵康   add plat of param
43
  		InlandSDK.initializeSDK("10000", "dkfjgljdlgjldjgl","1001");
83715f60d   赵康   add inlandSDKRelease
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
136
  		Passport.getInstance().registerCallback(new InlandSDKCallback<GumpUser>() {
  
  			@Override
  			public void onSuccess(GumpUser result) {
  				Logger.d(TAG, "gumpUser:" + result.toString());
  				btnLogin.setVisibility(View.GONE);
  				tvUserInfo.setText(formatUserInfo(result));
  				btnPay.setVisibility(View.VISIBLE);
  			}
  
  			@Override
  			public void onError(InlandSDKException error) {
  				Logger.d(TAG, "login error:" + error.getMessage());
  			}
  
  			@Override
  			public void onCancel() {
  				Logger.d(TAG, "login be canceled");
  			}
  		});
  
  		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("玄冥剑");
  				payRequest.setExtOrder("p100201508311730");
  				payRequest.setGumpUid(Passport.getInstance().getGumpUser().getUid());
  				InlandSDK.purchase(MainActivity.this, payRequest, new PurchaseCallback() {
  
  					@Override
  					public void onPurchaseError(Exception e) {
  						Logger.w(TAG, "purchase error:" + e.getMessage());
  						tvPurchaseResult.setText("purchase occured an error:" + e.getMessage());
  					}
  
  					@Override
  					public void onPurchaseSuccess(String gumpTransId, String extOrder) {
  						Logger.d(TAG, "purchase success:" + gumpTransId + ",extorder:" + extOrder);
  						tvPurchaseResult.setText("purchase " + gumpTransId + " success,extorder:" + extOrder);
  					}
  
  					@Override
  					public void onPurchaseCanceled() {
  						Logger.d(TAG, "purchase be canceled");
  						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();
  	}
  }