优化头像和map宠物显示速度
This commit is contained in:
@@ -28,9 +28,9 @@ android {
|
||||
applicationId "com.abbidot.tracker"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 35
|
||||
versionCode 2205
|
||||
// versionName "2.2.5"
|
||||
versionName "2.2.5-Beta1"
|
||||
versionCode 2206
|
||||
// versionName "2.2.6"
|
||||
versionName "2.2.6-Beta1"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ class MyApplication : Application() {
|
||||
|
||||
companion object {
|
||||
lateinit var instance: Application
|
||||
|
||||
//保存地图宠物头像对象在内存中,提高显示速度
|
||||
val mapPetHeadHashMap = hashMapOf<String, Any>()
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
|
||||
@@ -40,7 +40,9 @@ class AssignOptionsAdapter(
|
||||
} else {
|
||||
circleImageView.visibility = View.VISIBLE
|
||||
wrapImageView.visibility = View.GONE
|
||||
ViewUtil.instance.setPetTypeHead(circleImageView, item.value, item.menuType)
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
mContext, circleImageView, item.value, item.menuType
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class ChangePetListDialogAdapter(ctx: Context, list: MutableList<PetBean>?) :
|
||||
holder.setText(R.id.dialog_my_pet_name, item.petName)
|
||||
|
||||
holder.getImageView(R.id.dialog_my_pet_head).apply {
|
||||
ViewUtil.instance.setPetTypeHead(this, item.imgurl, item.petType)
|
||||
ViewUtil.instance.setPetTypeHead(mContext,this, item.imgurl, item.petType)
|
||||
setOnClickListener {
|
||||
if (null != mOnChangeClickListener) {
|
||||
mOnChangeClickListener!!.onCurrentClick()
|
||||
|
||||
@@ -116,7 +116,7 @@ class MyTrackerV2Adapter(
|
||||
petName.visibility = View.VISIBLE
|
||||
item.pet?.let {
|
||||
petName.text = it.petName
|
||||
ViewUtil.instance.setPetTypeHead(petHead, it.imgurl, it.petType)
|
||||
ViewUtil.instance.setPetTypeHead(mContext, petHead, it.imgurl, it.petType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class HomeMapNavigationActivity :
|
||||
// val mGoogleApiClient = mGoogleSignInClient.asGoogleApiClient()
|
||||
|
||||
|
||||
ViewUtil.instance.imageLoadUrl(
|
||||
ViewUtil.instance.imageLoadUrl(mContext,
|
||||
mViewBinding.homeMapNavigationPetHead.appHeadImage, pet!!.imgurl
|
||||
)
|
||||
if (TextUtils.isEmpty(historyDataBean!!.address)) {
|
||||
|
||||
@@ -140,7 +140,7 @@ class MapLiveActivity : BaseActivity<ActivityMapLiveBinding>(ActivityMapLiveBind
|
||||
|
||||
mViewBinding.apply {
|
||||
mapLivePetLayout.mapPetName.text = historyDataBean.petName
|
||||
ViewUtil.instance.imageLoadUrl(
|
||||
ViewUtil.instance.imageLoadUrl(mContext,
|
||||
mapLivePetLayout.mapPetHead.appHeadImage, historyDataBean.petImgurl
|
||||
)
|
||||
val batteryString =
|
||||
|
||||
@@ -89,7 +89,7 @@ class RechargeDeviceDetailCNActivity : BaseActivity<ActivityRechargeDeviceDetail
|
||||
} else {
|
||||
itemCardPetHead.appHeadImage.let {
|
||||
it.visibility = View.VISIBLE
|
||||
ViewUtil.instance.imageLoadUrl(it, rechargeDeviceBean.pet!!.imgurl)
|
||||
ViewUtil.instance.imageLoadUrl(mContext,it, rechargeDeviceBean.pet!!.imgurl)
|
||||
}
|
||||
itemCardPetName.let {
|
||||
it.visibility = View.VISIBLE
|
||||
|
||||
@@ -190,7 +190,7 @@ class RechargeOrderDetailCNActivity : BaseActivity<ActivityRechargeOrderDetailCn
|
||||
it.itemCardPetHead.appHeadImage.visibility = View.VISIBLE
|
||||
it.itemCardPetName.visibility = View.VISIBLE
|
||||
it.itemCardPetName.text = pet!!.petName
|
||||
ViewUtil.instance.imageLoadUrl(it.itemCardPetHead.appHeadImage, pet!!.imgurl)
|
||||
ViewUtil.instance.imageLoadUrl(mContext,it.itemCardPetHead.appHeadImage, pet!!.imgurl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class DebugActivity : BaseActivity<ActivityDebugBinding>(ActivityDebugBinding::i
|
||||
private fun setPetData() {
|
||||
val pet = mPetList!![mPetSelectPosition]
|
||||
mViewBinding.debugPetName.text = pet.petName
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
mViewBinding.debugPetHead.appHeadImage, pet.imgurl, pet.petType
|
||||
)
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ class UserProfileActivity :
|
||||
)
|
||||
|
||||
// mUploadImageUrl = MMKVUtil.getString(MMKVKey.HeadUrl)
|
||||
ViewUtil.instance.imageLoadUrl(
|
||||
ViewUtil.instance.imageLoadUrl(mContext,
|
||||
ilUserProfileHeadLayout.ilPetProfileHead.appHeadImage, "", R.drawable.pic_avatar_df
|
||||
)
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class UserProfileActivity :
|
||||
mViewBinding.ilUserProfileNameLayout.etInputContent.setText(info.userName)
|
||||
mViewBinding.ilUserProfileEmailLayout.etInputContent.setText(info.email)
|
||||
mUploadImageUrl = info.imgurl
|
||||
ViewUtil.instance.imageLoadUrl(
|
||||
ViewUtil.instance.imageLoadUrl(mContext,
|
||||
mViewBinding.ilUserProfileHeadLayout.ilPetProfileHead.appHeadImage,
|
||||
mUploadImageUrl,
|
||||
R.drawable.pic_avatar_df
|
||||
|
||||
@@ -60,7 +60,7 @@ class DataBoardActivity :
|
||||
}
|
||||
|
||||
mPetBean?.apply {
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
mViewBinding.ivDataBoardPetHead.appHeadImage, imgurl, petType
|
||||
)
|
||||
mDataDetailViewModel.getPetActivityDetailInfo(this@DataBoardActivity, petId, deviceId)
|
||||
|
||||
@@ -58,7 +58,7 @@ class MoreActivityActivity :
|
||||
}
|
||||
|
||||
mPetBean?.let {
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ilMoreActivityPetHead.appHeadImage, it.imgurl, it.petType
|
||||
)
|
||||
tvMoreActivityPetName.text = it.petName
|
||||
|
||||
@@ -47,7 +47,7 @@ class MoreSleepActivity :
|
||||
// mRightImageButton = addRightImageButton(R.drawable.selector_share_icon_pressed2)
|
||||
|
||||
mPetBean?.let {
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ilMoreSleepPetHead.appHeadImage, it.imgurl, it.petType
|
||||
)
|
||||
tvMoreSleepPetName.text = it.petName
|
||||
|
||||
@@ -9,7 +9,6 @@ import coil.load
|
||||
import com.abbidot.baselibrary.constant.ResultCode
|
||||
import com.abbidot.baselibrary.util.LogUtil
|
||||
import com.abbidot.baselibrary.util.Utils
|
||||
import com.abbidot.tracker.BuildConfig
|
||||
import com.abbidot.tracker.R
|
||||
import com.abbidot.tracker.base.BaseActivity
|
||||
import com.abbidot.tracker.bean.ActiveTimeBean
|
||||
@@ -52,7 +51,7 @@ class SharePetActivityActivity :
|
||||
|
||||
intent.extras?.apply {
|
||||
Util.getParcelableAdaptive(intent, ConstantString.Pet, PetBean::class.java)?.let {
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ilSharePetActivityPetHead.appHeadImage, it.imgurl, it.petType
|
||||
)
|
||||
tvSharePetActivityPetName.text = it.petName
|
||||
|
||||
@@ -56,7 +56,7 @@ class AddWifiPowerZone1Activity :
|
||||
|
||||
mViewBinding.apply {
|
||||
mPetBean?.let {
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ivAddWifiZone1PetHead.appHeadImage, it.imgurl, it.petType
|
||||
)
|
||||
}
|
||||
|
||||
@@ -928,7 +928,7 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
|
||||
it.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
|
||||
}
|
||||
mViewBinding.llLiveV2MapTopPet.homeDataPetHeadSmall.appHeadImage.let {
|
||||
ViewUtil.instance.setPetTypeHead(it, imgurl, petType)
|
||||
ViewUtil.instance.setPetTypeHead(mContext,it, imgurl, petType)
|
||||
ViewUtil.instance.viewAlphaAndRotationObjectAnimator(it)
|
||||
}
|
||||
//重新设置地图宠物头像
|
||||
|
||||
@@ -46,7 +46,7 @@ class FamilyMembersActivity :
|
||||
mViewBinding.apply {
|
||||
|
||||
mPetBean?.let {
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ilFamilyMembersPetHead.appHeadImage, it.imgurl, it.petType
|
||||
)
|
||||
mFamilyViewModel.getFamilies(this@FamilyMembersActivity, it.deviceId)
|
||||
|
||||
@@ -90,7 +90,7 @@ class PetProfileActivity :
|
||||
root.setBackgroundResource(R.color.white)
|
||||
ilPetProfileNameLayout.etInputContent.doAfterTextChanged {
|
||||
it?.let { s ->
|
||||
val text = s.toString().limitLetterChinese(16)
|
||||
val text = s.toString().limitLetterChinese(14)
|
||||
if (text != s.toString()) {
|
||||
s.replace(0, s.length, text)
|
||||
}
|
||||
@@ -266,7 +266,7 @@ class PetProfileActivity :
|
||||
private fun setPetData() {
|
||||
mViewBinding.apply {
|
||||
mPetBean?.let {
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ilPetProfileHeadLayout.ilPetProfileHead.appHeadImage, it.imgurl, it.petType
|
||||
)
|
||||
|
||||
@@ -331,7 +331,7 @@ class PetProfileActivity :
|
||||
val dataBean = typeList[pos]
|
||||
mPetBean?.apply {
|
||||
petType = dataBean.menuType
|
||||
if (TextUtils.isEmpty(mSelectPetHeadPath) && TextUtils.isEmpty(imgurl)) ViewUtil.instance.setPetTypeHead(
|
||||
if (TextUtils.isEmpty(mSelectPetHeadPath) && TextUtils.isEmpty(imgurl)) ViewUtil.instance.setPetTypeHead(mContext,
|
||||
mViewBinding.ilPetProfileHeadLayout.ilPetProfileHead.appHeadImage,
|
||||
imgurl,
|
||||
petType
|
||||
|
||||
@@ -69,12 +69,12 @@ class FirstPetProfileActivity :
|
||||
|
||||
mProfileCommon = PetProfileCommon(mContext, rvFirstPetProfileLabel, mPetBean)
|
||||
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ilFirstPetProfileHeadLayout.ilPetProfileHead.appHeadImage, "", 1
|
||||
)
|
||||
mPetBean?.apply {
|
||||
tvFirstPetProfilePetName.text = petName
|
||||
ViewUtil.instance.setPetTypeHead(
|
||||
ViewUtil.instance.setPetTypeHead(mContext,
|
||||
ilFirstPetProfileHeadLayout.ilPetProfileHead.appHeadImage, imgurl, petType
|
||||
)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class AccountV2Fragment :
|
||||
it.homeDataPetNameSmall.text =
|
||||
MMKVUtil.getString(MMKVKey.UserName, getString(R.string.app_name))
|
||||
val imageUrl = MMKVUtil.getString(MMKVKey.HeadUrl)
|
||||
ViewUtil.instance.imageLoadUrl(
|
||||
ViewUtil.instance.imageLoadUrl(mContext!!,
|
||||
it.homeDataPetHeadSmall.appHeadImage, imageUrl, R.drawable.pic_avatar_df
|
||||
)
|
||||
it.homeDataPetNameSmall.setCompoundDrawablesWithIntrinsicBounds(
|
||||
@@ -187,7 +187,7 @@ class AccountV2Fragment :
|
||||
MMKVUtil.putString(MMKVKey.CountryCode, info.countryCode)
|
||||
mViewBinding.llHomeAccountTopUser.let { view ->
|
||||
view.homeDataPetNameSmall.text = info.userName
|
||||
ViewUtil.instance.imageLoadUrl(
|
||||
ViewUtil.instance.imageLoadUrl(mContext!!,
|
||||
view.homeDataPetHeadSmall.appHeadImage,
|
||||
info.imgurl,
|
||||
R.drawable.pic_avatar_df
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.hardware.SensorEvent
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -14,6 +15,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.abbidot.baselibrary.util.AppUtils
|
||||
import com.abbidot.baselibrary.util.LogUtil
|
||||
import com.abbidot.tracker.MyApplication
|
||||
import com.abbidot.tracker.R
|
||||
import com.abbidot.tracker.base.BaseFragment
|
||||
import com.abbidot.tracker.bean.FencesBean
|
||||
@@ -29,6 +31,7 @@ import com.baidu.location.BDLocation
|
||||
import com.baidu.location.LocationClient
|
||||
import com.baidu.location.LocationClientOption
|
||||
import com.baidu.mapapi.map.BaiduMap
|
||||
import com.baidu.mapapi.map.BitmapDescriptor
|
||||
import com.baidu.mapapi.map.BitmapDescriptorFactory
|
||||
import com.baidu.mapapi.map.Circle
|
||||
import com.baidu.mapapi.map.CircleDottedStrokeType
|
||||
@@ -243,21 +246,28 @@ abstract class BaseBaiduMapFragment :
|
||||
needConvertGCJ02: Boolean = true,
|
||||
headBgResId: Int = R.drawable.pic_map_gps_avatar
|
||||
) {
|
||||
|
||||
val mapKey = if (TextUtils.isEmpty(mPetHeadUrl)) "pet_default_head"
|
||||
else mPetHeadUrl.substring(mPetHeadUrl.lastIndexOf("/") + 1, mPetHeadUrl.length)
|
||||
var bitmapDescriptor = MyApplication.mapPetHeadHashMap[mapKey]
|
||||
if (null == bitmapDescriptor || bitmapDescriptor !is BitmapDescriptor) {
|
||||
if (null == mPetHeadIconBitmap) {
|
||||
//设置头像
|
||||
mPetHeadIconBitmap =
|
||||
GoogleBitmapHelper.headToBitmap(mContext!!, headBgResId, mPetHeadUrl, mPetType)
|
||||
}
|
||||
bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(mPetHeadIconBitmap!!)
|
||||
//保存在内存中,提高显示速度
|
||||
MyApplication.mapPetHeadHashMap[mapKey] = bitmapDescriptor
|
||||
}
|
||||
|
||||
mMarker?.remove()
|
||||
|
||||
val latLng = getBaiduMapLatLng(lat, lon, needConvertGCJ02)
|
||||
|
||||
mPetLatLng = latLng
|
||||
|
||||
//构建MarkerOption,用于在地图上添加Marker
|
||||
val option =
|
||||
MarkerOptions().position(latLng).animateType(MarkerOptions.MarkerAnimateType.grow)
|
||||
.icon(BitmapDescriptorFactory.fromBitmap(mPetHeadIconBitmap))
|
||||
.icon(bitmapDescriptor as BitmapDescriptor)
|
||||
//在地图上添加Marker,并显示
|
||||
mMarker = mBaiduMap!!.addOverlay(option)
|
||||
}
|
||||
@@ -341,7 +351,10 @@ abstract class BaseBaiduMapFragment :
|
||||
* @param needConvertGCJ02 是否需要转换GCJ02坐标
|
||||
*/
|
||||
fun moveCameraLocation(
|
||||
lat: Double, lon: Double, needConvertGCJ02: Boolean = true, isAnimMoveCamera: Boolean = false
|
||||
lat: Double,
|
||||
lon: Double,
|
||||
needConvertGCJ02: Boolean = true,
|
||||
isAnimMoveCamera: Boolean = false
|
||||
) {
|
||||
val latLng = getBaiduMapLatLng(lat, lon, needConvertGCJ02)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.graphics.Bitmap
|
||||
import android.graphics.Point
|
||||
import android.location.Location
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -18,6 +19,7 @@ import com.abbidot.baselibrary.constant.MMKVKey
|
||||
import com.abbidot.baselibrary.util.AppUtils
|
||||
import com.abbidot.baselibrary.util.LogUtil
|
||||
import com.abbidot.baselibrary.util.MMKVUtil
|
||||
import com.abbidot.tracker.MyApplication
|
||||
import com.abbidot.tracker.R
|
||||
import com.abbidot.tracker.base.BaseFragment
|
||||
import com.abbidot.tracker.bean.FencesBean
|
||||
@@ -40,6 +42,7 @@ import com.google.android.gms.maps.GoogleMap
|
||||
import com.google.android.gms.maps.GoogleMapOptions
|
||||
import com.google.android.gms.maps.MapView
|
||||
import com.google.android.gms.maps.OnMapReadyCallback
|
||||
import com.google.android.gms.maps.model.BitmapDescriptor
|
||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory
|
||||
import com.google.android.gms.maps.model.CameraPosition
|
||||
import com.google.android.gms.maps.model.Circle
|
||||
@@ -387,14 +390,22 @@ abstract class BaseGoogleMapFragment :
|
||||
private suspend fun setPetHeadMarker(
|
||||
latLng: LatLng, headBgResId: Int = R.drawable.pic_map_gps_avatar
|
||||
) {
|
||||
val mapKey = if (TextUtils.isEmpty(mPetHeadUrl)) "pet_default_head"
|
||||
else mPetHeadUrl.substring(mPetHeadUrl.lastIndexOf("/") + 1, mPetHeadUrl.length)
|
||||
var bitmapDescriptor = MyApplication.mapPetHeadHashMap[mapKey]
|
||||
if (null == bitmapDescriptor || bitmapDescriptor !is BitmapDescriptor) {
|
||||
if (null == mPetHeadIconBitmap) {
|
||||
//设置头像
|
||||
mPetHeadIconBitmap =
|
||||
GoogleBitmapHelper.headToBitmap(mContext!!, headBgResId, mPetHeadUrl, mPetType)
|
||||
}
|
||||
bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(mPetHeadIconBitmap!!)
|
||||
//保存在内存中,提高显示速度
|
||||
MyApplication.mapPetHeadHashMap[mapKey] = bitmapDescriptor
|
||||
}
|
||||
val newLatLng = toGCJ02LatLon(latLng)
|
||||
val markerOptions = MarkerOptions().position(newLatLng)
|
||||
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(mPetHeadIconBitmap!!))
|
||||
markerOptions.icon(bitmapDescriptor)
|
||||
mMarker?.remove()
|
||||
mGoogleMap?.apply {
|
||||
mMarker = addMarker(markerOptions)
|
||||
@@ -406,15 +417,15 @@ abstract class BaseGoogleMapFragment :
|
||||
if (MMKVUtil.getBoolean(MMKVKey.isGpsToGCJ02)) {
|
||||
mUserLatLng?.let {
|
||||
if (null == mUserMarker) {
|
||||
mUserMarker = addImageMarker(it, R.drawable.icon_user_location_image,false)
|
||||
mUserMarker = addImageMarker(it, R.drawable.icon_user_location_image, false)
|
||||
} else {
|
||||
if (it.latitude == mUserMarker!!.position.latitude && it.longitude == mUserMarker!!.position.longitude) {
|
||||
} else {
|
||||
mUserMarker?.remove()
|
||||
mUserMarker = addImageMarker(it, R.drawable.icon_user_location_image,false)
|
||||
mUserMarker = addImageMarker(it, R.drawable.icon_user_location_image, false)
|
||||
}
|
||||
}
|
||||
mUserMarker?.setAnchor(0.5f,0.5f)
|
||||
mUserMarker?.setAnchor(0.5f, 0.5f)
|
||||
}
|
||||
}
|
||||
// else {
|
||||
|
||||
@@ -30,7 +30,7 @@ object GoogleBitmapHelper {
|
||||
* @param headUrl 网络宠物的头像url
|
||||
*/
|
||||
suspend fun headToBitmap(
|
||||
context: Context, @DrawableRes id: Int, headUrl: String, petType: Int
|
||||
context: Context, @DrawableRes headBgResId: Int, headUrl: String, petType: Int
|
||||
): Bitmap? {
|
||||
var headUrlBitmap = if (TextUtils.isEmpty(headUrl)) {
|
||||
var headResId = R.drawable.icon_pet_default_head_svg
|
||||
@@ -39,10 +39,14 @@ object GoogleBitmapHelper {
|
||||
} else {
|
||||
ImageUtil.getImageBitmapByUrl(context, headUrl)
|
||||
}
|
||||
if (null == headUrlBitmap) headUrlBitmap = BitmapFactory.decodeResource(
|
||||
context.resources, R.drawable.pic_avatar_df
|
||||
|
||||
if (null == headUrlBitmap) {
|
||||
headUrlBitmap =
|
||||
BitmapFactory.decodeResource(context.resources, R.drawable.pic_avatar_df)
|
||||
}
|
||||
return combineBitmap(
|
||||
ImageUtil.getBitmapFromDrawableAndSvg(context, headBgResId), headUrlBitmap!!
|
||||
)
|
||||
return combineBitmap(ImageUtil.getBitmapFromDrawableAndSvg(context, id), headUrlBitmap!!)
|
||||
// return combineBitmap(BitmapFactory.decodeResource(context.resources, id), headUrlBitmap)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,14 @@ package com.abbidot.tracker.ui.fragment.map.googlemap
|
||||
import android.content.Context
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Typeface
|
||||
import android.text.TextUtils
|
||||
import androidx.appcompat.widget.AppCompatSeekBar
|
||||
import androidx.core.view.isVisible
|
||||
import com.abbidot.baselibrary.constant.MMKVKey
|
||||
import com.abbidot.baselibrary.util.AppUtils
|
||||
import com.abbidot.baselibrary.util.LogUtil
|
||||
import com.abbidot.baselibrary.util.MMKVUtil
|
||||
import com.abbidot.tracker.MyApplication
|
||||
import com.abbidot.tracker.R
|
||||
import com.abbidot.tracker.bean.HistoryDataBean
|
||||
import com.abbidot.tracker.bean.PetBean
|
||||
@@ -35,7 +37,7 @@ class HistoryDataGoogleMapFragment : BaseGoogleMapFragment() {
|
||||
private lateinit var mVerticalTopToBottomSeekBar: AppCompatSeekBar
|
||||
|
||||
private val mMarkerOptions = MarkerOptions()
|
||||
private lateinit var mPetIconDescriptor: BitmapDescriptor
|
||||
private var mPetIconDescriptor: BitmapDescriptor? = null
|
||||
|
||||
private val mLatLngList = mutableListOf<LatLng>()
|
||||
|
||||
@@ -132,17 +134,23 @@ class HistoryDataGoogleMapFragment : BaseGoogleMapFragment() {
|
||||
return
|
||||
}
|
||||
mPetBean = petBean
|
||||
// lifecycleScope.launch {
|
||||
// }
|
||||
try {
|
||||
mPetBean?.apply {
|
||||
val mapKey = if (TextUtils.isEmpty(imgurl)) "pet_default_head"
|
||||
else imgurl.substring(imgurl.lastIndexOf("/") + 1, imgurl.length)
|
||||
var bitmapDescriptor = MyApplication.mapPetHeadHashMap[mapKey]
|
||||
if (null == bitmapDescriptor || bitmapDescriptor !is BitmapDescriptor) {
|
||||
var bitmap = GoogleBitmapHelper.headToBitmap(
|
||||
mContext!!, R.drawable.pic_map_gps_avatar, imgurl, petType
|
||||
)
|
||||
if (null == bitmap) bitmap = BitmapFactory.decodeResource(
|
||||
mContext!!.resources, R.drawable.icon_location_svg
|
||||
)
|
||||
mPetIconDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap!!)
|
||||
bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap!!)
|
||||
//保存在内存中,提高显示速度
|
||||
MyApplication.mapPetHeadHashMap[mapKey] = bitmapDescriptor
|
||||
}
|
||||
mPetIconDescriptor = bitmapDescriptor
|
||||
mMarker?.setIcon(mPetIconDescriptor)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -291,7 +299,7 @@ class HistoryDataGoogleMapFragment : BaseGoogleMapFragment() {
|
||||
* 设置宠物Marker经纬度
|
||||
*/
|
||||
fun setPetMarkerLatLng(latLng: LatLng) {
|
||||
if (::mPetIconDescriptor.isInitialized) {
|
||||
if (null != mPetIconDescriptor) {
|
||||
mGoogleMap?.apply {
|
||||
val newLatLng = toGCJ02LatLon(latLng)
|
||||
mMarkerOptions.position(newLatLng).icon(mPetIconDescriptor)
|
||||
|
||||
@@ -34,6 +34,7 @@ class FileUtil {
|
||||
* 保存头像目录名字
|
||||
*/
|
||||
const val HEAD_DIRECTORY_NAME = "headImage"
|
||||
const val TEMP_DIRECTORY_NAME = "temp"
|
||||
|
||||
/**
|
||||
* data首页截屏图片文件名字
|
||||
@@ -105,7 +106,7 @@ class FileUtil {
|
||||
return finalSize
|
||||
}
|
||||
|
||||
fun getFormatSize(size: Long): String {
|
||||
private fun getFormatSize(size: Long): String {
|
||||
if (size <= 0) {
|
||||
return "0.00\tKb"
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import coil.load
|
||||
import coil.request.CachePolicy
|
||||
import coil.request.ImageRequest
|
||||
import coil.request.ImageResult
|
||||
import coil.transform.Transformation
|
||||
import com.abbidot.baselibrary.constant.ConState
|
||||
import com.abbidot.baselibrary.constant.MMKVKey
|
||||
@@ -87,7 +89,7 @@ import com.qmuiteam.qmui.alpha.QMUIAlphaImageButton
|
||||
import com.qmuiteam.qmui.util.QMUIDisplayHelper
|
||||
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet.BottomListSheetBuilder
|
||||
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView
|
||||
import okhttp3.internal.http2.Header
|
||||
import java.io.File
|
||||
import java.util.Calendar
|
||||
|
||||
|
||||
@@ -631,28 +633,56 @@ class ViewUtil private constructor() {
|
||||
* 和圆角变换(RoundedCornersTransformation)
|
||||
*/
|
||||
fun imageLoadUrl(
|
||||
context: Context,
|
||||
imageView: ImageView,
|
||||
url: String,
|
||||
@DrawableRes errorImageResId: Int = R.drawable.icon_placeholder_image_svg,
|
||||
vararg transformations: Transformation
|
||||
) {
|
||||
var isEnableNetCache = true
|
||||
val fileName = url.substring(url.lastIndexOf("/") + 1, url.length) + ".temp"
|
||||
var file: File? = null
|
||||
if (!TextUtils.isEmpty(fileName)) {
|
||||
file = File(
|
||||
FileUtil.getDiskCacheDirectory(context, FileUtil.TEMP_DIRECTORY_NAME), fileName
|
||||
)
|
||||
if (file.exists()) isEnableNetCache = false
|
||||
}
|
||||
imageView.load(url) {
|
||||
listener(object : ImageRequest.Listener {
|
||||
override fun onStart(request: ImageRequest) {
|
||||
super.onStart(request)
|
||||
LogUtil.e("onStart")
|
||||
}
|
||||
|
||||
override fun onError(request: ImageRequest, throwable: Throwable) {
|
||||
super.onError(request, throwable)
|
||||
LogUtil.e("onError:${throwable.message}")
|
||||
}
|
||||
|
||||
override fun onSuccess(request: ImageRequest, metadata: ImageResult.Metadata) {
|
||||
super.onSuccess(request, metadata)
|
||||
LogUtil.e("onSuccess")
|
||||
file?.let {
|
||||
if (!it.exists()) it.createNewFile()
|
||||
}
|
||||
}
|
||||
})
|
||||
//placeholder预置展位图
|
||||
placeholder(errorImageResId)
|
||||
//失败时的错误占位图片
|
||||
error(errorImageResId)
|
||||
//淡入淡出的动画时间
|
||||
// crossfade(2000)
|
||||
val netCachePolicy = if (isEnableNetCache) CachePolicy.ENABLED else CachePolicy.DISABLED
|
||||
diskCachePolicy(CachePolicy.ENABLED)//设置磁盘的缓存策略
|
||||
memoryCachePolicy(CachePolicy.ENABLED)//设置内存的缓存策略
|
||||
networkCachePolicy(CachePolicy.ENABLED)//设置网络的缓存策略
|
||||
memoryCachePolicy(netCachePolicy)//设置内存的缓存策略
|
||||
networkCachePolicy(netCachePolicy)//设置网络的缓存策略
|
||||
// val okHttpCache = Cache(
|
||||
// context.cacheDir.resolve("okhttp_cache"), 50 * 1024 * 1024L
|
||||
// )
|
||||
// OkHttpClient.Builder().cache(okHttpCache)
|
||||
|
||||
// 请求优先 WebP 更小更快
|
||||
Header("Accept", "image/webp,image/jpeg;q=0.8")
|
||||
addHeader("Accept", "image/webp,image/jpeg;q=0.8")
|
||||
if (imageView.width > 0 && imageView.height > 0) {
|
||||
size(imageView.width, imageView.height)// 按View实际大小解码
|
||||
}
|
||||
@@ -1051,7 +1081,7 @@ class ViewUtil private constructor() {
|
||||
val pet = petList[selectPos]
|
||||
savePetSP(pet, selectPos)
|
||||
petName.text = pet.petName
|
||||
setPetTypeHead(petHead, pet.imgurl, pet.petType)
|
||||
setPetTypeHead(context, petHead, pet.imgurl, pet.petType)
|
||||
viewAlphaAndRotationObjectAnimator(petHead)
|
||||
}
|
||||
|
||||
@@ -1118,13 +1148,13 @@ class ViewUtil private constructor() {
|
||||
/**
|
||||
* 设置宠物头像
|
||||
*/
|
||||
fun setPetTypeHead(imageView: ImageView, imageUrl: String, type: Int) {
|
||||
fun setPetTypeHead(context: Context, imageView: ImageView, imageUrl: String, type: Int) {
|
||||
if (TextUtils.isEmpty(imageUrl)) {
|
||||
val defaultHead = if (type == 2) R.drawable.icon_pet_default_head_svg
|
||||
else R.drawable.icon_pet_default_head_svg
|
||||
imageView.load(defaultHead)
|
||||
} else {
|
||||
imageLoadUrl(imageView, imageUrl)
|
||||
imageLoadUrl(context, imageView, imageUrl)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1037,7 +1037,7 @@
|
||||
<string name="txt_geofencing">Geofencing</string>
|
||||
<string name="txt_route_records">Route History Records</string>
|
||||
<string name="txt_family_sharing">Family Members Sharing</string>
|
||||
<string name="txt_customer_support">30-days return guarantee</string>
|
||||
<string name="txt_customer_support">30-days Return Guarantee</string>
|
||||
<string name="txt_show_crash">The program has an exception and is about to exit</string>
|
||||
<string name="txt_activate_subscribe">Activate Subscription</string>
|
||||
<string name="txt_powered_off">Powered off</string>
|
||||
|
||||
Reference in New Issue
Block a user