Commit a4d3a63b authored by wangxuewei's avatar wangxuewei

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/src/main/java/com/ym/game/GameActivity.kt
parents 5e18878e 725d1edc
......@@ -13,11 +13,14 @@ import com.ym.game.net.GameApiClient
import com.ym.game.view.SiginDropsPopupwindow
import com.ym.game.view.TurntableDialog
import com.ym.library.AppliContext
import com.ym.library.module.AdEntity
import com.ym.library.Constant
import com.ym.library.net.BaseObserver
import com.ym.library.net.RxSchedulers
import com.ym.library.rxbus.RxBusConstant
import com.ym.library.rxbus.RxBusUtil
import com.ym.library.utils.SettingPreference
import com.ym.library.utils.JumpUtils
import com.ym.library.utils.Utils
import com.ym.library.widget.LoadingDialog
import com.ym.module.toponad.AdID
......@@ -84,6 +87,8 @@ class GameActivity : UnityPlayerActivity() {
*/
fun ranklistClick() {
Log.d("wxw", "上榜赚钱")
//JumpUtils.h5Jump("上榜赚钱", Constant.Param.RankList)
JumpUtils.h5Jump("水滴排行榜", Constant.Param.RankList, false)
}
/**
......@@ -91,6 +96,7 @@ class GameActivity : UnityPlayerActivity() {
*/
fun oneveryDayWelfareClick() {
Log.d("wxw", "每日福利")
JumpUtils.h5Jump("每日福利", Constant.Param.WelfareCenter, false)
}
......@@ -99,6 +105,7 @@ class GameActivity : UnityPlayerActivity() {
*/
fun clockInMakeMoney() {
Log.d("wxw", "打卡提现")
JumpUtils.h5Jump("打卡提现", Constant.Param.PunchRecord, false)
}
/**
......@@ -131,7 +138,7 @@ class GameActivity : UnityPlayerActivity() {
/**
* 打开飞行宝箱
*/
fun openFlyBox() {
fun openAdFlyBox() {
}
......@@ -315,7 +322,8 @@ class GameActivity : UnityPlayerActivity() {
//看视频领取加速剂
fun getVideoAcceleratorsReceive(callback: IUnitySendMessageCallback?, id: Int) {
GameApiClient.gameApi.getVideoAcceleratorsReceive(id).compose(RxSchedulers.observableIO2Main())
GameApiClient.gameApi.getVideoAcceleratorsReceive(id)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<StatusEntity>() {
override fun onSuccess(result: StatusEntity?) {
Log.d("wxw", "看视频领取加速剂" + Utils.obj2Str(result))
......@@ -330,5 +338,4 @@ class GameActivity : UnityPlayerActivity() {
}
}
\ No newline at end of file
......@@ -3,4 +3,9 @@ package com.ym.game.module
class FlyBoxEntity {
var type:Int?=0
var awardNum:Int?=0
var seedList: MutableList<SeedList> = ArrayList()
class SeedList{
var id:Int=0
var num:Int=0
}
}
\ No newline at end of file
......@@ -19,6 +19,10 @@ import com.ym.library.utils.EventUtils
import com.ym.library.utils.LogUtils
import com.ym.library.utils.Utils
import com.ym.xync.R
import com.ym.module.toponad.AdID
import com.ym.module.toponad.ToponManager
import com.ym.module.toponad.listener.ToponRewardListener
/**
*Craeted by ${junqi.li}
......
......@@ -137,7 +137,7 @@ class MainActivity : BaseActivity(), NavigationBottomView.OnTabSelectedListener,
}
//怎么玩
findViewById<ImageView>(R.id.iv_how_to_play)?.setOnClickListener {
JumpUtils.h5Jump("怎么玩", Constant.PLAY_URL)
JumpUtils.h5Jump("怎么玩", Constant.PLAY_URL,false)
}
}
......
......@@ -41,12 +41,12 @@ object CenterDialog:BaseDialog() {
.setOnClickListener { activity.finish() }
val clickUa: ClickableSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
JumpUtils.h5Jump("隐私政策", NetConfig.H5.WEB_URL_PRIVACY)
JumpUtils.h5Jump("隐私政策", NetConfig.H5.WEB_URL_PRIVACY,false)
}
}
val clickPrivat: ClickableSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
JumpUtils.h5Jump("用户协议", NetConfig.H5.WEB_URL_USER)
JumpUtils.h5Jump("用户协议", NetConfig.H5.WEB_URL_USER,false)
}
}
// 《隐私政策》和《用户协议》,请您在使用前仔细阅读并了解
......
......@@ -62,14 +62,26 @@
android:resource="@xml/bd_file_path" />
</provider>-->
<activity
android:name="com.ym.library.net.PermissionsActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="unspecified"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<activity
android:name="com.ym.library.activity.WebViewActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="web"
android:scheme="luckyfarm" />
</intent-filter>
</activity>
<!--全屏广告,激励视频-->
<!-- <activity
......
......@@ -15,7 +15,7 @@ import java.util.List;
public class Constant {
public static int REQUEST_CODE_ASK_PERMISSIONS = 0x0101;
public static final String scheme = "quweiguesssong";
public static final String scheme = "luckyfarm";
public static final String withdraw_right_top = "withdraw_right_top";
public static final String sign_in_again_video = "sign_in_again_video";
......@@ -452,6 +452,10 @@ public class Constant {
public static String district = "";
public static String street = "";
public static String makingMoneyUrl = "";
public static String WelfareCenter = "https://h5v3.zhangxinzhixun.com/huayuan/Welfare";//福利中心
public static String PunchRecord = "https://h5v3.zhangxinzhixun.com/huayuan/ClockIn";//打卡记录
public static String RankList = "https://h5v3.zhangxinzhixun.com/huayuan/Ranking";//排行榜
}
public static class SdkKey {
......
package com.ym.library.activity
import android.app.Activity
import android.app.AlertDialog
import android.app.DownloadManager
import android.content.ComponentName
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.PowerManager
import android.provider.Settings
import android.util.Base64
import android.util.Log
import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.FileProvider
import com.ym.library.AppliContext
import com.ym.library.Constant
import com.ym.library.module.NewsEntity
import com.ym.library.net.ApiClient
import com.ym.library.net.RxSchedulers
import com.ym.library.rxbus.RxBusConstant
import com.ym.library.rxbus.RxBusUtil
import com.ym.library.utils.*
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import okhttp3.ResponseBody
import org.jetbrains.anko.runOnUiThread
import org.json.JSONArray
import org.json.JSONObject
import retrofit2.Response
import java.io.File
import java.io.IOException
abstract class JavaInterface {
var act: Activity?
private val mWebView: WebView
constructor(act: Activity, web: WebView) {
this.act = act
this.mWebView = web
}
@JavascriptInterface
fun closeView() {
act?.finish()
}
@JavascriptInterface
fun getNovelUid(): String? {
System.out.println("getNovelUid()")
return SettingPreference.getUid()
}
@JavascriptInterface
fun getUserInfo(): String? {
var entity = SettingPreference.getUserInfoData()
if (entity != null) {
var data = Utils.obj2Str(entity)
System.out.println("getUserInfoData():$data")
return data
}
return ""
}
/**
* 获取状态栏高度
*/
@JavascriptInterface
fun getStatusBarHeight(): Int {
return Utils.px2dip(Utils.getStatusBarHeightFloat())
}
/**
* 获取token
*/
@JavascriptInterface
fun getToken(): String {
return SettingPreference.getToken()
}
/**
* 获取金币总数
*/
@JavascriptInterface
fun availCoins(): Int {
var user = SettingPreference.getUserInfoData()
println("availCoins()-------------$user-----")
return user?.availCoins ?: 0
}
/**
* 获取版本号名称
*/
@JavascriptInterface
fun getVersionName(): String {
return PhoneUtils.getAppVersionName(AppliContext.get())
}
/**
* H5缓存数据
*/
@JavascriptInterface
fun saveVideoData(data: String) {
println("saveVideoData()-------------$data-----")
SettingPreference.saveVideoData(data)
}
/**
* H5获取数据
*/
@JavascriptInterface
fun getVideoData(): String {
println("getVideoData()----------------:" + SettingPreference.getVideoData())
return SettingPreference.getVideoData()
}
/**
* 下载 并安装 App
* @param url 下载地址
*/
@JavascriptInterface
fun InstallAPP(url: String) {
var last = url.lastIndexOf("/") + 1
var apkName = url.substring(last)
if (!apkName.contains(".apk")) {
if (apkName?.length > 10) {
apkName = apkName.substring(apkName.length - 10)
}
apkName += ".apk"
}
if (ActivityCompat.checkSelfPermission(
AppliContext.get(),
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
) == PackageManager.PERMISSION_GRANTED
) {
checkDownloadStatus(url, apkName)
} else {
openAppDetails()
}
}
/**
* 检查下载状态
*
* @param url
* @param apkName
*/
private fun checkDownloadStatus(url: String, apkName: String) {
var isLoading = false
var query: DownloadManager.Query = DownloadManager.Query()
var downloadManager: DownloadManager =
AppliContext.get().getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
var c: Cursor = downloadManager.query(query)
if (c.moveToFirst()) {
var LoadingUrl = c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI))
if (url.equals(LoadingUrl)) {
isLoading = true
var status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS))
when (status) {
DownloadManager.STATUS_PAUSED -> Toast.makeText(
AppliContext.get(),
"正在下载",
Toast.LENGTH_SHORT
).show()
DownloadManager.STATUS_PENDING -> Toast.makeText(
AppliContext.get(),
"正在下载",
Toast.LENGTH_SHORT
).show()
DownloadManager.STATUS_RUNNING -> Toast.makeText(
AppliContext.get(),
"正在下载",
Toast.LENGTH_SHORT
).show()
DownloadManager.STATUS_SUCCESSFUL -> {
Log.i("DownLoadService", ">>>下载完成")
var str = c.getString(c.getColumnIndex(DownloadManager.COLUMN_URI))
Log.i("DownLoadService", str)
val file = File(
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Environment.DIRECTORY_DOWNLOADS,
apkName
)
isLoading
if (!file.exists()) {
isLoading = false
} else {
installAPK(
file
, apkName
)
}
}
DownloadManager.STATUS_FAILED -> {
Log.i("DownLoadService", ">>>下载失败")
}
}
}
}
if (!isLoading) {
val data = NewsEntity()
data.url = url
ZxDownLoadServices.startActionFoo(AppliContext.get(), data)
}
}
/**
* 打开 APP 的详情设置
*/
private fun openAppDetails() {
var builder = AlertDialog.Builder(act)
builder.setMessage("你还未获取存储权限哦,现在去获取?"); // 取消后可到 “应用信息 -> 权限” 中授予"
builder.setPositiveButton("确定", object : DialogInterface.OnClickListener {
override fun onClick(dialog: DialogInterface, which: Int) {
var intent = Intent()
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + AppliContext.get()?.getPackageName()))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
AppliContext.get().startActivity(intent)
}
})
builder.setNegativeButton("取消", null)
builder.show()
}
/**
* 打开 App
* @param packageName 包名
*/
@JavascriptInterface
fun OpenAPP(packageName: String) {
doStartApplicationWithPackageName(packageName)
}
/**
* 打开微信
*/
@JavascriptInterface
fun openWechat() {
try {
var intent = Intent()
var cmp = ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI")
intent.setAction(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.setComponent(cmp)
AppliContext.get().startActivity(intent)
} catch (e: Exception) {
}
}
/**
* 打开app
*
* @param packagename
*/
private fun doStartApplicationWithPackageName(packagename: String) {
// 通过包名获取此APP详细信息,包括Activities、services、versioncode、name等等
var packageinfo: PackageInfo? = null
try {
packageinfo = AppliContext.get().packageManager.getPackageInfo(packagename, 0);
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}
if (packageinfo == null) {
return
}
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
var resolveIntent = Intent(Intent.ACTION_MAIN, null)
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER)
resolveIntent.setPackage(packageinfo.packageName)
// 通过getPackageManager()的queryIntentActivities方法遍历
var resolveinfoList: List<ResolveInfo> =
AppliContext.get().packageManager.queryIntentActivities(resolveIntent, 0)
var resolveinfo: ResolveInfo = resolveinfoList.iterator().next()
if (resolveinfo != null) {
// packagename = 参数packname
val packageName = resolveinfo.activityInfo.packageName
// 这个就是我们要找的该APP的LAUNCHER的Activity[组织形式:packagename.mainActivityname]
val className = resolveinfo.activityInfo.name
// LAUNCHER Intent
var intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
// 设置ComponentName参数1:packagename参数2:MainActivity路径
val cn = ComponentName(packageName, className)
intent.component = cn
act?.startActivity(intent)
}
}
/**
* 判断指定包名的app是否已经安装,并且把结果返回给H5
*
* @param packageName
*/
/* @JavascriptInterface
fun CheckInstall(packageName: String) {
val isInstalled = SystemUtil.isInstalled(AppliContext.get(), packageName)
if (isInstalled) {
mWebView?.post(Runnable { mWebView?.loadUrl("javascript:CheckInstall_Return(1)") })
} else {
mWebView?.post(Runnable { mWebView?.loadUrl("javascript:CheckInstall_Return(0)") })
}
}*/
// fun checkInstall(packageName: String): Boolean {
// //判断app是否安装
// if (TextUtils.isEmpty(packageName)) {
// return false
// }
// try {
// AppliContext.get().getPackageManager().getPackageInfo(packageName, 0)
// return true
// } catch (e: PackageManager.NameNotFoundException) {
// return false
// }
//
// }
/**
* 打开浏览器试玩
*
* @param url
*/
@JavascriptInterface
fun openBrowser(url: String) {
Log.i("open:", url + "...")
//另一种下载方式
var intent = Intent()
intent.action = "android.intent.action.VIEW"
var content_url = Uri.parse(url)
intent.setData(content_url)
act?.startActivity(intent)
}
/**
* 网页游戏
* @param url 网址
*/
@JavascriptInterface
fun Browser(url: String) {
var intent = Intent()
intent.setAction("android.intent.action.VIEW")
var content_url = Uri.parse(url)
intent.setData(content_url);
if (intent.resolveActivity(AppliContext.get().getPackageManager()) != null) {
var componentName = intent.resolveActivity(AppliContext.get().getPackageManager())
AppliContext.get().startActivity(Intent.createChooser(intent, "请选择浏览器"))
} else {
Toast.makeText(AppliContext.get(), "没有匹配的程序", Toast.LENGTH_SHORT).show()
}
}
/**
* 下载安装APP,有两种方法
* 1.使用系统下载,贵公司需要集成到app中
* 2.直接打开浏览器下载
*
* @param url
*/
@JavascriptInterface
fun AwallDownLoad(url: String) {
Log.i("open:", url + "...");
//另一种下载方式
val intent = Intent()
intent.setAction("android.intent.action.VIEW");
var content_url = Uri.parse(url)
intent.setData(content_url)
act?.startActivity(intent)
}
/**
* 打开指定包名App
*
* @param packageName
*/
@JavascriptInterface
fun AwallOpen(packageName: String) {
Log.i("open:", "$packageName...")
doStartApplicationWithPackageName(packageName)
}
private fun installAPK(context: Context, file: File?) {
if (file == null || !file.exists()) return
val intent = Intent(Intent.ACTION_VIEW)
val uri: Uri
// 判断版本大于等于7.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// 即是在清单文件中配置的authorities
uri = FileProvider.getUriForFile(
context,
context.packageName + ".fileprovider",
file
)//newfile
// 给目标应用一个临时授权
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
} else {
uri = Uri.parse("file://" + file.toString())
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
intent.setDataAndType(uri, "application/vnd.android.package-archive")
//在服务中开启activity必须设置flag,后面解释
context.startActivity(intent)
}
/**
* 下载到本地后执行安装
*/
private fun installAPK(file: File, apkName: String) {
if (!file.exists())
return
var intent = Intent(Intent.ACTION_VIEW)
var uri: Uri
// 判断版本大于等于7.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// 即是在清单文件中配置的authorities
uri = FileProvider.getUriForFile(
AppliContext.get(),
Constant.Param.mPacketName + ".fileprovider",
file
)
// 给目标应用一个临时授权
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
} else {
uri = Uri.parse("file://" + file.toString())
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
intent.setDataAndType(uri, "application/vnd.android.package-archive")
//在服务中开启activity必须设置flag,后面解释
act?.startActivity(intent)
}
@JavascriptInterface
fun getAnalysisParams(): String {
val params = JSONObject()
val ts = System.currentTimeMillis()
params.put(Constant.Device.ts, ts)
params.put(Constant.Device.uid, SettingPreference.getUid())
params.put(Constant.Device.token, SettingPreference.getToken())
params.put(Constant.Device.aid, SettingPreference.getAndroidId())
params.put(Constant.Device.imei, SettingPreference.getImei())
params.put(Constant.Device.device, SettingPreference.getDevice())
params.put(Constant.Device.mac, SettingPreference.getMac())
params.put(Constant.Device.platform, "android")
params.put(Constant.Device.carrier, SettingPreference.getCarrier())
params.put(Constant.Device.w, SettingPreference.getW())
params.put(Constant.Device.vendor, Build.MANUFACTURER)
params.put(Constant.Device.h, SettingPreference.getH())
params.put(Constant.Device.ip, SettingPreference.getIp())
params.put(Constant.Device.imsi, SettingPreference.getImsi())
params.put(Constant.Device.model, SettingPreference.getModel())
params.put(Constant.Device.vn, SettingPreference.getVN())
params.put(Constant.Device.ntt, SettingPreference.getNTT())
params.put(Constant.Device.vc, SettingPreference.getVC())
params.put(Constant.Device.source, SettingPreference.getSource())
params.put(Constant.Device.ua, SettingPreference.getUA())
params.put(Constant.Device.svn, SettingPreference.getSVN())
var param = obj2Array(params)
System.out.println("-------------:$param")
return params.toString()
}
fun obj2Array(obj: JSONObject): String {
var array = JSONArray()
obj.keys().forEach {
val params = JSONObject()
params.put(it, obj.get(it))
array.put(params)
}
return array.toString()
}
@JavascriptInterface
fun apiClientPost(url: String, tag: String) {
ApiClient.userApi.webApiPost(url).compose(RxSchedulers.observableIO2Main())
.subscribe(object :
Observer<Response<ResponseBody>> {
override fun onSubscribe(d: Disposable) {
}
override fun onNext(responseBodyResponse: Response<ResponseBody>) {
try {
if (responseBodyResponse.body() != null) {
val str = responseBodyResponse.body()!!.string()
println("onNext str :$str")
mWebView.loadUrl(
"javascript:onApiSuc('${Base64.encodeToString(
str?.toByteArray(),
Base64.URL_SAFE
)}','$tag')"
)
} else {
// mWebView.loadUrl("javascript:onApiFail($tag)")
mWebView.loadUrl("javascript:onApiFail('$tag')")
}
} catch (e: IOException) {
mWebView.loadUrl("javascript:onApiFail('$tag')")
e.printStackTrace()
}
}
override fun onError(e: Throwable) {
mWebView.loadUrl("javascript:onApiFail('$tag')")
}
override fun onComplete() {
}
})
}
@JavascriptInterface
fun apiClientGet(url: String, tag: String) {
println("url:$url-------------tag:$tag")
ApiClient.userApi.webApiGet(url).compose(RxSchedulers.observableIO2Main())
.subscribe(object :
Observer<Response<ResponseBody>> {
override fun onSubscribe(d: Disposable) {
}
override fun onNext(responseBodyResponse: Response<ResponseBody>) {
try {
mWebView?.post {
if (responseBodyResponse.body() != null) {
val str = responseBodyResponse.body()?.string()
mWebView.loadUrl(
"javascript:onApiSuc('${Base64.encodeToString(
str?.toByteArray(),
Base64.URL_SAFE
)}','$tag')"
)
} else {
mWebView.loadUrl("javascript:onApiFail('$tag')")
}
}
} catch (e: IOException) {
mWebView.loadUrl("javascript:onApiFail('$tag')")
e.printStackTrace()
}
}
override fun onError(e: Throwable) {
mWebView.loadUrl("javascript:onApiFail('$tag')")
}
override fun onComplete() {
}
})
}
@JavascriptInterface
fun adJump(str: String) {
Log.d("glc", "adJump:" + str)
val data = Utils.str2Obj(str, NewsEntity::class.java) as NewsEntity?
if (data != null) {
JumpUtils.adJump(data)
}
}
@JavascriptInterface
fun videoPlay() {
mWebView.post {
mWebView.loadUrl("javascript:videoPlay()")
}
}
@JavascriptInterface
fun signIn() {
Log.d("qbs", "signIn---------------------------------------------------------------")
RxBus.get().post("sign", 0)
}
@JavascriptInterface
fun getSignSessionId(): String {
return SettingPreference.getSignSessionId()
}
// @JavascriptInterface
// fun onRewardVideo(codeId: String, coins: String) {
// mWebView?.post {
// AdDataSupport.h5RewardVideo(codeId, coins.toInt(), object : TTAdNative.RewardVideoAdListener {
// override fun onRewardVideoAdLoad(ad: TTRewardVideoAd?) {
// ad?.setRewardAdInteractionListener(object : TTRewardVideoAd.RewardAdInteractionListener {
// override fun onRewardVerify(p0: Boolean, p1: Int, p2: String?) {
// }
//
// override fun onSkippedVideo() {
// }
// override fun onAdShow() {
// Log.d("qbs","onAdShow")
// EventUtils.onEvent("exciting_video_play",codeId)
// }
//
// override fun onAdVideoBarClick() {
// Log.d("qbs","onAdVideoBarClick")
// EventUtils.onEvent("exciting_video_ad_click", codeId)
//
// }
//
// override fun onVideoComplete() {
//
// }
// override fun onAdClose() {
// mWebView.post {
// mWebView.loadUrl("javascript:onAdClose()")
// }
// }
//
// override fun onVideoError() {
// }
// })
// ad?.showRewardVideoAd(act)
// }
//
// override fun onRewardVideoCached() {
// }
//
// override fun onError(p0: Int, p1: String?) {
// }
// })
// }
// }
/**
* 是否填写身体数据
*/
@JavascriptInterface
fun getStepSettingType(): String {
return SettingPreference.getStepSettingType()
}
@JavascriptInterface
fun ignoreBatteryOptimization() {
try {
val powerManager =
AppliContext.get().getSystemService(Context.POWER_SERVICE) as PowerManager
val hasIgnored = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
powerManager?.isIgnoringBatteryOptimizations(AppliContext.get().getPackageName())
} else {
true
}
if (!hasIgnored) {
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + AppliContext.get().getPackageName()));
act?.startActivity(intent)
}
} catch (e: Exception) {
}
}
@JavascriptInterface
fun jumpStartInterface() {
var intent: Intent
try {
intent = getAutostartSettingIntent(act as Context)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
act?.startActivity(intent)
} catch (e: Exception) {//抛出异常就直接打开设置页面
intent = Intent(Settings.ACTION_SETTINGS)
act?.startActivity(intent)
}
}
/**
* 获取自启动管理页面的Intent
* @param context context
* @return 返回自启动管理页面的Intent
*/
private fun getAutostartSettingIntent(context: Context): Intent {
var componentName: ComponentName? = null
val brand = Build.MANUFACTURER
val intent = Intent()
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
when (brand.toLowerCase()) {
"samsung"//三星
-> componentName = ComponentName(
"com.samsung.android.sm",
"com.samsung.android.sm.app.dashboard.SmartManagerDashBoardActivity"
)
"huawei"//华为
->
intent.setAction("huawei.intent.action.HSM_BOOTAPP_MANAGER")
//荣耀V8,EMUI 8.0.0,Android 8.0上,以下两者效果一样
// componentName= ComponentName.unflattenFromString("com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity")
"xiaomi"//小米
-> componentName =
ComponentName(
"com.miui.securitycenter",
"com.huawei.systemmanager.optimize.process.ProtectActivity"
)
"vivo"//VIVO
->
// componentName = new ComponentName("com.iqoo.secure", "com.iqoo.secure.safaguard.PurviewTabActivity");
componentName =
ComponentName(
"com.iqoo.secure",
"com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"
)
"oppo"//OPPO
->
// componentName = new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity");
componentName = ComponentName(
"com.coloros.oppoguardelf",
"com.coloros.powermanager.fuelgaue.PowerUsageModelActivity"
)
"yulong", "360"//360
-> componentName = ComponentName(
"com.yulong.android.coolsafe",
"com.yulong.android.coolsafe.ui.activity.autorun.AutoRunListActivity"
)
"meizu"//魅族
-> componentName =
ComponentName("com.meizu.safe", "com.meizu.safe.permission.SmartBGActivity")
"oneplus"//一加
-> componentName = ComponentName(
"com.oneplus.security",
"com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity"
)
"letv"//乐视
-> {
intent.action = "com.letv.android.permissionautoboot"
intent.action = "android.settings.APPLICATION_DETAILS_SETTINGS"
intent.data = Uri.fromParts("package", context.packageName, null)
}
else//其他
-> {
intent.action = "android.settings.APPLICATION_DETAILS_SETTINGS"
intent.data = Uri.fromParts("package", context.packageName, null)
}
}// componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");//目前看是通用的
if (componentName != null) {
intent.component = componentName
}
return intent
}
/**
* 打开推送设置页面
*/
@JavascriptInterface
fun openPushSetteing() {
if (act != null)
Utils.requestNotify(act)
}
/**
* 判断是否打开推送权限
*/
@JavascriptInterface
fun isPushOpen(): Boolean {
return NotificationManagerCompat.from(AppliContext.get()).areNotificationsEnabled()
}
/**
* 跳到兑换商店页
*/
@JavascriptInterface
fun jumpShop() {
act?.runOnUiThread(Runnable {
RxBusUtil.getDefault().send(RxBusConstant.RX_MAIN_ACTIVITY_TAB, 1)
act?.finish()
// Constant.Utils.ExchangeShopFragmentBackFlag = false
})
}
/**
* 跳转web阅读页
*/
@JavascriptInterface
fun jumpWebActivity(json: String) {
act?.runOnUiThread(Runnable {
val newsEntity: NewsEntity = Utils.str2Obj(json, NewsEntity::class.java) as NewsEntity
JumpUtils.adJump(newsEntity)
/*JumpUtils.webH5Jump(
newsEntity.title,
newsEntity.url,
newsEntity.delay.toString(),
newsEntity.sid.toString(),
newsEntity.deep_url_re,
newsEntity.timeTrigger,
newsEntity.slot_id,
newsEntity.incentive_level.toString(),
newsEntity.alert,
newsEntity.alertRenderType
)*/
})
}
/**
* 上报
*/
@JavascriptInterface
fun eventUtils(action: String) {
EventUtils.onEvent(action)
}
/**
* 获取金币弹窗
* type 1水滴 2金币
*/
@JavascriptInterface
fun showDialog(waterDropCount: Int, type: Int) {
// mWebView.context.runOnUiThread {
// CenterDialog.showgetWaterDrop(mWebView.context,type,waterDropCount,object :DialogInterface.OnCancelListener {
// override fun onCancel(p0: DialogInterface?) {
// mWebView.context.runOnUiThread {
// mWebView?.loadUrl("javascript:onResume()")
// }
// }
// },mWebView)
// }
}
/**
* 提现成功弹窗
*/
@JavascriptInterface
fun showWithdrawSucces(cashStr: String) {
mWebView.context.runOnUiThread {
// CenterDialog.showGuideGetMoney(act,cashStr,mWebView)
}
}
}
\ No newline at end of file
package com.ym.userinfo.module.activity;
package com.ym.library.activity;
import android.graphics.Color;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.umeng.analytics.MobclickAgent;
import com.ym.library.R;
import com.ym.library.net.BaseActivity;
import com.ym.library.rxbus.RxBusConstant;
import com.ym.library.rxbus.RxBusUtil;
import com.ym.library.utils.StatusBarUtil;
import com.ym.module.userinfo.R;
import com.ym.library.utils.Utils;
import com.ym.module.toponad.AdID;
import com.ym.module.toponad.ToponManager;
import org.apache.poi.hssf.record.formula.functions.Int;
import org.jetbrains.annotations.NotNull;
public class WebViewActivity extends BaseActivity {
private String url;
private String title;
private LinearLayout layout;
private WebView webView;
@Override
......@@ -34,33 +44,28 @@ public class WebViewActivity extends BaseActivity {
@Override
public void init() {
url = getIntent().getData().getQueryParameter("url");
// url = getIntent().getStringExtra("url");
// title = getIntent().getStringExtra("title");
title = getIntent().getData().getQueryParameter("title");
RelativeLayout rl = findViewById(R.id.id_rl_toolbar);
if (getIntent().getData().getBooleanQueryParameter("showToolbar", true)) {
rl.setVisibility(View.VISIBLE);
} else {
rl.setVisibility(View.GONE);
}
layout = findViewById(R.id.activity_webview_layout);
initWebView();
initTitle();
}
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
private void initWebView() {
webView = findViewById(R.id.activity_webview);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
webView = new WebView(this);
webView.setBackgroundColor(getResources().getColor(R.color.color_FEDA83));
//设置WebView的宽高
webView.setLayoutParams(layoutParams);
//把webView添加到容器中
layout.addView(webView);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
// webView.getSettings().setDefaultFontSize(56);
......@@ -86,7 +91,7 @@ public class WebViewActivity extends BaseActivity {
// },"android");
// webView.addJavascriptInterface(new WebJavaInterface(this,webView).);
webView.addJavascriptInterface(new WebJavaInterface(), "android");
webView.addJavascriptInterface(new WebJavaInterface(this, webView), "android");
webView.setWebViewClient(new WebViewClient() {
@Override
......@@ -100,14 +105,35 @@ public class WebViewActivity extends BaseActivity {
}
private void initTitle() {
findViewById(R.id.iv_user_toolbar_back).setOnClickListener(new View.OnClickListener() {
findViewById(R.id.id_iv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
TextView tv_title = findViewById(R.id.tv_user_toolbar_title);
tv_title.setText(title+"");
tv_title.setText(title);
}
@Override
protected void onResume() {
super.onResume();
if (webView != null) {
webView.loadUrl("javascript:onResume()");
}
MobclickAgent.onResume(this);
// ToponManager.INSTANCE.initNativeAd(this, AdID.AD_WELFARE_CENTER_BIGIMAGE);
}
@Override
protected void onPause() {
super.onPause();
if (webView != null) {
webView.loadUrl("javascript:onPause()");
}
MobclickAgent.onPause(this);
RxBusUtil.getDefault()
.send(RxBusConstant.RX_MAIN_HIGH_WATER_DROP_UPDATE);
}
@Override
......@@ -118,13 +144,16 @@ public class WebViewActivity extends BaseActivity {
webView.removeAllViews();
webView.destroy();
webView = null;
layout.removeView(webView);
}
}
class WebJavaInterface {
@JavascriptInterface
public void finishH5() {
finish();
class WebJavaInterface extends JavaInterface {
public WebJavaInterface(@NotNull Activity act, @NotNull WebView web) {
super(act, web);
}
}
}
......@@ -2,6 +2,7 @@ package com.ym.library.net
import com.ym.library.module.*
import io.reactivex.Observable
import okhttp3.ResponseBody
import retrofit2.http.*
/**
......@@ -40,4 +41,21 @@ interface IUserApi {
@GET(NetConfig.User.URL_USER_WITHDRAW_BIND_WX)
fun bindWx(@Query("openId") oppenid: String,@Query("token") token: String): Observable<Response<WxBindEntity>>
/**
* h5-post接口
* @param
* @param
* @return
*/
@POST
fun webApiPost(@Url url: String): Observable<retrofit2.Response<ResponseBody>>
/**
* h5-get接口
* @param
* @param
* @return
*/
@GET
fun webApiGet(@Url url: String): Observable<retrofit2.Response<ResponseBody>>
}
\ No newline at end of file
......@@ -25,7 +25,8 @@ interface RounterApi {
@RounterUri(Constant.scheme + "://web")
fun getIntentActivityWeb(
@RounterParam("title") title: String,
@RounterParam("url") url: String
@RounterParam("url") url: String,
@RounterParam("showToolbar") showToolbar: Boolean
): Intent
@RounterUri(Constant.scheme + "://adshare")
......
......@@ -38,4 +38,6 @@ public class RxBusConstant {
public final static int RX_MAIN_UPDATE_HOME_INFO = 10005;
//MainFragment 每日水滴领取后刷新
public final static int RX_MAIN_WATER_DROP_UPDATE = 10008;
//MainFragment 高额水滴领取后刷新
public final static int RX_MAIN_HIGH_WATER_DROP_UPDATE = 10004;
}
......@@ -30,9 +30,9 @@ public class JumpUtils {
}
}
public static void h5Jump(String title, String url) {
public static void h5Jump(String title, String url,boolean showToolbar) {
try {
Intent intent = RounterBus.getRounter(RounterApi.class).getIntentActivityWeb(title, url);
Intent intent = RounterBus.getRounter(RounterApi.class).getIntentActivityWeb(title, url,showToolbar);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
AppliContext.get().startActivity(intent);
} catch (Exception e) {
......@@ -348,7 +348,7 @@ public class JumpUtils {
data.getDeep_url_re()
);
} else {
h5Jump(data.getTitle(), data.getUrl());
h5Jump(data.getTitle(), data.getUrl(),false);
}
} else if (data.getOpentype() == NewsEntity.AD_TYPE_APPMODEL && data.getStatus() != 2) {
if (appmodelId == 59) {
......
<?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">
<RelativeLayout
android:id="@+id/id_rl_toolbar"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="#994B00">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/id_iv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_webview_back"
android:layout_marginLeft="14dp"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/tv_user_toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:textSize="18sp"
android:textStyle="bold"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/activity_webview_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" />
</LinearLayout>
......@@ -23,4 +23,5 @@
<color name="transparent">#00000000</color>
<color name="transparent75">#60000000</color>
<color name="color_FEDA83">#FEDA83</color>
</resources>
......@@ -34,17 +34,6 @@
android:scheme="quweiguesssong" />
</intent-filter>
</activity>
<activity
android:name="com.ym.userinfo.module.activity.WebViewActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="web"
android:scheme="quweiguesssong" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -23,15 +23,15 @@ class SettingActivity : BaseActivity() {
tv_user_toolbar_title.text = "设置"
//用户协议
tv_setting_user_agreement.setOnClickListener {
JumpUtils.h5Jump("用户协议", Constant.Param.USER)
JumpUtils.h5Jump("用户协议", Constant.Param.USER,false)
}
//隐私条款
tv_setting_privacy_policy.setOnClickListener {
JumpUtils.h5Jump("隐私条款", Constant.Param.PRIVACY)
JumpUtils.h5Jump("隐私条款", Constant.Param.PRIVACY,false)
}
//关于我们
tv_setting_about_us.setOnClickListener {
JumpUtils.h5Jump("关于我们", Constant.Param.ABOUTUS)
JumpUtils.h5Jump("关于我们", Constant.Param.ABOUTUS,false)
}
//版本升级
id_setting_update_version.setOnClickListener {
......
......@@ -119,10 +119,10 @@ object UserDiaLog {
// mDialog.dismiss()
// }
mDialogView.findViewById<TextView>(R.id.tv_wx_login_user).setOnClickListener {
JumpUtils.h5Jump("隐私条款", Constant.Param.USER)
JumpUtils.h5Jump("隐私条款", Constant.Param.USER,false)
}
mDialogView.findViewById<TextView>(R.id.tv_wx_login_privacy).setOnClickListener {
JumpUtils.h5Jump("隐私条款", Constant.Param.PRIVACY)
JumpUtils.h5Jump("隐私条款", Constant.Param.PRIVACY,false)
}
......
<?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">
<include layout="@layout/layout_user_toolbar" />
<WebView
android:id="@+id/activity_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_FEDA83" />
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment