Skip to content

Commit

Permalink
enhance function
Browse files Browse the repository at this point in the history
  • Loading branch information
daisukiKaffuChino committed Feb 21, 2024
1 parent 96ed797 commit ae6f192
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "github.daisukiKaffuChino.MomoQR"
minSdk 26
targetSdk 34
versionCode 1
versionName "1.0"
versionCode 240221
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -25,7 +25,7 @@ android {
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand Down
33 changes: 13 additions & 20 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
-keep class **.R$* { *; }
-keep class com.jph.android.entity.** { *; } #实体类不参与混淆
-keep class com.jph.android.view.** { *; } #自定义控件不参与混淆
-keep class github.daisukiKaffuChino.MomoQR.logic.bean.** { *; }
-keepattributes Signature
-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.google.zxing.** {*;}
-dontwarn com.google.zxing.**
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
android:launchMode="singleTop"
android:screenOrientation="fullSensor" />

<activity android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:enabled="false"/>

<service
android:name=".service.ScanTileService"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package github.daisukiKaffuChino.MomoQR.logic.utils

import android.content.ContentResolver
import android.content.ContentValues
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import android.widget.Toast
import androidx.annotation.ColorInt
import com.google.zxing.BarcodeFormat
import com.google.zxing.BinaryBitmap
Expand Down Expand Up @@ -177,4 +182,35 @@ object QRCodeUtil {
}
return bitmap
}

fun saveBitmap(context: Context, bitmap: Bitmap) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val nowTime = System.currentTimeMillis()
val displayName = "QR$nowTime.png"
val values = ContentValues()
values.put(MediaStore.MediaColumns.DISPLAY_NAME, displayName)
values.put(MediaStore.MediaColumns.MIME_TYPE, "image/png")
values.put(
MediaStore.MediaColumns.RELATIVE_PATH,
Environment.DIRECTORY_PICTURES + "/MomoQR"
)
val uri =
context.contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
if (uri != null) {
val outputStream = context.contentResolver.openOutputStream(uri)
if (outputStream != null) {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
outputStream.close()
Toast.makeText(
context,
"Saved:\n/Pictures/MomoQR/$displayName",
Toast.LENGTH_SHORT
).show()
}
}
} else {
//TODO
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
binding.addFavBtn.setOnClickListener(v -> showEditTextDialog(EDITTEXT_DIALOG_FAV_TITLE));
binding.openLinkBtn.setOnClickListener(v ->
MyUtil.detectIntentAndStart(viewModel.contentLiveData.getValue()));

binding.remakeCodeImg.setOnLongClickListener(v -> {
v.setDrawingCacheEnabled(true);
QRCodeUtil.INSTANCE.saveBitmap(requireContext(), v.getDrawingCache());
v.setDrawingCacheEnabled(false);
return true;
});
viewModel.contentLiveData.observe(getViewLifecycleOwner(), result -> {
if (result != null & viewModel.isScanned) {
showScanResults(result, false);
Expand Down

0 comments on commit ae6f192

Please sign in to comment.