Forráskód Böngészése

Implement FAKE Ad

cooperku_kdanmobile 5 éve
szülő
commit
2ed00a59f6

+ 1 - 1
PDFReaderReaderModule

@@ -1 +1 @@
-Subproject commit 65675f9354b56f0a8ddb6290ce59664760fc2113
+Subproject commit bbcb6fcdb5f5e046c31170a843732a0bbfc1b7e2

+ 29 - 1
app/src/main/java/com/kdanmobile/pdfreaderviewapp/MyReaderActivity.kt

@@ -2,8 +2,15 @@ package com.kdanmobile.pdfreaderviewapp
 
 import android.content.Context
 import android.os.Bundle
+import android.widget.ImageView
+import android.widget.Toast
+import com.kdanmobile.kmpdfkit.manager.KMPDFFactory
+import com.kdanmobile.kmpdfkit.pdfcommon.FilePicker
+import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFPageAdapter
 import com.kdanmobile.reader.ReaderActivity
+import com.kdanmobile.reader.adpage.AbstractPageAdapter
 import com.kdanmobile.reader.setting.ReaderSettingDialogFragment
+import com.kdanmobile.reader.adpage.MyPageView
 import com.kdanmobile.reader.thumb.PdfThumbDialogFragment
 
 class MyReaderActivity : ReaderActivity() {
@@ -66,10 +73,31 @@ class MyReaderActivity : ReaderActivity() {
     }
 
     companion object {
-        val KEY_FILE_ABSOLUTE = ReaderActivity.KEY_FILE_ABSOLUTE
+        const val KEY_FILE_ABSOLUTE = ReaderActivity.KEY_FILE_ABSOLUTE
     }
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
+        //  廣告已讀取完畢
+        adPageHelper.isAdLoaded = {
+            true
+        }
+    }
+
+    override fun providePdfPageAdapter(context: Context, filePickerSupport: FilePicker.FilePickerSupport, kmpdfFactory: KMPDFFactory): KMPDFPageAdapter {
+        return object : AbstractPageAdapter(context, filePickerSupport, kmpdfFactory, adPageHelper) {
+            override fun setupViewContent(position: Int, pageView: MyPageView) {
+                //  建立假廣告頁面
+                val imageView = ImageView(context)
+                imageView.setBackgroundResource(R.drawable.pic_test_ad)
+                imageView.scaleType = ImageView.ScaleType.FIT_CENTER
+                pageView.layout.addView(imageView)
+
+                //  假廣告的點擊事件
+                imageView.setOnClickListener {
+                    Toast.makeText(context, "[$position][${pageView.page}] TEST", Toast.LENGTH_SHORT).show()
+                }
+            }
+        }
     }
 }

BIN
app/src/main/res/drawable/pic_test_ad.png