|
@@ -15,6 +15,7 @@ import android.widget.Toast;
|
|
|
import com.example.fqchannelsdk.R;
|
|
|
import com.fq.channel.sdk.api.FqGame;
|
|
|
import com.fq.channel.sdk.api.IResult;
|
|
|
+import com.fq.channel.sdk.api.bean.LoginInfo;
|
|
|
import com.fq.channel.sdk.base.net.HttpManager;
|
|
|
import com.fq.channel.sdk.base.net.callback.BaseCallback;
|
|
|
import com.fq.channel.sdk.base.Exception.BaseException;
|
|
@@ -24,9 +25,6 @@ import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
-//import com.fq.channel.sdk.api.FqGame;
|
|
|
-//import com.fq.channel.sdk.api.bean.LoginInfo;
|
|
|
-//import com.fq.channel.sdk.api.bean.PaymentInfo;
|
|
|
|
|
|
/**
|
|
|
* @Description: 描述
|
|
@@ -43,47 +41,54 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
FqLog.i(TAG, "onCreate: ");
|
|
|
initUI();
|
|
|
initSDK();
|
|
|
+ FqGame.onCreate(savedInstanceState);
|
|
|
}
|
|
|
|
|
|
//跟游戏的主Activity走
|
|
|
@Override
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
super.onSaveInstanceState(outState);
|
|
|
- //保存状态
|
|
|
+ FqGame.onSaveInstanceState(outState);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
super.onNewIntent(intent);
|
|
|
+ FqGame.onNewIntent(intent);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ FqGame.onActivityResult(requestCode, resultCode, data);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onRestart() {
|
|
|
super.onRestart();
|
|
|
FqLog.i(TAG, "onRestart: ");
|
|
|
+ FqGame.onRestart();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStart() {
|
|
|
super.onStart();
|
|
|
FqLog.i(TAG, "onStart: ");
|
|
|
+ FqGame.onStart();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
FqLog.i(TAG, "onResume: ");
|
|
|
+ FqGame.onResume();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onPause() {
|
|
|
super.onPause();
|
|
|
FqLog.i(TAG, "onPause: ");
|
|
|
+ FqGame.onPause();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -91,15 +96,17 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
protected void onStop() {
|
|
|
super.onStop();
|
|
|
FqLog.i(TAG, "onStop: ");
|
|
|
+ FqGame.onStop();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
FqLog.i(TAG, "onDestroy: ");
|
|
|
+ FqGame.onDestroy();
|
|
|
}
|
|
|
|
|
|
- private void initUI(){
|
|
|
+ private void initUI() {
|
|
|
findViewById(getResourceId("fq_login", "id")).setOnClickListener(this);
|
|
|
findViewById(getResourceId("fq_switch_account", "id")).setOnClickListener(this);
|
|
|
findViewById(getResourceId("fq_logout", "id")).setOnClickListener(this);
|
|
@@ -112,7 +119,7 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
int id = v.getId();
|
|
|
- switch (id){
|
|
|
+ switch (id) {
|
|
|
case R.id.fq_login:
|
|
|
login();
|
|
|
break;
|
|
@@ -120,7 +127,7 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
case R.id.fq_switch_account:
|
|
|
try {
|
|
|
switch_account();
|
|
|
- }catch (JSONException e){
|
|
|
+ } catch (JSONException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
@@ -147,52 +154,40 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private int getResourceId(String name, String defType){
|
|
|
+ private int getResourceId(String name, String defType) {
|
|
|
return this.getResources().getIdentifier(name, defType, this.getPackageName());
|
|
|
}
|
|
|
|
|
|
- private void initSDK(){
|
|
|
+ private void initSDK() {
|
|
|
FqGame.init(MainActivity.this, new IResult<String>() {
|
|
|
@Override
|
|
|
public void onSuccess(String s) {
|
|
|
- FqLog.i(TAG,"init success: "+s);
|
|
|
+ FqLog.i(TAG, "init success: " + s);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFail(String failMsg) {
|
|
|
- FqLog.i(TAG,"init fail:"+failMsg);
|
|
|
+ FqLog.i(TAG, "init fail:" + failMsg);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void login(){
|
|
|
-// FqGame.login(MainActivity.this, new FqGame.IResult<LoginInfo>() {
|
|
|
-// @Override
|
|
|
-// public void onSuccess(LoginInfo s) {
|
|
|
-// Log.i(TAG,"login success: "+s.getUid());
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onFail(String failMsg) {
|
|
|
-// Log.i(TAG,"login fail:"+failMsg);
|
|
|
-// }
|
|
|
-// });
|
|
|
- HttpManager.getInstance().get("http://wwww.baidu.com", new BaseCallback<String>() {
|
|
|
+ private void login() {
|
|
|
+ FqGame.login(MainActivity.this, new IResult<LoginInfo>() {
|
|
|
@Override
|
|
|
- public void onFailure(BaseException msg) {
|
|
|
- FqLog.e(TAG, "onFailure: ");
|
|
|
+ public void onSuccess(LoginInfo s) {
|
|
|
+ FqLog.i(TAG, "login success: " + s.getUid());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onSuccess(int code, String msg, String data) {
|
|
|
- FqLog.i(TAG, "onResponse: " + data);
|
|
|
+ public void onFail(String failMsg) {
|
|
|
+ FqLog.i(TAG, "login fail:" + failMsg);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- public void charge(){
|
|
|
+ public void charge() {
|
|
|
|
|
|
//get price
|
|
|
// String priceString = ((EditText)findViewById(getResourceId("fq_charge_price",
|
|
@@ -236,11 +231,10 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
private void exit() {// 退出接口
|
|
|
}
|
|
|
|
|
|
- private void showGameExitView(){
|
|
|
+ private void showGameExitView() {
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
|
|
builder.setTitle("游戏自带退出界面");
|
|
|
builder.setCancelable(false);
|
|
@@ -265,9 +259,9 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
|
|
|
private void dataReport() {
|
|
|
//get report data type
|
|
|
- String dataReportTypeString = ((EditText)findViewById(getResourceId("fq_report_type",
|
|
|
+ String dataReportTypeString = ((EditText) findViewById(getResourceId("fq_report_type",
|
|
|
"id"))).getText().toString();
|
|
|
- if (TextUtils.isEmpty(dataReportTypeString)){
|
|
|
+ if (TextUtils.isEmpty(dataReportTypeString)) {
|
|
|
showResult("请先填入上报类型");
|
|
|
return;
|
|
|
}
|
|
@@ -319,17 +313,17 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
}
|
|
|
|
|
|
private void switch_account() throws JSONException {
|
|
|
- HashMap hashMap = new HashMap<String,String>();
|
|
|
+ HashMap hashMap = new HashMap<String, String>();
|
|
|
JSONObject custom = new JSONObject();
|
|
|
- custom.put("ssoid","ssoid");
|
|
|
+ custom.put("ssoid", "ssoid");
|
|
|
custom.put("token", "token");
|
|
|
- hashMap.put("channelType","ansen");
|
|
|
- hashMap.put("gameId","123");
|
|
|
- hashMap.put("imei","123");
|
|
|
- hashMap.put("channelId","123");
|
|
|
- hashMap.put("channelParams",custom.toString());
|
|
|
+ hashMap.put("channelType", "ansen");
|
|
|
+ hashMap.put("gameId", "123");
|
|
|
+ hashMap.put("imei", "123");
|
|
|
+ hashMap.put("channelId", "123");
|
|
|
+ hashMap.put("channelParams", custom.toString());
|
|
|
|
|
|
- HttpManager.getInstance().post("http://192.168.1.152:9099/api/sdk/channel/v1/login",hashMap, new BaseCallback<String>() {
|
|
|
+ HttpManager.getInstance().post("http://192.168.1.152:9099/api/sdk/channel/v1/login", hashMap, new BaseCallback<String>() {
|
|
|
@Override
|
|
|
public void onFailure(BaseException msg) {
|
|
|
Log.i(TAG, "onFailure: ");
|
|
@@ -342,12 +336,12 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void showResult(String message){
|
|
|
+ private void showResult(String message) {
|
|
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
|
|
|
- private void exitAppProcess(Activity activity){
|
|
|
- if (!activity.isFinishing()){
|
|
|
+ private void exitAppProcess(Activity activity) {
|
|
|
+ if (!activity.isFinishing()) {
|
|
|
activity.finish();
|
|
|
}
|
|
|
android.os.Process.killProcess(android.os.Process.myPid());
|
|
@@ -376,6 +370,6 @@ public class MainActivity extends Activity implements View.OnClickListener {
|
|
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]
|
|
|
grantResults) {
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
- FqGame.onRequestPermissionsResult(requestCode,permissions,grantResults);
|
|
|
+ FqGame.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
}
|
|
|
}
|