Загрузить файлы в «/»
This commit is contained in:
parent
56d09fdd45
commit
8721eb1820
83
ReadMe.md
Normal file
83
ReadMe.md
Normal file
@ -0,0 +1,83 @@
|
||||
### **Color Picker**
|
||||
|
||||
Инструмент для работы с цветами.
|
||||
Получение значений RGB/HEX.
|
||||
|
||||
```kt
|
||||
package com.example.colorpicker
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
ColorPickerApp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ColorPickerApp() {
|
||||
var r by remember { mutableStateOf(128f) }
|
||||
var g by remember { mutableStateOf(128f) }
|
||||
var b by remember { mutableStateOf(128f) }
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
val color = Color(r / 255f, g / 255f, b / 255f)
|
||||
val hex = "#%02X%02X%02X".format(r.toInt(), g.toInt(), b.toInt())
|
||||
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
|
||||
Text("R: ${r.toInt()}")
|
||||
Slider(value = r, onValueChange = { r = it }, valueRange = 0f..255f)
|
||||
|
||||
Text("G: ${g.toInt()}")
|
||||
Slider(value = g, onValueChange = { g = it }, valueRange = 0f..255f)
|
||||
|
||||
Text("B: ${b.toInt()}")
|
||||
Slider(value = b, onValueChange = { b = it }, valueRange = 0f..255f)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(150.dp)
|
||||
.background(color)
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text("HEX: $hex")
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Button(onClick = {
|
||||
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("color", hex)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
|
||||
Toast.makeText(context, "Скопировано: $hex", Toast.LENGTH_SHORT).show()
|
||||
}) {
|
||||
Text("Copy HEX")
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
x
Reference in New Issue
Block a user