|
@@ -0,0 +1,409 @@
|
|
|
+package com.fq.channel.sdk;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.AlertDialog.Builder;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.DialogInterface.OnKeyListener;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.fq.channel.sdk.base.interfaces.FQPluginApi;
|
|
|
+import com.fq.channel.sdk.base.interfaces.PluginResult;
|
|
|
+import com.fq.channel.sdk.base.interfaces.PluginResultHandler;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class SdkPluginOppo extends FQPluginApi {
|
|
|
+
|
|
|
+ private static final String TAG = "FQSDK_LOGSdkPluginOppo";
|
|
|
+
|
|
|
+
|
|
|
+ * 数据统计
|
|
|
+ */
|
|
|
+ private int dataType;
|
|
|
+ private String roleId,roleName,roleLevel,zoneId,zoneName,serverId,serverName,balance,vipLevel,partyName;
|
|
|
+
|
|
|
+
|
|
|
+ * 初始化
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void init(Context activity, Map<String, Object> map,
|
|
|
+ final PluginResultHandler handler) {
|
|
|
+ Log.i(TAG, "init");
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.OK));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 登录
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void login(final Context activity, final PluginResultHandler handler) {
|
|
|
+ Log.i(TAG, "login ");
|
|
|
+
|
|
|
+ Builder builder = new Builder(activity);
|
|
|
+ builder.setTitle("登录");
|
|
|
+ builder.setMessage("请选择登录操作");
|
|
|
+ builder.setCancelable(false);
|
|
|
+ builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.OK,"登录成功"));
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNeutralButton("失败", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.ERROR,"登录失败"));
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.CANCEL));
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setOnKeyListener(new OnKeyListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.CANCEL));
|
|
|
+ dialog.dismiss();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.create().show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void pay(final Context activity, final Map<String, Object> map,
|
|
|
+ final PluginResultHandler handler) {
|
|
|
+ Log.i(TAG, "pay map:"+ (map != null?map.toString():""));
|
|
|
+
|
|
|
+ Builder builder = new Builder(activity);
|
|
|
+ builder.setTitle("支付");
|
|
|
+ builder.setMessage("请选择支付操作");
|
|
|
+ builder.setCancelable(false);
|
|
|
+ builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.OK));
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNeutralButton("失败", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.ERROR));
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.CANCEL));
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setOnKeyListener(new OnKeyListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
+ handler.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.CANCEL));
|
|
|
+ dialog.dismiss();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.create().show();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 退出
|
|
|
+ * @param context
|
|
|
+ * @param prh
|
|
|
+ */
|
|
|
+ public void exit(Context context,PluginResultHandler prh){
|
|
|
+ Log.d(TAG, "exit");
|
|
|
+
|
|
|
+ prh.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.CANCEL));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 注销
|
|
|
+ */
|
|
|
+ public void logout(final Context context,final PluginResultHandler cb){
|
|
|
+ Log.d(TAG, "logout");
|
|
|
+
|
|
|
+ Builder builder = new Builder(context);
|
|
|
+ builder.setTitle("注销");
|
|
|
+ builder.setMessage("是否注销?");
|
|
|
+ builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ Log.d(TAG, "注销成功");
|
|
|
+ cb.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.OK));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ Log.d(TAG, "注销失败");
|
|
|
+ cb.onHandlePluginResult(new PluginResult(
|
|
|
+ PluginResult.Status.ERROR));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void changeAccount(Activity activity, final PluginResultHandler prh) {
|
|
|
+ Log.d(TAG, " changeAccount ");
|
|
|
+
|
|
|
+ Builder builder = new Builder(activity);
|
|
|
+ builder.setTitle("切换账号");
|
|
|
+ builder.setMessage("请选择切换账号操作");
|
|
|
+ builder.setCancelable(false);
|
|
|
+ builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNeutralButton("失败", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.setOnKeyListener(new OnKeyListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
|
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
+ dialog.dismiss();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ builder.create().show();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showTips(final String message){
|
|
|
+ Handler handler = new Handler(Looper.getMainLooper());
|
|
|
+ handler.post(new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 游戏角色信息
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ public void setExtraBundle(Bundle data){
|
|
|
+ if(null == data){
|
|
|
+ data = new Bundle();
|
|
|
+ }
|
|
|
+ Log.i(TAG, "setExtraBundle data:"+data.toString());
|
|
|
+
|
|
|
+ roleName = data.getString("roleName") ;
|
|
|
+ roleLevel = data.getString("roleLevel") ;
|
|
|
+ roleId = data.getString("roleId") ;
|
|
|
+ serverId = data.getString("serverId");
|
|
|
+ serverName = data.getString("serverName") ;
|
|
|
+ balance = data.getString("balance") ;
|
|
|
+ vipLevel = data.getString("vipLevel") ;
|
|
|
+ partyName = data.getString("partyName") ;
|
|
|
+ zoneId = data.getString("zoneId") ;
|
|
|
+ zoneName = data.getString("zoneName") ;
|
|
|
+ dataType = data.getInt("dataType") ;
|
|
|
+
|
|
|
+ StringBuffer reportData = new StringBuffer();
|
|
|
+ reportData.append("[");
|
|
|
+ reportData.append(" roleName:"+roleName);
|
|
|
+ reportData.append(" roleLevel:"+roleLevel);
|
|
|
+ reportData.append(" roleId:"+roleId);
|
|
|
+ reportData.append(" serverId:"+serverId);
|
|
|
+ reportData.append(" serverName:"+serverName);
|
|
|
+ reportData.append(" balance:"+balance);
|
|
|
+ reportData.append(" vipLevel:"+vipLevel);
|
|
|
+ reportData.append(" partyName:"+zoneId);
|
|
|
+ reportData.append(" zoneName:"+zoneName);
|
|
|
+ reportData.append(" dataType:"+dataType);
|
|
|
+ reportData.append("]");
|
|
|
+
|
|
|
+ switch(dataType){
|
|
|
+ case 0 :
|
|
|
+ showTips("数据上报:创建角色 ");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 1 :
|
|
|
+ showTips("数据上报:角色升级");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2 :
|
|
|
+ showTips("数据上报:上传区服信息");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 3 :
|
|
|
+ showTips("数据上报:登录");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 4 :
|
|
|
+ showTips("数据上报:进入游戏");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 5 :
|
|
|
+ showTips("数据上报:支付");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 6 :
|
|
|
+ showTips("数据上报:退出游戏");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 7 :
|
|
|
+ showTips("数据上报:退出游戏");
|
|
|
+ Log.i(TAG, "reportData"+reportData);
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 释放资源时调用,当用户退出界面或者游戏的时候,
|
|
|
+ * 调用此接口,释放资源才允许退出!
|
|
|
+ * @param context
|
|
|
+ */
|
|
|
+ public void releaseSdkResource(Context context){
|
|
|
+ Log.i(TAG, "releaseSdkResource");
|
|
|
+
|
|
|
+ Toast.makeText(context, "释放SDK资源", Toast.LENGTH_SHORT).show();
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ Intent startMain = new Intent(Intent.ACTION_MAIN);
|
|
|
+ startMain.addCategory(Intent.CATEGORY_HOME);
|
|
|
+ startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ context.startActivity(startMain);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.e(TAG, "releaseSdkResource 抛出异常!") ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 复写生命周期方法,里面调用
|
|
|
+ */
|
|
|
+ public void onStart(Context context){
|
|
|
+ Log.i(TAG, "onStart");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onCreate(Context context, Bundle handler){
|
|
|
+ Log.i(TAG, "onCreate");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onRestart(Context context){
|
|
|
+ Log.i(TAG, "onRestart");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onResume(Context context){
|
|
|
+ Log.i(TAG, "onResume");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onPause(Context context){
|
|
|
+ Log.i(TAG, "onPause");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onStop(Context context){
|
|
|
+ Log.i(TAG, "onStop");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onDestroy(Context context){
|
|
|
+ Log.i(TAG, "onDestroy");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data){
|
|
|
+ Log.i(TAG, "onActivityResult requestCode:"+requestCode+" resultCode:"+resultCode+" data:"+data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onNewIntent(Intent intent){
|
|
|
+ Log.i(TAG, "onNewIntent");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void attachBaseContext(Context context) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onApplicationCreate(Context context) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onSaveInstanceState(Context context, Bundle outState){
|
|
|
+ Log.i(TAG, "onSaveInstanceState");
|
|
|
+ }
|
|
|
+}
|