diff --git a/common/src/main/java/com/yunbao/common/views/weight/JavascriptInterface.java b/common/src/main/java/com/yunbao/common/views/weight/JavascriptInterface.java new file mode 100644 index 000000000..45fb58914 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/weight/JavascriptInterface.java @@ -0,0 +1,12 @@ +package com.yunbao.common.views.weight; + +import android.app.Activity; + +public class JavascriptInterface { + private Activity context; + + public JavascriptInterface(Activity context) { + this.context = context; + } + +} diff --git a/common/src/main/java/com/yunbao/common/views/weight/PDLiveWebView.java b/common/src/main/java/com/yunbao/common/views/weight/PDLiveWebView.java new file mode 100644 index 000000000..b545ecc19 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/weight/PDLiveWebView.java @@ -0,0 +1,38 @@ +package com.yunbao.common.views.weight; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.util.AttributeSet; +import android.webkit.WebView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +/** + * pdlive对H5页面开放的web控件 + */ +public class PDLiveWebView extends WebView { + + public PDLiveWebView(@NonNull Activity context) { + super(context); + init(context); + } + + public PDLiveWebView(@NonNull Activity context, @Nullable AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public PDLiveWebView(@NonNull Activity context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + @SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"}) + private void init(Activity context) { + getSettings().setJavaScriptEnabled(true); // 是否开启JS支持 + getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口 + getSettings().setDomStorageEnabled(true); + this.addJavascriptInterface(new JavascriptInterface(context), "androidObject"); + } +} diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 3ea61dcae..91238fb2f 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -1381,7 +1381,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL public void openLuckGiftTip() { UserBean u = CommonAppConfig.getInstance().getUserBean(); String url = CommonAppConfig.HOST + "/h5/Noble/index.html?nickname=" + u.getUserNiceName() + "&usernobId=" + u.getNoble_id() + "&token=" + CommonAppConfig.getInstance().getToken() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&anchorUid=" + mLiveUid + "&anchorName=" + mAncherName; - startActivity(new Intent(this, ZhuangBanActivity.class).putExtra("url", url)); + startActivity(new Intent(this, ZhuangBanActivity.class).putExtra("url", url).putExtra("title", "")); } /** diff --git a/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java b/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java index 2c2613461..a968068da 100644 --- a/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/ZhuangBanActivity.java @@ -20,6 +20,7 @@ import android.webkit.WebViewClient; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ProgressBar; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.RequiresApi; @@ -59,6 +60,7 @@ public class ZhuangBanActivity extends AbsActivity { private SVGAImageView svga; private FrameLayout title; private TextView titleView; + private RelativeLayout rootView; @Override protected int getLayoutId() { @@ -78,11 +80,21 @@ public class ZhuangBanActivity extends AbsActivity { if (isFullWindow) { title.setVisibility(View.GONE); } - if (getIntent().hasExtra("title") && TextUtils.isEmpty(titleString)) { - title.setVisibility(View.GONE); - } else { - title.setVisibility(View.VISIBLE); - titleView.setText(titleString); + if (getIntent().hasExtra("title")) { + if (TextUtils.isEmpty(titleString)){ + title.setVisibility(View.GONE); + }else { + if (TextUtils.equals(titleString, "blank")) { + title.setVisibility(View.GONE); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) rootView.getLayoutParams(); + params.topMargin = DpUtil.dp2px(24); + rootView.setLayoutParams(params); + } else { + title.setVisibility(View.VISIBLE); + titleView.setText(titleString); + } + } + } mWebView = new WebView(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); @@ -256,7 +268,6 @@ public class ZhuangBanActivity extends AbsActivity { Log.i("tag", url); Intent intent = new Intent(mContext, ZhuangBanActivity.class); intent.putExtra("url", url); - intent.putExtra("isFull", false); intent.putExtra("title", title); mContext.startActivity(intent); @@ -369,7 +380,7 @@ public class ZhuangBanActivity extends AbsActivity { Intent intent = new Intent(context, ZhuangBanActivity.class); Log.i("tag", url); intent.putExtra(Constants.URL, url); - if (url.contains("Noble/index.html")){ + if (url.contains("Noble/index.html")) { intent.putExtra("title", ""); } context.startActivity(intent); diff --git a/live/src/main/res/layout/activity_zhuang_ban_new.xml b/live/src/main/res/layout/activity_zhuang_ban_new.xml index 728b6b731..21876d17b 100644 --- a/live/src/main/res/layout/activity_zhuang_ban_new.xml +++ b/live/src/main/res/layout/activity_zhuang_ban_new.xml @@ -40,6 +40,7 @@ diff --git a/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java b/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java index e4dc18a53..ec898e6c4 100644 --- a/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/ZhuangBanActivity.java @@ -74,20 +74,24 @@ public class ZhuangBanActivity extends AbsActivity { } v_spacing = (View) findViewById(R.id.v_spacing); lt_title = (LinearLayout) findViewById(R.id.lt_title); - if (getIntent().hasExtra("title") && TextUtils.isEmpty(titleString)) { - lt_title.setVisibility(View.GONE); - } else { - lt_title.setVisibility(View.VISIBLE); + LinearLayout rootView = (LinearLayout) findViewById(com.yunbao.live.R.id.rootView); + if (getIntent().hasExtra("title")) { + if (TextUtils.isEmpty(titleString)){ + lt_title.setVisibility(View.GONE); + }else { + if (TextUtils.equals(titleString, "blank")) { + lt_title.setVisibility(View.GONE); + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rootView.getLayoutParams(); + params.topMargin = DpUtil.dp2px(24); + rootView.setLayoutParams(params); + } else { + lt_title.setVisibility(View.VISIBLE); + } + } + } -// if (Constants.isTitle) { -// lt_title.setVisibility(View.VISIBLE); -// v_spacing.setVisibility(View.GONE); -// } else { -// lt_title.setVisibility(View.GONE); -// v_spacing.setVisibility(View.VISIBLE); -// } L.e("H5---5>" + url); - LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView); + mProgressBar = (ProgressBar) findViewById(R.id.progressbar); svga = (SVGAImageView) findViewById(R.id.svga); mWebView = new WebView(mContext);