| | |
| | | package com.hdl.photovoltaic.ui.me; |
| | | |
| | | |
| | | import android.content.Intent; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.Color; |
| | | import android.os.Bundle; |
| | | import android.provider.MediaStore; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.ActivityQrCodeMainBinding; |
| | | import com.hdl.photovoltaic.other.HdlCommonLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.ui.bean.QrCodeBean; |
| | | |
| | | /** |
| | | * 二维码名片的界面 |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setNotificationBarBackgroundColor(CustomBaseActivity.CustomColor.white); |
| | | setStatusBarTextColor(); |
| | | setStatusBarTranslucent(); |
| | | getWindow().setNavigationBarColor(getColor(R.color.text_00000000)); |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | |
| | | |
| | | |
| | | private void initEvent() { |
| | | viewBinding.toolbarTopQrCodeRl.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | finish(); |
| | | } |
| | | }); |
| | | |
| | | viewBinding.toolbarTopQrCodeRl.topMoreBtn.setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.saveTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //假设你已经有了一个二维码图片,这里是一个简化的截图方法 |
| | | viewBinding.qrCodeIv.setDrawingCacheEnabled(true); |
| | | Bitmap bitmap = viewBinding.qrCodeIv.getDrawingCache(); |
| | | // 保存截图到相册 |
| | | saveImageToGallery(bitmap); |
| | | // 清理缓存 |
| | | viewBinding.qrCodeIv.setDrawingCacheEnabled(false); |
| | | if (bitmap != null && !bitmap.isRecycled()) { |
| | | // 确保不是已经回收的Bitmap |
| | | // 进行你需要的操作 |
| | | Bitmap.createBitmap(bitmap).recycle(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | private void saveImageToGallery(Bitmap bitmap) { |
| | | String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "QRCode", null); |
| | | if (path != null) { |
| | | HdlThreadLogic.toast(_mActivity, getString(R.string.save_qr_code_successfully)); |
| | | // Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show(); |
| | | } else { |
| | | HdlThreadLogic.toast(_mActivity, getString(R.string.failed_to_save_qr_code)); |
| | | //Toast.makeText(this, "保存失败", Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | |
| | | private void initView() { |
| | | viewBinding.toolbarTopQrCodeRl.topTitleTv.setText(R.string.qr_code_business_card); |
| | | viewBinding.toolbarTopQrCodeRl.topBackLl.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopQrCodeRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C, null)); |
| | | viewBinding.toolbarTopQrCodeRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null)); |
| | | viewBinding.toolbarTopQrCodeRl.topMoreIv.setVisibility(View.VISIBLE); |
| | | viewBinding.toolbarTopQrCodeRl.topMoreIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.save_image)); |
| | | viewBinding.toolbarTopRl.topBarView.setBackgroundColor(getColor(R.color.text_00000000)); |
| | | viewBinding.toolbarTopRl.topTitleTv.setText(R.string.qr_code_business_card); |
| | | viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE); |
| | | // viewBinding.toolbarTopQrCodeRl.topMoreBtn.setVisibility(View.VISIBLE); |
| | | // viewBinding.toolbarTopQrCodeRl.topMoreIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.save_image)); |
| | | if (!TextUtils.isEmpty(UserConfigManage.getInstance().getUserName())) { |
| | | viewBinding.userNameTv.setVisibility(View.VISIBLE); |
| | | viewBinding.userNameTv.setText(UserConfigManage.getInstance().getUserName()); |
| | |
| | | viewBinding.userAccountTv.setVisibility(View.VISIBLE); |
| | | viewBinding.userAccountTv.setText(str); |
| | | } |
| | | String content = UserConfigManage.getInstance().getAccount(); |
| | | Bitmap bitmap = HdlCommonLogic.getInstance().createQRCodeBitmap(content, 229, 229, "UTF-8", "H", "1", Color.BLACK, Color.WHITE); |
| | | // QrCodeBean qrCodeBean = new QrCodeBean(); |
| | | // qrCodeBean.setUserEmail(UserConfigManage.getInstance().getBingEmail()); |
| | | // qrCodeBean.setUserPhone(UserConfigManage.getInstance().getBingPhone()); |
| | | // qrCodeBean.setUserName(UserConfigManage.getInstance().getUserName()); |
| | | // qrCodeBean.setAccount(UserConfigManage.getInstance().getAccount()); |
| | | String content = UserConfigManage.getInstance().getAccount();// new Gson().toJson(qrCodeBean);内容过长微信扫码显示有问题 |
| | | Bitmap bitmap = HdlCommonLogic.getInstance().createQRCodeBitmap(content, 168, 168, "UTF-8", "H", "0", getColor(R.color.text_00000000), Color.WHITE); |
| | | viewBinding.qrCodeIv.setImageBitmap(bitmap); |
| | | |
| | | } |