|
@@ -4,6 +4,8 @@ import android.Manifest
|
|
|
import android.annotation.SuppressLint
|
|
|
import android.app.Activity
|
|
|
import android.content.*
|
|
|
+import android.content.pm.PackageManager
|
|
|
+import android.content.pm.ResolveInfo
|
|
|
import android.graphics.Bitmap
|
|
|
import android.graphics.Canvas
|
|
|
import android.net.Uri
|
|
@@ -16,10 +18,11 @@ import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.widget.*
|
|
|
import androidx.appcompat.widget.AppCompatImageView
|
|
|
-import androidx.core.net.toFile
|
|
|
-import androidx.core.net.toUri
|
|
|
import coil.load
|
|
|
import coil.transform.RoundedCornersTransformation
|
|
|
+import com.hdl.xl.BuildConfig
|
|
|
+import com.hdl.xl.R
|
|
|
+import com.hdl.xl.model.User
|
|
|
import com.qmuiteam.qmui.kotlin.onClick
|
|
|
import com.qmuiteam.qmui.layout.QMUIFrameLayout
|
|
|
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder
|
|
@@ -34,9 +37,6 @@ import com.yanzhenjie.permission.FileProvider
|
|
|
import com.ysnows.base.utils.Toasts
|
|
|
import com.zhy.http.okhttp.OkHttpUtils
|
|
|
import com.zhy.http.okhttp.callback.FileCallBack
|
|
|
-import com.hdl.xl.BuildConfig
|
|
|
-import com.hdl.xl.R
|
|
|
-import com.hdl.xl.model.User
|
|
|
import okhttp3.Call
|
|
|
import java.io.File
|
|
|
import java.io.FileNotFoundException
|
|
@@ -65,10 +65,10 @@ object PopuDownWxUtils {
|
|
|
var uriToImage: Uri? = null
|
|
|
|
|
|
|
|
|
- fun show(context: Context, url: String,name:String?, id:String?,shareUrl:String,view: View, contentResolver: ContentResolver) {
|
|
|
- uriToImage=null
|
|
|
- tipDialog=null
|
|
|
- cr=null
|
|
|
+ fun show(context: Context, url: String, name: String?, id: String?, shareUrl: String, view: View, contentResolver: ContentResolver) {
|
|
|
+ uriToImage = null
|
|
|
+ tipDialog = null
|
|
|
+ cr = null
|
|
|
cr = contentResolver
|
|
|
var mNormalPopup = QMUIPopups.fullScreenPopup(context)
|
|
|
val builder: QMUISkinValueBuilder = QMUISkinValueBuilder.acquire()
|
|
@@ -90,14 +90,14 @@ object PopuDownWxUtils {
|
|
|
val flContainer: FrameLayout = layout.findViewById(R.id.fl_container)
|
|
|
val tvTag: TextView = layout.findViewById(R.id.tv_tag)
|
|
|
val tvPhone: TextView = layout.findViewById(R.id.tv_phone)
|
|
|
- tvTag.text=User.get()?.invite_code
|
|
|
- tvPhone.text=User.get()?.phone
|
|
|
- tvTitle.text=name
|
|
|
- tvName.text= User.get()?.name
|
|
|
+ tvTag.text = User.get()?.invite_code
|
|
|
+ tvPhone.text = User.get()?.phone
|
|
|
+ tvTitle.text = name
|
|
|
+ tvName.text = User.get()?.name
|
|
|
//生成二维码
|
|
|
|
|
|
- var z_shareurl=shareUrl+"?id=$id"+"&invite_code="+User.get()?.invite_code
|
|
|
- var mBitmap = CodeUtils.createImage(z_shareurl, 400, 400, null)
|
|
|
+ var z_shareurl = shareUrl + "?id=$id" + "&invite_code=" + User.get()?.invite_code
|
|
|
+ var mBitmap = CodeUtils.createImage(z_shareurl, 400, 400, null)
|
|
|
imgCode.setImageBitmap(mBitmap)
|
|
|
|
|
|
|
|
@@ -111,7 +111,7 @@ object PopuDownWxUtils {
|
|
|
//
|
|
|
// img.layoutParams = params
|
|
|
|
|
|
- img.load(url){
|
|
|
+ img.load(url) {
|
|
|
transformations(RoundedCornersTransformation(15f))
|
|
|
placeholder(R.drawable.bg_need_error)
|
|
|
error(R.drawable.bg_need_error)
|
|
@@ -121,8 +121,8 @@ object PopuDownWxUtils {
|
|
|
llShareOne.onClick {
|
|
|
//分享给好友
|
|
|
chose = 2
|
|
|
- // setShareImages(context, url)
|
|
|
- setChose(context,flContainer,chose.toString())
|
|
|
+ // setShareImages(context, url)
|
|
|
+ setChose(context, flContainer, chose.toString())
|
|
|
|
|
|
mNormalPopup.dismiss()
|
|
|
|
|
@@ -142,14 +142,14 @@ object PopuDownWxUtils {
|
|
|
|
|
|
//分享给朋友圈
|
|
|
chose = 3//分享到维信朋友圈
|
|
|
- setChose(context,flContainer,chose.toString())
|
|
|
+ setChose(context, flContainer, chose.toString())
|
|
|
mNormalPopup.dismiss()
|
|
|
|
|
|
}
|
|
|
llShareThree.onClick {
|
|
|
//分享到QQ
|
|
|
- chose=4
|
|
|
- setChoseQQ(context,flContainer,chose.toString())
|
|
|
+ chose = 4
|
|
|
+ setChoseQQ(context, flContainer, chose.toString())
|
|
|
|
|
|
mNormalPopup.dismiss()
|
|
|
}
|
|
@@ -191,11 +191,11 @@ object PopuDownWxUtils {
|
|
|
isFrist = false
|
|
|
if (flContainer != null) {
|
|
|
|
|
|
- var bitmap:Bitmap?=null
|
|
|
+ var bitmap: Bitmap? = null
|
|
|
|
|
|
Thread(Runnable {
|
|
|
- bitmap =setCreateBitmap(context,flContainer)
|
|
|
- SaveLocalUtils.saveBitmap(context, bitmap, "loc" + System.currentTimeMillis() + ".png")
|
|
|
+ bitmap = setCreateBitmap(context, flContainer)
|
|
|
+ SaveLocalUtils.saveBitmap(context, bitmap, "loc" + System.currentTimeMillis() + ".png")
|
|
|
|
|
|
|
|
|
}).start()
|
|
@@ -498,12 +498,15 @@ object PopuDownWxUtils {
|
|
|
* @param bmp 保存到相册
|
|
|
* @param picName
|
|
|
*/
|
|
|
- fun saveBmp2Gallery(context: Context,bmp: Bitmap?, picName: String, type: String) {
|
|
|
- val appDir = File(Environment.getExternalStorageDirectory(), "CZ")
|
|
|
+ fun saveBmp2Gallery(context: Context, bmp: Bitmap?, picName: String, type: String) {
|
|
|
+
|
|
|
+// val filePath = context.getExternalFilesDir(null).toString() + "/shareData/"+"$picName.jpg"
|
|
|
+// val file = File(filePath)
|
|
|
+ val appDir = File(context.getExternalFilesDir(null), "shareData")
|
|
|
if (!appDir.exists()) {
|
|
|
appDir.mkdir()
|
|
|
}
|
|
|
- val filePath = Environment.getExternalStorageDirectory().toString() + "/CZ/"
|
|
|
+ val filePath = context.getExternalFilesDir(null).toString()+ "/shareData/"
|
|
|
// 声明文件对象
|
|
|
var file: File? = null
|
|
|
// 声明输出流
|
|
@@ -517,6 +520,7 @@ object PopuDownWxUtils {
|
|
|
fos.close()
|
|
|
} catch (e: java.lang.Exception) {
|
|
|
e.stackTrace
|
|
|
+ Log.e("-shy-", "e:=: "+e )
|
|
|
}
|
|
|
|
|
|
//通知相册更新
|
|
@@ -528,7 +532,7 @@ object PopuDownWxUtils {
|
|
|
// sendBroadcast(intent);
|
|
|
try {
|
|
|
uriToImage = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
- FileProvider.getUriForFile(context, context.applicationContext.packageName.toString() + ".provider",
|
|
|
+ FileProvider.getUriForFile(context, context.applicationContext.packageName.toString() + ".provider",
|
|
|
file!!)
|
|
|
} else {
|
|
|
Uri.fromFile(file)
|
|
@@ -543,27 +547,31 @@ object PopuDownWxUtils {
|
|
|
// Dialog.dismissProgressDialog()
|
|
|
Toasts.toast(context, "已保存到相册了")
|
|
|
} else {
|
|
|
- share(context,uriToImage)
|
|
|
+ share(context, uriToImage)
|
|
|
}
|
|
|
} catch (e: java.lang.Exception) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun share(context: Context,uriToImage: Uri?) {
|
|
|
+ private fun share(context: Context, uriToImage: Uri?) {
|
|
|
if (context == null) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// var uriTo=uriToImage
|
|
|
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){//大于11
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {//大于11
|
|
|
+//
|
|
|
+// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
+// activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
+//
|
|
|
+//
|
|
|
//
|
|
|
-// uriTo= FileProvider.getUriForFile(context,BuildConfig.APPLICATION_ID,uriToImage?.toFile())
|
|
|
// }
|
|
|
|
|
|
- Log.e("-shy-", "uriTo=: "+uriToImage )
|
|
|
|
|
|
- if(chose==4){//分享到qq
|
|
|
+
|
|
|
+ Log.e("-shy-", "uriTo=: " + uriToImage)
|
|
|
+
|
|
|
+ if (chose == 4) {//分享到qq
|
|
|
|
|
|
val intent = Intent()
|
|
|
val comp = ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity")
|
|
@@ -579,23 +587,45 @@ object PopuDownWxUtils {
|
|
|
}
|
|
|
|
|
|
val shareIntent = Intent()
|
|
|
- var comp:ComponentName?=null
|
|
|
- if(chose==2){
|
|
|
+ var comp: ComponentName? = null
|
|
|
+ if (chose == 2) {
|
|
|
//发送图片给好友
|
|
|
- comp = ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI")
|
|
|
+ comp = ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI")
|
|
|
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//发送图片到朋友圈
|
|
|
- comp = ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");
|
|
|
+ comp = ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");
|
|
|
|
|
|
}
|
|
|
shareIntent.component = comp
|
|
|
+ shareIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
+ shareIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
shareIntent.action = Intent.ACTION_SEND
|
|
|
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage)
|
|
|
shareIntent.type = "image/jpeg"
|
|
|
if (context != null) {
|
|
|
- // Dialog.dismissProgressDialog()
|
|
|
- (context as Activity).startActivity(Intent.createChooser(shareIntent, title))
|
|
|
+ // Dialog.dismissProgressDialog()
|
|
|
+
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {//大于11
|
|
|
+
|
|
|
+ var resInfoList=context.packageManager.queryIntentActivities(shareIntent, PackageManager.MATCH_DEFAULT_ONLY) as List<ResolveInfo>
|
|
|
+ for(resolveInfo in resInfoList){
|
|
|
+ var packagename=resolveInfo.activityInfo.packageName
|
|
|
+ Log.e("-shy-", "packagename=: "+packagename )
|
|
|
+
|
|
|
+ context.grantUriPermission(packagename,uriToImage,Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
+ context.grantUriPermission(packagename,uriToImage,Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ (context as Activity).startActivity(Intent.createChooser(shareIntent, title))
|
|
|
+
|
|
|
+ }else{
|
|
|
+ (context as Activity).startActivity(Intent.createChooser(shareIntent, title))
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -603,7 +633,7 @@ object PopuDownWxUtils {
|
|
|
/**
|
|
|
* 将view转成bitmap
|
|
|
*/
|
|
|
- fun setCreateBitmap(context: Context,v: View): Bitmap? {
|
|
|
+ fun setCreateBitmap(context: Context, v: View): Bitmap? {
|
|
|
// if ( context!= null) {
|
|
|
// Dialog.showProgressingDialog(getContext(), getString(R.string.save) + getString(R.string.picture) + getString(R.string.province_luo))
|
|
|
// }
|
|
@@ -615,7 +645,7 @@ object PopuDownWxUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
- fun setChose(context: Context,flContainer:FrameLayout,type:String){
|
|
|
+ fun setChose(context: Context, flContainer: FrameLayout, type: String) {
|
|
|
//分享图片
|
|
|
if (WeChatUtil.isWeixinAvilible(context)) {
|
|
|
//进行微信的分享
|
|
@@ -631,24 +661,24 @@ object PopuDownWxUtils {
|
|
|
}, 2000) // 如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务
|
|
|
isFristo = false
|
|
|
if (uriToImage != null) {
|
|
|
- share(context,uriToImage)
|
|
|
+ share(context, uriToImage)
|
|
|
} else {
|
|
|
if (flContainer != null) {
|
|
|
- saveBmp2Gallery(context,setCreateBitmap(context,flContainer), "loc" + System.currentTimeMillis(), type)
|
|
|
+ saveBmp2Gallery(context, setCreateBitmap(context, flContainer), "loc" + System.currentTimeMillis(), type)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- Toast.makeText(context,"您未安装微信或微信版本过低,无法分享",Toast.LENGTH_SHORT).show()
|
|
|
+ Toast.makeText(context, "您未安装微信或微信版本过低,无法分享", Toast.LENGTH_SHORT).show()
|
|
|
val uri = Uri.parse("market://details?id=com.tencent.mm")
|
|
|
val it = Intent(Intent.ACTION_VIEW, uri)
|
|
|
- ( context as Activity).startActivity(it)
|
|
|
+ (context as Activity).startActivity(it)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
- fun setChoseQQ(context: Context,flContainer:FrameLayout,type:String){
|
|
|
+ fun setChoseQQ(context: Context, flContainer: FrameLayout, type: String) {
|
|
|
//分享图片
|
|
|
if (QqUtils.isQQInstall(context)) {
|
|
|
//进行微信的分享
|
|
@@ -664,20 +694,24 @@ object PopuDownWxUtils {
|
|
|
}, 2000) // 如果2秒钟内没有按下返回键,则启动定时器取消掉刚才执行的任务
|
|
|
isFristo = false
|
|
|
if (uriToImage != null) {
|
|
|
- share(context,uriToImage)
|
|
|
+ share(context, uriToImage)
|
|
|
} else {
|
|
|
if (flContainer != null) {
|
|
|
- saveBmp2Gallery(context,setCreateBitmap(context,flContainer), "loc" + System.currentTimeMillis(), type)
|
|
|
+ saveBmp2Gallery(context, setCreateBitmap(context, flContainer), "loc" + System.currentTimeMillis(), type)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- Toast.makeText(context,"您未安装微信或微信版本过低,无法分享",Toast.LENGTH_SHORT).show()
|
|
|
+ Toast.makeText(context, "您未安装微信或微信版本过低,无法分享", Toast.LENGTH_SHORT).show()
|
|
|
val uri = Uri.parse("market://details?id=com.tencent.mm")
|
|
|
val it = Intent(Intent.ACTION_VIEW, uri)
|
|
|
- ( context as Activity).startActivity(it)
|
|
|
+ (context as Activity).startActivity(it)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|