diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef3..b161e6f 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -2,7 +2,7 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/fiboBGAndroid/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/fiboBGAndroid/ExampleInstrumentedTest.kt index 8abb4a5..8b9eaa6 100644 --- a/app/src/androidTest/java/com/example/fiboBGAndroid/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/example/fiboBGAndroid/ExampleInstrumentedTest.kt @@ -19,6 +19,6 @@ class ExampleInstrumentedTest { fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.example.emptyviews", appContext.packageName) + assertEquals("com.example.fiboBGAndroid", appContext.packageName) } } \ No newline at end of file diff --git a/app/src/main/java/com/example/fiboBGAndroid/MainActivity.kt b/app/src/main/java/com/example/fiboBGAndroid/MainActivity.kt index 12fc4a5..b786f6a 100644 --- a/app/src/main/java/com/example/fiboBGAndroid/MainActivity.kt +++ b/app/src/main/java/com/example/fiboBGAndroid/MainActivity.kt @@ -1,3 +1,4 @@ +@file:Suppress("SpellCheckingInspection") package com.example.fiboBGAndroid @@ -10,7 +11,6 @@ import android.icu.util.GregorianCalendar import android.os.Bundle import android.view.View import android.widget.Button -import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity @@ -21,15 +21,10 @@ import kotlin.random.Random class MainActivity : AppCompatActivity() { - class counter { - var times: Int = 0 - } - val times = counter() - lateinit var myButton: Button - lateinit var myText: TextView - lateinit var mainLayout: ConstraintLayout - lateinit var canvasview: View + private lateinit var myButton: Button + private lateinit var mainLayout: ConstraintLayout + private lateinit var canvasview: View override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() @@ -40,23 +35,17 @@ class MainActivity : AppCompatActivity() { insets } myButton = findViewById(R.id.button) - myText = findViewById(R.id.textView) mainLayout = findViewById(R.id.main) canvasview = findViewById(R.id.view) myButton.setOnClickListener { - csacsi(myText, times, mainLayout, canvasview) + csacsi(mainLayout, canvasview) } } - private fun csacsi (tv: TextView, numb: counter, m: ConstraintLayout, cv: View) { - numb.times++ - val nu = numb.times + private fun csacsi (m: ConstraintLayout, cv: View) { val colors = List(3) { Random.nextInt(0,255)} val color = Color.rgb(colors[0],colors[1],colors[2]) - //m.setBackgroundColor(color) m.background= CustomDrawable(color, cv) - val text ="You pressed the button $nu.times times(${colors[0]})" - tv.text = text } } @@ -65,8 +54,6 @@ class MainActivity : AppCompatActivity() { class CustomDrawable(col: Int, private val v: View) : Drawable() { private val paint = Paint() - var color = paint.color - init { paint.color = col // Set your custom color } @@ -74,8 +61,8 @@ class CustomDrawable(col: Int, private val v: View) : Drawable() { override fun draw(canvas: Canvas) { // Draw whatever you want here. Example: drawing a simple rectangle canvas.drawRect(v.left.toFloat(), v.top.toFloat() + v.height.toFloat()/3, v.width.toFloat(), v.height.toFloat(), paint) - val a = mutableListOf(Color.rgb(255,0,0), Color.rgb(0,255,0),Color.rgb(1,0,255),Color.rgb(255,0,0),Color.rgb(0,0,255),) - fibVec(fiboTime(), v, canvas) + val a = fiboTime() + fibVec(a, v, canvas) } override fun setAlpha(alpha: Int) { @@ -85,7 +72,9 @@ class CustomDrawable(col: Int, private val v: View) : Drawable() { override fun setColorFilter(colorFilter: ColorFilter?) { paint.colorFilter = colorFilter } - + @Deprecated("This method is deprecated and will be removed in future versions", + ReplaceWith("android.graphics.PixelFormat.OPAQUE", "android") + ) override fun getOpacity(): Int = android.graphics.PixelFormat.OPAQUE } @@ -111,10 +100,10 @@ fun fibVec(timeVals: IntArray, v: View, canvas: Canvas){ val border = unit/20 val paint11 = Paint().apply{ - color = timeVals[4] + color = timeVals[3] } val paint12 = Paint().apply { - color = timeVals[3] + color = timeVals[4] } val paint2 = Paint().apply{ @@ -122,11 +111,11 @@ fun fibVec(timeVals: IntArray, v: View, canvas: Canvas){ } val paint3 = Paint().apply{ - color = timeVals[0] + color = timeVals[1] } val paint5 = Paint().apply{ - color = timeVals[1] + color = timeVals[0] } val bck = Paint().apply{ @@ -146,17 +135,25 @@ fun fibVec(timeVals: IntArray, v: View, canvas: Canvas){ } fun fiboTime(): IntArray { - val now: GregorianCalendar = GregorianCalendar() + val now = GregorianCalendar() var h:Int = now.get(GregorianCalendar.HOUR) + + if (h != 0) { + h += 1 + } else { + h = 12 + } + var m:Int = (now.get(GregorianCalendar.MINUTE)/5)*5 val fiboBlocks = intArrayOf(5,3,2,1,1) val mins = intArrayOf(0,0,0,0,0) val hours = intArrayOf(0,0,0,0,0) - val returnVal = intArrayOf(0,0,0,0,0) + val returnVal = intArrayOf(0,0,0,0,0,0) val colors = intArrayOf(Color.rgb(100,100,100), Color.rgb(255,0,0), - Color.rgb(0,0,255),Color.rgb(0,255,0)) - var blockElement = 0; + Color.rgb(0,0,255), + Color.rgb(0,255,0)) + var blockElement = 0 while (m != 0){ if (fiboBlocks[blockElement]*5 > m){ blockElement++ @@ -166,7 +163,7 @@ fun fiboTime(): IntArray { m -= fiboBlocks[blockElement]*5 blockElement++ } - blockElement = 0; + blockElement = 0 while (h != 0){ if (fiboBlocks[blockElement] > h){ blockElement++ @@ -176,6 +173,7 @@ fun fiboTime(): IntArray { h -= fiboBlocks[blockElement] blockElement++ } + (0..4).forEach { i -> returnVal[i] = colors[mins[i]+hours[i]] }