Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-android
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 489ab2cd
authored
Aug 13, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
9b80fef5
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
322 additions
and
67 deletions
app/build.gradle
app/proguard-rules.pro
app/src/main/AndroidManifest.xml
app/src/main/assets/dist.zip
app/src/main/java/com/polysoft/nafmii/bean/OpenUrlBean.java
app/src/main/java/com/polysoft/nafmii/fragment/AdvertisementFragment.java
app/src/main/java/com/polysoft/nafmii/fragment/HomeWebviewFragment.java
app/src/main/java/com/polysoft/nafmii/fragment/InsideWebViewFragment.java
app/src/main/java/com/polysoft/nafmii/fragment/OutsideWebViewFragment.java
app/src/main/java/com/polysoft/nafmii/fragment/WebViewFragment.java
app/src/main/java/com/polysoft/nafmii/fragment/home/ModuleUrlHandle.java
app/src/main/java/com/polysoft/nafmii/utils/StatusBarUtils.java
app/src/main/java/com/polysoft/nafmii/viewmodel/AdvertisementViewModel.java
app/src/main/java/com/polysoft/nafmii/webview/HomeWebviewHandler.java
app/src/main/java/com/polysoft/nafmii/webview/NativeApi.java
app/src/main/java/com/polysoft/nafmii/webview/WebviewHandler.java
app/src/main/java/com/whaty/nafmii/activity/OutsideWebviewActivity.java
app/src/main/res/layout/activity_webview.xml
app/build.gradle
View file @
489ab2c
...
...
@@ -15,7 +15,8 @@ android {
versionName
"1.0"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
buildConfigField
"String"
,
"API_HOST"
,
"\"http://new.ynyc6666.com/shop/server/\""
buildConfigField
"String"
,
"API_HOST"
,
"\"http://10.10.81.189/nafmii/app/\""
buildConfigField
"String"
,
"IMG_API"
,
"\"http://10.10.81.172/group1/\""
buildConfigField
"String"
,
"WX_APPID"
,
"\"1234567890\""
buildConfigField
"boolean"
,
"SHOW_INPUT"
,
"true"
ndk
{
...
...
@@ -79,6 +80,7 @@ dependencies {
implementation
'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.7.0'
implementation
'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
implementation
'com.github.bumptech.glide:glide:4.12.0'
implementation
'org.greenrobot:eventbus:3.2.0'
implementation
"io.objectbox:objectbox-android:$objectboxVersion"
annotationProcessor
"io.objectbox:objectbox-processor:$objectboxVersion"
implementation
'me.jessyan:autosize:1.2.1'
...
...
app/proguard-rules.pro
View file @
489ab2c
...
...
@@ -20,6 +20,7 @@
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# x5
-
dontwarn
dalvik
.
**
-
dontwarn
com
.
tencent
.
smtt
.
**
-
keep
class
com
.
tencent
.
smtt
.
**
{
...
...
@@ -27,4 +28,30 @@
}
-
keep
class
com
.
tencent
.
tbs
.
**
{
*
;
}
\ No newline at end of file
}
# eventbus
-
keepattributes
*
Annotation
*
-
keepclassmembers
class
*
{
@
org
.
greenrobot
.
eventbus
.
Subscribe
<
methods
>
;
}
-
keep
enum
org
.
greenrobot
.
eventbus
.
ThreadMode
{
*
;
}
# And if you use AsyncExecutor:
-
keepclassmembers
class
*
extends
org
.
greenrobot
.
eventbus
.
util
.
ThrowableFailureEvent
{
<
init
>
(
java
.
lang
.
Throwable
);
}
# okhttp3
# JSR 305 annotations are for embedding nullability information.
-
dontwarn
javax
.
annotation
.
**
# A resource is loaded with a relative path so the package of this class must be preserved.
-
keepnames
class
okhttp3
.
internal
.
publicsuffix
.
PublicSuffixDatabase
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-
dontwarn
org
.
codehaus
.
mojo
.
animal_sniffer
.
*
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-
dontwarn
okhttp3
.
internal
.
platform
.
ConscryptPlatform
-
dontwarn
org
.
conscrypt
.
ConscryptHostnameVerifier
\ No newline at end of file
app/src/main/AndroidManifest.xml
View file @
489ab2c
...
...
@@ -54,6 +54,9 @@
<activity
android:name=
".activity.HomeActivity"
android:theme=
"@style/Nafmii.Fullscreen.NoTitleBar"
/>
<activity
android:name=
".activity.OutsideWebviewActivity"
android:theme=
"@style/Nafmii.Fullscreen.NoTitleBar"
/>
<activity
android:name=
".activity.InputUrlActivity"
></activity>
<activity
android:name=
".activity.TestHomeActivity"
...
...
app/src/main/assets/dist.zip
View file @
489ab2c
No preview for this file type
app/src/main/java/com/polysoft/nafmii/bean/OpenUrlBean.java
0 → 100644
View file @
489ab2c
package
com
.
polysoft
.
nafmii
.
bean
;
public
class
OpenUrlBean
{
private
String
linkUrl
;
private
String
linkType
;
private
String
title
;
private
String
nav
;
private
String
backClsName
;
public
String
getLinkUrl
()
{
return
linkUrl
;
}
public
void
setLinkUrl
(
String
linkUrl
)
{
this
.
linkUrl
=
linkUrl
;
}
public
String
getLinkType
()
{
return
linkType
;
}
public
void
setLinkType
(
String
linkType
)
{
this
.
linkType
=
linkType
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getNav
()
{
return
nav
;
}
public
void
setNav
(
String
nav
)
{
this
.
nav
=
nav
;
}
public
String
getBackClsName
()
{
return
backClsName
;
}
public
void
setBackClsName
(
String
backClsName
)
{
this
.
backClsName
=
backClsName
;
}
}
app/src/main/java/com/polysoft/nafmii/fragment/AdvertisementFragment.java
View file @
489ab2c
package
com
.
polysoft
.
nafmii
.
fragment
;
import
android.content.Intent
;
import
android.graphics.drawable.Drawable
;
import
android.os.Bundle
;
import
android.os.CountDownTimer
;
...
...
@@ -19,10 +20,13 @@ import com.bumptech.glide.Glide;
import
com.bumptech.glide.request.target.DrawableImageViewTarget
;
import
com.bumptech.glide.request.transition.Transition
;
import
com.polysoft.nafmii.bean.AdvertisementBean
;
import
com.polysoft.nafmii.bean.OpenUrlBean
;
import
com.polysoft.nafmii.utils.IntentUtils
;
import
com.whaty.nafmii.BuildConfig
;
import
com.whaty.nafmii.R
;
import
com.whaty.nafmii.activity.
AdvertisementWebviewAct
vity
;
import
com.whaty.nafmii.activity.
HomeActi
vity
;
import
com.whaty.nafmii.activity.IActivityEvent
;
import
com.whaty.nafmii.activity.OutsideWebviewActivity
;
public
class
AdvertisementFragment
extends
Fragment
implements
View
.
OnClickListener
{
...
...
@@ -33,6 +37,8 @@ public class AdvertisementFragment extends Fragment implements View.OnClickListe
private
boolean
finished
=
false
;
private
View
mRootView
;
private
AdvertisementBean
mBean
;
public
static
AdvertisementFragment
newInstance
(
String
data
)
{
AdvertisementFragment
fragment
=
new
AdvertisementFragment
();
Bundle
args
=
new
Bundle
();
...
...
@@ -59,8 +65,8 @@ public class AdvertisementFragment extends Fragment implements View.OnClickListe
this
.
mCountDown
=
view
.
findViewById
(
R
.
id
.
advertisement_countdown
);
this
.
mImgView
.
setOnClickListener
(
this
);
this
.
loadAdvertisementImageTest
();
//
this.loadAdvertisementImage();
//
this.loadAdvertisementImageTest();
this
.
loadAdvertisementImage
();
}
@Override
...
...
@@ -68,8 +74,8 @@ public class AdvertisementFragment extends Fragment implements View.OnClickListe
if
(
v
.
getId
()
==
R
.
id
.
advertisement_pass
)
{
this
.
dispatchActivityEvent
();
}
else
if
(
v
.
getId
()
==
R
.
id
.
advertisement_imgview
)
{
if
(
this
.
setFinishedFlag
())
{
IntentUtils
.
startActivity
(
getActivity
(),
AdvertisementWebviewActvity
.
class
);
if
(
null
!=
this
.
mBean
&&
this
.
setFinishedFlag
())
{
this
.
startAdvertsementDetail
(
this
.
mBean
);
}
}
}
...
...
@@ -80,9 +86,16 @@ public class AdvertisementFragment extends Fragment implements View.OnClickListe
this
.
dispatchActivityEvent
();
return
;
}
AdvertisementBean
bean
=
JSON
.
parseObject
(
json
,
AdvertisementBean
.
class
);
Glide
.
with
(
getContext
()).
load
(
bean
.
getPicUrl
()).
into
(
new
DrawableImageViewTarget
(
this
.
mImgView
)
{
this
.
mBean
=
JSON
.
parseObject
(
json
,
AdvertisementBean
.
class
);
if
(
TextUtils
.
isEmpty
(
mBean
.
getPicUrl
()))
{
return
;
}
if
(
TextUtils
.
isEmpty
(
mBean
.
getPicUrl
()))
{
this
.
startCountDown
();
return
;
}
String
imgUrl
=
BuildConfig
.
IMG_API
+
mBean
.
getPicUrl
();
Glide
.
with
(
getContext
()).
load
(
imgUrl
).
into
(
new
DrawableImageViewTarget
(
this
.
mImgView
)
{
@Override
public
void
onResourceReady
(
@NonNull
Drawable
resource
,
@Nullable
Transition
<?
super
Drawable
>
transition
)
{
super
.
onResourceReady
(
resource
,
transition
);
...
...
@@ -96,6 +109,24 @@ public class AdvertisementFragment extends Fragment implements View.OnClickListe
this
.
startCountDown
();
}
private
void
startAdvertsementDetail
(
AdvertisementBean
bean
)
{
if
(
null
==
bean
)
{
return
;
}
OpenUrlBean
dataBean
=
new
OpenUrlBean
();
dataBean
.
setBackClsName
(
HomeActivity
.
class
.
getName
());
dataBean
.
setLinkType
(
bean
.
getLinkType
());
if
(
"1"
.
equals
(
bean
.
getLinkType
()))
{
dataBean
.
setLinkUrl
(
bean
.
getInsideUrl
());
}
else
{
dataBean
.
setNav
(
"1"
);
dataBean
.
setLinkUrl
(
bean
.
getOutsideUrl
());
}
Intent
intent
=
new
Intent
(
getActivity
(),
OutsideWebviewActivity
.
class
);
intent
.
putExtra
(
"data"
,
JSON
.
toJSONString
(
dataBean
));
IntentUtils
.
startActivity
(
getActivity
(),
intent
);
}
private
void
startCountDown
()
{
long
unit
=
1000
,
maxSecond
=
5
;
...
...
app/src/main/java/com/polysoft/nafmii/fragment/HomeWebviewFragment.java
View file @
489ab2c
...
...
@@ -3,6 +3,7 @@ package com.polysoft.nafmii.fragment;
import
android.os.Bundle
;
import
com.polysoft.nafmii.webview.HomeWebviewHandler
;
import
com.polysoft.nafmii.webview.WebviewHandler
;
import
com.tencent.smtt.sdk.WebView
;
public
class
HomeWebviewFragment
extends
WebViewFragment
{
...
...
@@ -16,8 +17,7 @@ public class HomeWebviewFragment extends WebViewFragment {
}
@Override
protected
void
setWebView
(
WebView
webView
)
{
super
.
setWebView
(
webView
);
super
.
setWebviewHandler
(
new
HomeWebviewHandler
(
this
,
webView
));
protected
WebviewHandler
initWeviewHandle
(
WebView
webView
)
{
return
new
HomeWebviewHandler
(
this
,
webView
);
}
}
app/src/main/java/com/polysoft/nafmii/fragment/InsideWebViewFragment.java
0 → 100644
View file @
489ab2c
package
com
.
polysoft
.
nafmii
.
fragment
;
import
android.os.Bundle
;
public
class
InsideWebViewFragment
extends
WebViewFragment
{
public
static
InsideWebViewFragment
newInstance
()
{
Bundle
args
=
new
Bundle
();
InsideWebViewFragment
fragment
=
new
InsideWebViewFragment
();
fragment
.
setArguments
(
args
);
return
fragment
;
}
}
app/src/main/java/com/polysoft/nafmii/fragment/OutsideWebViewFragment.java
0 → 100644
View file @
489ab2c
package
com
.
polysoft
.
nafmii
.
fragment
;
public
class
OutsideWebViewFragment
extends
WebViewFragment
{
}
app/src/main/java/com/polysoft/nafmii/fragment/WebViewFragment.java
View file @
489ab2c
...
...
@@ -59,7 +59,6 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
super
.
onViewCreated
(
view
,
savedInstanceState
);
this
.
mWebviewLayout
=
view
.
findViewById
(
R
.
id
.
webview_layout
);
this
.
initWebView
();
}
public
IWebview
getWebview
()
{
...
...
@@ -147,20 +146,16 @@ public class WebViewFragment extends Fragment implements WebviewLoadListener {
this
.
mWebview
.
loadUrl
(
url
);
}
protected
void
setWebviewHandler
(
WebviewHandler
handler
)
{
this
.
mWebviewHandler
=
handler
;
}
protected
void
setWebView
(
WebView
webView
)
{
webView
.
setWebChromeClient
(
new
MyWebChromeClient
(
this
));
webView
.
setWebViewClient
(
new
MyWebViewClient
(
this
));
this
.
mWebview
=
webView
;
protected
WebviewHandler
initWeviewHandle
(
WebView
webView
)
{
return
new
WebviewHandler
(
this
,
webView
);
}
private
void
initWebView
()
{
WebView
webView
=
X5WebviewUtils
.
create
(
getActivity
());
this
.
setWebView
(
webView
);
this
.
showWebviewLayout
(
webView
);
this
.
mWebview
=
X5WebviewUtils
.
create
(
getActivity
());
this
.
mWebview
.
setWebChromeClient
(
new
MyWebChromeClient
(
this
));
this
.
mWebview
.
setWebViewClient
(
new
MyWebViewClient
(
this
));
this
.
mWebviewHandler
=
this
.
initWeviewHandle
(
this
.
mWebview
);
this
.
showWebviewLayout
(
this
.
mWebview
);
this
.
loadUrl
(
super
.
getArguments
().
getString
(
"url"
,
""
));
}
...
...
app/src/main/java/com/polysoft/nafmii/fragment/home/ModuleUrlHandle.java
View file @
489ab2c
...
...
@@ -19,24 +19,17 @@ import java.util.Map;
public
class
ModuleUrlHandle
{
private
final
Activity
activity
;
private
IModuleHandle
moduleUrl
,
moduleBean
;
ModuleUrlHandle
(
Activity
activity
)
{
this
.
activity
=
activity
;
}
public
IModuleHandle
getModuleHandle
(
ModulesEnum
module
)
{
if
(
null
==
this
.
moduleUrl
)
{
this
.
moduleUrl
=
new
ModuleUrlImpl
(
module
);
}
return
this
.
moduleUrl
;
return
new
ModuleUrlImpl
(
module
);
}
public
IModuleHandle
getModuleHandle
(
MenuBean
bean
)
{
if
(
null
==
this
.
moduleBean
)
{
this
.
moduleBean
=
new
ModuleBeanImpl
(
bean
);
}
return
this
.
moduleBean
;
return
new
ModuleBeanImpl
(
bean
);
}
public
String
getModuleUrl
(
ModulesEnum
module
)
{
...
...
app/src/main/java/com/polysoft/nafmii/utils/StatusBarUtils.java
View file @
489ab2c
...
...
@@ -193,12 +193,15 @@ public class StatusBarUtils {
//获取状态栏高度
public
static
int
getStatusBarHeight
(
Context
context
)
{
return
dip2px
(
context
,
getStatusBarHeightDP
(
context
));
}
public
static
int
getStatusBarHeightDP
(
Context
context
)
{
int
result
=
0
;
int
resourceId
=
context
.
getResources
().
getIdentifier
(
"status_bar_height"
,
"dimen"
,
"android"
);
if
(
resourceId
>
0
)
{
result
=
context
.
getResources
().
getDimensionPixelSize
(
resourceId
);
}
return
dip2px
(
context
,
result
)
;
return
result
;
}
/**
...
...
app/src/main/java/com/polysoft/nafmii/viewmodel/AdvertisementViewModel.java
View file @
489ab2c
...
...
@@ -47,10 +47,10 @@ public class AdvertisementViewModel extends ViewModel {
}
private
void
fetchData
()
{
TimerUtils
.
setTimeout
(()
->
{
DataEntity
entity
=
ObjectBox
.
findByName
(
DB_KEY
);
this
.
postModelValue
(
null
==
entity
?
null
:
entity
.
getValue
());
},
2
000
);
//
TimerUtils.setTimeout(() -> {
//
DataEntity entity = ObjectBox.findByName(DB_KEY);
//
this.postModelValue(null == entity ? null : entity.getValue());
// }, 3
000);
ServerApi
.
postAdvertisement
(
new
RequestBack
<
String
>()
{
@Override
...
...
@@ -80,9 +80,9 @@ public class AdvertisementViewModel extends ViewModel {
}
public
boolean
empty
()
{
if
(
BuildConfig
.
DEBUG
)
{
return
true
;
}
//
if (BuildConfig.DEBUG) {
//
return true;
//
}
return
TextUtils
.
isEmpty
(
data
);
}
}
...
...
app/src/main/java/com/polysoft/nafmii/webview/HomeWebviewHandler.java
View file @
489ab2c
...
...
@@ -14,21 +14,22 @@ public class HomeWebviewHandler extends WebviewHandler {
public
HomeWebviewHandler
(
Fragment
fragment
,
WebView
webView
)
{
super
(
fragment
,
webView
);
webView
.
addJavascriptInterface
(
new
NativeApi
(
this
),
"$NativeApi"
);
}
@Override
public
void
setButtomMenu
(
MenuBean
bean
)
{
HomeActivity
activity
=
(
HomeActivity
)
this
.
fragment
.
getActivity
();
activity
.
setModuleStatus
(
bean
);
}
@Override
public
void
setTextZoom
(
int
zoom
)
{
FragmentManager
manager
=
super
.
getFragmentManager
();
List
<
Fragment
>
fragments
=
manager
.
getFragments
();
for
(
Fragment
fmt
:
fragments
)
{
String
tag
=
fmt
.
getTag
();
WebView
webview
=
((
WebViewFragment
)
fmt
).
getWebview
(
).
getWebview
();
webview
.
getSettings
().
setTextZoom
(
zoom
);
IWebview
webview
=
((
WebViewFragment
)
fmt
).
getWebview
();
webview
.
get
Webview
().
get
Settings
().
setTextZoom
(
zoom
);
}
}
}
app/src/main/java/com/polysoft/nafmii/webview/NativeApi.java
View file @
489ab2c
...
...
@@ -23,6 +23,7 @@ import com.polysoft.nafmii.utils.PermissionUtils;
import
com.polysoft.nafmii.utils.StatusBarUtils
;
import
com.polysoft.nafmii.wechat.ShareBean
;
import
com.polysoft.nafmii.wechat.WechatApi
;
import
com.whaty.nafmii.activity.OutsideWebviewActivity
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -30,10 +31,10 @@ import java.util.List;
import
java.util.Map
;
public
class
NativeApi
{
private
final
Home
WebviewHandler
handler
;
private
final
WebviewHandler
handler
;
private
final
Activity
mActivity
;
public
NativeApi
(
Home
WebviewHandler
handler
)
{
public
NativeApi
(
WebviewHandler
handler
)
{
this
.
handler
=
handler
;
this
.
mActivity
=
handler
.
getFragment
().
getActivity
();
}
...
...
@@ -63,7 +64,7 @@ public class NativeApi {
new
JsInterfaceHandler
(
handler
).
parse
(
params
,
(
data
,
js
)
->
{
String
type
=
data
.
getString
(
"type"
);
if
(
"1"
.
equals
(
type
))
{
// 指纹人脸
this
.
mActivity
.
runOnUiThread
(()->
FingerprintDialog
.
show
(
handler
.
getFragmentManager
(),
result
->
{
this
.
mActivity
.
runOnUiThread
(()
->
FingerprintDialog
.
show
(
handler
.
getFragmentManager
(),
result
->
{
js
.
callJs
(
result
);
}));
}
else
if
(
"2"
.
equals
(
type
))
{
// 微信
...
...
@@ -138,11 +139,8 @@ public class NativeApi {
@JavascriptInterface
public
void
nativeCamera
(
String
params
)
{
new
JsInterfaceHandler
(
handler
).
parse
(
params
,
new
JsInterfaceHandler
.
JsHandle
()
{
@Override
public
void
handle
(
JSONObject
data
,
JsInterfaceHandler
.
JsInterface
js
)
{
new
JsInterfaceHandler
(
handler
).
parse
(
params
,
(
data
,
js
)
->
{
}
});
String
permissions
[]
=
{
Manifest
.
permission
.
CAMERA
};
if
(
PermissionUtils
.
checkAndRequestMorePermissions
(
this
.
mActivity
,
permissions
))
{
...
...
@@ -168,6 +166,19 @@ public class NativeApi {
// }
}
@JavascriptInterface
public
void
nativeOpenUrl
(
String
param
)
{
new
JsInterfaceHandler
(
handler
).
parse
(
param
,
(
data
,
js
)
->
{
mActivity
.
runOnUiThread
(()
->
{
Intent
intent
=
new
Intent
(
mActivity
,
OutsideWebviewActivity
.
class
);
intent
.
putExtra
(
"data"
,
data
.
toJSONString
());
mActivity
.
startActivity
(
intent
);
});
});
}
// @JavascriptInterface
// public void callNativeUpdate(String params) {
// final JSONObject json = JSONObject.parseObject(params);
...
...
@@ -215,21 +226,6 @@ public class NativeApi {
// });
// }
//
// @JavascriptInterface
// public void callNativeClearCache(String params) {
// JSONObject json = TextUtils.isEmpty(params) ? new JSONObject() : JSONObject.parseObject(params);
// final String jsMethodName = json.getString("jsMethodName");
// this.mActivity.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// WebViewCacheInterceptorInst.getInstance().clearCache();
// if (!TextUtils.isEmpty(jsMethodName)) {
// javaTojs.callJs(jsMethodName, "");
// }
// }
// });
// }
}
app/src/main/java/com/polysoft/nafmii/webview/WebviewHandler.java
View file @
489ab2c
...
...
@@ -5,7 +5,9 @@ import android.text.TextUtils;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.FragmentManager
;
import
com.polysoft.nafmii.bean.MenuBean
;
import
com.tencent.smtt.sdk.WebView
;
import
com.whaty.nafmii.activity.HomeActivity
;
public
class
WebviewHandler
implements
IWebview
{
...
...
@@ -18,6 +20,7 @@ public class WebviewHandler implements IWebview {
public
WebviewHandler
(
Fragment
fragment
,
WebView
webView
)
{
this
.
fragment
=
fragment
;
this
.
webView
=
webView
;
webView
.
addJavascriptInterface
(
new
NativeApi
(
this
),
"$NativeApi"
);
}
@Override
...
...
@@ -60,6 +63,13 @@ public class WebviewHandler implements IWebview {
this
.
backIntercept
=
intercept
;
}
public
void
setTextZoom
(
int
zoom
)
{
this
.
webView
.
getSettings
().
setTextZoom
(
zoom
);
}
public
void
setButtomMenu
(
MenuBean
bean
)
{
}
protected
FragmentManager
getFragmentManager
()
{
return
this
.
fragment
.
getActivity
().
getSupportFragmentManager
();
}
...
...
app/src/main/java/com/whaty/nafmii/activity/OutsideWebviewActivity.java
0 → 100644
View file @
489ab2c
package
com
.
whaty
.
nafmii
.
activity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.view.KeyEvent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
androidx.fragment.app.FragmentManager
;
import
androidx.fragment.app.FragmentTransaction
;
import
com.alibaba.fastjson.JSON
;
import
com.polysoft.nafmii.bean.OpenUrlBean
;
import
com.polysoft.nafmii.fragment.WebViewFragment
;
import
com.polysoft.nafmii.utils.FileUtils
;
import
com.polysoft.nafmii.utils.StatusBarUtils
;
import
com.polysoft.nafmii.utils.ToastUtils
;
import
com.polysoft.nafmii.webview.IWebview
;
import
com.whaty.nafmii.R
;
public
class
OutsideWebviewActivity
extends
WebviewActivity
{
private
OpenUrlBean
mBean
;
private
WebViewFragment
mFragment
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
}
@Override
public
void
onCoreInitFinished
(
boolean
flag
)
{
String
data
=
super
.
getIntent
().
getStringExtra
(
"data"
);
this
.
mBean
=
JSON
.
parseObject
(
data
,
OpenUrlBean
.
class
);
if
(
null
==
this
.
mBean
)
{
ToastUtils
.
showLong
(
"加载错误"
);
}
super
.
setContentView
(
R
.
layout
.
activity_webview
);
this
.
initView
();
}
private
void
initView
()
{
this
.
initNavTitle
();
int
containerId
=
R
.
id
.
framelayout
;
FragmentManager
manager
=
getSupportFragmentManager
();
this
.
mFragment
=
WebViewFragment
.
newInstance
(
this
.
getUrl
());
FragmentTransaction
transaction
=
manager
.
beginTransaction
();
transaction
.
replace
(
containerId
,
this
.
mFragment
,
"outside_webview"
).
commitNow
();
}
private
void
initNavTitle
()
{
if
(!
"1"
.
equals
(
this
.
mBean
.
getNav
()))
{
return
;
}
View
layout
=
super
.
findViewById
(
R
.
id
.
nav_layout
);
int
paddingTop
=
StatusBarUtils
.
getStatusBarHeightDP
(
this
);
layout
.
setPadding
(
0
,
paddingTop
,
0
,
0
);
super
.
findViewById
(
R
.
id
.
nav_layout
).
setVisibility
(
View
.
VISIBLE
);
if
(!
TextUtils
.
isEmpty
(
this
.
mBean
.
getTitle
()))
{
TextView
title
=
super
.
findViewById
(
R
.
id
.
nav_title
);
title
.
setText
(
this
.
mBean
.
getTitle
());
}
super
.
findViewById
(
R
.
id
.
nav_back
).
setOnClickListener
((
v
)
->
{
this
.
backAction
();
});
}
@Override
public
boolean
onKeyDown
(
int
keyCode
,
KeyEvent
event
)
{
this
.
backAction
();
return
false
;
}
private
void
backAction
()
{
if
(
null
==
this
.
mBean
||
null
==
this
.
mFragment
)
{
super
.
finish
();
return
;
}
IWebview
webview
=
this
.
mFragment
.
getWebview
();
if
(
null
!=
webview
&&
webview
.
canGoBack
())
{
return
;
}
this
.
close
();
}
private
void
close
()
{
String
backCls
=
this
.
mBean
.
getBackClsName
();
if
(!
TextUtils
.
isEmpty
(
backCls
))
{
try
{
Class
<?>
aClass
=
Class
.
forName
(
backCls
);
super
.
startActivity
(
new
Intent
(
this
,
aClass
));
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
}
super
.
finish
();
}
private
String
getUrl
()
{
String
type
=
this
.
mBean
.
getLinkType
();
String
url
=
this
.
mBean
.
getLinkUrl
();
if
(
"1"
.
equals
(
type
)
&&
!
TextUtils
.
isEmpty
(
url
))
{
// 内链
String
root
=
FileUtils
.
getIndex
().
toString
();
if
(
url
.
startsWith
(
"#"
))
{
return
root
+
url
;
}
else
if
(
root
.
startsWith
(
"http"
))
{
String
[]
split
=
url
.
split
(
"#"
);
if
(
split
.
length
>
1
)
{
return
root
+
"#"
+
split
[
1
];
}
}
}
return
url
;
// 外链
}
}
app/src/main/res/layout/activity_webview.xml
View file @
489ab2c
...
...
@@ -18,6 +18,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:visibility=
"gone"
tools:ignore=
"MissingConstraints"
>
<include
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment