Fix the bugs in hour display
This commit is contained in:
parent
942759fd06
commit
53fa85e679
@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="deploymentTargetSelector">
|
<component name="deploymentTargetSelector">
|
||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="fiboBGAndroid">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
</selectionStates>
|
</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() {
|
fun useAppContext() {
|
||||||
// Context of the app under test.
|
// Context of the app under test.
|
||||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
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
|
package com.example.fiboBGAndroid
|
||||||
|
|
||||||
|
|
||||||
@ -10,7 +11,6 @@ import android.icu.util.GregorianCalendar
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -21,15 +21,10 @@ import kotlin.random.Random
|
|||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
class counter {
|
|
||||||
var times: Int = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
val times = counter()
|
private lateinit var myButton: Button
|
||||||
lateinit var myButton: Button
|
private lateinit var mainLayout: ConstraintLayout
|
||||||
lateinit var myText: TextView
|
private lateinit var canvasview: View
|
||||||
lateinit var mainLayout: ConstraintLayout
|
|
||||||
lateinit var canvasview: View
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
@ -40,23 +35,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
insets
|
insets
|
||||||
}
|
}
|
||||||
myButton = findViewById(R.id.button)
|
myButton = findViewById(R.id.button)
|
||||||
myText = findViewById(R.id.textView)
|
|
||||||
mainLayout = findViewById(R.id.main)
|
mainLayout = findViewById(R.id.main)
|
||||||
canvasview = findViewById(R.id.view)
|
canvasview = findViewById(R.id.view)
|
||||||
|
|
||||||
myButton.setOnClickListener {
|
myButton.setOnClickListener {
|
||||||
csacsi(myText, times, mainLayout, canvasview)
|
csacsi(mainLayout, canvasview)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private fun csacsi (tv: TextView, numb: counter, m: ConstraintLayout, cv: View) {
|
private fun csacsi (m: ConstraintLayout, cv: View) {
|
||||||
numb.times++
|
|
||||||
val nu = numb.times
|
|
||||||
val colors = List(3) { Random.nextInt(0,255)}
|
val colors = List(3) { Random.nextInt(0,255)}
|
||||||
val color = Color.rgb(colors[0],colors[1],colors[2])
|
val color = Color.rgb(colors[0],colors[1],colors[2])
|
||||||
//m.setBackgroundColor(color)
|
|
||||||
m.background= CustomDrawable(color, cv)
|
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() {
|
class CustomDrawable(col: Int, private val v: View) : Drawable() {
|
||||||
private val paint = Paint()
|
private val paint = Paint()
|
||||||
|
|
||||||
var color = paint.color
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
paint.color = col // Set your custom color
|
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) {
|
override fun draw(canvas: Canvas) {
|
||||||
// Draw whatever you want here. Example: drawing a simple rectangle
|
// 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)
|
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),)
|
val a = fiboTime()
|
||||||
fibVec(fiboTime(), v, canvas)
|
fibVec(a, v, canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setAlpha(alpha: Int) {
|
override fun setAlpha(alpha: Int) {
|
||||||
@ -85,7 +72,9 @@ class CustomDrawable(col: Int, private val v: View) : Drawable() {
|
|||||||
override fun setColorFilter(colorFilter: ColorFilter?) {
|
override fun setColorFilter(colorFilter: ColorFilter?) {
|
||||||
paint.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
|
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 border = unit/20
|
||||||
|
|
||||||
val paint11 = Paint().apply{
|
val paint11 = Paint().apply{
|
||||||
color = timeVals[4]
|
color = timeVals[3]
|
||||||
}
|
}
|
||||||
val paint12 = Paint().apply {
|
val paint12 = Paint().apply {
|
||||||
color = timeVals[3]
|
color = timeVals[4]
|
||||||
}
|
}
|
||||||
|
|
||||||
val paint2 = Paint().apply{
|
val paint2 = Paint().apply{
|
||||||
@ -122,11 +111,11 @@ fun fibVec(timeVals: IntArray, v: View, canvas: Canvas){
|
|||||||
}
|
}
|
||||||
|
|
||||||
val paint3 = Paint().apply{
|
val paint3 = Paint().apply{
|
||||||
color = timeVals[0]
|
color = timeVals[1]
|
||||||
|
|
||||||
}
|
}
|
||||||
val paint5 = Paint().apply{
|
val paint5 = Paint().apply{
|
||||||
color = timeVals[1]
|
color = timeVals[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
val bck = Paint().apply{
|
val bck = Paint().apply{
|
||||||
@ -146,17 +135,25 @@ fun fibVec(timeVals: IntArray, v: View, canvas: Canvas){
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fiboTime(): IntArray {
|
fun fiboTime(): IntArray {
|
||||||
val now: GregorianCalendar = GregorianCalendar()
|
val now = GregorianCalendar()
|
||||||
var h:Int = now.get(GregorianCalendar.HOUR)
|
var h:Int = now.get(GregorianCalendar.HOUR)
|
||||||
|
|
||||||
|
if (h != 0) {
|
||||||
|
h += 1
|
||||||
|
} else {
|
||||||
|
h = 12
|
||||||
|
}
|
||||||
|
|
||||||
var m:Int = (now.get(GregorianCalendar.MINUTE)/5)*5
|
var m:Int = (now.get(GregorianCalendar.MINUTE)/5)*5
|
||||||
val fiboBlocks = intArrayOf(5,3,2,1,1)
|
val fiboBlocks = intArrayOf(5,3,2,1,1)
|
||||||
val mins = intArrayOf(0,0,0,0,0)
|
val mins = intArrayOf(0,0,0,0,0)
|
||||||
val hours = 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),
|
val colors = intArrayOf(Color.rgb(100,100,100),
|
||||||
Color.rgb(255,0,0),
|
Color.rgb(255,0,0),
|
||||||
Color.rgb(0,0,255),Color.rgb(0,255,0))
|
Color.rgb(0,0,255),
|
||||||
var blockElement = 0;
|
Color.rgb(0,255,0))
|
||||||
|
var blockElement = 0
|
||||||
while (m != 0){
|
while (m != 0){
|
||||||
if (fiboBlocks[blockElement]*5 > m){
|
if (fiboBlocks[blockElement]*5 > m){
|
||||||
blockElement++
|
blockElement++
|
||||||
@ -166,7 +163,7 @@ fun fiboTime(): IntArray {
|
|||||||
m -= fiboBlocks[blockElement]*5
|
m -= fiboBlocks[blockElement]*5
|
||||||
blockElement++
|
blockElement++
|
||||||
}
|
}
|
||||||
blockElement = 0;
|
blockElement = 0
|
||||||
while (h != 0){
|
while (h != 0){
|
||||||
if (fiboBlocks[blockElement] > h){
|
if (fiboBlocks[blockElement] > h){
|
||||||
blockElement++
|
blockElement++
|
||||||
@ -176,6 +173,7 @@ fun fiboTime(): IntArray {
|
|||||||
h -= fiboBlocks[blockElement]
|
h -= fiboBlocks[blockElement]
|
||||||
blockElement++
|
blockElement++
|
||||||
}
|
}
|
||||||
|
|
||||||
(0..4).forEach { i ->
|
(0..4).forEach { i ->
|
||||||
returnVal[i] = colors[mins[i]+hours[i]]
|
returnVal[i] = colors[mins[i]+hours[i]]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user