作者 潘达康

H5聚合转原生完成

... ... @@ -30,4 +30,6 @@ android {
dependencies {
implementation fileTree(include: ["*.jar", "*.aar"], dir: "libs")
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
\ No newline at end of file
... ...
... ... @@ -21,6 +21,7 @@ import android.webkit.WebViewClient;
import com.agg.h5game.tools.AggH5Log;
import com.agg.h5game.tools.AggH5Tools;
import com.agg.h5game.tools.MResource;
import com.agg.h5game.tools.ParamsTools;
import com.stss.sdk.InitResult;
import com.stss.sdk.PayResult;
... ... @@ -59,7 +60,7 @@ public class AggH5MainActivity extends Activity {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_main);
setContentView(MResource.getIdByName(mContext, "layout", "activity_main"));
initView();
initSDK();
... ... @@ -67,7 +68,7 @@ public class AggH5MainActivity extends Activity {
if (!TextUtils.isEmpty(gameUrl)) {
h5game = gameUrl;
}
h5game = String.format(h5game, STSSConstants.sdkParams.getGame_id(),"0");
h5game = String.format(h5game, STSSConstants.sdkParams.getGame_id(), STSSConstants.sdkParams.getCurrChannel());
String newH5Url = h5game + "?" + ParamsTools.getParams(mContext, currToken);
AggH5Log.d(TAG, newH5Url);
webView.loadUrl(newH5Url);
... ... @@ -75,7 +76,7 @@ public class AggH5MainActivity extends Activity {
private void initView() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
webView = findViewById(R.id.webview);
webView = findViewById(MResource.getIdByName(mContext, "id", "webview"));
webView.addJavascriptInterface(new AggH5AndroidToJs(), "AggH5Game");
//页面缩放,适应手机屏幕
... ... @@ -112,8 +113,13 @@ public class AggH5MainActivity extends Activity {
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
AggH5Log.d(TAG, "url for finish: " + url);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
login();
}
}, 1500);
}
});
}
... ...
... ... @@ -12,6 +12,8 @@ import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import com.agg.h5game.tools.MResource;
public class AggH5SplashActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
... ... @@ -30,9 +32,9 @@ public class AggH5SplashActivity extends Activity {
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
setContentView(MResource.getIdByName(this, "layout", "activity_splash"));
ImageView mIvSplash = findViewById(R.id.img_splash);
ImageView mIvSplash = findViewById(MResource.getIdByName(this, "id", "img_splash"));
Animation animation = new AlphaAnimation(1.0f,0.5f);
animation.setDuration(2000);
... ...
package com.agg.h5game.tools;
import android.content.Context;
public class MResource {
public static int getIdByName(Context context, String className, String resName) {
return context.getResources().getIdentifier(resName,className,context.getPackageName());
}
public static int getStyleId(Context context, String styleName) {
return context.getResources().getIdentifier(styleName, "style", context.getPackageName());
}
public static String getStringByName(Context context, String className, String resName) {
String packageName = context.getPackageName();
int id = context.getResources().getIdentifier(resName,className,packageName);
return context.getResources().getString(id);
}
}
... ...
... ... @@ -20,6 +20,7 @@ public class ParamsTools {
if (token != null) {
params.put("uid", token.getGame_uid());
params.put("game_uid", token.getGame_uid());
params.put("channel_uid", token.getChannel_uid());
params.put("token", token.getToken());
}
return mapToQueryString(params);
... ...