Commit 25089161 authored by jyx's avatar jyx

添加二维码分享功能

parent fc12fd52
......@@ -170,7 +170,8 @@ dependencies {
implementation 'com.romandanylyk:pageindicatorview:1.0.3'
// xtablayout
implementation 'com.androidkun:XTabLayout:1.1.4'
// zxing
implementation 'com.king.zxing:zxing-lite:1.1.7-androidx'
// 工具类
// gson
......@@ -178,7 +179,6 @@ dependencies {
// BASE64Decoder
implementation files('libs/sun.misc.BASE64Decoder.jar')
// 三方接入
// leakcanary
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
......
......@@ -102,7 +102,8 @@
<activity
android:name=".ui.activitys.SplashYlhActivity"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:theme="@style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
package com.mints.goodmoney;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
......@@ -50,10 +51,23 @@ public class MintsApplication extends MultiDexApplication {
mContext = this.getApplicationContext();
// 判断应用是否在前台
ForegroundOrBackground.init(this);
// 9.0之后不可多进程使用一个目录下的WebView,写在SDK初始化之前
androidPWebView();
// 三方配置
thirdConfig();
}
private void androidPWebView() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String processName = getProcessName(this);
String packageName = this.getPackageName();
if (!packageName.equals(processName)) {
// 为不同进程webView设置不同目录
WebView.setDataDirectorySuffix(processName);
}
}
}
@Override
public void onLowMemory() {
android.os.Process.killProcess(android.os.Process.myPid());
......@@ -161,4 +175,16 @@ public class MintsApplication extends MultiDexApplication {
}
return defaultSubscribeScheduler;
}
private String getProcessName(Context context) {
if (context == null) return null;
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == android.os.Process.myPid()) {
return processInfo.processName;
}
}
return null;
}
}
......@@ -77,6 +77,12 @@ object Constant {
const val FRAGMENT_CLICK_FRIENDS = 3
const val FRAGMENT_CLICK_MY = 4
const val FRAGMENT_TAG_MAIN = "FRAGMENT_TAG_MAIN"
const val FRAGMENT_TAG_CHANNEL = "FRAGMENT_TAG_CHANNEL"
const val FRAGMENT_TAG_PAN = "FRAGMENT_TAG_PAN"
const val FRAGMENT_TAG_FRIENDS = "FRAGMENT_TAG_FRIENDS"
const val FRAGMENT_TAG_MY = "FRAGMENT_TAG_MY"
// 协议地址
var REGISTER_URL = BuildConfig.MainIp + "gm/register.html"//服务协议
var PRIVACY_URL = BuildConfig.MainIp + "gm/privacy.html"//隐私协议
......
......@@ -18,7 +18,7 @@ public class TTPreLoadCarrierExpressManager {
private FrameLayout ttFrameLayout;
private TTNativeExpressManager ttNativeExpressManager;
private HandlerThread mHandlerThread = new HandlerThread("TTPreLoadHandlerThread");
private HandlerThread mHandlerThread;
private Handler mWorkHandler;
private Handler mMainHandler = new Handler(Looper.getMainLooper());
......@@ -31,22 +31,20 @@ public class TTPreLoadCarrierExpressManager {
return _inst;
}
private TTPreLoadCarrierExpressManager() {
init();
}
private void init() {
public void init() {
ttNativeExpressManager = new TTNativeExpressManager();
ttNativeExpressManager.initTTAd(false);
// 启动异步线程
mHandlerThread = new HandlerThread("TTPreLoadHandlerThread");
mHandlerThread.start();
mWorkHandler = new Handler(mHandlerThread.getLooper()) {
@Override
public void handleMessage(@NonNull Message msg) {
// 工作线程进行加载数据
super.handleMessage(msg);
// 工作线程进行加载数据
if (msg.what == mTTPreLoadWhat) {
loadTtFrameLayoutInThread((String) msg.obj);
}
......@@ -55,10 +53,14 @@ public class TTPreLoadCarrierExpressManager {
}
public void onDestroy() {
mHandlerThread.quit();
mHandlerThread = null;
mWorkHandler.removeCallbacksAndMessages(null);
mWorkHandler = null;
if (mHandlerThread != null) {
mHandlerThread.quit();
mHandlerThread = null;
}
if (mWorkHandler != null) {
mWorkHandler.removeCallbacksAndMessages(null);
mWorkHandler = null;
}
}
public FrameLayout getTtFrameLayout() {
......@@ -71,24 +73,21 @@ public class TTPreLoadCarrierExpressManager {
try {
ttFrameLayout = new FrameLayout(context);
ttNativeExpressManager.getNativeExpressInit(codeId, ttFrameLayout, 340, 0);
ttNativeExpressManager.setTTNativeExpressManagerListener(view -> {
ttNativeExpressManager.setTTNativeExpressManagerListener(view -> mMainHandler.post(() -> {
// 主线程更新UI操作
mMainHandler.post(() -> {
// 主线程更新UI操作
if (view == null) {
ttFrameLayout = null;
} else {
if (view == null) {
try {
ttFrameLayout = view;
} catch (Exception e) {
e.printStackTrace();
ttFrameLayout = null;
} else {
try {
ttFrameLayout = view;
} catch (Exception e) {
e.printStackTrace();
ttFrameLayout = null;
}
}
});
});
}
}));
} catch (Exception e) {
e.printStackTrace();
......@@ -99,9 +98,11 @@ public class TTPreLoadCarrierExpressManager {
* 预加载 信息流
*/
public void loadTtFrameLayout(String codeId) {
Message msg = Message.obtain();
msg.what = mTTPreLoadWhat;
msg.obj = codeId;
mWorkHandler.sendMessage(msg);
if (mWorkHandler != null) {
Message msg = Message.obtain();
msg.what = mTTPreLoadWhat;
msg.obj = codeId;
mWorkHandler.sendMessage(msg);
}
}
}
......@@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.ireader.ireadersdk.IreaderApi
import com.mints.goodmoney.R
......@@ -19,6 +20,7 @@ import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.fragment.*
import kotlinx.android.synthetic.main.activity_main.*
/**
* 描述:main
* 作者:孟崔广
......@@ -40,7 +42,6 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
override fun getContentViewLayoutID() = R.layout.activity_main
override fun initViewsAndEvents() {
ZhangyueManager.onCreateIreader(baseApplication)
if (moneyFragment == null) {
......@@ -124,7 +125,7 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
if (moneyFragment == null) {
moneyFragment = MoneyFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), moneyFragment!!)
addOrShowFragment(supportFragmentManager, moneyFragment!!, Constant.FRAGMENT_TAG_MAIN)
tab_iv_main.isSelected = true
tab_tv_main.isSelected = true
......@@ -152,7 +153,7 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
if (channelFragment == null) {
channelFragment = HorizChannelFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), channelFragment!!)
addOrShowFragment(supportFragmentManager, channelFragment!!, Constant.FRAGMENT_TAG_CHANNEL)
tab_iv_main.isSelected = false
tab_tv_main.isSelected = false
tab_iv_channel.isSelected = true
......@@ -174,7 +175,7 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
if (friendsFragment == null) {
friendsFragment = FriendsFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), friendsFragment!!)
addOrShowFragment(supportFragmentManager, friendsFragment!!, Constant.FRAGMENT_TAG_FRIENDS)
tab_iv_main.isSelected = false
tab_tv_main.isSelected = false
tab_iv_channel.isSelected = false
......@@ -195,7 +196,7 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
if (panFragment == null) {
panFragment = PanFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), panFragment!!)
addOrShowFragment(supportFragmentManager, panFragment!!, Constant.FRAGMENT_TAG_PAN)
tab_iv_main.isSelected = false
tab_tv_main.isSelected = false
tab_iv_channel.isSelected = false
......@@ -216,7 +217,7 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
if (myFragment == null) {
myFragment = MyFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), myFragment!!)
addOrShowFragment(supportFragmentManager, myFragment!!, Constant.FRAGMENT_TAG_MY)
tab_iv_main.isSelected = false
tab_tv_main.isSelected = false
tab_iv_channel.isSelected = false
......@@ -232,17 +233,18 @@ class MainActivity : BaseActivity(), MainView, View.OnClickListener {
/**
* 添加或者显示碎片
*
* @param transaction
* @param fm
* @param fragment
*/
private fun addOrShowFragment(transaction: FragmentTransaction,
fragment: Fragment) {
private fun addOrShowFragment(fm: FragmentManager,
fragment: Fragment, tag: String) {
if (currentFragment === fragment) return
if (!fragment.isAdded) { // 如果当前fragment未被添加,则添加到Fragment管理器中
transaction.hide(currentFragment!!)
.add(R.id.content_layout, fragment).commitAllowingStateLoss()
val ft: FragmentTransaction = fm.beginTransaction()
if (!fragment.isAdded && null == fm.findFragmentByTag(tag)) { // 如果当前fragment未被添加,则添加到Fragment管理器中
ft.hide(currentFragment!!)
.add(R.id.content_layout, fragment, tag).commitAllowingStateLoss()
} else {
transaction.hide(currentFragment!!).show(fragment).commitAllowingStateLoss()
ft.hide(currentFragment!!).show(fragment).commitAllowingStateLoss()
}
currentFragment = fragment
}
......
......@@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import cn.sharesdk.framework.Platform
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.wechat.favorite.WechatFavorite
import cn.sharesdk.wechat.friends.Wechat
import com.daimajia.androidanimations.library.Techniques
import com.daimajia.androidanimations.library.YoYo
......@@ -28,6 +29,7 @@ import com.mints.goodmoney.ui.fragment.base.BaseFragment
import com.mints.goodmoney.ui.widgets.BonusDialog
import com.mints.goodmoney.ui.widgets.CustomDialogAsApple
import com.mints.goodmoney.ui.widgets.DialogListener
import com.mints.goodmoney.ui.widgets.ShareDialog
import com.mints.goodmoney.utils.ImageUtil
import com.mints.goodmoney.utils.SpanUtils
import com.scwang.smartrefresh.layout.api.RefreshLayout
......@@ -181,6 +183,21 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
}
}
mFriendsHallMsgBean?.let {
if (it.button == "戳我分红") {
showRedbox(btn_get_bonus)
}
}
}
}
override fun onPause() {
super.onPause()
mFriendsHallMsgBean?.let {
if (it.button == "戳我分红") {
stopRedbox()
}
}
}
......@@ -345,24 +362,26 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
R.id.btn_invite -> {
// 邀请好友
if (!ps.getBoolean(Constant.FIRST_SHARE_INVITED, false)) {
// 第一次邀请提示弹框
firstWeChatInvite()
} else {
val wechatSp = Platform.ShareParams()
wechatSp.shareType = Platform.SHARE_WEBPAGE
wechatSp.title = Constant.SHARE_TITLE
wechatSp.text = Constant.SHARE_CONTENT
wechatSp.imageData = ImageUtil.drawableToBitmap(ContextCompat.getDrawable(requireContext(), R.mipmap.ic_launcher))
wechatSp.url = Constant.SHARE_URL
val wechat = ShareSDK.getPlatform(Wechat.NAME)
if (wechat.isClientValid) {
// 执行图文分享
wechat.share(wechatSp)
} else {
showToast("请先安装微信")
}
}
shareImgDialog()
// if (!ps.getBoolean(Constant.FIRST_SHARE_INVITED, false)) {
// // 第一次邀请提示弹框
// firstWeChatInvite()
// } else {
// val wechatSp = Platform.ShareParams()
// wechatSp.shareType = Platform.SHARE_WEBPAGE
// wechatSp.title = Constant.SHARE_TITLE
// wechatSp.text = Constant.SHARE_CONTENT
// wechatSp.imageData = ImageUtil.drawableToBitmap(ContextCompat.getDrawable(requireContext(), R.mipmap.ic_launcher))
// wechatSp.url = Constant.SHARE_URL
// val wechat = ShareSDK.getPlatform(Wechat.NAME)
// if (wechat.isClientValid) {
// // 执行图文分享
// wechat.share(wechatSp)
// } else {
// showToast("请先安装微信")
// }
// }
}
R.id.tv_right_subtitle -> {
......@@ -446,6 +465,11 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
}
}
private fun shareImgDialog() {
val shareDialog = ShareDialog(requireActivity())
shareDialog.show()
}
/**
* 第一次微信分享弹框
*/
......
......@@ -19,9 +19,7 @@ import com.yilan.sdk.player.ylplayer.callback.OnPlayerCallBack
import com.yilan.sdk.ui.category.ChannelFragment
import kotlinx.android.synthetic.main.fragment_horiz_channel.cdvvYilanTime
import kotlinx.android.synthetic.main.fragment_horiz_channel.vs_tips
import kotlinx.android.synthetic.main.fragment_main_first.*
import net.grandcentrix.tray.AppPreferences
import kotlinx.android.synthetic.main.fragment_horiz_channel.*
class HorizChannelFragment : BaseFragment(), HorizChannelView, View.OnClickListener {
......@@ -73,6 +71,14 @@ class HorizChannelFragment : BaseFragment(), HorizChannelView, View.OnClickListe
registerPlayerCallBack()
channelFragment?.onResume()
if (isToCreateReward) {
// 防止界面切换 重置红包动画
// 好兔视频已加载 且 红包已转满
if (!cdvvYilanTime.isPlaying) {
cdvvYilanTime.startAnim()
}
}
}
}
......@@ -84,12 +90,20 @@ class HorizChannelFragment : BaseFragment(), HorizChannelView, View.OnClickListe
}
pauseDownloadTime()
channelFragment?.onPause()
if (isToCreateReward) {
// 防止界面切换 重置红包动画
// 好兔视频已加载 且 红包已转满
if (!cdvvYilanTime.isPlaying) {
cdvvYilanTime.stopAnim()
}
}
}
override fun onDestroyView() {
cdvvYilanTime?.onDestory()
cdvvYilanTime?.setCountDownVedioListener(null)
cdvvYilanTime?.onDestory()
super.onDestroyView()
}
......
......@@ -12,6 +12,7 @@ import com.mints.goodmoney.ad.video.VedioAdingManager
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.manager.ShumeiManager
import com.mints.goodmoney.manager.TTPreLoadCarrierExpressManager
import com.mints.goodmoney.manager.TTPreLoadExpressManager
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.MainVedioMsgBean
......@@ -72,6 +73,8 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
vedioAdingManager = VedioAdingManager.getInstance(activity)
// 奖励页预加载 信息流广告
TTPreLoadExpressManager.getInstance().loadTtFrameLayout()
// 喝水页预加载 信息流广告
TTPreLoadCarrierExpressManager.getInstance().init()
// 首次显示权限弹窗
showPowerDialog()
......@@ -107,6 +110,15 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
registerPlayerCallBack()
littleVideoFragment?.onResume()
if (isToCreateReward) {
// 防止界面切换 重置红包动画
// 好兔视频已加载 且 红包已转满
if (!isFirstLoadVedio && !cdvvYilanTime.isPlaying) {
cdvvYilanTime.startAnim()
}
}
}
}
......@@ -124,6 +136,14 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
pauseDownloadTime()
littleVideoFragment?.onPause()
if (isToCreateReward) {
// 防止界面切换 重置红包动画
// 好兔视频已加载 且 红包已转满
if (!isFirstLoadVedio && !cdvvYilanTime.isPlaying) {
cdvvYilanTime.stopAnim()
}
}
}
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
......@@ -259,18 +279,18 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
isFirstLoadVedio = false
initTimeview()
} else {
LogUtil.d(TAG, "registerPlayerCallBack onStart")
// LogUtil.d(TAG, "registerPlayerCallBack onStart")
resumeDownloadTime(videoid)
}
}
override fun onPause(pager: String, p1: String?, p2: String?) {
LogUtil.d(TAG, "registerPlayerCallBack onPause")
// LogUtil.d(TAG, "registerPlayerCallBack onPause")
pauseDownloadTime()
}
override fun onResume(pager: String, videoid: String, p2: String?) {
LogUtil.d(TAG, "registerPlayerCallBack onResume")
// LogUtil.d(TAG, "registerPlayerCallBack onResume")
resumeDownloadTime(videoid)
}
......@@ -279,7 +299,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
override fun onLoopComplete(pager: String?, videoID: String, taskID: String?, num: Int) {
LogUtil.d(TAG, "registerPlayerCallBack onLoopComplete")
// LogUtil.d(TAG, "registerPlayerCallBack onLoopComplete")
addVedioIdList(videoID)
pauseDownloadTime()
}
......@@ -296,7 +316,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
}
override fun onStop(pager: String, p1: String?, p2: String?) {
LogUtil.d(TAG, "registerPlayerCallBack onStop")
// LogUtil.d(TAG, "registerPlayerCallBack onStop")
// pauseDownloadTime()
}
})
......@@ -403,7 +423,7 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
* 红包倒计时初始化
*/
private fun initTimeview() {
cdvvYilanTime.setCountDownVedioListener {
cdvvYilanTime?.setCountDownVedioListener {
if (isFirstWatchVideo) {
// 第一次观看完视频提醒用户
val vs = vs_tips.inflate()
......@@ -419,8 +439,8 @@ class MainFragment : BaseFragment(), HomeView, View.OnClickListener {
stopDownloadTime()
}
val vedioTime = ps.getInt(Constant.MAIN_VEDIO_TIME, 30)
cdvvYilanTime.setTime(vedioTime)
cdvvYilanTime.start()
cdvvYilanTime?.setTime(vedioTime)
cdvvYilanTime?.start()
}
/**
......
......@@ -143,6 +143,11 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
super.onHiddenChanged(hidden)
}
override fun onPause() {
super.onPause()
item_clock_signview.stopRedbox()
}
override fun onResume() {
super.onResume()
if (AppConfig.fragmentClickFlag == Constant.FRAGMENT_CLICK_MY) {
......@@ -554,7 +559,8 @@ class MyFragment : BaseFragment(), MyView, OnItemChildClickListener, OnRefreshLi
}
R.id.iv_right_icon2 -> {
// 跳转QQ客服
jumpQQ()
// jumpQQ()
jumpQQGroup()
}
R.id.item_customer_service -> {
// 跳转加入QQ群
......
......@@ -46,12 +46,9 @@ public class CountDownVedioView extends LinearLayout {
}
private void initListener() {
cdCountVedioView.setOnLoadingFinishListener(new CountDownView.OnLoadingFinishListener() {
@Override
public void finish() {
if (countDownVedioListener != null) {
countDownVedioListener.finish();
}
cdCountVedioView.setOnLoadingFinishListener(() -> {
if (countDownVedioListener != null) {
countDownVedioListener.finish();
}
});
}
......@@ -114,6 +111,24 @@ public class CountDownVedioView extends LinearLayout {
}
}
/**
* 开始红包动画
*/
public void startAnim() {
if (rope != null && !rope.isRunning()) {
showRedbox();
}
}
/**
* 暂停红包动画
*/
public void stopAnim() {
if (rope != null && rope.isRunning()) {
rope.stop();
}
}
public void stopRedbox() {
if (ivCountVedioRedbox != null && rope != null) {
rope.stop();
......@@ -121,6 +136,8 @@ public class CountDownVedioView extends LinearLayout {
}
public void onDestory() {
if (cdCountVedioView.callOnClick())
if (rope != null) {
rope.stop();
rope = null;
......
......@@ -10,7 +10,9 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import androidx.core.content.ContextCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
......@@ -18,7 +20,6 @@ import android.view.animation.LinearInterpolator;
import com.mints.goodmoney.R;
public class CountDownView extends View {
private Context mContext;//上下文
private Paint mPaintBackGround;//背景画笔
......@@ -208,31 +209,26 @@ public class CountDownView extends View {
}
public void reset() {
if (set != null) {
set.cancel();
}
// Android8及8以下回调 onAnimatioinEnd 造成递归调用
// if (set != null) {
// set.cancel();
// }
ValueAnimator animator = ValueAnimator.ofFloat(0, 0);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mSweepAngle = (float) valueAnimator.getAnimatedValue();
//获取到需要绘制的角度,重新绘制
invalidate();
}
animator.addUpdateListener(valueAnimator -> {
mSweepAngle = (float) valueAnimator.getAnimatedValue();
//获取到需要绘制的角度,重新绘制
invalidate();
});
animator.start();
}
public void start() {
ValueAnimator animator = ValueAnimator.ofFloat(mmSweepAngleStart, mmSweepAngleEnd);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mSweepAngle = (float) valueAnimator.getAnimatedValue();
//获取到需要绘制的角度,重新绘制
invalidate();
}
animator.addUpdateListener(valueAnimator -> {
mSweepAngle = (float) valueAnimator.getAnimatedValue();
//获取到需要绘制的角度,重新绘制
invalidate();
});
//这里是时间获取和赋值
if (set == null) {
......
package com.mints.goodmoney.ui.widgets
import android.app.Dialog
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import cn.sharesdk.framework.Platform
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.wechat.favorite.WechatFavorite
import cn.sharesdk.wechat.friends.Wechat
import com.mints.goodmoney.MintsApplication
import com.mints.goodmoney.R
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.utils.ImageUtil
import com.mints.goodmoney.utils.QRCodeUtil
import com.mints.goodmoney.utils.ToastUtil
class ShareDialog(context: Context) :
Dialog(context, R.style.dialog) {
private val lp: WindowManager.LayoutParams
private val llDialogShareWx: LinearLayout
private val llDialogShareQq: LinearLayout
private val imgShare: ImageView
private val imgQrCode: ImageView
private val rlView: RelativeLayout
private val tvDialogShareNext: TextView
init {
setContentView(R.layout.dialog_share)
// 设置window属性
lp = window!!.attributes
lp.gravity = Gravity.BOTTOM
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.MATCH_PARENT
lp.windowAnimations = R.style.DialogAnimBottom
// lp.alpha = 1.0f;//透明效果
window!!.attributes = lp
// 设置外部不可关闭
// setCancelable(false)
// setCanceledOnTouchOutside(false)
// setOnKeyListener { _, i, _ ->
// i == KeyEvent.KEYCODE_BACK
// }
// 查找View
llDialogShareWx = findViewById<View>(R.id.llDialogShareWx) as LinearLayout
llDialogShareQq = findViewById<View>(R.id.llDialogShareQq) as LinearLayout
imgShare = findViewById<View>(R.id.img_share) as ImageView
imgQrCode = findViewById<View>(R.id.img_qr_code) as ImageView
rlView = findViewById<View>(R.id.rl_view) as RelativeLayout
tvDialogShareNext = findViewById<View>(R.id.tvDialogShareNext) as TextView
// llDialogShareWx.setOnClickListener(listener)
// llDialogShareQq.setOnClickListener(listener)
// tvDialogShareNext.setOnClickListener(listener)
llDialogShareWx.setOnClickListener {
shareWechat()
}
val QRCode = QRCodeUtil.createQRCode(Constant.SHARE_URL, 50)
// imgQrCode.setImageBitmap(QRCode)
imgQrCode.background = BitmapDrawable(QRCode)
}
private fun shareWechat() {
rlView.isDrawingCacheEnabled = true
rlView.drawingCacheQuality = View.DRAWING_CACHE_QUALITY_HIGH
//测量在屏幕上宽和高
// rlView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
// View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED))
//确定View的大小和位置的,然后将其绘制出来
// rlView.layout(0, 0, rlView.measuredWidth, rlView.measuredHeight)
rlView.buildDrawingCache()
val bitmap: Bitmap = rlView.drawingCache
val wechatSp = Platform.ShareParams()
wechatSp.shareType = Platform.SHARE_IMAGE
wechatSp.title = Constant.SHARE_TITLE
wechatSp.text = Constant.SHARE_CONTENT
wechatSp.imageData = bitmap
wechatSp.url = Constant.SHARE_URL
val wechat = ShareSDK.getPlatform(Wechat.NAME)
if (wechat.isClientValid) {
// 执行图文分享
wechat.share(wechatSp)
} else {
ToastUtil.show(MintsApplication.getContext(), "请先安装微信")
}
}
private fun shareWechatFavoite() {
val wechatSp = Platform.ShareParams()
wechatSp.shareType = Platform.SHARE_IMAGE
wechatSp.title = Constant.SHARE_TITLE
wechatSp.text = Constant.SHARE_CONTENT
wechatSp.imageData = ImageUtil.drawableToBitmap(ContextCompat.getDrawable(context, R.mipmap.bg_eat))
wechatSp.url = Constant.SHARE_URL
val wechat = ShareSDK.getPlatform(WechatFavorite.NAME)
if (wechat.isClientValid) {
// 执行图文分享
wechat.share(wechatSp)
} else {
ToastUtil.show(MintsApplication.getContext(), "请先安装微信")
}
}
}
\ No newline at end of file
......@@ -785,7 +785,7 @@ public class BubbleSeekBar extends View {
mBubbleCenterRawX = mBubbleCenterRawSolidX + mThumbCenterX - mLeft;
mLayoutParams.x = (int) (mBubbleCenterRawX + 0.5f);
if (mBubbleView.getParent() != null) {
if (mBubbleView.getParent() != null && mWindowManager != null) {
mWindowManager.updateViewLayout(mBubbleView, mLayoutParams);
}
mBubbleView.setProgressText(isShowProgressInFloat ?
......
package com.mints.goodmoney.utils;
import android.graphics.Bitmap;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.util.Hashtable;
public class QRCodeUtil {
/**
* 生成二维码
*
* @param text 需要生成二维码的文字、网址等
* @param size 需要生成二维码的大小()
* @return bitmap
*/
public static Bitmap createQRCode(String text, int size) {
try {
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, size, size, hints);
int[] pixels = new int[size * size];
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * size + x] = 0xff000000;
} else {
pixels[y * size + x] = 0xffffffff;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(size, size,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
return null;
}
}
}
......@@ -23,7 +23,7 @@ public class ToastUtil {
private static Handler mHandler = new Handler(Looper.getMainLooper());
private static Toast mToast = null;
private static Object mSynObj = new Object();
private static final Object mSynObj = new Object();
public static void show(Context context, String msg) {
showToast(context, msg, Toast.LENGTH_SHORT, Gravity.CENTER);
......@@ -70,27 +70,32 @@ public class ToastUtil {
@Override
public void run() {
synchronized (mSynObj) {
if (mToast != null) {
if (Integer.valueOf(android.os.Build.VERSION.SDK) < 12)
mToast.cancel();
View view = mToast.getView();
if (view != null) {
if (view instanceof TextView) {
TextView toastView = (TextView) view;
toastView.setText(msg);
try {
if (mToast != null) {
if (Integer.valueOf(android.os.Build.VERSION.SDK) < 12)
mToast.cancel();
View view = mToast.getView();
if (view != null) {
if (view instanceof TextView) {
TextView toastView = (TextView) view;
toastView.setText(msg);
}
}
} else {
mToast = new Toast(context);
TextView toastView = (TextView) LayoutInflater.from(context).inflate(R.layout.toast_view, null);
toastView.setText(msg);
mToast.setView(toastView);
}
} else {
mToast = new Toast(context);
mToast.setDuration(len);
mToast.setGravity(gravity, 0, 80);
mToast.show();
} catch (Exception e) {
TextView toastView = (TextView) LayoutInflater.from(context).inflate(R.layout.toast_view, null);
toastView.setText(msg);
mToast.setView(toastView);
}
mToast.setDuration(len);
mToast.setGravity(gravity, 0, 80);
mToast.show();
}
}
});
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:background="@color/transparent">
<RelativeLayout
android:id="@+id/rl_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@color/white"
android:gravity="center_horizontal"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/img_share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/bg_eat" />
<TextView
android:id="@+id/tv_share_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/img_share"
android:layout_marginTop="20dp"
android:text="@string/app_name"
android:textColor="@color/main_mints" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_share_code"
android:layout_marginTop="10dp"
android:text="好玩好赚钱"
android:textColor="@color/main_mints" />
<ImageView
android:id="@+id/img_qr_code"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_below="@id/img_share"
android:layout_alignParentEnd="true"
android:scaleType="fitXY" />
</RelativeLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_tab_friends"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/llDialogShareWx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@mipmap/ic_share_wx" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="微信"
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/llDialogShareQq"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="@mipmap/ic_wx_friends" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="朋友圈"
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<View style="@style/line_3" />
<TextView
android:id="@+id/tvDialogShareNext"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:text="取消"
android:textColor="@color/black"
android:textSize="18sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- <style name="AppTheme" parent="AppTheme.Base" />-->
<!-- <style name="AppTheme" parent="AppTheme.Base" />-->
<style name="CustomAppTheme" parent="AppTheme.Base" />
......@@ -23,7 +23,7 @@
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.NoActionBarTranslucent" parent="AppTheme.Base">
<style name="AppTheme.NoActionBarTranslucent" parent="AppTheme.Base">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
......@@ -32,4 +32,13 @@
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="Theme.NoDisplay" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@null</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowNoDisplay">false</item>
</style>
</resources>
\ 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