作者 潘达康

H5聚合转原生完成

@@ -30,4 +30,6 @@ android { @@ -30,4 +30,6 @@ android {
30 30
31 dependencies { 31 dependencies {
32 implementation fileTree(include: ["*.jar", "*.aar"], dir: "libs") 32 implementation fileTree(include: ["*.jar", "*.aar"], dir: "libs")
  33 + implementation 'com.android.support:support-v4:28.0.0'
  34 + implementation 'com.android.support:appcompat-v7:28.0.0'
33 } 35 }
@@ -21,6 +21,7 @@ import android.webkit.WebViewClient; @@ -21,6 +21,7 @@ import android.webkit.WebViewClient;
21 21
22 import com.agg.h5game.tools.AggH5Log; 22 import com.agg.h5game.tools.AggH5Log;
23 import com.agg.h5game.tools.AggH5Tools; 23 import com.agg.h5game.tools.AggH5Tools;
  24 +import com.agg.h5game.tools.MResource;
24 import com.agg.h5game.tools.ParamsTools; 25 import com.agg.h5game.tools.ParamsTools;
25 import com.stss.sdk.InitResult; 26 import com.stss.sdk.InitResult;
26 import com.stss.sdk.PayResult; 27 import com.stss.sdk.PayResult;
@@ -59,7 +60,7 @@ public class AggH5MainActivity extends Activity { @@ -59,7 +60,7 @@ public class AggH5MainActivity extends Activity {
59 super.onCreate(savedInstanceState); 60 super.onCreate(savedInstanceState);
60 mContext = this; 61 mContext = this;
61 62
62 - setContentView(R.layout.activity_main); 63 + setContentView(MResource.getIdByName(mContext, "layout", "activity_main"));
63 initView(); 64 initView();
64 initSDK(); 65 initSDK();
65 66
@@ -67,7 +68,7 @@ public class AggH5MainActivity extends Activity { @@ -67,7 +68,7 @@ public class AggH5MainActivity extends Activity {
67 if (!TextUtils.isEmpty(gameUrl)) { 68 if (!TextUtils.isEmpty(gameUrl)) {
68 h5game = gameUrl; 69 h5game = gameUrl;
69 } 70 }
70 - h5game = String.format(h5game, STSSConstants.sdkParams.getGame_id(),"0"); 71 + h5game = String.format(h5game, STSSConstants.sdkParams.getGame_id(), STSSConstants.sdkParams.getCurrChannel());
71 String newH5Url = h5game + "?" + ParamsTools.getParams(mContext, currToken); 72 String newH5Url = h5game + "?" + ParamsTools.getParams(mContext, currToken);
72 AggH5Log.d(TAG, newH5Url); 73 AggH5Log.d(TAG, newH5Url);
73 webView.loadUrl(newH5Url); 74 webView.loadUrl(newH5Url);
@@ -75,7 +76,7 @@ public class AggH5MainActivity extends Activity { @@ -75,7 +76,7 @@ public class AggH5MainActivity extends Activity {
75 76
76 private void initView() { 77 private void initView() {
77 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 78 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
78 - webView = findViewById(R.id.webview); 79 + webView = findViewById(MResource.getIdByName(mContext, "id", "webview"));
79 webView.addJavascriptInterface(new AggH5AndroidToJs(), "AggH5Game"); 80 webView.addJavascriptInterface(new AggH5AndroidToJs(), "AggH5Game");
80 81
81 //页面缩放,适应手机屏幕 82 //页面缩放,适应手机屏幕
@@ -112,7 +113,12 @@ public class AggH5MainActivity extends Activity { @@ -112,7 +113,12 @@ public class AggH5MainActivity extends Activity {
112 public void onPageFinished(WebView view, String url) { 113 public void onPageFinished(WebView view, String url) {
113 super.onPageFinished(view, url); 114 super.onPageFinished(view, url);
114 AggH5Log.d(TAG, "url for finish: " + url); 115 AggH5Log.d(TAG, "url for finish: " + url);
115 - login(); 116 + new Handler().postDelayed(new Runnable() {
  117 + @Override
  118 + public void run() {
  119 + login();
  120 + }
  121 + }, 1500);
116 } 122 }
117 }); 123 });
118 } 124 }
@@ -12,6 +12,8 @@ import android.view.animation.AlphaAnimation; @@ -12,6 +12,8 @@ import android.view.animation.AlphaAnimation;
12 import android.view.animation.Animation; 12 import android.view.animation.Animation;
13 import android.widget.ImageView; 13 import android.widget.ImageView;
14 14
  15 +import com.agg.h5game.tools.MResource;
  16 +
15 public class AggH5SplashActivity extends Activity { 17 public class AggH5SplashActivity extends Activity {
16 @Override 18 @Override
17 protected void onCreate(Bundle savedInstanceState) { 19 protected void onCreate(Bundle savedInstanceState) {
@@ -30,9 +32,9 @@ public class AggH5SplashActivity extends Activity { @@ -30,9 +32,9 @@ public class AggH5SplashActivity extends Activity {
30 } 32 }
31 33
32 super.onCreate(savedInstanceState); 34 super.onCreate(savedInstanceState);
33 - setContentView(R.layout.activity_splash); 35 + setContentView(MResource.getIdByName(this, "layout", "activity_splash"));
34 36
35 - ImageView mIvSplash = findViewById(R.id.img_splash); 37 + ImageView mIvSplash = findViewById(MResource.getIdByName(this, "id", "img_splash"));
36 38
37 Animation animation = new AlphaAnimation(1.0f,0.5f); 39 Animation animation = new AlphaAnimation(1.0f,0.5f);
38 animation.setDuration(2000); 40 animation.setDuration(2000);
  1 +package com.agg.h5game.tools;
  2 +
  3 +import android.content.Context;
  4 +
  5 +public class MResource {
  6 + public static int getIdByName(Context context, String className, String resName) {
  7 + return context.getResources().getIdentifier(resName,className,context.getPackageName());
  8 + }
  9 +
  10 + public static int getStyleId(Context context, String styleName) {
  11 + return context.getResources().getIdentifier(styleName, "style", context.getPackageName());
  12 + }
  13 +
  14 + public static String getStringByName(Context context, String className, String resName) {
  15 + String packageName = context.getPackageName();
  16 + int id = context.getResources().getIdentifier(resName,className,packageName);
  17 + return context.getResources().getString(id);
  18 + }
  19 +}
@@ -20,6 +20,7 @@ public class ParamsTools { @@ -20,6 +20,7 @@ public class ParamsTools {
20 if (token != null) { 20 if (token != null) {
21 params.put("uid", token.getGame_uid()); 21 params.put("uid", token.getGame_uid());
22 params.put("game_uid", token.getGame_uid()); 22 params.put("game_uid", token.getGame_uid());
  23 + params.put("channel_uid", token.getChannel_uid());
23 params.put("token", token.getToken()); 24 params.put("token", token.getToken());
24 } 25 }
25 return mapToQueryString(params); 26 return mapToQueryString(params);