Skip to content

Commit

Permalink
#update webview
Browse files Browse the repository at this point in the history
  • Loading branch information
wumeng1 authored and wumeng1 committed Jun 30, 2021
1 parent 96ec286 commit ba061f1
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 49 deletions.
22 changes: 12 additions & 10 deletions app/src/main/java/com/mirkowu/mvm/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class MainActivity : BaseActivity<EmptyMediator>() {
offscreenPageLimit = pagerAdapter.count
}
val PERMISSION_STORAGE = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE
)

BuglyManager.setOnUpgradeListener { upgradeInfo, isManual ->
Expand All @@ -64,18 +64,20 @@ class MainActivity : BaseActivity<EmptyMediator>() {
ToastUtils.showShort("当前已是最新版本!")
}
}
// Beta.upgradeStateListener
// BuglyManager.checkUpgrade(false,false)
// Beta.upgradeStateListener
// BuglyManager.checkUpgrade(false,false)
}

fun mvcClick(view: View?) {
fun webLocalClick(view: View?) {
// MVCActivity.start(this)
// WebViewActivity.start(context, "ces", "http://www.baidu.com/")
WebActivity.start(context, "ces", "file:///android_asset/test.html")
Log.d("WebActivity", "start: ")
}

fun webNetClick(view: View?) {
// CommonWebActivity.start(context, "ces", "http://www.baid")
// WebViewActivity.start(context, "ces", "https://x5.tencent.com/docs/questions.html")
// WebViewActivity.start(context, "ces", "file:///android_asset/test.html")
WebActivity.start(context, "ces", "file:///android_asset/test.html")
// WebActivity.start(context, "ces", "http://www.baidu.com/")
WebActivity.start(context, "标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题", "http://www.baidu.com/")
Log.d("WebActivity", "start: ")
}

Expand Down
15 changes: 13 additions & 2 deletions app/src/main/res/layout/fragment_databinding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="mvcClick"
android:text="WebView"
android:onClick="webLocalClick"
android:text="WebView本地"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.282" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="webNetClick"
android:text="WebView网络"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ext {
targetSdkVersion = 29
compileSdkVersion = 29

mvm_version = '1.0.14'
mvm_version = '1.0.17'
appcompat_version = '1.3.0'
core_ktx_version = '1.5.0'
lifecycle_version = '2.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ protected void initView() {
protected void configToolbar(String title, @NonNull WebConfig webConfig) {
mToolbar.setTitle(title);
mToolbar.setShowBackIcon(webConfig.isShowBack());
mToolbar.setCloseIcon(R.drawable.widget_ic_close_black);
mToolbar.setShowCloseIcon(false);
mToolbar.setVisibility(webConfig.isShowToolbar() ? View.VISIBLE : View.GONE);
mProgressBar.setVisibility(webConfig.isShowProgress() ? View.VISIBLE : View.GONE);
}
Expand All @@ -114,19 +116,22 @@ protected void clearHistory() {

@NonNull
protected WebConfig getWebConfig() {
boolean showClose = true;
return new WebConfig()
.setShowBack(true)
.setShowClose(showClose)
.setShowToolbar(true)
.setShowProgress(true)
// .setJsInjectionArrays(new String[]{"android"})
.setCallBack(new IWebViewCallBack() {
@Override
public void pageStarted(CommonWebView webView, String url) {

}

@Override
public void pageFinished(CommonWebView webView, String url) {
//显示关闭按钮
mToolbar.setShowCloseIcon(webView.canGoBack() && showClose);
}

@Override
Expand Down Expand Up @@ -160,26 +165,29 @@ protected void handleWebResult(int requestCode, int resultCode, Intent data) {

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (handleWebBack(keyCode, event)) {
if (keyCode == KeyEvent.KEYCODE_BACK && handleWebBack()) {
return true;
}

return super.onKeyDown(keyCode, event);
}

@Override
public void onBackPressed() {
if (handleWebBack()) {
return;
}
super.onBackPressed();
}

/**
* 处理返回键
*
* @param keyCode
* @param event
* @return
*/
protected boolean handleWebBack(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (mWebView != null && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
protected boolean handleWebBack() {
if (mWebView != null && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ProgressBar;

Expand Down Expand Up @@ -117,19 +116,22 @@ protected void configWebSettings(@NonNull WebConfig webConfig) {

@NonNull
protected WebConfig getWebConfig() {
boolean showClose = true;
return new WebConfig()
.setShowBack(true)
.setShowClose(showClose)
.setShowToolbar(true)
.setShowProgress(true)
// .setJsInjectionArrays(new String[]{"android"})
.setCallBack(new IWebViewCallBack() {
@Override
public void pageStarted(CommonWebView webView, String url) {

}

@Override
public void pageFinished(CommonWebView webView, String url) {
//显示关闭按钮
mToolbar.setShowCloseIcon(webView.canGoBack() && showClose);
}

@Override
Expand Down Expand Up @@ -165,16 +167,12 @@ protected void handleWebResult(int requestCode, int resultCode, Intent data) {
/**
* 处理返回键
*
* @param keyCode
* @param event
* @return
*/
public boolean handleWebBack(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (mWebView != null && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
public boolean handleWebBack() {
if (mWebView != null && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void saveWebArchive(String basename, boolean autoName, ValueCallback<Stri
super.saveWebArchive(basename, autoName, valueCallback);
}

protected boolean onBackHandle() {
public boolean onBackHandle() {
if (canGoBack()) {
goBack();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* 处理可配置的业务逻辑。但这些逻辑webView有可能用不到。所以是可用可不用的。
*/
public class WebConfig {
// private String mTitleText; //标题文案
// private String mTitleText; //标题文案
private boolean mShowToolbar; //设置是否需要标题栏,true表示需要,false表示不需要
private boolean mShowBack; //设置是否需要标题栏,true表示需要,false表示不需要
private boolean mShowBack; //设置是否需要返回键,true表示需要,false表示不需要
private boolean mShowClose; //设置是否需要关闭键,true表示需要,false表示不需要
private boolean mShowProgress; //设置是否需要进度条,true表示需要,false表示不需要
private IWebViewCallBack mWebViewCallBack; //WebView回调统一处理
private String mUserAgent;
Expand All @@ -35,6 +36,7 @@ public WebConfig setShowToolbar(boolean showToolbar) {
mShowToolbar = showToolbar;
return this;
}

/**
* @param showBack 左上角是否需要返回键,true表示需要,false表示不需要
* @return
Expand All @@ -44,6 +46,15 @@ public WebConfig setShowBack(boolean showBack) {
return this;
}

/**
* @param showClose 左上角是否需要关闭键,true表示需要,false表示不需要
* @return
*/
public WebConfig setShowClose(boolean showClose) {
mShowClose = showClose;
return this;
}

/**
* @param showProgress 是否展示进度条 true表示展示,false表示不展示
* @return
Expand Down Expand Up @@ -104,9 +115,13 @@ public String[] getJsInjectionArrays() {
public boolean isShowToolbar() {
return mShowToolbar;
}

public boolean isShowBack() {
return mShowBack;
}
public boolean isShowClose() {
return mShowClose;
}

public boolean isShowProgress() {
return mShowProgress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
android:layout_alignParentTop="true"
android:background="#FFFFFF"
android:visibility="gone"
app:backIcon="@drawable/widget_ic_back_black" />
app:backIcon="@drawable/widget_ic_back_black"
app:closeIcon="@drawable/widget_ic_close_black"
app:titleEllipsize="marquee" />

<com.mirkowu.lib_webview.CommonWebView
android:id="@+id/mWebView"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ public void setMediumStyle() {
setBoldWith(STYLE_MEDIUM);
}

// @Override
// public boolean isFocused() {
// if (getEllipsize() == TextUtils.TruncateAt.MARQUEE) {
// return true;
// } else {
// return super.isFocused();
// }
// }
}
Loading

0 comments on commit ba061f1

Please sign in to comment.