Showing
1 changed file
with
323 additions
and
202 deletions
| ... | @@ -803,81 +803,197 @@ android:authorities="originPackageTag.provider" | ... | @@ -803,81 +803,197 @@ android:authorities="originPackageTag.provider" |
| 803 | 803 | ||
| 804 | # 7. 完整的接入demo | 804 | # 7. 完整的接入demo |
| 805 | ```java | 805 | ```java |
| 806 | +package com.youai.foolsdk.demo; | ||
| 807 | + | ||
| 808 | +import android.Manifest; | ||
| 806 | import android.app.Activity; | 809 | import android.app.Activity; |
| 807 | import android.app.AlertDialog; | 810 | import android.app.AlertDialog; |
| 811 | +import android.app.Application; | ||
| 808 | import android.content.DialogInterface; | 812 | import android.content.DialogInterface; |
| 809 | import android.content.Intent; | 813 | import android.content.Intent; |
| 810 | import android.content.res.Configuration; | 814 | import android.content.res.Configuration; |
| 815 | +import android.os.Build; | ||
| 811 | import android.os.Bundle; | 816 | import android.os.Bundle; |
| 817 | +import android.os.Handler; | ||
| 812 | import android.util.Log; | 818 | import android.util.Log; |
| 813 | import android.view.KeyEvent; | 819 | import android.view.KeyEvent; |
| 814 | import android.view.View; | 820 | import android.view.View; |
| 821 | +import android.view.View.OnClickListener; | ||
| 815 | import android.view.WindowManager.LayoutParams; | 822 | import android.view.WindowManager.LayoutParams; |
| 816 | import android.widget.Button; | 823 | import android.widget.Button; |
| 817 | -import com.gzyouai.fengniao.sdk.framework.PoolExitDialogListener; | 824 | +import android.widget.TextView; |
| 818 | -import com.gzyouai.fengniao.sdk.framework.PoolExitListener; | 825 | +import android.widget.Toast; |
| 819 | -import com.gzyouai.fengniao.sdk.framework.PoolLoginInfo; | 826 | + |
| 820 | -import com.gzyouai.fengniao.sdk.framework.PoolLoginListener; | 827 | +import com.gzpublic.app.sdk.framework.PoolEventParameterName; |
| 821 | -import com.gzyouai.fengniao.sdk.framework.PoolLogoutListener; | 828 | +import com.gzpublic.app.sdk.framework.PoolEventType; |
| 822 | -import com.gzyouai.fengniao.sdk.framework.PoolPayInfo; | 829 | +import com.gzpublic.app.sdk.framework.PoolExitDialogListener; |
| 823 | -import com.gzyouai.fengniao.sdk.framework.PoolPayListener; | 830 | +import com.gzpublic.app.sdk.framework.PoolExitListener; |
| 824 | -import com.gzyouai.fengniao.sdk.framework.PoolRoleInfo; | 831 | +import com.gzpublic.app.sdk.framework.PoolExpansionListener; |
| 825 | -import com.gzyouai.fengniao.sdk.framework.PoolRoleListener; | 832 | +import com.gzpublic.app.sdk.framework.PoolLoginInfo; |
| 826 | -import com.gzyouai.fengniao.sdk.framework.PoolSDKCallBackListener; | 833 | +import com.gzpublic.app.sdk.framework.PoolLoginListener; |
| 827 | -import com.gzyouai.fengniao.sdk.framework.PoolSDKCode; | 834 | +import com.gzpublic.app.sdk.framework.PoolLogoutListener; |
| 828 | -import com.gzyouai.fengniao.sdk.framework.PoolSdkConfig; | 835 | +import com.gzpublic.app.sdk.framework.PoolPayInfo; |
| 829 | -import com.gzyouai.fengniao.sdk.framework.PoolSdkHelper; | 836 | +import com.gzpublic.app.sdk.framework.PoolPayListener; |
| 830 | -import com.gzyouai.fengniao.sdk.framework.PoolSdkLog; | 837 | +import com.gzpublic.app.sdk.framework.PoolPayOrderConfirmHandler; |
| 831 | - | 838 | +import com.gzpublic.app.sdk.framework.PoolReport; |
| 832 | -public class AppActivity extends Activity { | 839 | +import com.gzpublic.app.sdk.framework.PoolRoleInfo; |
| 833 | - | 840 | +import com.gzpublic.app.sdk.framework.PoolRoleListener; |
| 834 | - private Button yaLoginBt; | 841 | +import com.gzpublic.app.sdk.framework.PoolSDKCallBackListener; |
| 835 | - private Button yaEnterGameBt; | 842 | +import com.gzpublic.app.sdk.framework.PoolSDKCode; |
| 836 | - private Button yaPayBt; | 843 | +import com.gzpublic.app.sdk.framework.PoolSdkConfig; |
| 837 | - private Button yaSubmitRoleDataBt; | 844 | +import com.gzpublic.app.sdk.framework.PoolSdkHelper; |
| 838 | - private Button yaChannelCenter; | 845 | +import com.gzpublic.app.sdk.framework.PoolSdkLog; |
| 839 | - private Button yaLogoutBt; | 846 | +import org.json.JSONArray; |
| 840 | - private Button yaForumBt; | 847 | +import org.json.JSONException; |
| 841 | - private Button yaSwitchAccountBt; | 848 | +import org.json.JSONObject; |
| 849 | + | ||
| 850 | +import java.util.HashMap; | ||
| 851 | +import java.util.Locale; | ||
| 852 | +import java.util.Map; | ||
| 853 | + | ||
| 854 | +public class AppActivity extends Activity implements OnClickListener { | ||
| 855 | + //新的view | ||
| 856 | + private Button btLogin; | ||
| 857 | + private Button btEnterGame; | ||
| 858 | + private Button btPay; | ||
| 859 | + private Button btLogout; | ||
| 860 | + private Button btSubRoleInfo; | ||
| 861 | + private Button btOpenChannel; | ||
| 862 | + private Button btSwitchAcc; | ||
| 863 | + private Button btOpenBbs; | ||
| 864 | + private Button btQueryProducts; | ||
| 865 | + private Button pb_bt_verifyname; | ||
| 866 | + | ||
| 867 | + private Bundle saveBundle; | ||
| 868 | + //提示LOG | ||
| 869 | + private TextView txMsg,txSdkMsg; | ||
| 870 | + private Activity mContext; | ||
| 871 | + private PoolPayListener mPoolPayListener = new PoolPayListener() { | ||
| 872 | + | ||
| 873 | + @Override | ||
| 874 | + public void onPaySuccess(String paramCustom) {//支付回调以服务端通知为准 | ||
| 875 | + // TODO Auto-generated method stub | ||
| 876 | + //[{"orderId":"20180116114151740535D825","state":0,"productId":"1","productName":"金币","amout":0}] | ||
| 877 | + if(paramCustom == null || paramCustom.length() <= 0) | ||
| 878 | + { | ||
| 879 | + PoolSdkLog.logError("paysuccess data error :" + paramCustom); | ||
| 880 | + return; | ||
| 881 | + } | ||
| 882 | + try { | ||
| 883 | + PoolSdkLog.logInfo("paySuccess:" + paramCustom); | ||
| 884 | + JSONArray jsonArray = new JSONArray(paramCustom); | ||
| 885 | + StringBuilder orderIds = new StringBuilder(); | ||
| 886 | + int length = jsonArray.length(); | ||
| 887 | + for (int i = 0; i < length; i++) { | ||
| 888 | + JSONObject jb = jsonArray.getJSONObject(i); | ||
| 889 | + String orderId = jb.getString("orderId"); | ||
| 890 | + orderIds.append(orderId); | ||
| 891 | + if(i != length -1) {//最后一项不加分割符 | ||
| 892 | + orderIds.append(","); | ||
| 893 | + } | ||
| 894 | + } | ||
| 895 | + PoolSdkHelper.paymentSuccess(AppActivity.this, orderIds.toString()); | ||
| 896 | + } catch (JSONException e) { | ||
| 897 | + // TODO Auto-generated catch block | ||
| 898 | + e.printStackTrace(); | ||
| 899 | + } | ||
| 900 | + upTx("支付成功回调:" + paramCustom); | ||
| 901 | + } | ||
| 902 | + | ||
| 903 | + @Override | ||
| 904 | + public void onPayFailed(String paramCustom, String errorMsg) { | ||
| 905 | + // TODO Auto-generated method stub | ||
| 906 | + System.out.println("支付失败回调:" + paramCustom + "; errorMsg:" | ||
| 907 | + + errorMsg); | ||
| 908 | + upTx("支付失败回调:" + paramCustom + "; errorMsg:" | ||
| 909 | + + errorMsg); | ||
| 910 | + } | ||
| 911 | + }; | ||
| 912 | + | ||
| 913 | + @Override | ||
| 914 | + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
| 915 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
| 916 | + PoolSdkHelper.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
| 917 | + init(saveBundle); | ||
| 918 | + } | ||
| 842 | 919 | ||
| 843 | @Override | 920 | @Override |
| 844 | protected void onCreate(Bundle savedInstanceState) { | 921 | protected void onCreate(Bundle savedInstanceState) { |
| 845 | super.onCreate(savedInstanceState); | 922 | super.onCreate(savedInstanceState); |
| 846 | - int layoutId = getResources().getIdentifier("public_sdk_self_game_login", "layout", getPackageName()); | 923 | + saveBundle = savedInstanceState; |
| 924 | + int layoutId = getResources().getIdentifier( | ||
| 925 | + "public_sdk_self_test", "layout", getPackageName()); | ||
| 847 | setContentView(layoutId); | 926 | setContentView(layoutId); |
| 848 | - initLoginView(); | 927 | + mContext = this; |
| 928 | + initView(); | ||
| 929 | + PoolSdkLog.setIsShowLog(true); | ||
| 930 | + PoolSdkConfig.readPoolSdkConfigData(this); | ||
| 849 | 931 | ||
| 850 | - //================================↓↓↓↓↓公共SDK接入代码示例↓↓↓↓↓================================== | 932 | + if(getApplicationInfo().targetSdkVersion >= 23 && Build.VERSION.SDK_INT >= 23){ |
| 933 | + requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE,Manifest.permission.WRITE_EXTERNAL_STORAGE},1); | ||
| 934 | + }else {//不需要权限直接调用init | ||
| 935 | + this.init(savedInstanceState); | ||
| 936 | + } | ||
| 851 | 937 | ||
| 852 | - //PoolSdkHelper.isDebug = true; | 938 | + txSdkMsg.setText("sdksimplename:"+ PoolSdkConfig.getConfigByKey("sdksimplename") |
| 853 | - PoolSdkLog.setIsShowLog(true); | 939 | + +"\nsdkversioncode:"+PoolSdkConfig.getConfigByKey("sdkversioncode") |
| 940 | + +"\ngamesimplename:"+PoolSdkConfig.getConfigByKey("gamesimplename") | ||
| 941 | + +"\nlogincheckurl:"+PoolSdkConfig.getConfigByKey("logincheckurl") | ||
| 942 | + ); | ||
| 943 | + } | ||
| 944 | + | ||
| 945 | + private void init( Bundle savedInstanceState){ | ||
| 854 | PoolSdkHelper.init(this, new PoolSDKCallBackListener() { | 946 | PoolSdkHelper.init(this, new PoolSDKCallBackListener() { |
| 855 | @Override | 947 | @Override |
| 856 | public void poolSdkCallBack(int code, String msg) { | 948 | public void poolSdkCallBack(int code, String msg) { |
| 857 | - // TODO Auto-generated method stub | 949 | + PoolSdkLog.logInfo("poolSdkCallBack:code:" + code + ",msg:" + msg); |
| 858 | - PoolSdkLog.logInfo("callback: code:" + code + "msg:" + msg); | 950 | + upTx("poolSdkCallBack:code:" + code + ",msg:" + msg); |
| 859 | switch (code) { | 951 | switch (code) { |
| 860 | - case PoolSDKCode.POOLSDK_INIT_SUCCESS: | 952 | + case PoolSDKCode.POOLSDK_INIT_SUCCESS:// 初始化成功 |
| 861 | - // 收到初始化成功回调才可以调用其他接口 | 953 | + PoolSdkLog.logInfo("游戏中收到初始化成功回调"); |
| 862 | - PoolSdkLog.logInfo("SDK初始化成功"); | 954 | + new Handler().postDelayed(new Runnable() { |
| 955 | + | ||
| 956 | + @Override | ||
| 957 | + public void run() { | ||
| 863 | login(); | 958 | login(); |
| 959 | + } | ||
| 960 | + }, 1000); | ||
| 864 | break; | 961 | break; |
| 865 | case PoolSDKCode.POOLSDK_INIT_FAIL: | 962 | case PoolSDKCode.POOLSDK_INIT_FAIL: |
| 866 | break; | 963 | break; |
| 964 | + case PoolSDKCode.POOLSDK_QUERY_WITH_PRODUCTS: | ||
| 965 | + //msg:为查询的结果值 | ||
| 966 | + /** | ||
| 967 | + * {//查询商品信息返回数据 | ||
| 968 | + * "android.test.purchased0": {//key为商品ID | ||
| 969 | + * "displayPrice": "₩1167.28",//显示价格 | ||
| 970 | + * "price": "₩1,167", //实际价格(去除小数点) 充值传递 | ||
| 971 | + * "priceAmountMicros": 1167284249, //数字价格 | ||
| 972 | + * "priceCurrencyCode": "KRW", //货币代码 | ||
| 973 | + * "sku": "android.test.purchased0",//商品ID | ||
| 974 | + * "title": "名称示例" | ||
| 975 | + * } | ||
| 976 | + * } | ||
| 977 | + */ | ||
| 978 | + break; | ||
| 979 | + case PoolSDKCode.POOLSDK_EXTENDS_CODE1://实名认证成功才有回调 | ||
| 980 | + //msg为生日 | ||
| 981 | + break; | ||
| 867 | default: | 982 | default: |
| 868 | break; | 983 | break; |
| 869 | } | 984 | } |
| 870 | } | 985 | } |
| 871 | - }); | 986 | + },savedInstanceState);// init(this);// this为游戏的activity对象 |
| 872 | - | 987 | + PoolSdkHelper.setPayListener(mPoolPayListener); |
| 873 | PoolSdkHelper.setLogoutCallback(new PoolLogoutListener() { | 988 | PoolSdkHelper.setLogoutCallback(new PoolLogoutListener() { |
| 874 | @Override | 989 | @Override |
| 875 | public void onLogoutSuccess() { | 990 | public void onLogoutSuccess() { |
| 876 | - //注销账号成功回调在这里通知,游戏收到注销成功,需自行回到登陆界面调用登陆接口 | 991 | + // TODO: 此处处理SDK登出的逻辑 |
| 877 | - PoolSdkLog.logInfo("游戏中logoutSuccess"); | 992 | + PoolSdkLog.logInfo("游戏中收到logoutSuccess回调"); |
| 878 | login(); | 993 | login(); |
| 879 | } | 994 | } |
| 880 | }); | 995 | }); |
| 996 | + PoolSdkHelper.trackEvent(getApplicationContext(), PoolEventType.POOL_RES_LOADED, null); | ||
| 881 | } | 997 | } |
| 882 | 998 | ||
| 883 | @Override | 999 | @Override |
| ... | @@ -930,61 +1046,52 @@ public class AppActivity extends Activity { | ... | @@ -930,61 +1046,52 @@ public class AppActivity extends Activity { |
| 930 | 1046 | ||
| 931 | @Override | 1047 | @Override |
| 932 | public void onConfigurationChanged(Configuration newConfig) { | 1048 | public void onConfigurationChanged(Configuration newConfig) { |
| 933 | - // TODO Auto-generated method stub | ||
| 934 | super.onConfigurationChanged(newConfig); | 1049 | super.onConfigurationChanged(newConfig); |
| 935 | PoolSdkHelper.onConfigurationChanged(newConfig); | 1050 | PoolSdkHelper.onConfigurationChanged(newConfig); |
| 936 | } | 1051 | } |
| 937 | 1052 | ||
| 938 | @Override | 1053 | @Override |
| 939 | protected void onSaveInstanceState(Bundle outState) { | 1054 | protected void onSaveInstanceState(Bundle outState) { |
| 940 | - // TODO Auto-generated method stub | ||
| 941 | super.onSaveInstanceState(outState); | 1055 | super.onSaveInstanceState(outState); |
| 942 | PoolSdkHelper.onSaveInstanceState(outState); | 1056 | PoolSdkHelper.onSaveInstanceState(outState); |
| 943 | } | 1057 | } |
| 944 | 1058 | ||
| 945 | @Override | 1059 | @Override |
| 946 | protected void onRestoreInstanceState(Bundle savedInstanceState) { | 1060 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 947 | - // TODO Auto-generated method stub | ||
| 948 | super.onRestoreInstanceState(savedInstanceState); | 1061 | super.onRestoreInstanceState(savedInstanceState); |
| 949 | PoolSdkHelper.onRestoreInstanceState(savedInstanceState); | 1062 | PoolSdkHelper.onRestoreInstanceState(savedInstanceState); |
| 950 | } | 1063 | } |
| 951 | 1064 | ||
| 952 | @Override | 1065 | @Override |
| 953 | public void onWindowFocusChanged(boolean hasFocus) { | 1066 | public void onWindowFocusChanged(boolean hasFocus) { |
| 954 | - // TODO Auto-generated method stub | ||
| 955 | super.onWindowFocusChanged(hasFocus); | 1067 | super.onWindowFocusChanged(hasFocus); |
| 956 | PoolSdkHelper.onWindowFocusChanged(hasFocus); | 1068 | PoolSdkHelper.onWindowFocusChanged(hasFocus); |
| 957 | } | 1069 | } |
| 958 | 1070 | ||
| 959 | @Override | 1071 | @Override |
| 960 | public void onWindowAttributesChanged(LayoutParams params) { | 1072 | public void onWindowAttributesChanged(LayoutParams params) { |
| 961 | - // TODO Auto-generated method stub | ||
| 962 | super.onWindowAttributesChanged(params); | 1073 | super.onWindowAttributesChanged(params); |
| 963 | PoolSdkHelper.onWindowAttributesChanged(params); | 1074 | PoolSdkHelper.onWindowAttributesChanged(params); |
| 964 | } | 1075 | } |
| 965 | 1076 | ||
| 966 | @Override | 1077 | @Override |
| 967 | - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
| 968 | - // TODO Auto-generated method stub | ||
| 969 | - super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
| 970 | - PoolSdkHelper.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
| 971 | - } | ||
| 972 | - | ||
| 973 | - //返回按钮退出游戏示例 | ||
| 974 | - @Override | ||
| 975 | public boolean dispatchKeyEvent(KeyEvent pKeyEvent) { | 1078 | public boolean dispatchKeyEvent(KeyEvent pKeyEvent) { |
| 976 | - if (pKeyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK&& pKeyEvent.getAction() == KeyEvent.ACTION_DOWN) { | 1079 | + if (pKeyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK |
| 977 | - | 1080 | + && pKeyEvent.getAction() == KeyEvent.ACTION_DOWN) { |
| 978 | - //点击返回,判断渠道SDK有无退出框 | ||
| 979 | if (PoolSdkHelper.hasExitDialog()) { | 1081 | if (PoolSdkHelper.hasExitDialog()) { |
| 980 | PoolSdkHelper.showExitDialog(new PoolExitDialogListener() { | 1082 | PoolSdkHelper.showExitDialog(new PoolExitDialogListener() { |
| 981 | @Override | 1083 | @Override |
| 982 | public void onDialogResult(int code, String msg) { | 1084 | public void onDialogResult(int code, String msg) { |
| 983 | switch (code) { | 1085 | switch (code) { |
| 984 | - case PoolSDKCode.EXIT_SUCCESS:// 退出成功游戏处理自己退出逻辑 | 1086 | + case PoolSDKCode.EXIT_SUCCESS: |
| 1087 | + // 退出成功游戏处理自己退出逻辑 | ||
| 1088 | + PoolSdkLog.logInfo("游戏调用自己退出逻辑"); | ||
| 985 | finish(); | 1089 | finish(); |
| 1090 | + System.exit(0); | ||
| 986 | break; | 1091 | break; |
| 987 | - case PoolSDKCode.EXIT_CANCEL:// 取消退出 | 1092 | + case PoolSDKCode.EXIT_CANCEL: |
| 1093 | + // 取消退出 | ||
| 1094 | + PoolSdkLog.logInfo("收到取消退出回调"); | ||
| 988 | break; | 1095 | break; |
| 989 | default: | 1096 | default: |
| 990 | break; | 1097 | break; |
| ... | @@ -992,7 +1099,7 @@ public class AppActivity extends Activity { | ... | @@ -992,7 +1099,7 @@ public class AppActivity extends Activity { |
| 992 | } | 1099 | } |
| 993 | }); | 1100 | }); |
| 994 | } else { | 1101 | } else { |
| 995 | - //没有则调用游戏的退出界面 | 1102 | + // TODO: 调用游戏的退出界面 |
| 996 | showGameExitTips(); | 1103 | showGameExitTips(); |
| 997 | } | 1104 | } |
| 998 | return false; | 1105 | return false; |
| ... | @@ -1000,58 +1107,152 @@ public class AppActivity extends Activity { | ... | @@ -1000,58 +1107,152 @@ public class AppActivity extends Activity { |
| 1000 | return super.dispatchKeyEvent(pKeyEvent); | 1107 | return super.dispatchKeyEvent(pKeyEvent); |
| 1001 | } | 1108 | } |
| 1002 | 1109 | ||
| 1110 | + private void showGameExitTips() { | ||
| 1111 | + AlertDialog.Builder dialog = new AlertDialog.Builder(this); | ||
| 1112 | + int ic_dialog_alert_id = getRedIdByName("ic_dialog_alert", "drawable"); | ||
| 1113 | + dialog.setIcon(ic_dialog_alert_id); | ||
| 1114 | + dialog.setTitle("提示"); | ||
| 1115 | + dialog.setMessage("是否退出游戏?"); | ||
| 1116 | + dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { | ||
| 1117 | + @Override | ||
| 1118 | + public void onClick(DialogInterface dialog, int which) { | ||
| 1119 | + PoolSdkHelper.exitGame(new PoolExitListener() { | ||
| 1120 | + @Override | ||
| 1121 | + public void onExitGame() { | ||
| 1122 | + finish(); | ||
| 1123 | + } | ||
| 1124 | + }); | ||
| 1125 | + } | ||
| 1126 | + }); | ||
| 1127 | + dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
| 1128 | + @Override | ||
| 1129 | + public void onClick(DialogInterface dialog, int which) { | ||
| 1130 | + dialog.dismiss(); | ||
| 1131 | + } | ||
| 1132 | + }); | ||
| 1133 | + dialog.show(); | ||
| 1134 | + } | ||
| 1003 | 1135 | ||
| 1004 | - /** | 1136 | + private int getRedIdByName(String resName, String resType) { |
| 1005 | - * 切换帐号/注销账号 | 1137 | + return getResources().getIdentifier(resName, resType, getPackageName()); |
| 1006 | - */ | 1138 | + } |
| 1007 | - private void switchAccount() { | ||
| 1008 | - //游戏请先调用 PoolSdkHelper.hasLogout() PoolSdkHelper.hasSwitchAccount() 接口 判断渠道SDK有没有该接口 | ||
| 1009 | 1139 | ||
| 1010 | - if(PoolSdkHelper.hasLogout()){ | 1140 | + private void initView(){ |
| 1011 | - //如果渠道SDK有注销接口,那么游戏可以添加注销按钮,实现 PoolSdkHelper.logout(this); 结果在注销监听回调中处理 | 1141 | + btLogin = (Button) findViewById(getRedIdByName("pb_bt_login", "id")); |
| 1012 | - PoolSdkHelper.logout(this); | 1142 | + btEnterGame = (Button) findViewById(getRedIdByName("pb_bt_entergame", "id")); |
| 1143 | + btPay = (Button) findViewById(getRedIdByName("pb_bt_pay", "id")); | ||
| 1144 | + btLogout = (Button) findViewById(getRedIdByName("pb_bt_logout", "id")); | ||
| 1145 | + btSubRoleInfo = (Button) findViewById(getRedIdByName("pb_bt_subrole", "id")); | ||
| 1146 | + btOpenChannel = (Button) findViewById(getRedIdByName("pb_bt_openchannel", "id")); | ||
| 1147 | + btSwitchAcc = (Button) findViewById(getRedIdByName("pb_bt_switchacc", "id")); | ||
| 1148 | + btOpenBbs = (Button) findViewById(getRedIdByName("pb_bt_openbbs", "id")); | ||
| 1149 | + btQueryProducts = findViewById(getRedIdByName("pool_query_products_id","id")); | ||
| 1150 | + pb_bt_verifyname = (Button) findViewById(getRedIdByName("pb_bt_verifyname", "id")); | ||
| 1151 | + | ||
| 1152 | + txMsg = (TextView) findViewById(getRedIdByName("tx_msg", "id")); | ||
| 1153 | + txSdkMsg = (TextView) findViewById(getRedIdByName("tx_sdk_msg", "id")); | ||
| 1154 | + | ||
| 1155 | + btLogin.setOnClickListener(this); | ||
| 1156 | + btEnterGame.setOnClickListener(this); | ||
| 1157 | + btPay.setOnClickListener(this); | ||
| 1158 | + btLogout.setOnClickListener(this); | ||
| 1159 | + btSubRoleInfo.setOnClickListener(this); | ||
| 1160 | + btOpenChannel.setOnClickListener(this); | ||
| 1161 | + btSwitchAcc.setOnClickListener(this); | ||
| 1162 | + btOpenBbs.setOnClickListener(this); | ||
| 1163 | + btQueryProducts.setOnClickListener(this); | ||
| 1164 | + pb_bt_verifyname.setOnClickListener(this); | ||
| 1165 | + } | ||
| 1013 | 1166 | ||
| 1014 | - }else if(PoolSdkHelper.hasSwitchAccount()){ | 1167 | + public void yaOnClick(View view) { |
| 1015 | - //如果渠道SDK有切换账号接口,那么游戏可以添加切换账号按钮,实现 PoolSdkHelper.switchAccount(this); 新账号结果在登陆回调中处理 | 1168 | + } |
| 1016 | - PoolSdkHelper.switchAccount(this); | 1169 | + |
| 1017 | - }else{ | 1170 | + @Override |
| 1018 | - //直接回到登录界面调用登录 | 1171 | + public void onClick(View view) { |
| 1019 | - int layoutId = getResources().getIdentifier("public_sdk_self_game_login", "layout", getPackageName()); | 1172 | + //新view |
| 1020 | - setContentView(layoutId); | 1173 | + if (view == btLogin) { |
| 1021 | - initLoginView(); | 1174 | + login(); |
| 1175 | + }else if (view == btEnterGame) { | ||
| 1176 | + submitRoleData(10,PoolRoleInfo.Type_EnterGame); | ||
| 1177 | + //PoolReport.reportEnterGame("chufan","角色名", 12, "201","服务器名"); | ||
| 1178 | + }else if (view == btPay) { | ||
| 1179 | + pay(); | ||
| 1180 | + }else if (view == btLogout) { | ||
| 1181 | + logout(); | ||
| 1182 | + }else if (view == btSubRoleInfo) { | ||
| 1183 | + submitRoleData(11,PoolRoleInfo.Type_RoleUpgrade); | ||
| 1184 | + }else if (view == btOpenChannel) { | ||
| 1185 | + channelCenter(); | ||
| 1186 | + }else if (view == btSwitchAcc) { | ||
| 1187 | + switchAccount(); | ||
| 1188 | + }else if (view == btOpenBbs) { | ||
| 1189 | + trackEvent(); | ||
| 1190 | + }else if(view == btQueryProducts){ | ||
| 1191 | + queryProducts(); | ||
| 1192 | + }else if (view == pb_bt_verifyname){ | ||
| 1193 | + Toast.makeText(this,PoolSdkHelper.verifyRealName(this),Toast.LENGTH_SHORT).show(); | ||
| 1022 | } | 1194 | } |
| 1023 | } | 1195 | } |
| 1024 | 1196 | ||
| 1025 | - private void openForum(){ | 1197 | + private void trackEvent(){ |
| 1026 | - PoolSdkHelper.openForum(); | 1198 | + Map<String,Object> valueMap = new HashMap<>(); |
| 1199 | + valueMap.put(PoolEventParameterName.POOL_ORDER_ID,System.currentTimeMillis()+"");//订单号 | ||
| 1200 | + valueMap.put(PoolEventParameterName.POOL_CURRENCY,"USD");//货币类型 USD:美元 CNY:人民币 | ||
| 1201 | + valueMap.put(PoolEventParameterName.POOL_PRICE,6);//充值金额 | ||
| 1202 | + PoolSdkHelper.trackEvent(getApplicationContext(), PoolEventType.POOL_RES_LOADED,valueMap); | ||
| 1027 | } | 1203 | } |
| 1028 | 1204 | ||
| 1029 | - //单独注销按钮 注销账号 | ||
| 1030 | private void logout(){ | 1205 | private void logout(){ |
| 1031 | - if(PoolSdkHelper.hasLogout()){ | 1206 | +// if(PoolSdkHelper.hasLogout()){ |
| 1032 | - PoolSdkHelper.logout(this);//结果回调通知到PoolLogoutListener | 1207 | +// PoolSdkHelper.logout(this);//结果回调通知到PoolLogoutListener |
| 1208 | +// } | ||
| 1033 | } | 1209 | } |
| 1210 | + | ||
| 1211 | + private void upTx(final String msg){ | ||
| 1212 | + mContext.runOnUiThread(new Runnable() { | ||
| 1213 | + | ||
| 1214 | + @Override | ||
| 1215 | + public void run() { | ||
| 1216 | + txMsg.setText(msg); | ||
| 1217 | + } | ||
| 1218 | + }); | ||
| 1219 | +// new Handler().post(new Runnable() { | ||
| 1220 | +// | ||
| 1221 | +// @Override | ||
| 1222 | +// public void run() { | ||
| 1223 | +// txMsg.setText(msg); | ||
| 1224 | +// } | ||
| 1225 | +// }); | ||
| 1034 | } | 1226 | } |
| 1035 | 1227 | ||
| 1036 | private void login() { | 1228 | private void login() { |
| 1037 | - | 1229 | + PoolSdkLog.logError("调用login"); |
| 1038 | PoolSdkHelper.login("登录自定义字段", new PoolLoginListener() { | 1230 | PoolSdkHelper.login("登录自定义字段", new PoolLoginListener() { |
| 1039 | @Override | 1231 | @Override |
| 1040 | public void onLoginSuccess(PoolLoginInfo poolLoginInfo) { | 1232 | public void onLoginSuccess(PoolLoginInfo poolLoginInfo) { |
| 1041 | - String userType = poolLoginInfo.getUserType(); | 1233 | + final String userType = poolLoginInfo.getUserType(); |
| 1042 | - String timestamp = poolLoginInfo.getTimestamp(); | 1234 | + final String timestamp = poolLoginInfo.getTimestamp(); |
| 1043 | - String serverSign = poolLoginInfo.getServerSign(); | 1235 | + final String serverSign = poolLoginInfo.getServerSign(); |
| 1044 | - String openId = poolLoginInfo.getOpenID(); | 1236 | + final String openId = poolLoginInfo.getOpenID(); |
| 1045 | // TODO: 把以上信息发送给游戏服务端做登录校验,需要其他信息请从poolLoginInfo对象中获取 | 1237 | // TODO: 把以上信息发送给游戏服务端做登录校验,需要其他信息请从poolLoginInfo对象中获取 |
| 1046 | 1238 | ||
| 1047 | - System.out.println("登录成功 userType = " + userType + "; timestamp = " + timestamp + "; serverSign = " + serverSign + "; openId = " + openId); | 1239 | + System.out.println("登录成功回调:userType = " + userType |
| 1240 | + + "; timestamp = " + timestamp + "; serverSign = " | ||
| 1241 | + + serverSign + "; openId = " + openId); | ||
| 1242 | + upTx("登录成功回调:userType = " + userType | ||
| 1243 | + + "; timestamp = " + timestamp + "; serverSign = " | ||
| 1244 | + + serverSign + "; openId = " + openId); | ||
| 1048 | } | 1245 | } |
| 1049 | 1246 | ||
| 1050 | @Override | 1247 | @Override |
| 1051 | - public void onLoginFailed(String errorMsg) { | 1248 | + public void onLoginFailed(final String errorMsg) { |
| 1052 | - System.out.println("登录失败 = " + errorMsg); | 1249 | + System.out.println("登录失败回调 :" + errorMsg); |
| 1250 | + upTx("登录失败回调 :" + errorMsg); | ||
| 1053 | } | 1251 | } |
| 1054 | }); | 1252 | }); |
| 1253 | + | ||
| 1254 | + | ||
| 1255 | + PoolPayOrderConfirmHandler.getInstance(this, 2000, 1000).startOrderConfirmOp(mPoolPayListener); | ||
| 1055 | } | 1256 | } |
| 1056 | 1257 | ||
| 1057 | private void pay() { | 1258 | private void pay() { |
| ... | @@ -1061,9 +1262,9 @@ public class AppActivity extends Activity { | ... | @@ -1061,9 +1262,9 @@ public class AppActivity extends Activity { |
| 1061 | * 以下所有字段都是必填项 | 1262 | * 以下所有字段都是必填项 |
| 1062 | */ | 1263 | */ |
| 1063 | // 设置充值金额,单位“元” | 1264 | // 设置充值金额,单位“元” |
| 1064 | - poolPayInfo.setAmount("1"); | 1265 | + poolPayInfo.setAmount("100"); |
| 1065 | // 服务器id | 1266 | // 服务器id |
| 1066 | - poolPayInfo.setServerID("8"); | 1267 | + poolPayInfo.setServerID("1209"); |
| 1067 | // 服务器名 | 1268 | // 服务器名 |
| 1068 | poolPayInfo.setServerName("我是服务器名"); | 1269 | poolPayInfo.setServerName("我是服务器名"); |
| 1069 | // 角色id | 1270 | // 角色id |
| ... | @@ -1081,23 +1282,10 @@ public class AppActivity extends Activity { | ... | @@ -1081,23 +1282,10 @@ public class AppActivity extends Activity { |
| 1081 | // 兑换比例 | 1282 | // 兑换比例 |
| 1082 | poolPayInfo.setExchange("10"); | 1283 | poolPayInfo.setExchange("10"); |
| 1083 | // 自定义参数 | 1284 | // 自定义参数 |
| 1084 | - poolPayInfo.setCustom("operator=xwrw&server_id=39&player_id=2081&cp_order_id=001000100000020811491470345294&dext=2"); | 1285 | + poolPayInfo.setCustom("我是自定义参数"); |
| 1085 | 1286 | ||
| 1086 | // TODO Auto-generated method stub | 1287 | // TODO Auto-generated method stub |
| 1087 | - PoolSdkHelper.pay(poolPayInfo, new PoolPayListener() { | 1288 | + PoolSdkHelper.pay(poolPayInfo, mPoolPayListener); |
| 1088 | - | ||
| 1089 | - @Override | ||
| 1090 | - public void onPaySuccess(String paramCustom) { | ||
| 1091 | - System.out.println("支付成功 = " + paramCustom); | ||
| 1092 | - } | ||
| 1093 | - | ||
| 1094 | - @Override | ||
| 1095 | - public void onPayFailed(String paramCustom, String errorMsg) { | ||
| 1096 | - System.out.println("支付失败 = " + paramCustom + "; errorMsg = " | ||
| 1097 | - + errorMsg); | ||
| 1098 | - } | ||
| 1099 | - }); | ||
| 1100 | - | ||
| 1101 | } | 1289 | } |
| 1102 | 1290 | ||
| 1103 | /** | 1291 | /** |
| ... | @@ -1105,19 +1293,19 @@ public class AppActivity extends Activity { | ... | @@ -1105,19 +1293,19 @@ public class AppActivity extends Activity { |
| 1105 | * | 1293 | * |
| 1106 | * 1、登录游戏主场景 2、创建角色 3、角色升级 | 1294 | * 1、登录游戏主场景 2、创建角色 3、角色升级 |
| 1107 | */ | 1295 | */ |
| 1108 | - private void submitRoleData() { | 1296 | + private void submitRoleData(int level,String callType) { |
| 1109 | /******************************************** | 1297 | /******************************************** |
| 1110 | * 以下所有字段都是必填项 | 1298 | * 以下所有字段都是必填项 |
| 1111 | */ | 1299 | */ |
| 1112 | - PoolRoleInfo poolRoleInfo = new PoolRoleInfo(); | 1300 | + final PoolRoleInfo poolRoleInfo = new PoolRoleInfo(); |
| 1113 | poolRoleInfo.setRoleID("123456"); | 1301 | poolRoleInfo.setRoleID("123456"); |
| 1114 | - poolRoleInfo.setRoleLevel("10"); | 1302 | + poolRoleInfo.setRoleLevel(level+""); |
| 1115 | poolRoleInfo.setRoleSex("0"); | 1303 | poolRoleInfo.setRoleSex("0"); |
| 1116 | poolRoleInfo.setRoleName("我是角色名"); | 1304 | poolRoleInfo.setRoleName("我是角色名"); |
| 1117 | - poolRoleInfo.setServerID("8"); | 1305 | + poolRoleInfo.setServerID("1209"); |
| 1118 | poolRoleInfo.setServerName("我是服务器名"); | 1306 | poolRoleInfo.setServerName("我是服务器名"); |
| 1119 | poolRoleInfo.setCustom("角色创建时间"); | 1307 | poolRoleInfo.setCustom("角色创建时间"); |
| 1120 | - poolRoleInfo.setRoleCTime(System.currentTimeMillis()/1000);//角色创建时间(秒) | 1308 | + poolRoleInfo.setRoleCTime((long)1509331962);//角色创建时间(秒) |
| 1121 | poolRoleInfo.setPartyName("公会名称"); | 1309 | poolRoleInfo.setPartyName("公会名称"); |
| 1122 | poolRoleInfo.setRoleType("狂战");//角色类型 | 1310 | poolRoleInfo.setRoleType("狂战");//角色类型 |
| 1123 | poolRoleInfo.setRoleChangeTime(System.currentTimeMillis()/1000);//角色更新时间 | 1311 | poolRoleInfo.setRoleChangeTime(System.currentTimeMillis()/1000);//角色更新时间 |
| ... | @@ -1125,14 +1313,15 @@ public class AppActivity extends Activity { | ... | @@ -1125,14 +1313,15 @@ public class AppActivity extends Activity { |
| 1125 | poolRoleInfo.setDiamond("1000");//余额 | 1313 | poolRoleInfo.setDiamond("1000");//余额 |
| 1126 | poolRoleInfo.setMoneyType("金币");//商品单位 | 1314 | poolRoleInfo.setMoneyType("金币");//商品单位 |
| 1127 | 1315 | ||
| 1128 | - poolRoleInfo.setCallType(PoolRoleInfo.Type_EnterGame); | 1316 | + poolRoleInfo.setCallType(callType); |
| 1129 | // poolRoleInfo.setCallType(PoolRoleInfo.Type_CreateRole); | 1317 | // poolRoleInfo.setCallType(PoolRoleInfo.Type_CreateRole); |
| 1130 | // poolRoleInfo.setCallType(PoolRoleInfo.Type_RoleUpgrade); | 1318 | // poolRoleInfo.setCallType(PoolRoleInfo.Type_RoleUpgrade); |
| 1131 | 1319 | ||
| 1132 | PoolSdkHelper.submitRoleData(poolRoleInfo, new PoolRoleListener() { | 1320 | PoolSdkHelper.submitRoleData(poolRoleInfo, new PoolRoleListener() { |
| 1133 | @Override | 1321 | @Override |
| 1134 | public void onRoleDataSuccess(String paramCustom) { | 1322 | public void onRoleDataSuccess(String paramCustom) { |
| 1135 | - System.out.println("提交角色数据成功 = " + paramCustom); | 1323 | + System.out.println("提交角色数据成功:" + poolRoleInfo.verboseInfo()); |
| 1324 | + upTx("提交角色数据成功:" + poolRoleInfo.verboseInfo()); | ||
| 1136 | } | 1325 | } |
| 1137 | }); | 1326 | }); |
| 1138 | } | 1327 | } |
| ... | @@ -1149,107 +1338,39 @@ public class AppActivity extends Activity { | ... | @@ -1149,107 +1338,39 @@ public class AppActivity extends Activity { |
| 1149 | } | 1338 | } |
| 1150 | 1339 | ||
| 1151 | /** | 1340 | /** |
| 1152 | - * 实名认证接入示例 | 1341 | + * 切换帐号 |
| 1153 | */ | 1342 | */ |
| 1154 | - private void verifyRealName(){ | 1343 | + private void switchAccount() { |
| 1155 | - String realNameInfo = PoolSdkHelper.verifyRealName(paramActivity);//cp通过查询接口得到实名信息,其值一般为玩家的生日日期 | 1344 | + if(PoolSdkHelper.hasLogout()){ |
| 1156 | - if ("".equals(realNameInfo)){//渠道没有实名功能,此时cp需调用自己的实名功能 | 1345 | + PoolSdkHelper.logout(this);//注销成功后结果回调通知到PoolLogoutListener中 |
| 1157 | - //cp方实名认证逻辑。。。 | 1346 | + }else if(PoolSdkHelper.hasSwitchAccount()){ |
| 1158 | - }else if ("0".equals(realNameInfo)){//渠道有实名功能,但玩家未实名 | 1347 | + PoolSdkHelper.switchAccount(this);//切换成功后回回调结果到登录成功通知中(与登录通知数据一样) |
| 1159 | - boolean hasVerifyView = PoolSdkHelper.hasFunction("hasRealNameVerifyView");//cp通过此接口判断是否能调用渠道的实名认证界面 | 1348 | + }else{//渠道不存在注销和切换账号接口,游戏可自定处理逻辑 |
| 1160 | - if (hasVerifyView){//为true则表示能调用,false则表示无法调用渠道的实名界面 | ||
| 1161 | - //cp调渠道的实名认证逻辑,此接口的回调在初始化时传入的回调实例,code为 POOLSDK_EXTENDS_CODE1 | ||
| 1162 | - PoolSdkHelper.callFunc("showRealNameVerifyView",null); | ||
| 1163 | - } | ||
| 1164 | - }else{//玩家在渠道实名了 | ||
| 1165 | } | 1349 | } |
| 1166 | } | 1350 | } |
| 1167 | 1351 | ||
| 1168 | - //================================↑↑↑↑↑公共SDK接入代码示例↑↑↑↑↑================================== | 1352 | + /** |
| 1169 | - | 1353 | + * 扩展接口 |
| 1170 | - private void showGameExitTips() { | 1354 | + */ |
| 1171 | - AlertDialog.Builder dialog = new AlertDialog.Builder(this); | 1355 | + private void expansionInterface() { |
| 1172 | - int ic_dialog_alert_id = getRedIdByName("ic_dialog_alert", "drawable"); | 1356 | + PoolSdkHelper.expansionInterface("自定义参数", new PoolExpansionListener() { |
| 1173 | - dialog.setIcon(ic_dialog_alert_id); | ||
| 1174 | - dialog.setTitle("提示"); | ||
| 1175 | - dialog.setMessage("是否退出游戏?"); | ||
| 1176 | - dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { | ||
| 1177 | - @Override | ||
| 1178 | - public void onClick(DialogInterface dialog, int which) { | ||
| 1179 | - PoolSdkHelper.exitGame(new PoolExitListener() { | ||
| 1180 | - @Override | ||
| 1181 | - public void onExitGame() { | ||
| 1182 | - finish(); | ||
| 1183 | - } | ||
| 1184 | - }); | ||
| 1185 | - } | ||
| 1186 | - }); | ||
| 1187 | - dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
| 1188 | @Override | 1357 | @Override |
| 1189 | - public void onClick(DialogInterface dialog, int which) { | 1358 | + public void onSuccess(String paramCustom) { |
| 1190 | - dialog.dismiss(); | ||
| 1191 | } | 1359 | } |
| 1192 | }); | 1360 | }); |
| 1193 | - dialog.show(); | ||
| 1194 | - } | ||
| 1195 | - | ||
| 1196 | - private int getRedIdByName(String resName, String resType) { | ||
| 1197 | - return getResources().getIdentifier(resName, resType, getPackageName()); | ||
| 1198 | } | 1361 | } |
| 1199 | 1362 | ||
| 1200 | - private void initLoginView() { | 1363 | + /** |
| 1201 | - int ya_login_bt = getRedIdByName("ya_login_bt", "id");// getResources().getIdentifier("ya_login_bt", | 1364 | + * 商品查询接口 |
| 1202 | - // "id", | 1365 | + */ |
| 1203 | - // getPackageName()); | 1366 | + private void queryProducts(){ |
| 1204 | - yaLoginBt = (Button) findViewById(ya_login_bt); | 1367 | + PoolSdkLog.logError(PoolSdkHelper.hasFunction("hasQueryWithProducts") + "SSS"); |
| 1205 | - yaLoginBt.setText("登录"); | 1368 | + Map productMap = new HashMap<Object,Object>(); |
| 1206 | - yaEnterGameBt = (Button) findViewById(getRedIdByName( | 1369 | + productMap.put("productId1",""); |
| 1207 | - "ya_enter_game_bt", "id")); | 1370 | + productMap.put("productId2",""); |
| 1208 | - yaEnterGameBt.setText("进入游戏"); | 1371 | + PoolSdkHelper.callFunc("queryWithProducts",productMap); |
| 1209 | - } | ||
| 1210 | - | ||
| 1211 | - private void initGameView() { | ||
| 1212 | - yaPayBt = (Button) findViewById(getRedIdByName("ya_pay_bt", "id")); | ||
| 1213 | - yaPayBt.setText("支付"); | ||
| 1214 | - yaSubmitRoleDataBt = (Button) findViewById(getRedIdByName( | ||
| 1215 | - "ya_submit_role_data_bt", "id")); | ||
| 1216 | - yaSubmitRoleDataBt.setText("提交角色数据"); | ||
| 1217 | - yaChannelCenter = (Button) findViewById(getRedIdByName( | ||
| 1218 | - "ya_channel_center", "id")); | ||
| 1219 | - yaChannelCenter.setText("渠道中心"); | ||
| 1220 | - PoolSdkLog.logError("" + yaPayBt + "yachannel:" + yaChannelCenter); | ||
| 1221 | - | ||
| 1222 | - yaLogoutBt = (Button) findViewById(getRedIdByName("logout_bt", "id")); | ||
| 1223 | - | ||
| 1224 | - yaSwitchAccountBt = (Button) findViewById(getRedIdByName("ya_switch_account_bt", "id")); | ||
| 1225 | - yaSwitchAccountBt.setText("切换账号"); | ||
| 1226 | - | ||
| 1227 | - yaForumBt = (Button) findViewById(getRedIdByName("forum_bt", "id")); | ||
| 1228 | - } | ||
| 1229 | - | ||
| 1230 | - public void yaOnClick(View view) { | ||
| 1231 | - if (view == yaLoginBt) { | ||
| 1232 | - login(); | ||
| 1233 | - } else if (view == yaEnterGameBt) { | ||
| 1234 | - setContentView(getRedIdByName("public_sdk_self_game", "layout"));// (R.layout.game); | ||
| 1235 | - //模拟调用聊天接口: | ||
| 1236 | - //PoolSdkHelper.reportChat("content", "世界", "roleId", "roleName", 10, "serverId", "serverName"); | ||
| 1237 | - | ||
| 1238 | - initGameView(); | ||
| 1239 | - } else if (view == yaPayBt) { | ||
| 1240 | - pay(); | ||
| 1241 | - } else if (view == yaSubmitRoleDataBt) { | ||
| 1242 | - submitRoleData(); | ||
| 1243 | - } else if (view == yaChannelCenter) { | ||
| 1244 | - channelCenter(); | ||
| 1245 | - } else if (view == yaLogoutBt){ | ||
| 1246 | - logout(); | ||
| 1247 | - } else if (view == yaForumBt){ | ||
| 1248 | - openForum(); | ||
| 1249 | - } else if(view == yaSwitchAccountBt){//切换账号 | ||
| 1250 | - switchAccount(); | ||
| 1251 | - } | ||
| 1252 | } | 1372 | } |
| 1253 | } | 1373 | } |
| 1254 | 1374 | ||
| 1375 | + | ||
| 1255 | ``` | 1376 | ``` |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment