Aperture: Add golden ratio grid mode
Change-Id: I425dfb98f20c879c82585618265d2debbf8984fd
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index 1e26a44..cb11989 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -566,6 +566,7 @@
GridMode.OFF -> R.drawable.ic_grid_off
GridMode.ON_3 -> R.drawable.ic_grid_on_3
GridMode.ON_4 -> R.drawable.ic_grid_on_4
+ GridMode.ON_GOLDENRATIO -> R.drawable.ic_grid_on_goldenratio
}
)
)
@@ -578,17 +579,14 @@
sharedPreferences.lastGridMode = when (sharedPreferences.lastGridMode) {
GridMode.OFF -> GridMode.ON_3
GridMode.ON_3 -> GridMode.ON_4
- GridMode.ON_4 -> GridMode.OFF
+ GridMode.ON_4 -> GridMode.ON_GOLDENRATIO
+ GridMode.ON_GOLDENRATIO -> GridMode.OFF
}
setGridMode(sharedPreferences.lastGridMode)
}
private fun setGridMode(gridMode: GridMode) {
- gridView.size = when (gridMode) {
- GridMode.OFF -> 0
- GridMode.ON_3 -> 3
- GridMode.ON_4 -> 4
- }
+ gridView.mode = gridMode
updateGridIcon()
}
diff --git a/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt b/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt
index 9c85591..8f91b87 100644
--- a/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt
+++ b/app/src/main/java/org/lineageos/aperture/SharedPreferencesExt.kt
@@ -93,6 +93,7 @@
"off" -> GridMode.OFF
"on_3" -> GridMode.ON_3
"on_4" -> GridMode.ON_4
+ "on_goldenratio" -> GridMode.ON_GOLDENRATIO
// Default to off
else -> GridMode.OFF
}
@@ -104,6 +105,7 @@
GridMode.OFF -> "off"
GridMode.ON_3 -> "on_3"
GridMode.ON_4 -> "on_4"
+ GridMode.ON_GOLDENRATIO -> "on_goldenratio"
}
)
}
diff --git a/app/src/main/java/org/lineageos/aperture/ui/GridView.kt b/app/src/main/java/org/lineageos/aperture/ui/GridView.kt
index ad6e140..b1d4244 100644
--- a/app/src/main/java/org/lineageos/aperture/ui/GridView.kt
+++ b/app/src/main/java/org/lineageos/aperture/ui/GridView.kt
@@ -12,6 +12,7 @@
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
+import org.lineageos.aperture.utils.GridMode
/**
* A simple view that shows a 3x3 grid
@@ -19,7 +20,7 @@
class GridView(context: Context?, attributeSet: AttributeSet?) : View(context, attributeSet) {
private val paint: Paint = Paint()
- var size = 0
+ var mode: GridMode = GridMode.OFF
set(value) {
field = value
invalidate()
@@ -35,6 +36,13 @@
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
+ val size = when (mode) {
+ GridMode.OFF -> 0
+ GridMode.ON_3 -> 3
+ GridMode.ON_4 -> 4
+ GridMode.ON_GOLDENRATIO -> 3
+ }
+
if (size <= 0) {
return
}
@@ -42,12 +50,29 @@
val width = width.toFloat()
val height = height.toFloat()
- val widthSection = (width / size)
- val heightSection = (height / size)
+ val unitDiv = if (mode == GridMode.ON_GOLDENRATIO) GOLDEN_RATIO_UNIT else size.toFloat()
+
+ val widthSection = width / unitDiv
+ val heightSection = height / unitDiv
for (i in size - 1 downTo 1) {
- canvas.drawLine(widthSection * i, 0F, widthSection * i, height, paint)
- canvas.drawLine(0F, heightSection * i, width, heightSection * i, paint)
+ val position =
+ if (mode == GridMode.ON_GOLDENRATIO && i == 2) 1 + GOLDEN_RATIO
+ else i.toFloat()
+
+ canvas.drawLine(
+ widthSection * position, 0F,
+ widthSection * position, height, paint
+ )
+ canvas.drawLine(
+ 0F, heightSection * position,
+ width, heightSection * position, paint
+ )
}
}
+
+ companion object {
+ private const val GOLDEN_RATIO = 0.618f
+ private const val GOLDEN_RATIO_UNIT = 2 + GOLDEN_RATIO
+ }
}
diff --git a/app/src/main/java/org/lineageos/aperture/utils/GridMode.kt b/app/src/main/java/org/lineageos/aperture/utils/GridMode.kt
index 4736bc9..8fa7fc4 100644
--- a/app/src/main/java/org/lineageos/aperture/utils/GridMode.kt
+++ b/app/src/main/java/org/lineageos/aperture/utils/GridMode.kt
@@ -10,4 +10,5 @@
OFF,
ON_3,
ON_4,
+ ON_GOLDENRATIO,
}
diff --git a/app/src/main/res/drawable/ic_grid_on_goldenratio.xml b/app/src/main/res/drawable/ic_grid_on_goldenratio.xml
new file mode 100644
index 0000000..05f3476
--- /dev/null
+++ b/app/src/main/res/drawable/ic_grid_on_goldenratio.xml
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="#000000"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M22,11V9h-7V2h-2v7h-2V2H9v7H2v2h7v2H2v2h7v7h2v-7h2v7h2v-7h7v-2h-7v-2H22zM13,13h-2v-2h2V13z" />
+</vector>