Fix the bugs in hour display
This commit is contained in:
parent
942759fd06
commit
53fa85e679
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="deploymentTargetSelector">
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<SelectionState runConfigName="fiboBGAndroid">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
|
||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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]]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user