pull/1072/head
gedoor 3 years ago
parent adf2744e1c
commit d194c366f6
  1. 4
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  3. 9
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  4. 2
      app/src/main/java/io/legado/app/utils/QRCodeUtils.kt

@ -12,6 +12,7 @@ import android.widget.PopupWindow
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
@ -112,7 +113,8 @@ class BookSourceEditActivity :
R.id.menu_share_str -> share(GSON.toJson(getSource())) R.id.menu_share_str -> share(GSON.toJson(getSource()))
R.id.menu_share_qr -> shareWithQr( R.id.menu_share_qr -> shareWithQr(
GSON.toJson(getSource()), GSON.toJson(getSource()),
getString(R.string.share_book_source) getString(R.string.share_book_source),
ErrorCorrectionLevel.L
) )
R.id.menu_help -> showRuleHelp() R.id.menu_help -> showRuleHelp()
R.id.menu_login -> getSource().let { R.id.menu_login -> getSource().let {

@ -10,6 +10,7 @@ import android.view.ViewTreeObserver
import android.widget.EditText import android.widget.EditText
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.activity.viewModels import androidx.activity.viewModels
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
@ -117,7 +118,8 @@ class RssSourceEditActivity :
R.id.menu_share_str -> share(GSON.toJson(getRssSource())) R.id.menu_share_str -> share(GSON.toJson(getRssSource()))
R.id.menu_share_qr -> shareWithQr( R.id.menu_share_qr -> shareWithQr(
GSON.toJson(getRssSource()), GSON.toJson(getRssSource()),
getString(R.string.share_rss_source) getString(R.string.share_rss_source),
ErrorCorrectionLevel.L
) )
R.id.menu_help -> showRuleHelp() R.id.menu_help -> showRuleHelp()
} }

@ -21,6 +21,7 @@ import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.core.content.edit import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import java.io.File import java.io.File
@ -146,8 +147,12 @@ fun Context.share(text: String, title: String = getString(R.string.share)) {
} }
@SuppressLint("SetWorldReadable") @SuppressLint("SetWorldReadable")
fun Context.shareWithQr(text: String, title: String = getString(R.string.share)) { fun Context.shareWithQr(
val bitmap = QRCodeUtils.createQRCode(text) text: String,
title: String = getString(R.string.share),
errorCorrectionLevel: ErrorCorrectionLevel = ErrorCorrectionLevel.H
) {
val bitmap = QRCodeUtils.createQRCode(text, errorCorrectionLevel = errorCorrectionLevel)
if (bitmap == null) { if (bitmap == null) {
toastOnUi(R.string.text_too_long_qr_error) toastOnUi(R.string.text_too_long_qr_error)
} else { } else {

@ -28,7 +28,7 @@ object QRCodeUtils {
* @param heightPix 二维码的高 * @param heightPix 二维码的高
* @param logo 二维码中间的logo * @param logo 二维码中间的logo
* @param ratio logo所占比例 因为二维码的最大容错率为30%所以建议ratio的范围小于0.3 * @param ratio logo所占比例 因为二维码的最大容错率为30%所以建议ratio的范围小于0.3
* @return * @param errorCorrectionLevel
*/ */
fun createQRCode( fun createQRCode(
content: String, content: String,

Loading…
Cancel
Save