Dynamic zoom chips

This commit is contained in:
Luke Hubmayer-Werner 2024-08-26 21:45:46 +09:30
parent 04a64bd621
commit cefa7ad82d
2 changed files with 11 additions and 89 deletions

View File

@ -24,6 +24,7 @@ import androidx.drawerlayout.widget.DrawerLayout
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import com.google.android.material.chip.Chip
import com.lhw.pdf.databinding.ActivityMainBinding import com.lhw.pdf.databinding.ActivityMainBinding
import com.tom_roush.pdfbox.android.PDFBoxResourceLoader import com.tom_roush.pdfbox.android.PDFBoxResourceLoader
import java.io.File import java.io.File
@ -195,17 +196,16 @@ class MainActivity : AppCompatActivity() {
presentations.values.forEach {it.setScrollProgress(progress)} presentations.values.forEach {it.setScrollProgress(progress)}
} }
binding.appBarMain.contentMain.chipPages1.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 1F } val pageZoomLevels = arrayOf(1F, 1.5F, 2F, 2.5F, 3F, 3.5F, 4F, 5F, 6F, 8F, 10F)
binding.appBarMain.contentMain.chipPages15.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 1.5F } val chipGroupPages = binding.appBarMain.contentMain.chipGroupPages
binding.appBarMain.contentMain.chipPages2.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 2F } pageZoomLevels.forEach { pages ->
binding.appBarMain.contentMain.chipPages25.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 2.5F } val chip = Chip(this)
binding.appBarMain.contentMain.chipPages3.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 3F } chip.text = "$pages pages"
binding.appBarMain.contentMain.chipPages35.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 3.5F } chip.isCheckable = true
binding.appBarMain.contentMain.chipPages4.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 4F } chip.isChecked = (pages == pagesPerLandscape)
binding.appBarMain.contentMain.chipPages5.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 5F } chip.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = pages }
binding.appBarMain.contentMain.chipPages6.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 6F } chipGroupPages.addView(chip)
binding.appBarMain.contentMain.chipPages8.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 8F } }
binding.appBarMain.contentMain.chipPages10.setOnCheckedChangeListener { _, checked -> if (checked) pagesPerLandscape = 10F }
binding.appBarMain.contentMain.chipAutoCrop.setOnCheckedChangeListener { _, checked -> binding.appBarMain.contentMain.chipAutoCrop.setOnCheckedChangeListener { _, checked ->
renderAutoCrop = checked renderAutoCrop = checked
updatePresentations() updatePresentations()

View File

@ -67,84 +67,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"> android:layout_weight="1">
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_1"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 page" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_1.5"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.5 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_2"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_2.5"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2.5 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_3"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="3 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_3.5"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3.5 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_4"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_5"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_6"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_8"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8 pages" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_pages_10"
android:checkable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 pages" />
</com.google.android.material.chip.ChipGroup> </com.google.android.material.chip.ChipGroup>
<com.google.android.material.chip.ChipGroup <com.google.android.material.chip.ChipGroup