Commit d62a59ba authored by wanglei's avatar wanglei

...

parent 76efc9b1
......@@ -198,7 +198,7 @@ class CreateFragment : BaseFragment<FragmentCreateBinding>(FragmentCreateBinding
@SuppressLint("NotifyDataSetChanged")
private fun itemKeyClick(key: String) {
val bean = functions1.find { it.key == key }
val bean = functions1.find { it.key == key } ?: functions2.find { it.key == key }
if (bean?.isPlaying == true) {
bean.showGuide = false
AppPreferences.getInstance().put("${key}_guide", false)
......@@ -245,41 +245,57 @@ class CreateFragment : BaseFragment<FragmentCreateBinding>(FragmentCreateBinding
KEY_WHATSAPP -> {
val activity = requireActivity() as MainActivity?
activity?.showWhatsappDialog(activity.launcher)
functionRvAdapter2?.functionAdapter?.changeGuide()
}
KEY_FACEBOOK -> {
val activity = requireActivity() as MainActivity?
activity?.showFacebookDialog()
functionRvAdapter2?.functionAdapter?.changeGuide()
}
KEY_INSTAGRAM -> {
val activity = requireActivity() as MainActivity?
activity?.showInstagramDialog()
functionRvAdapter2?.functionAdapter?.changeGuide()
}
KEY_X -> {
val activity = requireActivity() as MainActivity?
activity?.showXDialog()
functionRvAdapter2?.functionAdapter?.changeGuide()
}
KEY_PAYPAL -> {
val activity = requireActivity() as MainActivity?
activity?.showPaypalDialog()
functionRvAdapter2?.functionAdapter?.changeGuide()
}
KEY_SPOTIFY -> {
val activity = requireActivity() as MainActivity?
activity?.showSpotifyDialog()
functionRvAdapter2?.functionAdapter?.changeGuide()
}
KEY_YOUTUBE -> {
val activity = requireActivity() as MainActivity?
activity?.showYoutubeDialog()
functionRvAdapter2?.functionAdapter?.changeGuide()
}
KEY_ADDRESS -> {
val activity = requireActivity() as MainActivity?
activity?.showAddressDialog()
functionRvAdapter2?.functionAdapter?.changeGuide()
}
}
}
......
package com.base.scanqrclear.ui.scan
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Environment
import androidx.activity.addCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.updatePadding
import com.base.scanqrclear.R
import com.base.scanqrclear.ads.AdsMgr
import com.base.scanqrclear.ads.AdsShowCallBack
import com.base.scanqrclear.base.BaseActivity
import com.base.scanqrclear.bean.config.AdConfigBean
import com.base.scanqrclear.databinding.ActivityPdfResultBinding
import com.base.scanqrclear.luma.FileHelps.deleteIfExists
import com.base.scanqrclear.ui.widget.HintDialog.showHintDialog
import com.base.scanqrclear.utils.BarUtils
import com.base.scanqrclear.utils.LogEx
import com.base.scanqrclear.utils.ToastUtils.toast
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
import com.google.mlkit.vision.documentscanner.GmsDocumentScannerOptions
import com.google.mlkit.vision.documentscanner.GmsDocumentScannerOptions.RESULT_FORMAT_JPEG
import com.google.mlkit.vision.documentscanner.GmsDocumentScannerOptions.RESULT_FORMAT_PDF
import com.google.mlkit.vision.documentscanner.GmsDocumentScannerOptions.SCANNER_MODE_FULL
import com.google.mlkit.vision.documentscanner.GmsDocumentScanning
import com.google.mlkit.vision.documentscanner.GmsDocumentScanningResult
import com.gyf.immersionbar.ktx.immersionBar
import java.io.File
class PdfResultActivity : BaseActivity<ActivityPdfResultBinding>(ActivityPdfResultBinding::inflate) {
private var uri: String = ""
private var scannerLauncher: ActivityResultLauncher<IntentSenderRequest>? = null
override fun initView() {
super.initView()
binding.clTop.updatePadding(top = BarUtils.getStatusBarHeight())
initScannerLauncher()
uri = intent.extras?.getString("uri") ?: ""
val name = uri.split("/").last()
binding.tvPdfName.text = name
......@@ -28,11 +53,73 @@ class PdfResultActivity : BaseActivity<ActivityPdfResultBinding>(ActivityPdfResu
override fun initListener() {
super.initListener()
onBackPressedDispatcher.addCallback {
finish()
if (AdConfigBean.adsConfigBean.functionBackShowAd) {
AdsMgr.showInsert(this@PdfResultActivity, false, object : AdsShowCallBack() {
override fun close(where: Int) {
finishToMainTop()
}
override fun failed(where: Int) {
finishToMainTop()
}
override fun googleFailed(where: Int) {
finishToMainTop()
}
})
}
}
binding.flBack.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.tvExit.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
binding.llDelete.setOnClickListener {
showHintDialog(
getString(R.string.do_you_want_to_delete_this_pdf)
) {
// file:///data/user/0/com.tool.advanced.cleaner/cache/mlkit_docscan_ui_client/268059987162265.pdf
val file = File(uri.replace("file://", ""))
val flag = file.deleteIfExists()
LogEx.logDebug(TAG, "flag=$flag uri=$uri")
if (flag) {
toast("Delete Success!", true)
}
finishToMainTop()
}
}
binding.llSavePdf.setOnClickListener {
val file = File(uri.replace("file://", ""))
val copyFile = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), file.name)
Thread {
val resultFile = file.copyTo(copyFile)
val flag = resultFile.exists()
LogEx.logDebug(TAG, "flag=$flag resultFile=$resultFile")
if (flag) {
runOnUiThread {
toast("Save pdf success!", true)
}
}
}.start()
}
binding.tvRescan.setOnClickListener {
val options = GmsDocumentScannerOptions.Builder()
.setGalleryImportAllowed(true)
// .setPageLimit(2)
.setResultFormats(RESULT_FORMAT_JPEG, RESULT_FORMAT_PDF)
.setScannerMode(SCANNER_MODE_FULL)
.build()
val scanner = GmsDocumentScanning.getClient(options)
scanner.getStartScanIntent(this)
.addOnSuccessListener { intentSender ->
scannerLauncher?.launch(IntentSenderRequest.Builder(intentSender).build())
}
.addOnFailureListener {
toast("Don't support GmsDocumentScanner", true)
}
}
}
private fun displayFromUri(uri: String) {
......@@ -55,4 +142,28 @@ class PdfResultActivity : BaseActivity<ActivityPdfResultBinding>(ActivityPdfResu
}
}
private fun initScannerLauncher() {
scannerLauncher = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result ->
if (result.resultCode == RESULT_OK) {
val data = GmsDocumentScanningResult.fromActivityResultIntent(result.data)
data?.pages?.forEach { page ->
val imageUri = page.imageUri
// imageUri=file:///data/user/0/com.tool.advanced.cleaner/cache/mlkit_docscan_ui_client/268059886691727.jpg
LogEx.logDebug(TAG, "imageUri=$imageUri")
}
val pdfUri = data?.pdf?.uri
val pdfPageCount = data?.pdf?.pageCount
LogEx.logDebug(TAG, "pdfUri=$pdfUri")
// pdfUri=file:///data/user/0/com.tool.advanced.cleaner/cache/mlkit_docscan_ui_client/268059987162265.pdf
LogEx.logDebug(TAG, "pdfPageCount=$pdfPageCount")
startActivity(Intent(this, PdfResultActivity::class.java).apply {
putExtra("uri", pdfUri.toString())
})
}
}
}
}
\ No newline at end of file
......@@ -48,10 +48,10 @@ class ScanOtherActivity : BaseActivity<ActivityScanOtherBinding>(ActivityScanOth
adapter.submitList(
listOf(
FunctionUIBean(KEY_FOOD, R.mipmap.foodscan, getString(R.string.food_scan)),
FunctionUIBean(KEY_COIN, R.mipmap.coinscan, getString(R.string.coin_scan)),
FunctionUIBean(KEY_BANKNOTE, R.mipmap.banknote, getString(R.string.banknote_scan)),
// FunctionUIBean(KEY_COIN, R.mipmap.coinscan, getString(R.string.coin_scan)),
// FunctionUIBean(KEY_BANKNOTE, R.mipmap.banknote, getString(R.string.banknote_scan)),
FunctionUIBean(KEY_DOCUMENT, R.mipmap.document, getString(R.string.document_scan)),
FunctionUIBean(KEY_BUSINESS_CARD, R.mipmap.business, getString(R.string.business_card))
// FunctionUIBean(KEY_BUSINESS_CARD, R.mipmap.business, getString(R.string.business_card))
),
)
adapter.itemClick = { item ->
......
......@@ -11,6 +11,7 @@ import com.base.scanqrclear.databinding.DialogHintBinding
object HintDialog {
fun Activity.showHintDialog(
content:String?=null,
confirm: () -> Unit
) {
val dialog = AlertDialog.Builder(this).create()
......@@ -29,6 +30,9 @@ object HintDialog {
params?.height = FrameLayout.LayoutParams.WRAP_CONTENT
params?.gravity = Gravity.TOP
content?.let {
binding.tvContent.text=it
}
binding.tvBtn1.setOnClickListener {
dialog.dismiss()
}
......
......@@ -69,6 +69,7 @@
tools:ignore="DisableBaselineAlignment">
<LinearLayout
android:id="@+id/llSavePdf"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
......@@ -80,7 +81,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginVertical="10dp"
android:src="@mipmap/replace"
android:src="@mipmap/save_pdf"
tools:ignore="ContentDescription" />
<TextView
......@@ -89,7 +90,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12dp"
android:includeFontPadding="false"
android:text="@string/replace_style"
android:text="Save to PDF"
android:textColor="@color/black"
android:textSize="12sp" />
......@@ -100,6 +101,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="gone"
tools:ignore="UseCompoundDrawables">
<ImageView
......@@ -127,6 +129,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="gone"
tools:ignore="UseCompoundDrawables">
<ImageView
......@@ -150,6 +153,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/llDelete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
......@@ -190,27 +194,27 @@
app:layout_constraintTop_toBottomOf="@id/ll">
<TextView
android:id="@+id/tvShare"
android:id="@+id/tvExit"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:background="@drawable/bg_f3f3f5_80"
android:gravity="center"
android:text="@string/share"
android:text="@string/exit"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvSave"
android:id="@+id/tvRescan"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:background="@drawable/bg_6473f8_80"
android:gravity="center"
android:text="@string/save_to_album"
android:text="@string/rescan"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold" />
......
......@@ -18,6 +18,7 @@
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/tvContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
......
......@@ -49,7 +49,6 @@
app:layout_constraintTop_toTopOf="@id/tv_weather" />
<!-- <ImageView-->
<!-- android:id="@+id/ivVip"-->
<!-- android:layout_width="wrap_content"-->
......
......@@ -294,5 +294,7 @@
<string name="vertical_version">Vertical Version</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="rescan">Rescan</string>
<string name="do_you_want_to_delete_this_pdf">Do you want to delete this pdf?</string>
</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