Blame view

android/GameSDKSample/src/com/gumptech/loginsdk/sample/MainActivity.java 5.42 KB
c04253501   赵康   tag:release3.3.3_...
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  package com.gumptech.loginsdk.sample;
  
  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;
  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;
  import com.gumpsdk.wuruid.R;
  
  public class MainActivity extends Activity  implements PurchaseCallback{
  
      private static final String TAG = "MainActivity";
  
      private TextView tvVersion;
      private TextView userInfo;
  
      private Button btnLoginOrLogout;
  
      private String appId = "10022";
      private String appKey = "93a27b0bd99bac3e68a440b48aa421ab";
  
      @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();
                  payInfo.putString("nick", "thi");
                  payInfo.putString("product", "元宝");
                  payInfo.putFloat("amount", 0.0f);
                  payInfo.putString("extraInfo", "This is demo!");
b53b3a306   赵康   update 3.3.4,解除vk...
60
61
                  payInfo.putString("serverId", "5025");
                  GumpSDK.pay(MainActivity.this, payInfo, "7798753", MainActivity.this);
c04253501   赵康   tag:release3.3.3_...
62
63
64
65
66
67
68
69
70
71
72
73
74
              }
          });
          /**
           * 设置否是开启debug模式
           */
          GumpSDK.setDebugState(true);
          /**
           * 设置是否启用facebook登录
           */
          GumpSDK.setFBEnable(true);
          /**
           * 设置是否启用Vk登录
           */
b53b3a306   赵康   update 3.3.4,解除vk...
75
          GumpSDK.setVKEnable(true);
c04253501   赵康   tag:release3.3.3_...
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
          /**
           * 设置屏幕方向
           */
          GumpSDK.setScreenLandscape(false);
          /**
           * 设置用户登录状态监听器
           */
          GumpSDK.setUserStateListener(new LoginStateListener() {
              @Override
              public void onLoginSuccess(GumpUser user) {
              	ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
              	cm.setText(user.getSessionKey());
                  
                  String userType=null;
                  switch(user.getAccountType()){
                  case GumpPreference.ACCOUNT_TYPE_FB:
                  	userType = "Facebook登录";
                  	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;
                  }
                  userInfo.setText(" Userid:" + user.getUid() + "
   accountType:(" + user.getAccountType()+") "+userType + "
   sessionKey:" + user.getSessionKey());
                  btnLoginOrLogout.setText("Logout");
                  btnLoginOrLogout.setTag(1);
              }
  
              @Override
  			public void onLoginFailed(int code, String msg) {
                  userInfo.setText(msg);
                  Toast.makeText(MainActivity.this, "Login failed:code="+code+",message="+msg, Toast.LENGTH_SHORT).show();
              }
  
              @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);
                  }
              }
          });
  
  
          tvVersion.setText("SDK Version:" + GumpSDK.getVersion());
      }
  
      @Override
      public void onPurchaseCompleted(PurchaseResult result) {
          Log.i(TAG,"purchase completed");
      }
  
      @Override
      public void onPurchaseError(int code, String msg) {
          Log.i(TAG,"purchase error");
      }
  
      @Override
      public void onPurchaseCanceled() {
          Log.i(TAG,"purchase canceled");
      }
  }