Sfoglia il codice sorgente

Show screenshot in ExportPdfDialog

Wayne 6 anni fa
parent
commit
22993bfc83

+ 31 - 2
src/main/java/com/bomostory/sceneeditmodule/share/ExportPdfDialog.kt

@@ -1,5 +1,8 @@
 package com.bomostory.sceneeditmodule.share
 
+import android.content.Context
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
 import android.os.Bundle
 import android.support.v4.app.DialogFragment
 import android.support.v4.app.FragmentManager
@@ -7,7 +10,6 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import com.example.tfat.myapplication.R
-import com.squareup.picasso.Picasso
 import kotlinx.android.synthetic.main.dialog_export_pdf.view.*
 
 class ExportPdfDialog : DialogFragment() {
@@ -41,18 +43,45 @@ class ExportPdfDialog : DialogFragment() {
             btn_exportPdfDialog_cancel.setOnClickListener { this@ExportPdfDialog.dismiss() }
             btn_exportPdfDialog_print.setOnClickListener { onClickPrint.run() }
             if (image1Path != "") {
+                val bitmap = decodeImage(context, image1Path)
+                iv_exportPdfDialog_standard_1.setImageBitmap(bitmap)
+                // Picasso not work, don't know why
+                /*
                 Picasso.get().load(image1Path).into(iv_exportPdfDialog_standard_1)
-                Picasso.get().load(image1Path).into(iv_exportPdfDialog_foldableBooklet_1)
+                */
             }
             if (image2Path != "") {
+                val bitmap = decodeImage(context, image2Path)
+                iv_exportPdfDialog_standard_2.setImageBitmap(bitmap)
+                // Picasso not work, don't know why
+                /*
                 Picasso.get().load(image2Path).into(iv_exportPdfDialog_standard_2)
+                */
             }
             if (image3Path != "") {
+                val bitmap = decodeImage(context, image3Path)
+                iv_exportPdfDialog_standard_3.setImageBitmap(bitmap)
+                // Picasso not work, don't know why
+                /*
                 Picasso.get().load(image3Path).into(iv_exportPdfDialog_standard_3)
+                */
             }
         }
     }
 
+    private fun decodeImage(context: Context, imgPath: String): Bitmap {
+        val options = BitmapFactory.Options().apply {
+            inJustDecodeBounds = true
+        }
+        BitmapFactory.decodeFile(imgPath, options)
+        options.apply {
+            inJustDecodeBounds = false
+            val viewWidth = context.resources.getDimension(R.dimen.export_pdf_screenshot_width)
+            inSampleSize = (outWidth / viewWidth).toInt()
+        }
+        return BitmapFactory.decodeFile(imgPath, options)
+    }
+
     fun show(manager: FragmentManager?) {
         manager?.apply {
             val ft = beginTransaction()

+ 10 - 8
src/main/res/layout/dialog_export_pdf.xml

@@ -52,8 +52,10 @@
 
     <ImageView
         android:id="@+id/iv_exportPdfDialog_standard_1"
-        android:layout_width="144dp"
-        android:layout_height="72dp"
+        android:layout_width="@dimen/export_pdf_screenshot_width"
+        android:layout_height="@dimen/export_pdf_screenshot_height"
+        android:background="#33AA00"
+        android:src="#111111"
         android:layout_marginTop="24dp"
         android:scaleType="centerCrop"
         app:layout_constraintLeft_toLeftOf="@id/tv_exportPdfDialog_standard"
@@ -61,8 +63,8 @@
 
     <ImageView
         android:id="@+id/iv_exportPdfDialog_standard_2"
-        android:layout_width="144dp"
-        android:layout_height="72dp"
+        android:layout_width="@dimen/export_pdf_screenshot_width"
+        android:layout_height="@dimen/export_pdf_screenshot_height"
         android:layout_marginLeft="16dp"
         android:scaleType="centerCrop"
         app:layout_constraintLeft_toRightOf="@id/iv_exportPdfDialog_standard_1"
@@ -70,8 +72,8 @@
 
     <ImageView
         android:id="@+id/iv_exportPdfDialog_standard_3"
-        android:layout_width="144dp"
-        android:layout_height="72dp"
+        android:layout_width="@dimen/export_pdf_screenshot_width"
+        android:layout_height="@dimen/export_pdf_screenshot_height"
         android:layout_marginLeft="16dp"
         android:scaleType="centerCrop"
         app:layout_constraintLeft_toRightOf="@id/iv_exportPdfDialog_standard_2"
@@ -101,8 +103,8 @@
 
     <ImageView
         android:id="@+id/iv_exportPdfDialog_foldableBooklet_1"
-        android:layout_width="144dp"
-        android:layout_height="72dp"
+        android:layout_width="@dimen/export_pdf_screenshot_width"
+        android:layout_height="@dimen/export_pdf_screenshot_height"
         android:layout_marginTop="24dp"
         android:scaleType="centerCrop"
         app:layout_constraintLeft_toLeftOf="@id/tv_exportPdfDialog_foldableBooklet"

+ 3 - 0
src/main/res/values/dimens.xml

@@ -14,4 +14,7 @@
 
     <dimen name="cover_editor_dialog_width">800dp</dimen>
     <dimen name="cover_editor_dialog_height">544dp</dimen>
+
+    <dimen name="export_pdf_screenshot_width">144dp</dimen>
+    <dimen name="export_pdf_screenshot_height">72dp</dimen>
 </resources>