中建365-绑定设备
parent
485b67d188
commit
0913f3115c
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.xty.base">
|
package="com.xty.base">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
</manifest>
|
</manifest>
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.xty.base.h5
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.webkit.JavascriptInterface
|
||||||
|
import com.xty.base.act.BaseVmAct
|
||||||
|
import com.xty.base.act.IBaseAct
|
||||||
|
import com.xty.common.Const
|
||||||
|
import com.xty.common.LogUtils
|
||||||
|
import com.xty.common.MMkvHelper
|
||||||
|
import com.xty.common.util.ToastUtils
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
open class CloudJSBridge(val context: Context, val listener: IJsBridge) {
|
||||||
|
private var baseActivity: BaseVmAct<*> = context as BaseVmAct<*>
|
||||||
|
@JavascriptInterface
|
||||||
|
fun getBaseInfoData(str: String?) {
|
||||||
|
LogUtils.e("CloudJSBridge","getBaseInfoData str")
|
||||||
|
str?.apply {
|
||||||
|
val userId = if (MMkvHelper.getLong(Const.USER_ID).toString() == "0") {
|
||||||
|
""
|
||||||
|
} else { LogUtils.e("CloudJSBridge","str")
|
||||||
|
MMkvHelper.getLong(Const.USER_ID).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
val jsonObject = JSONObject()
|
||||||
|
jsonObject.put("statuHeight", WebUtils.getStatesBar())
|
||||||
|
jsonObject.put("token", MMkvHelper.getString(Const.Auth_Token))
|
||||||
|
|
||||||
|
jsonObject.put("userId", userId)
|
||||||
|
listener.sendDataToJS("sendBaseInfo", jsonObject.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun getIsFromApp(str:String?){
|
||||||
|
LogUtils.e("CloudJSBridge","getIsFromApp str")
|
||||||
|
str?.let {
|
||||||
|
val jsonObject = JSONObject()
|
||||||
|
jsonObject.put("isAPP", 1)
|
||||||
|
listener.sendDataToJS("sendIsFrom ", jsonObject.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
fun onBack(str: String?){
|
||||||
|
LogUtils.e("CloudJSBridge","onBack str")
|
||||||
|
baseActivity.finish()
|
||||||
|
}
|
||||||
|
@JavascriptInterface
|
||||||
|
fun gotoElectronicFence(str: String?){
|
||||||
|
LogUtils.e("CloudJSBridge","gotoElectronicFence str")
|
||||||
|
ToastUtils(context).showToast("敬请期待")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.xty.base.h5
|
||||||
|
|
||||||
|
interface IJsBridge {
|
||||||
|
fun sendDataToJS(functionName: String, data: String)
|
||||||
|
|
||||||
|
fun switchView(name: String, data: String)
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.xty.base.h5
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
class JsBridge(context: Context, listener: IJsBridge) : CloudJSBridge(context, listener) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.xty.base.h5
|
||||||
|
|
||||||
|
import com.xty.base.utils.ContextUtils
|
||||||
|
import com.xty.base.utils.SystemBarHelper
|
||||||
|
import com.xty.base.utils.SystemBarHelper.getStatusBarHeight
|
||||||
|
|
||||||
|
|
||||||
|
object WebUtils {
|
||||||
|
private var mSbar = -1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取状态栏高度
|
||||||
|
*
|
||||||
|
* @return 状态栏高度px
|
||||||
|
*/
|
||||||
|
@Synchronized
|
||||||
|
fun getStatesBar(): Int {
|
||||||
|
if (mSbar < 0) {
|
||||||
|
mSbar = getStatusBarHeight(ContextUtils.getContext())
|
||||||
|
}
|
||||||
|
return mSbar
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun getDensityDpi(): Int {
|
||||||
|
val displayMetrics = ContextUtils.getApplication().resources.displayMetrics
|
||||||
|
return displayMetrics.density.toInt()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.xty.base.utils
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
|
||||||
|
object ContextUtils {
|
||||||
|
|
||||||
|
private var context: Context? = null
|
||||||
|
private var mApplication: Application? = null
|
||||||
|
|
||||||
|
fun ContextUtils() {
|
||||||
|
throw UnsupportedOperationException("u can't instantiate me...")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化工具类
|
||||||
|
*
|
||||||
|
* @param context 上下文
|
||||||
|
*/
|
||||||
|
fun init(context: Context) {
|
||||||
|
ContextUtils.context = context.applicationContext
|
||||||
|
if (context is Application) {
|
||||||
|
mApplication = context.getApplicationContext() as Application
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ApplicationContext
|
||||||
|
*
|
||||||
|
* @return ApplicationContext
|
||||||
|
*/
|
||||||
|
fun getContext(): Context {
|
||||||
|
if (context != null) return context!!
|
||||||
|
throw NullPointerException("u should init first")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ApplicationContext
|
||||||
|
*
|
||||||
|
* @return ApplicationContext
|
||||||
|
*/
|
||||||
|
fun getApplication(): Application {
|
||||||
|
if (mApplication != null) return mApplication!!
|
||||||
|
throw NullPointerException("u should init first")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.xty.base.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
|
||||||
|
|
||||||
|
object SystemBarHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取状态栏高度
|
||||||
|
*/
|
||||||
|
fun getStatusBarHeight(context: Context): Int {
|
||||||
|
var result = 0
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
val resId = context.resources.getIdentifier("status_bar_height", "dimen", "android")
|
||||||
|
if (resId > 0) {
|
||||||
|
result = context.resources.getDimensionPixelSize(resId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.tencent.smtt.sdk.WebView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:id="@+id/webView"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Binary file not shown.
Loading…
Reference in New Issue