Skip to content

Commit

Permalink
完善WebViewActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwfqin committed May 27, 2020
1 parent c963aef commit bc69431
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 113 deletions.
20 changes: 1 addition & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@
# 导入指南
``` groovy
// 测试版
def quicklib = "4.0.4"
def quicklib = "4.0.5"
// quicklib(Base)
implementation "com.sdwfqin.quicklib:quicklib:$quicklib"
Expand All @@ -123,22 +121,6 @@ implementation "com.sdwfqin.quicklib:paylib:$quicklib"
implementation "com.sdwfqin.quicklib:imageloader:$quicklib"
// Android 自定义View组件
implementation "com.sdwfqin.quicklib:widget:$quicklib"
// =================================================
// 稳定版
// quicklib(Base)
implementation 'com.sdwfqin.quicklib:quicklib:3.3.0'
// 支付模块
implementation 'com.sdwfqin.quicklib:paylib:3.1.0'
// Android 图片加载库(Glide封装)
implementation 'com.sdwfqin.quick:imageloader:3.2.0'
// Android 自定义View组件
implementation 'com.sdwfqin.quick:widget:3.2.0'
```

# 相关文档
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
20 changes: 16 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<!-- FileProvider文件共享 -->
<provider
android:name="androidx.core.content.FileProvider"
Expand Down Expand Up @@ -78,10 +79,21 @@
<activity
android:name=".ui.components.ShowSvgActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity android:name=".ui.components.WindowFloatAndScreenshotActivity" />
<activity android:name=".ui.mvvm.WeatherMvvmActivity" />
<activity android:name=".ui.mvp.WeatherMvpActivity" />
<activity android:name=".ui.components.CircleProgressDemoActivity" />
<activity
android:name=".ui.components.WebViewMainActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name=".ui.components.WindowFloatAndScreenshotActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name=".ui.mvvm.WeatherMvvmActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name=".ui.mvp.WeatherMvpActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name=".ui.components.CircleProgressDemoActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/com/sdwfqin/quickseed/base/ArouterConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public class ArouterConstants {
*/
public static final String COMPONENTS_SHOWSVG = "/components/showsvg";

/**
* 自定义WebView
*/
public static final String COMPONENTS_CUSTOMWEBVIEW = "/components/customwebview";

/**
* 悬浮窗与截图
*/
Expand All @@ -67,4 +62,14 @@ public class ArouterConstants {
* 圆(方)形加载进度条
*/
public static final String COMPONENTS_CIRCLEPROGRESSDEMO = "/components/circleprogressdemo";

/**
* WebViewDemo
*/
public static final String COMPONENTS_WEBVIEW = "/components/webview";

/**
* 自定义WebView
*/
public static final String COMPONENTS_CUSTOMWEBVIEW = "/components/customwebview";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.sdwfqin.quickseed.ui.components;

import android.widget.ArrayAdapter;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sdwfqin.quicklib.base.BaseActivity;
import com.sdwfqin.quicklib.base.QuickConstants;
import com.sdwfqin.quicklib.webview.QuickWebViewActivity;
import com.sdwfqin.quicklib.webview.QuickWebViewLoadDataActivity;
import com.sdwfqin.quickseed.R;
import com.sdwfqin.quickseed.base.ArouterConstants;
import com.sdwfqin.quickseed.databinding.ActivitySampleListBinding;

/**
* WebView示例
* <p>
*
* @author 张钦
* @date 2020/5/27
*/
@Route(path = ArouterConstants.COMPONENTS_WEBVIEW)
public class WebViewMainActivity extends BaseActivity<ActivitySampleListBinding> {

private String[] mTitle = new String[]{
"默认",
"自定义",
"加载本地html"
};

@Override
protected ActivitySampleListBinding getViewBinding() {
return ActivitySampleListBinding.inflate(getLayoutInflater());
}

@Override
protected void initEventAndData() {
mTopBar.setTitle("WebView Demo");
mTopBar.addLeftBackImageButton().setOnClickListener(v -> finish());

mBinding.list.setAdapter(new ArrayAdapter<>(mContext, R.layout.item_list, R.id.tv_items, mTitle));
}

@Override
protected void initClickListener() {
mBinding.list.setOnItemClickListener((adapterView, view, i, l) -> {
switch (i) {
case 0:
QuickWebViewActivity.launch("https://www.baidu.com");
break;
case 1:
ARouter.getInstance().build(ArouterConstants.COMPONENTS_CUSTOMWEBVIEW).navigation();
break;
case 2:
QuickWebViewLoadDataActivity.launch(null, "测试标题", QuickConstants.HEAD + "哈哈哈哈" + QuickConstants.END, false);
break;
default:
}
});
}
}
19 changes: 7 additions & 12 deletions app/src/main/java/com/sdwfqin/quickseed/ui/main/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.sdwfqin.quicklib.base.BaseFragment;
import com.sdwfqin.quicklib.dialog.HintDialog;
import com.sdwfqin.quicklib.imagepreview.ImagePreviewActivity;
import com.sdwfqin.quicklib.webview.QuickWebViewActivity;
import com.sdwfqin.quickseed.R;
import com.sdwfqin.quickseed.base.ArouterConstants;
import com.sdwfqin.quickseed.databinding.FragmentMainBinding;
Expand All @@ -37,10 +36,9 @@ public class MainFragment extends BaseFragment<FragmentMainBinding> {
"Camerax(支持二维码识别)",
"VLayoutDemo",
"展示SVG图片",
"跳转网页",
"自定义Webview",
"WebView",
"悬浮窗与截图",
"弹窗",
"支持换肤的弹窗",
"Mvvm Demo",
"Mvp Demo",
"圆(方)形加载进度条",
Expand Down Expand Up @@ -88,15 +86,12 @@ protected void initClickListener() {
ARouter.getInstance().build(ArouterConstants.COMPONENTS_SHOWSVG).navigation();
break;
case 7:
QuickWebViewActivity.launch("https://www.baidu.com");
ARouter.getInstance().build(ArouterConstants.COMPONENTS_WEBVIEW).navigation();
break;
case 8:
ARouter.getInstance().build(ArouterConstants.COMPONENTS_CUSTOMWEBVIEW).navigation();
break;
case 9:
ARouter.getInstance().build(ArouterConstants.COMPONENTS_WINDOWFLOATANDSCREENSHOT).navigation();
break;
case 10:
case 9:
HintDialog hintDialog = new HintDialog(mContext);
hintDialog.setFollowSkin(true);
hintDialog.show();
Expand All @@ -115,13 +110,13 @@ public void right() {
}
});
break;
case 11:
case 10:
ARouter.getInstance().build(ArouterConstants.COMPONENTS_MVVM).navigation();
break;
case 12:
case 11:
ARouter.getInstance().build(ArouterConstants.COMPONENTS_MVP).navigation();
break;
case 13:
case 12:
ARouter.getInstance().build(ArouterConstants.COMPONENTS_CIRCLEPROGRESSDEMO).navigation();
break;
default:
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_sample_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {

versionCode = 40094
versionName = "4.0.4"
versionCode = 40095
versionName = "4.0.5"

qmui = "2.0.0-alpha09"
okhttp = "4.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import android.webkit.WebView;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.StringUtils;
import com.just.agentweb.AgentWeb;
import com.just.agentweb.WebChromeClient;
import com.sdwfqin.quicklib.base.BaseActivity;
import com.sdwfqin.quicklib.databinding.QuickActivityWebViewBinding;

/**
* 描述:
* 描述:WebViewActivity基类
*
* @author zhangqin
* @date 2018/6/19
Expand All @@ -28,14 +27,6 @@ protected QuickActivityWebViewBinding getViewBinding() {

@Override
protected void initEventAndData() {

if (!StringUtils.isEmpty(getUrl())) {
mUrl = getUrl();
} else {
showMsg("未获取到url地址");
finish();
}

mTopBar.setTitle(getActivityTitle());

mTopBar.addLeftBackImageButton().setOnClickListener(v -> {
Expand All @@ -48,27 +39,28 @@ protected void initEventAndData() {
initWebView();
}

@Override
protected void initClickListener() {

}

private void initWebView() {
mAgentWeb = AgentWeb.with(mContext)
protected AgentWeb.CommonBuilder getWebViewCommonBuilder() {
return AgentWeb.with(mContext)
//传入AgentWeb 的父控件 ,如果父控件为 RelativeLayout , 那么第二参数需要传入 RelativeLayout.LayoutParams ,第一个参数和第二个参数应该对应。
.setAgentWebParent(mBinding.container, new LinearLayout.LayoutParams(-1, -1))
.useDefaultIndicator()// 使用默认进度条
.setWebChromeClient(new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
mTopBar.setTitle(title);
if (isAutoSetTitle()) {
mTopBar.setTitle(title);
}
}
})
});
}

protected void initWebView() {
mAgentWeb = getWebViewCommonBuilder()
//.defaultProgressBarColor() // 使用默认进度条颜色
.createAgentWeb()
.ready()
.go(mUrl);
.go(mUrl = getUrl());
}

@Override
Expand Down Expand Up @@ -107,17 +99,20 @@ protected void onDestroy() {

/**
* 设置url地址
*
* @return
*/
public abstract String getUrl();

/**
* 设置标题
*
* @return
*/
public String getActivityTitle() {
return "";
}

/**
* 是否监听标题变化
*/
protected boolean isAutoSetTitle() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.sdwfqin.quicklib.base.QuickArouterConstants;

/**
* 描述:WebViewActivity
* 描述:默认WebViewActivity
*
* @author 张钦
* @date 2018/1/16
Expand All @@ -19,7 +19,7 @@ public class QuickWebViewActivity extends QuickBaseWebViewActivity {
* @param url 页面地址
*/
public static void launch(String url) {
launch(url, null);
launch(url, "");
}

/**
Expand All @@ -29,11 +29,23 @@ public static void launch(String url) {
* @param title 默认标题
*/
public static void launch(String url, String title) {
launch(url, "", true);
}

/**
* 加载网页,带有默认标题
*
* @param url 页面地址
* @param title 默认标题
* @param autoSetTitle 是否自动监听设置标题
*/
public static void launch(String url, String title, boolean autoSetTitle) {
ARouter
.getInstance()
.build(QuickArouterConstants.QUICK_WEBVIEW)
.withString("url", url)
.withString("title", title)
.withBoolean("autoSetTitle", autoSetTitle)
.navigation();
}

Expand All @@ -49,4 +61,9 @@ public String getActivityTitle() {
}
return super.getActivityTitle();
}

@Override
protected boolean isAutoSetTitle() {
return getIntent().getBooleanExtra("autoSetTitle", true);
}
}
Loading

0 comments on commit bc69431

Please sign in to comment.