Commit 8041fa43 by YKai

feat: 友盟库升级优化,储存工具拓展

parent 14967758
...@@ -33,7 +33,7 @@ ext { ...@@ -33,7 +33,7 @@ ext {
//-------------- 功能组件 -------------- //-------------- 功能组件 --------------
//第一步 //第一步
"ydl-platform" : "0.0.41.56", "ydl-platform" : "0.0.41.57",
//第二步 若干 //第二步 若干
"ydl-webview" : "0.0.38.57", "ydl-webview" : "0.0.38.57",
...@@ -116,7 +116,7 @@ ext { ...@@ -116,7 +116,7 @@ ext {
//-------------- 功能组件 -------------- //-------------- 功能组件 --------------
//第一步 //第一步
"ydl-platform" : "0.0.41.56", "ydl-platform" : "0.0.41.57",
//第二步 若干 //第二步 若干
"ydl-webview" : "0.0.38.57", "ydl-webview" : "0.0.38.57",
...@@ -230,17 +230,17 @@ ext { ...@@ -230,17 +230,17 @@ ext {
"BaseRecyclerViewAdapterHelper": "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34", "BaseRecyclerViewAdapterHelper": "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.34",
"flowlayout" : "cn.lankton:flowlayout:3.1.0", "flowlayout" : "cn.lankton:flowlayout:3.1.0",
"androidanimations" : "com.daimajia.androidanimations:library:2.3@aar", "androidanimations" : "com.daimajia.androidanimations:library:2.3@aar",
//友盟统计 // //友盟统计
"umeng-common" : "com.umeng.umsdk:common:9.3.8", "umeng-common" : "com.umeng.umsdk:common:9.4.7",
"umeng-asms" : "com.umeng.umsdk:asms:1.2.2", "umeng-asms" : "com.umeng.umsdk:asms:1.4.1",
//友盟社会化分享 // //友盟社会化分享
"umeng-share-core" : "com.umeng.umsdk:share-core:7.1.4", // "umeng-share-core" : "com.umeng.umsdk:share-core:7.1.4",
"umeng-share-qq" : "com.umeng.umsdk:share-qq:7.1.4", // "umeng-share-qq" : "com.umeng.umsdk:share-qq:7.1.4",
"umeng-share-wechat" : "com.umeng.umsdk:share-wx:7.1.4", // "umeng-share-wechat" : "com.umeng.umsdk:share-wx:7.1.4",
//分享面板 // //分享面板
"umeng-shareboard" : "com.umeng.umsdk:share-board:7.1.4", // "umeng-shareboard" : "com.umeng.umsdk:share-board:7.1.4",
"umeng-wx-guanfang" : "com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.6.5", // "umeng-wx-guanfang" : "com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.6.5",
"umeng-qq-guanfang" : "com.tencent.tauth:qqopensdk:3.51.2", // "umeng-qq-guanfang" : "com.tencent.tauth:qqopensdk:3.51.2",
//删除集成调试库,其功能合并到umeng基础组件库。 //删除集成调试库,其功能合并到umeng基础组件库。
//"umeng-debug" : "com.umeng.sdk:debug:1.0.0", //"umeng-debug" : "com.umeng.sdk:debug:1.0.0",
......
...@@ -143,12 +143,12 @@ dependencies { ...@@ -143,12 +143,12 @@ dependencies {
api rootProject.ext.dependencies["eventbus"] api rootProject.ext.dependencies["eventbus"]
api rootProject.ext.dependencies["umeng-common"] api rootProject.ext.dependencies["umeng-common"]
api rootProject.ext.dependencies["umeng-asms"] api rootProject.ext.dependencies["umeng-asms"]
api rootProject.ext.dependencies["umeng-share-core"] // api rootProject.ext.dependencies["umeng-share-core"]
api rootProject.ext.dependencies["umeng-share-qq"] // api rootProject.ext.dependencies["umeng-share-qq"]
api rootProject.ext.dependencies["umeng-share-wechat"] // api rootProject.ext.dependencies["umeng-share-wechat"]
api rootProject.ext.dependencies["umeng-shareboard"] // api rootProject.ext.dependencies["umeng-shareboard"]
api rootProject.ext.dependencies["umeng-wx-guanfang"] // api rootProject.ext.dependencies["umeng-wx-guanfang"]
api rootProject.ext.dependencies["umeng-qq-guanfang"] // api rootProject.ext.dependencies["umeng-qq-guanfang"]
api rootProject.ext.dependencies["stetho"] api rootProject.ext.dependencies["stetho"]
api rootProject.ext.dependencies["stetho-okhttp3"] api rootProject.ext.dependencies["stetho-okhttp3"]
api rootProject.ext.dependencies["bugly-crashreport"] api rootProject.ext.dependencies["bugly-crashreport"]
......
package com.ydl.ydlcommon.actions.share //package com.ydl.ydlcommon.actions.share
import android.app.Activity
import android.graphics.Bitmap
import android.text.TextUtils
import com.umeng.socialize.ShareAction
import com.umeng.socialize.UMShareListener
import com.umeng.socialize.bean.SHARE_MEDIA
import com.umeng.socialize.media.UMImage
import com.umeng.socialize.media.UMMin
import com.umeng.socialize.media.UMWeb
import com.umeng.socialize.shareboard.ShareBoardConfig
import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.ydl.ydlcommon.view.dialog.CustomShareDialog
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.ToastUtil
/**
* 分享工具类
*/
object ShareUtils {
var platform: SHARE_MEDIA? = null
var callBack: ShareActionCallBack? = null
/**
* 直接分享到指定平台
* @param platform
*/
fun shareTo(platform: SHARE_MEDIA?, context: Activity, share_title: String, share_url: String, share_context: String?, share_head: String?) {
LogUtil.d("shareTo")
val web = UMWeb(share_url)
web.title = share_title //标题
if (platform == SHARE_MEDIA.WEIXIN_CIRCLE) {
web.title = "$share_title\n$share_context"
}
web.setThumb(UMImage(context, share_head
?: "http://static.ydlcdn.com/v1/images/logo320.png")) //缩略图
web.description = share_context//描述
ShareAction(context)
.setPlatform(platform)
.setCallback(object : UMShareListener {
override fun onStart(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "开始分享------")
}
override fun onResult(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享结束------")
callBack?.onShareSuccessed(share_media)
callBack = null
}
override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
LogUtil.e("ydl", "分享出错------" + throwable.message)
try {
var message = handleMessage(throwable.message!!)
ToastUtil.toastShort("分享失败," + message)
} catch (e: Exception) {
ToastUtil.toastShort("分享错误")
}
callBack?.onShareFailed(share_media, throwable)
callBack = null
}
override fun onCancel(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享取消------")
}
})
.withMedia(web)
.share()
}
/**
* 分享纯图片到微信
*/
fun sharePicToWeiXin(context: Activity, bitmap: Bitmap?) {
if (bitmap == null) {
ToastUtil.toastShort("数据异常,请重试")
return
}
if (platform == null) {
ToastUtil.toastShort("分享异常,请重试")
return
}
val image = UMImage(context, bitmap)//bitmap文件
val thumb = UMImage(context, bitmap)
image.setThumb(thumb)
image.compressStyle = UMImage.CompressStyle.SCALE//大小压缩,默认为大小压缩,适合普通很大的图
image.compressStyle = UMImage.CompressStyle.QUALITY//质量压缩,适合长图的分享
ShareAction(context)
.setPlatform(platform)
.setCallback(object : UMShareListener {
override fun onStart(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "开始分享------")
}
override fun onResult(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享结束------")
callBack?.onShareSuccessed(share_media)
callBack = null
}
override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
LogUtil.e("ydl", "分享出错------" + throwable.message)
try {
var message = handleMessage(throwable.message!!)
ToastUtil.toastShort("分享失败," + message)
} catch (e: Exception) {
ToastUtil.toastShort("分享错误")
}
callBack?.onShareFailed(share_media, throwable)
callBack = null
}
override fun onCancel(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享取消------")
}
})
.withMedia(image)
.share()
}
/**
* 分享小程序类型
*/
fun shareSmailWeixin(context: Activity, share_title: String, share_url: String, share_context: String?, image: String?, path: String?, id: String?, shareListener: UMShareListener?) {
val umMin = UMMin(share_url) //兼容低版本的网页链接
val img = UMImage(context, image)
img.compressStyle = UMImage.CompressStyle.SCALE
umMin.setThumb(img) // 小程序消息封面图片
umMin.title = share_title // 小程序消息title
umMin.description = share_context // 小程序消息描述
umMin.path = path //小程序页面路径
umMin.userName = id // 小程序原始id,在微信平台查询
ShareAction(context)
.withMedia(umMin)
.setPlatform(SHARE_MEDIA.WEIXIN)
.setCallback(shareListener)
.share()
}
/**
* 自定义分享弹出框
* author harvie
* @param activity
* @param actions 扩展按钮
* @param share_title
* @param share_url
* @param share_context
* @param share_head
*/
fun share(activity: Activity, share_title: String?, share_url: String?, share_context: String?, share_head: String?, actions: List<ShareMoreBean>) {
var content = share_context
var image = share_head
if (share_title == null || share_url == null) {
ToastHelper.show("缺少分享参数")
return
}
if (TextUtils.isEmpty(share_head)) {
image = "http://static.ydlcdn.com/v1/images/logo320.png"
}
if (TextUtils.isEmpty(content)) content = share_title
val dialog = CustomShareDialog(activity)
dialog.setShareBody(share_title, share_url, content ?: "", image!!)
dialog.addActions(actions)
dialog.show()
}
/**
* 友盟自带分享弹框
*/
fun share(activity: Activity, share_title: String?, share_url: String?, share_context: String?, share_head: String?) {
LogUtil.d("share")
var content = share_context
var image = share_head
if (share_title == null || share_url == null) {
ToastHelper.show("缺少分享参数")
return
}
if (share_head == null || share_head == "") {
image = "http://static.ydlcdn.com/v1/images/logo320.png"
}
if (TextUtils.isEmpty(content)) content = share_title
val web = UMWeb(share_url)
web.title = share_title//标题
web.setThumb(UMImage(activity, image)) //缩略图
web.description = content//描述
val config = ShareBoardConfig()
config.setIndicatorVisibility(false)
if (activity.packageName.endsWith("yidianling_atk9")) {
ShareAction(activity).withMedia(web)
.setDisplayList(SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
.setCallback(object : UMShareListener {
override fun onStart(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "开始分享------")
}
override fun onResult(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享结束------")
}
override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
LogUtil.e("ydl", "分享出错------" + throwable.message)
try {
var message = handleMessage(throwable.message!!)
ToastUtil.toastShort("分享失败," + message)
} catch (e: Exception) {
ToastUtil.toastShort("分享错误")
}
}
override fun onCancel(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享取消------")
}
})
.open(config)
} else {
ShareAction(activity).withMedia(web)
.setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
.setCallback(object : UMShareListener {
override fun onStart(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "开始分享------")
}
override fun onResult(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享结束------")
callBack?.onShareSuccessed(share_media)
callBack = null
}
override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
LogUtil.e("ydl", "分享出错------" + throwable.message)
try {
var message = handleMessage(throwable.message!!)
ToastUtil.toastShort("分享失败," + message)
} catch (e: Exception) {
ToastUtil.toastShort("分享错误")
}
callBack?.onShareFailed(share_media, throwable)
callBack = null
}
override fun onCancel(share_media: SHARE_MEDIA) {
LogUtil.e("ydl", "分享取消------")
}
})
.open(config)
}
}
/**
* 强制处理分享失败消息
*/
fun handleMessage(msg: String): String {
var index = msg.indexOf("错误信息")
var message = msg.substring(index, msg!!.length)
var lastIndex = message.indexOf(" ")
message = message.substring(0, lastIndex)
return message
}
}
// //
/** //import android.app.Activity
* //import android.graphics.Bitmap
*/ //import android.text.TextUtils
class ShareMoreBean(var imageResId: Int, var actionName: String, //扩展按钮动作 //import com.umeng.socialize.ShareAction
var shareMoreAction: ShareMoreAction?) //import com.umeng.socialize.UMShareListener
//import com.umeng.socialize.bean.SHARE_MEDIA
//分享动作 //import com.umeng.socialize.media.UMImage
interface ShareMoreAction { //import com.umeng.socialize.media.UMMin
fun onClick() //import com.umeng.socialize.media.UMWeb
} //import com.umeng.socialize.shareboard.ShareBoardConfig
//import com.ydl.ydlcommon.utils.remind.ToastHelper
interface ShareActionCallBack { //import com.ydl.ydlcommon.view.dialog.CustomShareDialog
fun onShareSuccessed(share_media: SHARE_MEDIA) //import com.yidianling.common.tools.LogUtil
fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable) //import com.yidianling.common.tools.ToastUtil
} ///**
// * 分享工具类
// */
//
//object ShareUtils {
//
// var platform: SHARE_MEDIA? = null
//
// var callBack: ShareActionCallBack? = null
//
// /**
// * 直接分享到指定平台
// * @param platform
// */
// fun shareTo(platform: SHARE_MEDIA?, context: Activity, share_title: String, share_url: String, share_context: String?, share_head: String?) {
// LogUtil.d("shareTo")
// val web = UMWeb(share_url)
// web.title = share_title //标题
// if (platform == SHARE_MEDIA.WEIXIN_CIRCLE) {
// web.title = "$share_title\n$share_context"
// }
// web.setThumb(UMImage(context, share_head
// ?: "http://static.ydlcdn.com/v1/images/logo320.png")) //缩略图
// web.description = share_context//描述
// ShareAction(context)
// .setPlatform(platform)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// callBack?.onShareSuccessed(share_media)
// callBack = null
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// callBack?.onShareFailed(share_media, throwable)
// callBack = null
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .withMedia(web)
// .share()
// }
//
// /**
// * 分享纯图片到微信
// */
// fun sharePicToWeiXin(context: Activity, bitmap: Bitmap?) {
// if (bitmap == null) {
// ToastUtil.toastShort("数据异常,请重试")
// return
// }
// if (platform == null) {
// ToastUtil.toastShort("分享异常,请重试")
// return
// }
// val image = UMImage(context, bitmap)//bitmap文件
//
// val thumb = UMImage(context, bitmap)
// image.setThumb(thumb)
//
// image.compressStyle = UMImage.CompressStyle.SCALE//大小压缩,默认为大小压缩,适合普通很大的图
// image.compressStyle = UMImage.CompressStyle.QUALITY//质量压缩,适合长图的分享
// ShareAction(context)
// .setPlatform(platform)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// callBack?.onShareSuccessed(share_media)
// callBack = null
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// callBack?.onShareFailed(share_media, throwable)
// callBack = null
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .withMedia(image)
// .share()
// }
//
// /**
// * 分享小程序类型
// */
// fun shareSmailWeixin(context: Activity, share_title: String, share_url: String, share_context: String?, image: String?, path: String?, id: String?, shareListener: UMShareListener?) {
// val umMin = UMMin(share_url) //兼容低版本的网页链接
// val img = UMImage(context, image)
// img.compressStyle = UMImage.CompressStyle.SCALE
// umMin.setThumb(img) // 小程序消息封面图片
// umMin.title = share_title // 小程序消息title
// umMin.description = share_context // 小程序消息描述
// umMin.path = path //小程序页面路径
// umMin.userName = id // 小程序原始id,在微信平台查询
// ShareAction(context)
// .withMedia(umMin)
// .setPlatform(SHARE_MEDIA.WEIXIN)
// .setCallback(shareListener)
// .share()
// }
//
// /**
// * 自定义分享弹出框
// * author harvie
// * @param activity
// * @param actions 扩展按钮
// * @param share_title
// * @param share_url
// * @param share_context
// * @param share_head
// */
// fun share(activity: Activity, share_title: String?, share_url: String?, share_context: String?, share_head: String?, actions: List<ShareMoreBean>) {
// var content = share_context
// var image = share_head
// if (share_title == null || share_url == null) {
// ToastHelper.show("缺少分享参数")
// return
// }
// if (TextUtils.isEmpty(share_head)) {
// image = "http://static.ydlcdn.com/v1/images/logo320.png"
// }
// if (TextUtils.isEmpty(content)) content = share_title
// val dialog = CustomShareDialog(activity)
// dialog.setShareBody(share_title, share_url, content ?: "", image!!)
// dialog.addActions(actions)
// dialog.show()
//
// }
//
// /**
// * 友盟自带分享弹框
// */
// fun share(activity: Activity, share_title: String?, share_url: String?, share_context: String?, share_head: String?) {
// LogUtil.d("share")
// var content = share_context
// var image = share_head
// if (share_title == null || share_url == null) {
// ToastHelper.show("缺少分享参数")
// return
// }
// if (share_head == null || share_head == "") {
// image = "http://static.ydlcdn.com/v1/images/logo320.png"
// }
// if (TextUtils.isEmpty(content)) content = share_title
//
// val web = UMWeb(share_url)
// web.title = share_title//标题
// web.setThumb(UMImage(activity, image)) //缩略图
// web.description = content//描述
// val config = ShareBoardConfig()
// config.setIndicatorVisibility(false)
// if (activity.packageName.endsWith("yidianling_atk9")) {
// ShareAction(activity).withMedia(web)
// .setDisplayList(SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .open(config)
// } else {
// ShareAction(activity).withMedia(web)
// .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
// .setCallback(object : UMShareListener {
// override fun onStart(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "开始分享------")
// }
//
// override fun onResult(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享结束------")
// callBack?.onShareSuccessed(share_media)
// callBack = null
// }
//
// override fun onError(share_media: SHARE_MEDIA, throwable: Throwable) {
// LogUtil.e("ydl", "分享出错------" + throwable.message)
// try {
// var message = handleMessage(throwable.message!!)
// ToastUtil.toastShort("分享失败," + message)
// } catch (e: Exception) {
// ToastUtil.toastShort("分享错误")
// }
// callBack?.onShareFailed(share_media, throwable)
// callBack = null
// }
//
// override fun onCancel(share_media: SHARE_MEDIA) {
// LogUtil.e("ydl", "分享取消------")
// }
// })
// .open(config)
// }
//
// }
//
//
// /**
// * 强制处理分享失败消息
// */
// fun handleMessage(msg: String): String {
// var index = msg.indexOf("错误信息")
// var message = msg.substring(index, msg!!.length)
// var lastIndex = message.indexOf(" ")
// message = message.substring(0, lastIndex)
// return message
// }
//}
//
////
///**
// *
// */
//class ShareMoreBean(var imageResId: Int, var actionName: String, //扩展按钮动作
// var shareMoreAction: ShareMoreAction?)
//
////分享动作
//interface ShareMoreAction {
// fun onClick()
//}
//
//interface ShareActionCallBack {
// fun onShareSuccessed(share_media: SHARE_MEDIA)
// fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable)
//}
...@@ -37,71 +37,10 @@ import java.util.Collections; ...@@ -37,71 +37,10 @@ import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import static com.umeng.socialize.utils.ContextUtil.getPackageName;
public class DeviceTool { public class DeviceTool {
public static void openPersisonSetting(Activity activity) {
String brand = Build.BRAND;//手机厂商
if (TextUtils.equals(brand.toLowerCase(), "redmi") || TextUtils.equals(brand.toLowerCase(), "xiaomi")) {
gotoMiuiPermission(activity);//小米
} else if (TextUtils.equals(brand.toLowerCase(), "meizu")) {
gotoMeizuPermission(activity);
} else {
activity.startActivity(getAppDetailSettingIntent());
}
gotoMiuiPermission(activity);
}
/**
* 跳转到miui的权限管理页面
*/
private static void gotoMiuiPermission(Activity activity) {
Intent i = new Intent("miui.intent.action.APP_PERM_EDITOR");
ComponentName componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
i.setComponent(componentName);
i.putExtra("extra_pkgname", getPackageName());
try {
activity.startActivity(i);
} catch (Exception e) {
e.printStackTrace();
gotoMeizuPermission(activity);
}
}
/**
* 获取应用详情页面intent
*
* @return
*/
private static Intent getAppDetailSettingIntent() {
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 9) {
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
localIntent.setData(Uri.fromParts("package", getPackageName(), null));
} else if (Build.VERSION.SDK_INT <= 8) {
localIntent.setAction(Intent.ACTION_VIEW);
localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
localIntent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
}
return localIntent;
}
/**
* 跳转到魅族的权限管理系统
*/
private static void gotoMeizuPermission(Activity activity) {
Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra("packageName", getPackageName());
try {
activity.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
activity.startActivity(getAppDetailSettingIntent());
}
}
//获取虚拟按键栏高度 //获取虚拟按键栏高度
public static int getNavigationBarHeight(Context context) { public static int getNavigationBarHeight(Context context) {
......
package com.ydl.ydlcommon.utils; package com.ydl.ydlcommon.utils;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import com.ydl.ydlcommon.base.BaseApp; import com.ydl.ydlcommon.base.BaseApp;
public class SharedPreferencesEditor { public class SharedPreferencesEditor {
private static final String app_sharedPreference_name = "yidianling_zj";
public static final String TEMP_TEST = "temp_test";//临时SP public static final String TEMP_TEST = "temp_test";//临时SP
/********************************************自定义文件存储***********************************************/ /********************************************自定义文件存储***********************************************/
...@@ -20,13 +22,34 @@ public class SharedPreferencesEditor { ...@@ -20,13 +22,34 @@ public class SharedPreferencesEditor {
editor.commit(); editor.commit();
} }
public static void putFileStringApply(String fileName,String key,String value) {
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
fileName, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putString(key, value);
editor.apply();
}
public static String getFileString(String fileName,String key) { public static String getFileString(String fileName,String key) {
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences( SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
fileName, Activity.MODE_PRIVATE); fileName, Activity.MODE_PRIVATE);
return mySharedPreferences.getString(key, ""); return mySharedPreferences.getString(key, "");
} }
/***********************************************临时保存************************************************/ public static void writeSharedPreference(Context context, String key, String value) {
SharedPreferences mySharedPreferences = context.getSharedPreferences(
app_sharedPreference_name, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}
public static String readSharedPreference(Context context, String key) {
SharedPreferences mySharedPreferences = context.getSharedPreferences(
app_sharedPreference_name, Activity.MODE_PRIVATE);
return mySharedPreferences.getString(key, "");
}
public static void putString(String key, String value) { public static void putString(String key, String value) {
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences( SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
TEMP_TEST, Activity.MODE_PRIVATE); TEMP_TEST, Activity.MODE_PRIVATE);
...@@ -41,12 +64,62 @@ public class SharedPreferencesEditor { ...@@ -41,12 +64,62 @@ public class SharedPreferencesEditor {
return mySharedPreferences.getString(key, ""); return mySharedPreferences.getString(key, "");
} }
public static final void clear(){ public static void putBoolean(String key, boolean value) {
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
TEMP_TEST, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putBoolean(key, value);
editor.commit();
}
public static void putInt(String key, int value) {
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
TEMP_TEST, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.putInt(key, value);
editor.commit();
}
SharedPreferences mySharedPreferencestemp = BaseApp.Companion.getApp().getSharedPreferences( public static boolean getBoolean(String key) {
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
TEMP_TEST, Activity.MODE_PRIVATE); TEMP_TEST, Activity.MODE_PRIVATE);
SharedPreferences.Editor editort = mySharedPreferencestemp.edit(); return mySharedPreferences.getBoolean(key, false);
editort.clear(); }
editort.commit();
public static int getInt(String key){
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
TEMP_TEST, Activity.MODE_PRIVATE);
return mySharedPreferences.getInt(key, 0);
}
public static void saveValue(Context context , String SPKey, String key, int val){
SharedPreferences sp = context.getSharedPreferences(SPKey, 0);
sp.edit().putInt(key, val).commit();
}
public static int getIntValueFromSP(Context context, String SPKey, String key){
SharedPreferences sp = context.getSharedPreferences(SPKey, 0);
return sp.getInt(key, 0);
}
public static void clearValues(Context context, String SPKey){
SharedPreferences sp = context.getSharedPreferences(SPKey, 0);
sp.edit().clear().commit();
}
public static final void clearByName(String name){
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
name, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.clear();
editor.commit();
}
public static final void clear(){
SharedPreferences mySharedPreferences = BaseApp.Companion.getApp().getSharedPreferences(
app_sharedPreference_name, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = mySharedPreferences.edit();
editor.clear();
editor.commit();
} }
} }
package com.ydl.ydlcommon.view.dialog //package com.ydl.ydlcommon.view.dialog
//
import android.app.Activity //import android.app.Activity
import android.app.Dialog //import android.app.Dialog
import android.os.Bundle //import android.os.Bundle
import android.view.View //import android.view.View
import android.view.ViewGroup //import android.view.ViewGroup
import android.widget.AdapterView //import android.widget.AdapterView
import android.widget.ImageView //import android.widget.ImageView
import com.umeng.socialize.bean.SHARE_MEDIA //import com.umeng.socialize.bean.SHARE_MEDIA
import com.ydl.ydlcommon.R //import com.ydl.ydlcommon.R
import com.ydl.ydlcommon.actions.share.ShareMoreBean //import com.ydl.ydlcommon.actions.share.ShareMoreBean
import com.ydl.ydlcommon.actions.share.ShareUtils //import com.ydl.ydlcommon.actions.share.ShareUtils
import com.ydl.ydlcommon.adapter.CommonAdapter //import com.ydl.ydlcommon.adapter.CommonAdapter
import com.ydl.ydlcommon.view.BaseViewHolder //import com.ydl.ydlcommon.view.BaseViewHolder
import kotlinx.android.synthetic.main.platform_share_custom_ui.* //import kotlinx.android.synthetic.main.platform_share_custom_ui.*
//
/** ///**
* 自定义分享Dialog // * 自定义分享Dialog
* Created by hgw on 2017/3/22. // * Created by hgw on 2017/3/22.
*/ // */
//
class CustomShareDialog(private val context: Activity) : Dialog(context, R.style.platform_transparentFrameWindowStyle), View.OnClickListener { //class CustomShareDialog(private val context: Activity) : Dialog(context, R.style.platform_transparentFrameWindowStyle), View.OnClickListener {
//
//
private var share_title: String? = null // private var share_title: String? = null
private var share_url: String? = null // private var share_url: String? = null
private var share_context: String? = null // private var share_context: String? = null
private var share_head: String? = null // private var share_head: String? = null
private var list: List<ShareMoreBean>? = null // private var list: List<ShareMoreBean>? = null
//
private var adapter: CommonAdapter<ShareMoreBean>? = null // private var adapter: CommonAdapter<ShareMoreBean>? = null
//
override fun onCreate(savedInstanceState: Bundle?) { // override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) // super.onCreate(savedInstanceState)
setContentView(R.layout.platform_share_custom_ui) // setContentView(R.layout.platform_share_custom_ui)
//
initView() // initView()
//
val window = window // val window = window
// 设置显示动画 // // 设置显示动画
window!!.setWindowAnimations(R.style.platform_main_menu_animstyle) // window!!.setWindowAnimations(R.style.platform_main_menu_animstyle)
val wl = window.attributes // val wl = window.attributes
wl.x = 0 // wl.x = 0
wl.y = context.windowManager.defaultDisplay.height // wl.y = context.windowManager.defaultDisplay.height
// 以下这两句是为了保证按钮可以水平满屏 // // 以下这两句是为了保证按钮可以水平满屏
wl.width = ViewGroup.LayoutParams.MATCH_PARENT // wl.width = ViewGroup.LayoutParams.MATCH_PARENT
wl.height = ViewGroup.LayoutParams.WRAP_CONTENT // wl.height = ViewGroup.LayoutParams.WRAP_CONTENT
//
// 设置显示位置 // // 设置显示位置
onWindowAttributesChanged(wl) // onWindowAttributesChanged(wl)
// 设置点击外围解散 // // 设置点击外围解散
setCanceledOnTouchOutside(true) // setCanceledOnTouchOutside(true)
} // }
//
private fun initView() { // private fun initView() {
//
share_weichat.setOnClickListener(this) // share_weichat.setOnClickListener(this)
share_pyq.setOnClickListener(this) // share_pyq.setOnClickListener(this)
share_qqzone.setOnClickListener(this) // share_qqzone.setOnClickListener(this)
share_qq.setOnClickListener(this) // share_qq.setOnClickListener(this)
//
//
if (list == null || list!!.isEmpty()) { // if (list == null || list!!.isEmpty()) {
grid_view!!.visibility = View.GONE // grid_view!!.visibility = View.GONE
return // return
} else { // } else {
grid_view!!.visibility = View.VISIBLE // grid_view!!.visibility = View.VISIBLE
} // }
adapter = object : CommonAdapter<ShareMoreBean>() { // adapter = object : CommonAdapter<ShareMoreBean>() {
override fun getView(position: Int, convertView1: View?, parent: ViewGroup): View { // override fun getView(position: Int, convertView1: View?, parent: ViewGroup): View {
var convertView = convertView1 // var convertView = convertView1
val holder: BaseViewHolder // val holder: BaseViewHolder
if (convertView == null) { // if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.platform_item_custom_share_ui, null) // convertView = layoutInflater.inflate(R.layout.platform_item_custom_share_ui, null)
holder = BaseViewHolder(convertView) // holder = BaseViewHolder(convertView)
convertView!!.tag = holder // convertView!!.tag = holder
} else { // } else {
holder = convertView.tag as BaseViewHolder // holder = convertView.tag as BaseViewHolder
} // }
val imageView = holder.getView<ImageView>(R.id.share_img) // val imageView = holder.getView<ImageView>(R.id.share_img)
//加载图标 // //加载图标
imageView.setImageResource(mDataList[position].imageResId) // imageView.setImageResource(mDataList[position].imageResId)
//设置title // //设置title
holder.setText(R.id.text_title, mDataList[position].actionName) // holder.setText(R.id.text_title, mDataList[position].actionName)
return convertView // return convertView
} // }
} // }
grid_view!!.adapter = adapter // grid_view!!.adapter = adapter
grid_view!!.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ -> // grid_view!!.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
val action = adapter!!.dataList[position].shareMoreAction // val action = adapter!!.dataList[position].shareMoreAction
action?.onClick() // action?.onClick()
dismiss() // dismiss()
} // }
adapter!!.update(list) // adapter!!.update(list)
} // }
//
//设置分享内容 // //设置分享内容
fun setShareBody(share_title: String, share_url: String, share_context: String, share_head: String) { // fun setShareBody(share_title: String, share_url: String, share_context: String, share_head: String) {
this.share_title = share_title // this.share_title = share_title
this.share_url = share_url // this.share_url = share_url
this.share_context = share_context // this.share_context = share_context
this.share_head = share_head // this.share_head = share_head
} // }
//
//添加扩展按钮 // //添加扩展按钮
fun addActions(list1: List<ShareMoreBean>) { // fun addActions(list1: List<ShareMoreBean>) {
this.list = list1 // this.list = list1
} // }
//
override fun onClick(v: View) { // override fun onClick(v: View) {
when (v.id) { // when (v.id) {
R.id.share_weichat -> { // R.id.share_weichat -> {
ShareUtils.shareTo(SHARE_MEDIA.WEIXIN, context, share_title!!, share_url!!, share_context!!, share_head) // ShareUtils.shareTo(SHARE_MEDIA.WEIXIN, context, share_title!!, share_url!!, share_context!!, share_head)
dismiss() // dismiss()
} // }
R.id.share_pyq -> { // R.id.share_pyq -> {
ShareUtils.shareTo(SHARE_MEDIA.WEIXIN_CIRCLE, context, share_title!!, share_url!!, share_context!!, share_head) // ShareUtils.shareTo(SHARE_MEDIA.WEIXIN_CIRCLE, context, share_title!!, share_url!!, share_context!!, share_head)
dismiss() // dismiss()
} // }
R.id.share_qq -> { // R.id.share_qq -> {
ShareUtils.shareTo(SHARE_MEDIA.QQ, context, share_title!!, share_url!!, share_context!!, share_head) // ShareUtils.shareTo(SHARE_MEDIA.QQ, context, share_title!!, share_url!!, share_context!!, share_head)
dismiss() // dismiss()
} // }
R.id.share_qqzone -> { // R.id.share_qqzone -> {
ShareUtils.shareTo(SHARE_MEDIA.QZONE, context, share_title!!, share_url!!, share_context!!, share_head) // ShareUtils.shareTo(SHARE_MEDIA.QZONE, context, share_title!!, share_url!!, share_context!!, share_head)
dismiss() // dismiss()
} // }
} // }
} // }
//
override fun show() { // override fun show() {
if (null == context) { // if (null == context) {
return // return
} // }
if (context is Activity) { // if (context is Activity) {
if (context.isFinishing) { // if (context.isFinishing) {
return // return
} // }
} // }
super.show() // super.show()
} // }
} //}
//
package com.ydl.ydlcommon.view.dialog //package com.ydl.ydlcommon.view.dialog
//
import android.annotation.SuppressLint //import android.annotation.SuppressLint
import android.app.Activity //import android.app.Activity
import android.app.DialogFragment //import android.app.DialogFragment
import android.graphics.drawable.ColorDrawable //import android.graphics.drawable.ColorDrawable
import android.os.Bundle //import android.os.Bundle
import android.text.TextUtils //import android.text.TextUtils
import android.util.Base64 //import android.util.Base64
import android.view.* //import android.view.*
import android.widget.LinearLayout //import android.widget.LinearLayout
import com.bumptech.glide.load.engine.DiskCacheStrategy //import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.umeng.socialize.bean.SHARE_MEDIA //import com.umeng.socialize.bean.SHARE_MEDIA
import com.ydl.ydl_image.module.GlideApp //import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydlcommon.R //import com.ydl.ydlcommon.R
import com.ydl.ydlcommon.actions.share.ShareActionCallBack //import com.ydl.ydlcommon.actions.share.ShareActionCallBack
import com.ydl.ydlcommon.actions.share.ShareUtils //import com.ydl.ydlcommon.actions.share.ShareUtils
import com.ydl.ydlcommon.utils.ImageUtil //import com.ydl.ydlcommon.utils.ImageUtil
import com.ydl.ydlcommon.utils.ScreenUtil //import com.ydl.ydlcommon.utils.ScreenUtil
import com.yidianling.common.tools.RxImageTool //import com.yidianling.common.tools.RxImageTool
import kotlinx.android.synthetic.main.platform_dialog_share.* //import kotlinx.android.synthetic.main.platform_dialog_share.*
import java.util.concurrent.Executors //import java.util.concurrent.Executors
//
//
/** ///**
* @author yuanWai // * @author yuanWai
* @描述:分享弹窗 // * @描述:分享弹窗
* @Copyright Copyright (c) 2018 // * @Copyright Copyright (c) 2018
* @Company 壹点灵 // * @Company 壹点灵
* @date 2019/2/19 // * @date 2019/2/19
*/ // */
class YDLShareDialog : DialogFragment { //class YDLShareDialog : DialogFragment {
//
private var mActivity: Activity? = null // private var mActivity: Activity? = null
private var shareTitle: String? = null // private var shareTitle: String? = null
private var shareUrl: String? = null // private var shareUrl: String? = null
private var shareContent: String? = null // private var shareContent: String? = null
private var base64DataStr: String? = null // private var base64DataStr: String? = null
private var shareHead: String? = null // private var shareHead: String? = null
private var mCallback: ICallBack? = null // private var mCallback: ICallBack? = null
private var mShareCallBack: IShareCallBack? = null // private var mShareCallBack: IShareCallBack? = null
//
//小程序页面地址 // //小程序页面地址
private var path: String? = null // private var path: String? = null
//小程序id // //小程序id
private var minProgramId: String? = null // private var minProgramId: String? = null
//
private var dp55 = 0 // private var dp55 = 0
private var dp7 = 0 // private var dp7 = 0
private var llmargin = 0 // private var llmargin = 0
//
@SuppressLint("ValidFragment") // @SuppressLint("ValidFragment")
constructor(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?) : super() { // constructor(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?) : super() {
this.mActivity = activity // this.mActivity = activity
this.shareTitle = shareTitle // this.shareTitle = shareTitle
this.shareUrl = shareUrl // this.shareUrl = shareUrl
this.shareContent = shareContent // this.shareContent = shareContent
this.shareHead = shareHead // this.shareHead = shareHead
} // }
//
//传递小程序参数 // //传递小程序参数
@SuppressLint("ValidFragment") // @SuppressLint("ValidFragment")
constructor(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, path: String?, minProgramId: String?) : super() { // constructor(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, path: String?, minProgramId: String?) : super() {
this.mActivity = activity // this.mActivity = activity
this.shareTitle = shareTitle // this.shareTitle = shareTitle
this.shareUrl = shareUrl // this.shareUrl = shareUrl
this.shareContent = shareContent // this.shareContent = shareContent
this.shareHead = shareHead // this.shareHead = shareHead
this.path = path // this.path = path
this.minProgramId = minProgramId // this.minProgramId = minProgramId
} // }
//
constructor() : super() {} // constructor() : super() {}
//
init { // init {
dp55 = RxImageTool.dip2px(55f) // dp55 = RxImageTool.dip2px(55f)
llmargin = (ScreenUtil.screenWidth - RxImageTool.dip2px(260f)) / 3 // llmargin = (ScreenUtil.screenWidth - RxImageTool.dip2px(260f)) / 3
dp7 = RxImageTool.dip2px(7.5f) // dp7 = RxImageTool.dip2px(7.5f)
} // }
//
companion object { // companion object {
var typeStyle: Int = 0 // var typeStyle: Int = 0
/** // /**
* 1.为显示1排(5个) 2.为显示2排(隐藏动态和举报)3.为显示2排(隐藏动态和删除) 4.为显示1排(4个)隐藏动态按钮 5:生成海报按钮、隐藏动态 6:保存海报按钮、隐藏动态 7.为显示1排(4个)隐藏动态按钮 // * 1.为显示1排(5个) 2.为显示2排(隐藏动态和举报)3.为显示2排(隐藏动态和删除) 4.为显示1排(4个)隐藏动态按钮 5:生成海报按钮、隐藏动态 6:保存海报按钮、隐藏动态 7.为显示1排(4个)隐藏动态按钮
*/ // */
const val TYPE1 = 1 // const val TYPE1 = 1
const val TYPE2 = 2 // const val TYPE2 = 2
const val TYPE3 = 3 // const val TYPE3 = 3
const val TYPE4 = 4 // const val TYPE4 = 4
const val TYPE5 = 5 // const val TYPE5 = 5
const val TYPE6 = 6 // const val TYPE6 = 6
const val TYPE7 = 7 // const val TYPE7 = 7
/** // /**
* 点击事件类型 1.动态 2.删除 3.举报 4.返回首页 5:生成海报 6:保存本地 7:分享纯图片 // * 点击事件类型 1.动态 2.删除 3.举报 4.返回首页 5:生成海报 6:保存本地 7:分享纯图片
*/ // */
const val CLICK_DYNAMIC = 1 // const val CLICK_DYNAMIC = 1
const val CLICK_DELETE = 2 // const val CLICK_DELETE = 2
const val CLICK_REPORT = 3 // const val CLICK_REPORT = 3
const val CLICK_BACKHOME = 4 // const val CLICK_BACKHOME = 4
const val CLICK_POSTER = 5 // const val CLICK_POSTER = 5
const val CLICK_SAVE = 6 // const val CLICK_SAVE = 6
const val CLICK_SHARE_IMAGE = 7 // const val CLICK_SHARE_IMAGE = 7
//
fun style1(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog { // fun style1(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
typeStyle = TYPE1 // typeStyle = TYPE1
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
} // }
//
//支持分享小程序 // //支持分享小程序
fun style1(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, minProgramPath: String? = "", minProgramId: String? = ""): YDLShareDialog { // fun style1(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, minProgramPath: String? = "", minProgramId: String? = ""): YDLShareDialog {
typeStyle = TYPE1 // typeStyle = TYPE1
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead, minProgramPath, minProgramId) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead, minProgramPath, minProgramId)
} // }
//
fun style2(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog { // fun style2(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
typeStyle = TYPE2 // typeStyle = TYPE2
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
} // }
//
fun style3(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog { // fun style3(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
typeStyle = TYPE3 // typeStyle = TYPE3
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
} // }
//
fun style4(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog { // fun style4(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
typeStyle = TYPE4 // typeStyle = TYPE4
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
} // }
//
fun style5(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog { // fun style5(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
typeStyle = TYPE5 // typeStyle = TYPE5
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
} // }
//
fun style6(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog { // fun style6(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?): YDLShareDialog {
typeStyle = TYPE6 // typeStyle = TYPE6
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead)
} // }
//
//支持分享小程序 // //支持分享小程序
fun style7(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, minProgramPath: String? = "", minProgramId: String? = ""): YDLShareDialog { // fun style7(activity: Activity, shareTitle: String?, shareUrl: String?, shareContent: String?, shareHead: String?, minProgramPath: String? = "", minProgramId: String? = ""): YDLShareDialog {
typeStyle = TYPE7 // typeStyle = TYPE7
return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead, minProgramPath, minProgramId) // return YDLShareDialog(activity, shareTitle, shareUrl, shareContent, shareHead, minProgramPath, minProgramId)
} // }
} // }
//
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View { // override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
//去掉dialog的标题,需要在setContentView()之前 // //去掉dialog的标题,需要在setContentView()之前
this.dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) // this.dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
val window = this.dialog.window // val window = this.dialog.window
//去掉dialog默认的padding // //去掉dialog默认的padding
window!!.decorView.setPadding(0, 0, 0, 0) // window!!.decorView.setPadding(0, 0, 0, 0)
val lp = window.attributes // val lp = window.attributes
lp.width = WindowManager.LayoutParams.MATCH_PARENT // lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.WRAP_CONTENT // lp.height = WindowManager.LayoutParams.WRAP_CONTENT
//设置dialog的位置在底部 // //设置dialog的位置在底部
lp.gravity = Gravity.BOTTOM // lp.gravity = Gravity.BOTTOM
//设置dialog的动画 // //设置dialog的动画
lp.windowAnimations = R.style.platform_BottomDialogAnimation // lp.windowAnimations = R.style.platform_BottomDialogAnimation
window.attributes = lp // window.attributes = lp
window.setBackgroundDrawable(ColorDrawable()) // window.setBackgroundDrawable(ColorDrawable())
return inflater!!.inflate(R.layout.platform_dialog_share, null) // return inflater!!.inflate(R.layout.platform_dialog_share, null)
} // }
//
//
/** // /**
* 设置咨询师海报的图片 // * 设置咨询师海报的图片
* @param base64DataStr base64数据 // * @param base64DataStr base64数据
*/ // */
fun setPosterPicture(base64DataStr: String) { // fun setPosterPicture(base64DataStr: String) {
this.base64DataStr = base64DataStr // this.base64DataStr = base64DataStr
} // }
//
override fun onResume() { // override fun onResume() {
super.onResume() // super.onResume()
initView() // initView()
initParams() // initParams()
} // }
//
/** // /**
* 初始化样式 // * 初始化样式
*/ // */
private fun initParams() { // private fun initParams() {
when (typeStyle) { // when (typeStyle) {
TYPE1 -> { // TYPE1 -> {
//样式1 // //样式1
ll_layout2.visibility = View.GONE // ll_layout2.visibility = View.GONE
} // }
TYPE2 -> { // TYPE2 -> {
//样式2 // //样式2
ll_dynamic.visibility = View.GONE // ll_dynamic.visibility = View.GONE
ll_report.visibility = View.GONE // ll_report.visibility = View.GONE
setStyle() // setStyle()
val deleteParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT) // val deleteParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
deleteParams.setMargins(dp7, 0, llmargin, 0) // deleteParams.setMargins(dp7, 0, llmargin, 0)
deleteParams.weight = 0f // deleteParams.weight = 0f
ll_delete.layoutParams = deleteParams // ll_delete.layoutParams = deleteParams
} // }
TYPE3 -> { // TYPE3 -> {
//样式3 // //样式3
ll_dynamic.visibility = View.GONE // ll_dynamic.visibility = View.GONE
ll_delete.visibility = View.GONE // ll_delete.visibility = View.GONE
setStyle() // setStyle()
val reportParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT) // val reportParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
reportParams.setMargins(dp7, 0, llmargin, 0) // reportParams.setMargins(dp7, 0, llmargin, 0)
reportParams.weight = 0f // reportParams.weight = 0f
ll_report.layoutParams = reportParams // ll_report.layoutParams = reportParams
} // }
TYPE4 -> { // TYPE4 -> {
//样式4 // //样式4
ll_dynamic.visibility = View.GONE // ll_dynamic.visibility = View.GONE
ll_layout2.visibility = View.GONE // ll_layout2.visibility = View.GONE
setStyle() // setStyle()
} // }
TYPE5 -> { // TYPE5 -> {
//样式5 // //样式5
ll_dynamic.visibility = View.GONE // ll_dynamic.visibility = View.GONE
ll_poster.visibility = View.VISIBLE // ll_poster.visibility = View.VISIBLE
ll_layout2.visibility = View.GONE // ll_layout2.visibility = View.GONE
} // }
TYPE6 -> { // TYPE6 -> {
//样式6 // //样式6
ll_dynamic.visibility = View.GONE // ll_dynamic.visibility = View.GONE
ll_save.visibility = View.VISIBLE // ll_save.visibility = View.VISIBLE
ll_layout2.visibility = View.GONE // ll_layout2.visibility = View.GONE
} // }
TYPE7 -> { // TYPE7 -> {
//样式7 // //样式7
ll_layout2.visibility = View.GONE // ll_layout2.visibility = View.GONE
ll_dynamic.visibility = View.GONE // ll_dynamic.visibility = View.GONE
} // }
} // }
//
showPictureView() // showPictureView()
} // }
//
//
private fun showPictureView() { // private fun showPictureView() {
if (TextUtils.isEmpty(base64DataStr)) { // if (TextUtils.isEmpty(base64DataStr)) {
return // return
} // }
cv_pic.visibility = View.VISIBLE // cv_pic.visibility = View.VISIBLE
//
Executors.newCachedThreadPool().execute { // Executors.newCachedThreadPool().execute {
var imageByte = Base64.decode(base64DataStr, Base64.DEFAULT) // var imageByte = Base64.decode(base64DataStr, Base64.DEFAULT)
mActivity!!.runOnUiThread { // mActivity!!.runOnUiThread {
GlideApp.with(this) // GlideApp.with(this)
.load(imageByte) // .load(imageByte)
.diskCacheStrategy(DiskCacheStrategy.NONE) // .diskCacheStrategy(DiskCacheStrategy.NONE)
.into(img_pic) // .into(img_pic)
} // }
} // }
//
tv_save_pic.setOnClickListener { // tv_save_pic.setOnClickListener {
ImageUtil.savePicture(mActivity, base64DataStr) // ImageUtil.savePicture(mActivity, base64DataStr)
} // }
} // }
//
private fun setStyle() { // private fun setStyle() {
val weixinParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT) // val weixinParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
weixinParams.setMargins(dp7, 0, 0, 0) // weixinParams.setMargins(dp7, 0, 0, 0)
weixinParams.weight = 0f // weixinParams.weight = 0f
ll_weixin.layoutParams = weixinParams // ll_weixin.layoutParams = weixinParams
//
val friendsParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT) // val friendsParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
friendsParams.setMargins(llmargin, 0, 0, 0) // friendsParams.setMargins(llmargin, 0, 0, 0)
friendsParams.weight = 0f // friendsParams.weight = 0f
ll_friends.layoutParams = friendsParams // ll_friends.layoutParams = friendsParams
//
val qqzoneParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT) // val qqzoneParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
qqzoneParams.setMargins(llmargin, 0, 0, 0) // qqzoneParams.setMargins(llmargin, 0, 0, 0)
qqzoneParams.weight = 0f // qqzoneParams.weight = 0f
ll_qqzone.layoutParams = qqzoneParams // ll_qqzone.layoutParams = qqzoneParams
//
val qqParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT) // val qqParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
qqParams.setMargins(llmargin, 0, dp7, 0) // qqParams.setMargins(llmargin, 0, dp7, 0)
qqParams.weight = 0f // qqParams.weight = 0f
ll_qq.layoutParams = qqParams // ll_qq.layoutParams = qqParams
ll_layout.invalidate() // ll_layout.invalidate()
//
val backhomeParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT) // val backhomeParams = LinearLayout.LayoutParams(dp55, ViewGroup.LayoutParams.WRAP_CONTENT)
backhomeParams.setMargins(0, 0, 0, 0) // backhomeParams.setMargins(0, 0, 0, 0)
backhomeParams.weight = 0f // backhomeParams.weight = 0f
ll_backhome.layoutParams = backhomeParams // ll_backhome.layoutParams = backhomeParams
} // }
//
fun setCallBack(callback: ICallBack) { // fun setCallBack(callback: ICallBack) {
this.mCallback = callback // this.mCallback = callback
} // }
//
fun setShareCallBack(callBack: IShareCallBack) { // fun setShareCallBack(callBack: IShareCallBack) {
this.mShareCallBack = callBack // this.mShareCallBack = callBack
} // }
//
private fun initView() { // private fun initView() {
ll_poster.setOnClickListener { // ll_poster.setOnClickListener {
//生成海报 // //生成海报
mCallback?.callBack(CLICK_POSTER) // mCallback?.callBack(CLICK_POSTER)
dismiss() // dismiss()
} // }
//
ll_save.setOnClickListener { // ll_save.setOnClickListener {
//保存本地 // //保存本地
mCallback?.callBack(CLICK_SAVE) // mCallback?.callBack(CLICK_SAVE)
dismiss() // dismiss()
} // }
ll_dynamic.setOnClickListener { // ll_dynamic.setOnClickListener {
//动态 // //动态
mCallback?.callBack(CLICK_DYNAMIC) // mCallback?.callBack(CLICK_DYNAMIC)
dismiss() // dismiss()
} // }
ll_weixin.setOnClickListener { // ll_weixin.setOnClickListener {
//分享海报到微信:直接分享图片到微信 // //分享海报到微信:直接分享图片到微信
if (typeStyle == TYPE6) { // if (typeStyle == TYPE6) {
ShareUtils.platform = SHARE_MEDIA.WEIXIN // ShareUtils.platform = SHARE_MEDIA.WEIXIN
mCallback?.callBack(CLICK_SHARE_IMAGE) // mCallback?.callBack(CLICK_SHARE_IMAGE)
} else { // } else {
//微信 // //微信
if (TextUtils.isEmpty(minProgramId)) { // if (TextUtils.isEmpty(minProgramId)) {
share(SHARE_MEDIA.WEIXIN) // share(SHARE_MEDIA.WEIXIN)
} else { // } else {
shareMinWeixin() // shareMinWeixin()
} // }
} // }
} // }
ll_friends.setOnClickListener { // ll_friends.setOnClickListener {
//分享海报到微信朋友圈:直接分享图片到微信朋友圈 // //分享海报到微信朋友圈:直接分享图片到微信朋友圈
if (typeStyle == TYPE6) { // if (typeStyle == TYPE6) {
ShareUtils.platform = SHARE_MEDIA.WEIXIN_CIRCLE // ShareUtils.platform = SHARE_MEDIA.WEIXIN_CIRCLE
mCallback?.callBack(CLICK_SHARE_IMAGE) // mCallback?.callBack(CLICK_SHARE_IMAGE)
} else { // } else {
//微信朋友圈 // //微信朋友圈
share(SHARE_MEDIA.WEIXIN_CIRCLE) // share(SHARE_MEDIA.WEIXIN_CIRCLE)
} // }
} // }
ll_qqzone.setOnClickListener { // ll_qqzone.setOnClickListener {
//分享海报到qq空间:直接分享图片到qq空间 // //分享海报到qq空间:直接分享图片到qq空间
if (typeStyle == TYPE6) { // if (typeStyle == TYPE6) {
ShareUtils.platform = SHARE_MEDIA.QZONE // ShareUtils.platform = SHARE_MEDIA.QZONE
mCallback?.callBack(CLICK_SHARE_IMAGE) // mCallback?.callBack(CLICK_SHARE_IMAGE)
} else { // } else {
//qq空间 // //qq空间
share(SHARE_MEDIA.QZONE) // share(SHARE_MEDIA.QZONE)
} // }
} // }
ll_qq.setOnClickListener { // ll_qq.setOnClickListener {
//分享海报到qq:直接分享图片到qq // //分享海报到qq:直接分享图片到qq
if (typeStyle == TYPE6) { // if (typeStyle == TYPE6) {
ShareUtils.platform = SHARE_MEDIA.QQ // ShareUtils.platform = SHARE_MEDIA.QQ
mCallback?.callBack(CLICK_SHARE_IMAGE) // mCallback?.callBack(CLICK_SHARE_IMAGE)
} else { // } else {
//qq // //qq
share(SHARE_MEDIA.QQ) // share(SHARE_MEDIA.QQ)
} // }
} // }
if (TYPE2 == typeStyle || TYPE3 == typeStyle) { // if (TYPE2 == typeStyle || TYPE3 == typeStyle) {
ll_delete.setOnClickListener { // ll_delete.setOnClickListener {
//删除 // //删除
mCallback?.callBack(CLICK_DELETE) // mCallback?.callBack(CLICK_DELETE)
dismiss() // dismiss()
} // }
ll_report.setOnClickListener { // ll_report.setOnClickListener {
//举报 // //举报
mCallback?.callBack(CLICK_REPORT) // mCallback?.callBack(CLICK_REPORT)
dismiss() // dismiss()
} // }
ll_backhome.setOnClickListener { // ll_backhome.setOnClickListener {
//返回首页 // //返回首页
mCallback?.callBack(CLICK_BACKHOME) // mCallback?.callBack(CLICK_BACKHOME)
dismiss() // dismiss()
} // }
} // }
tv_cancel.setOnClickListener { // tv_cancel.setOnClickListener {
//取消 // //取消
dismiss() // dismiss()
} // }
rl_root.setOnClickListener { // rl_root.setOnClickListener {
//取消 // //取消
dismiss() // dismiss()
} // }
} // }
//
private fun share(platform: SHARE_MEDIA) { // private fun share(platform: SHARE_MEDIA) {
ShareUtils.shareTo(platform, mActivity!!, shareTitle!!, shareUrl!!, shareContent, shareHead) // ShareUtils.shareTo(platform, mActivity!!, shareTitle!!, shareUrl!!, shareContent, shareHead)
ShareUtils.callBack = object : ShareActionCallBack { // ShareUtils.callBack = object : ShareActionCallBack {
override fun onShareSuccessed(share_media: SHARE_MEDIA) { // override fun onShareSuccessed(share_media: SHARE_MEDIA) {
mShareCallBack?.onShareSuccessed(share_media) // mShareCallBack?.onShareSuccessed(share_media)
} // }
//
override fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable) { // override fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable) {
mShareCallBack?.onShareFailed(share_media, throwable) // mShareCallBack?.onShareFailed(share_media, throwable)
} // }
} // }
dismiss() // dismiss()
} // }
//
/** // /**
* 分享小程序 // * 分享小程序
*/ // */
private fun shareMinWeixin() { // private fun shareMinWeixin() {
//分享小程序到微信 // //分享小程序到微信
ShareUtils.shareSmailWeixin(mActivity!!, shareTitle!!, shareUrl!!, shareContent, shareHead, path, minProgramId, null) // ShareUtils.shareSmailWeixin(mActivity!!, shareTitle!!, shareUrl!!, shareContent, shareHead, path, minProgramId, null)
dismiss() // dismiss()
} // }
//
interface ICallBack { // interface ICallBack {
fun callBack(type: Int) // fun callBack(type: Int)
} // }
//
interface IShareCallBack { // interface IShareCallBack {
fun onShareSuccessed(share_media: SHARE_MEDIA) // fun onShareSuccessed(share_media: SHARE_MEDIA)
fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable) // fun onShareFailed(share_media: SHARE_MEDIA, throwable: Throwable)
} // }
} //}
\ No newline at end of file \ No newline at end of file
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