Blame view
InlandSDKDemo/src/com/gump/inland/sdk/demo/MainActivity.java
4.33 KB
83715f60d
![]() |
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
![]() |
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
![]() |
40 |
InlandSDK.setIsDebugEnable(false); |
2a5af05fa
![]() |
41 |
InlandSDK.setScreenLandscape(true); |
e845715e1
![]() |
42 |
InlandSDK.initializeSDK("10006", "6731f0406495c0a92ea7931f94b307b7"); |
83715f60d
![]() |
43 44 45 46 |
Passport.getInstance().registerCallback(new InlandSDKCallback<GumpUser>() { @Override public void onSuccess(GumpUser result) { |
e0ca8afd8
![]() |
47 |
Log.d(TAG, "gumpUser:" + result.toString()); |
83715f60d
![]() |
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
![]() |
55 |
Log.d(TAG, "login error:" + error.getMessage()); |
83715f60d
![]() |
56 57 58 59 |
} @Override public void onCancel() { |
e0ca8afd8
![]() |
60 |
Log.d(TAG, "login be canceled"); |
83715f60d
![]() |
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
![]() |
79 |
payRequest.setExtOrder("p100201508311731"); |
83715f60d
![]() |
80 81 82 83 |
payRequest.setGumpUid(Passport.getInstance().getGumpUser().getUid()); InlandSDK.purchase(MainActivity.this, payRequest, new PurchaseCallback() { @Override |
84509c18a
![]() |
84 |
public void onPurchaseError(final Exception e) { |
e0ca8afd8
![]() |
85 |
Log.w(TAG, "purchase error:" + e.getMessage()); |
84509c18a
![]() |
86 87 88 89 90 91 92 |
runOnUiThread(new Runnable() { @Override public void run() { tvPurchaseResult.setText("purchase occured an error:" + e.getMessage()); } }); |
83715f60d
![]() |
93 94 95 |
} @Override |
84509c18a
![]() |
96 |
public void onPurchaseSuccess(final String gumpTransId, final String extOrder) { |
e0ca8afd8
![]() |
97 |
Log.d(TAG, "purchase success:" + gumpTransId + ",extorder:" + extOrder); |
84509c18a
![]() |
98 99 100 101 102 103 104 |
runOnUiThread(new Runnable() { @Override public void run() { tvPurchaseResult.setText("purchase " + gumpTransId + " success,extorder:" + extOrder); } }); |
83715f60d
![]() |
105 106 107 108 |
} @Override public void onPurchaseCanceled() { |
e0ca8afd8
![]() |
109 |
Log.d(TAG, "purchase be canceled"); |
84509c18a
![]() |
110 111 112 113 114 115 116 |
runOnUiThread(new Runnable() { @Override public void run() { tvPurchaseResult.setText("purchase be canceled"); } }); |
83715f60d
![]() |
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
} }); } }); } @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(); } } |