Ver código fonte

Show cover in ExportPdfDialog

Wayne 6 anos atrás
pai
commit
b384cd6a40

+ 4 - 1
src/main/java/com/bomostory/sceneeditmodule/CoverDrawer.kt

@@ -5,10 +5,13 @@ import android.graphics.*
 import com.example.tfat.myapplication.R
 
 object CoverDrawer {
+    private const val DEFAULT_HEIGHT = 1080f
+
     fun drawFrontCover(width: Int, height: Int, name: String, coverColor: Int): Bitmap {
+        val scale = height.toFloat() / DEFAULT_HEIGHT
         val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
             color = Color.WHITE
-            textSize = 100f
+            textSize = 100f * scale
             textAlign = Paint.Align.CENTER
             flags += Paint.FAKE_BOLD_TEXT_FLAG
         }

+ 1 - 0
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt

@@ -429,6 +429,7 @@ class MovieEditActivity : AppCompatActivity(),
 
     private fun onClickExportPdf() {
         ExportPdfDialog().also { exportPdfDialog ->
+            exportPdfDialog.project = viewModel.project!!
             exportPdfDialog.image1Path = viewModel.project?.scene1File?.path ?: ""
             exportPdfDialog.image2Path = viewModel.project?.scene2File?.path ?: ""
             exportPdfDialog.onClickPrint = Runnable {

+ 20 - 0
src/main/java/com/bomostory/sceneeditmodule/share/ExportPdfDialog.kt

@@ -9,6 +9,8 @@ import android.support.v4.app.FragmentManager
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import com.bomostory.sceneeditmodule.CoverDrawer
+import com.bomostory.sceneeditmodule.basicdata.Project
 import com.example.tfat.myapplication.R
 import kotlinx.android.synthetic.main.dialog_export_pdf.view.*
 
@@ -20,6 +22,7 @@ class ExportPdfDialog : DialogFragment() {
         Booklet,
     }
 
+    lateinit var project: Project
     var image1Path = ""
     var image2Path = ""
     var image3Path = ""
@@ -66,9 +69,26 @@ class ExportPdfDialog : DialogFragment() {
                 Picasso.get().load(image3Path).into(iv_exportPdfDialog_standard_3)
                 */
             }
+            iv_exportPdfDialog_foldableBookletCoverFront.setImageBitmap(createFrontCover(context))
+            iv_exportPdfDialog_foldableBookletCoverBack.setImageBitmap(createBackCover(context))
         }
     }
 
+    private fun createFrontCover(context: Context): Bitmap {
+        val width = context.resources.getDimension(R.dimen.export_pdf_cover_width).toInt()
+        val height = context.resources.getDimension(R.dimen.export_pdf_cover_height).toInt()
+        val name = project.name ?: ""
+        val color = project.frontCoverColor.getColor(context)
+        return CoverDrawer.drawFrontCover(width, height, name, color)
+    }
+
+    private fun createBackCover(context: Context): Bitmap {
+        val width = context.resources.getDimension(R.dimen.export_pdf_cover_width).toInt()
+        val height = context.resources.getDimension(R.dimen.export_pdf_cover_height).toInt()
+        val color = project.backCoverColor.getColor(context)
+        return CoverDrawer.drawBackCover(context, width, height, color)
+    }
+
     private fun decodeImage(context: Context, imgPath: String): Bitmap {
         val options = BitmapFactory.Options().apply {
             inJustDecodeBounds = true

+ 8 - 0
src/main/res/drawable/border_dotted_line_cooa_1dp.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <stroke
+        android:width="2dp"
+        android:color="@color/cocoa"
+        android:dashWidth="10px"
+        android:dashGap="10px" />
+</shape>

+ 15 - 4
src/main/res/layout/dialog_export_pdf.xml

@@ -102,14 +102,25 @@
         app:layout_constraintTop_toTopOf="@id/rb_exportPdfDialog_foldableBooklet" />
 
     <ImageView
-        android:id="@+id/iv_exportPdfDialog_foldableBooklet_1"
-        android:layout_width="@dimen/export_pdf_screenshot_width"
+        android:id="@+id/iv_exportPdfDialog_foldableBookletCoverFront"
+        android:layout_width="@dimen/export_pdf_cover_width"
+        android:foreground="@drawable/border_dotted_line_cooa_1dp"
         android:layout_height="@dimen/export_pdf_screenshot_height"
         android:layout_marginTop="24dp"
         android:scaleType="centerCrop"
         app:layout_constraintLeft_toLeftOf="@id/tv_exportPdfDialog_foldableBooklet"
         app:layout_constraintTop_toBottomOf="@id/tv_exportPdfDialog_foldableBooklet" />
 
+    <ImageView
+        android:id="@+id/iv_exportPdfDialog_foldableBookletCoverBack"
+        android:layout_width="@dimen/export_pdf_cover_width"
+        android:layout_height="@dimen/export_pdf_screenshot_height"
+        android:foreground="@drawable/border_dotted_line_cooa_1dp"
+        android:scaleType="centerCrop"
+        app:layout_constraintBottom_toBottomOf="@id/iv_exportPdfDialog_foldableBookletCoverFront"
+        app:layout_constraintLeft_toRightOf="@id/iv_exportPdfDialog_foldableBookletCoverFront"
+        app:layout_constraintTop_toTopOf="@id/iv_exportPdfDialog_foldableBookletCoverFront" />
+
     <ImageView
         android:id="@+id/iv_exportPdfDialog_foldableBooklet_2"
         android:layout_width="488dp"
@@ -118,9 +129,9 @@
         android:layout_marginRight="40dp"
         android:scaleType="centerCrop"
         android:src="@drawable/ic_img_foldable"
-        app:layout_constraintLeft_toRightOf="@id/iv_exportPdfDialog_foldableBooklet_1"
+        app:layout_constraintLeft_toRightOf="@id/iv_exportPdfDialog_foldableBookletCoverBack"
         app:layout_constraintRight_toRightOf="parent"
-        app:layout_constraintTop_toTopOf="@id/iv_exportPdfDialog_foldableBooklet_1" />
+        app:layout_constraintTop_toTopOf="@id/iv_exportPdfDialog_foldableBookletCoverBack" />
     <Button
         android:id="@+id/btn_exportPdfDialog_print"
         style="@style/Widget.AppCompat.Button.Borderless.Colored"

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

@@ -17,4 +17,6 @@
 
     <dimen name="export_pdf_screenshot_width">144dp</dimen>
     <dimen name="export_pdf_screenshot_height">72dp</dimen>
+    <dimen name="export_pdf_cover_width">72dp</dimen>
+    <dimen name="export_pdf_cover_height">72dp</dimen>
 </resources>