Commit 1c13d8ef authored by jyx's avatar jyx

代码优化

parent 25089161
......@@ -10,7 +10,6 @@ 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
......@@ -363,25 +362,25 @@ class FriendsFragment : BaseFragment(), FriendsView, OnRefreshListener, View.OnC
R.id.btn_invite -> {
// 邀请好友
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("请先安装微信")
// }
// }
// 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 -> {
......
......@@ -3,7 +3,6 @@ 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
......@@ -41,7 +40,7 @@ class ShareDialog(context: Context) :
lp = window!!.attributes
lp.gravity = Gravity.BOTTOM
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.WRAP_CONTENT
lp.windowAnimations = R.style.DialogAnimBottom
// lp.alpha = 1.0f;//透明效果
window!!.attributes = lp
......@@ -68,9 +67,8 @@ class ShareDialog(context: Context) :
shareWechat()
}
val QRCode = QRCodeUtil.createQRCode(Constant.SHARE_URL, 50)
// imgQrCode.setImageBitmap(QRCode)
imgQrCode.background = BitmapDrawable(QRCode)
val QRCode = QRCodeUtil.createQRCode(Constant.SHARE_URL, 100)
imgQrCode.setImageBitmap(QRCode)
}
private fun shareWechat() {
......
package com.mints.goodmoney.utils;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
......@@ -24,7 +25,7 @@ public class QRCodeUtil {
try {
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, size, size, hints);
......@@ -39,14 +40,36 @@ public class QRCodeUtil {
}
}
Bitmap bitmap = Bitmap.createBitmap(size, size,
Bitmap.Config.ARGB_8888);
Bitmap.Config.RGB_565);
bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
return bitmap;
Bitmap zoomBitmap = zoomBitmap(bitmap, size, size);
bitmap.recycle();
return zoomBitmap;
} catch (WriterException e) {
e.printStackTrace();
return null;
}
}
/**
* 图片缩放
*
* @param bitmap 对象
* @param w 要缩放的宽度
* @param h 要缩放的高度
* @return newBmp 新 Bitmap对象
*/
public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
float scaleWidth = ((float) w / width);
float scaleHeight = ((float) h / height);
matrix.postScale(scaleWidth, scaleHeight);
Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
matrix, true);
return newBmp;
}
}
......@@ -42,12 +42,12 @@
android:textColor="@color/main_mints" />
<ImageView
android:background="@color/main_mints"
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" />
android:layout_alignParentEnd="true" />
</RelativeLayout>
......
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