Skip to content

Commit 3eaefd0

Browse files
committed
修改主题配色
1 parent 1717460 commit 3eaefd0

File tree

19 files changed

+216
-143
lines changed

19 files changed

+216
-143
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Calculator-Compose
2+
3+
这是一款完全使用 Jetpack Compose 实现的计算器 APP。
4+
5+
## 功能特性
6+
7+
| 是否支持 | 功能 |
8+
| :----: | :------: |
9+
|| 基础四则运算(标准、程序员) |
10+
|| 无限输入(标准) |
11+
|| % , 1/x , x² , √x 扩展运算(标准)|
12+
|| 运算过程历史记录(标准) |
13+
|| 二进制、八进制、十进制、十六进制随意切换并实时换算(程序员) |
14+
|| 位运算:左移、右移(程序员) |
15+
|| 逻辑运算:AND、OR、NOT、XOR(程序员) |
16+
|| 无限连续计算(标准、程序员) |
17+
|| 符合人体握持习惯的横屏键盘 |
18+
|| 旋转手机自动切换标准和程序员键盘 |
19+
|| 深色模式 |
20+
|| 酷炫的数字动效 |
21+
22+
**注意:**
23+
24+
1. 标准模式使用 BigDecimal 计算,所以理论支持无限位数数字计算
25+
2. 程序员模式因为涉及到二进制计算,所以采用 64 位储存大小,故不支持无限位数计算
26+
27+
## 截图
28+
29+
| 浅色 | 深色 |
30+
| :----: | :----: |
31+
| ![1](./docs/img/screenshot1.jpg) <br /> 标准模式 | ![2](./docs/img/screenshot2.jpg) <br /> 标准模式 |
32+
| ![3](./docs/img/screenshot3.jpg) <br /> 历史记录 | ![4](./docs/img/screenshot4.jpg) <br /> 历史记录 |
33+
| ![5](./docs/img/screenshot5.jpg) <br /> 程序员模式 | ![6](./docs/img/screenshot6.jpg) <br /> 程序员模式 |
34+
35+
## 其他
36+
布局和处理逻辑参考了 *微软计算器*
37+
38+
实现细节:*待补充*

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ dependencies {
7171
kapt "com.google.dagger:hilt-compiler:2.42"
7272
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
7373

74+
implementation "com.google.accompanist:accompanist-systemuicontroller:0.25.1"
75+
7476
testImplementation 'junit:junit:4.13.2'
7577
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
7678
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

app/src/main/java/com/equationl/calculator_compose/MainActivity.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import androidx.activity.compose.setContent
66
import androidx.compose.foundation.layout.fillMaxSize
77
import androidx.compose.material.MaterialTheme
88
import androidx.compose.material.Surface
9+
import androidx.compose.runtime.SideEffect
910
import androidx.compose.ui.Modifier
1011
import com.equationl.calculator_compose.ui.theme.CalculatorComposeTheme
1112
import com.equationl.calculator_compose.view.HomeScreen
13+
import com.google.accompanist.systemuicontroller.rememberSystemUiController
1214
import dagger.hilt.android.AndroidEntryPoint
1315

1416
@AndroidEntryPoint
@@ -17,11 +19,22 @@ class MainActivity : ComponentActivity() {
1719
super.onCreate(savedInstanceState)
1820
setContent {
1921
CalculatorComposeTheme {
20-
// A surface container using the 'background' color from the theme
22+
val backgroundColor = MaterialTheme.colors.background
23+
2124
Surface(
2225
modifier = Modifier.fillMaxSize(),
23-
color = MaterialTheme.colors.background
26+
color = backgroundColor
2427
) {
28+
val systemUiController = rememberSystemUiController()
29+
val useDarkIcons = MaterialTheme.colors.isLight
30+
31+
SideEffect {
32+
systemUiController.setSystemBarsColor(
33+
color = backgroundColor,
34+
darkIcons = useDarkIcons
35+
)
36+
}
37+
2538
HomeScreen()
2639
}
2740
}

app/src/main/java/com/equationl/calculator_compose/dataModel/KeyBoardData.kt

Lines changed: 82 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.equationl.calculator_compose.dataModel
22

3+
import androidx.compose.material.MaterialTheme
4+
import androidx.compose.runtime.Composable
35
import androidx.compose.ui.graphics.Color
46

57
// 数字按键
@@ -36,8 +38,6 @@ const val KeyIndex_Rsh = 111
3638
const val KeyIndex_And = 112
3739
const val KeyIndex_Or = 113
3840
const val KeyIndex_Not = 114
39-
const val KeyIndex_NAnd = 115
40-
const val KeyIndex_NOr = 116
4141
const val KeyIndex_XOr = 117
4242

4343
// 功能按键
@@ -46,111 +46,115 @@ const val KeyIndex_CE = 1001
4646
const val KeyIndex_Clear = 1002
4747
const val KeyIndex_Back = 1003
4848

49-
// 预留按键
50-
const val KeyIndex_Null = -1
5149

50+
@Composable
51+
fun numberColor(): Color = MaterialTheme.colors.secondary
5252

53-
val NumberColor = Color.White
54-
val FunctionColor = Color.LightGray
55-
val EqualColor = Color.Cyan
56-
val UnavailableColor = Color.Transparent
53+
@Composable
54+
fun functionColor(): Color = MaterialTheme.colors.primary
5755

58-
val StandardKeyBoardBtn = listOf(
59-
listOf(
60-
KeyBoardData("%", FunctionColor, KeyIndex_Percentage),
61-
KeyBoardData("CE", FunctionColor, KeyIndex_CE),
62-
KeyBoardData("C", FunctionColor, KeyIndex_Clear),
63-
KeyBoardData("", FunctionColor, KeyIndex_Back),
64-
),
65-
listOf(
66-
KeyBoardData("1/x", FunctionColor, KeyIndex_Reciprocal),
67-
KeyBoardData("", FunctionColor, KeyIndex_Pow2),
68-
KeyBoardData("√x", FunctionColor, KeyIndex_Sqrt),
69-
KeyBoardData(Operator.Divide.showText, FunctionColor, KeyIndex_Divide),
70-
),
71-
listOf(
72-
KeyBoardData("7", NumberColor, KeyIndex_7),
73-
KeyBoardData("8", NumberColor, KeyIndex_8),
74-
KeyBoardData("9", NumberColor, KeyIndex_9),
75-
KeyBoardData(Operator.MULTIPLY.showText, FunctionColor, KeyIndex_Multiply),
76-
),
77-
listOf(
78-
KeyBoardData("4", NumberColor, KeyIndex_4),
79-
KeyBoardData("5", NumberColor, KeyIndex_5),
80-
KeyBoardData("6", NumberColor, KeyIndex_6),
81-
KeyBoardData(Operator.MINUS.showText, FunctionColor, KeyIndex_Minus),
82-
),
83-
listOf(
84-
KeyBoardData("1", NumberColor, KeyIndex_1),
85-
KeyBoardData("2", NumberColor, KeyIndex_2),
86-
KeyBoardData("3", NumberColor, KeyIndex_3),
87-
KeyBoardData(Operator.ADD.showText, FunctionColor, KeyIndex_Add),
88-
),
89-
listOf(
90-
KeyBoardData("+/-", NumberColor, KeyIndex_NegativeNumber),
91-
KeyBoardData("0", NumberColor, KeyIndex_0),
92-
KeyBoardData(".", NumberColor, KeyIndex_Point),
93-
KeyBoardData("=", EqualColor, KeyIndex_Equal),
56+
@Composable
57+
fun equalColor(): Color = MaterialTheme.colors.primaryVariant
58+
59+
@Composable
60+
fun standardKeyBoardBtn(): List<List<KeyBoardData>> = listOf(
61+
listOf(
62+
KeyBoardData("%", functionColor(), KeyIndex_Percentage),
63+
KeyBoardData("CE", functionColor(), KeyIndex_CE),
64+
KeyBoardData("C", functionColor(), KeyIndex_Clear),
65+
KeyBoardData("", functionColor(), KeyIndex_Back),
66+
),
67+
listOf(
68+
KeyBoardData("1/x", functionColor(), KeyIndex_Reciprocal),
69+
KeyBoardData("", functionColor(), KeyIndex_Pow2),
70+
KeyBoardData("√x", functionColor(), KeyIndex_Sqrt),
71+
KeyBoardData(Operator.Divide.showText, functionColor(), KeyIndex_Divide),
72+
),
73+
listOf(
74+
KeyBoardData("7", numberColor(), KeyIndex_7),
75+
KeyBoardData("8", numberColor(), KeyIndex_8),
76+
KeyBoardData("9", numberColor(), KeyIndex_9),
77+
KeyBoardData(Operator.MULTIPLY.showText, functionColor(), KeyIndex_Multiply),
78+
),
79+
listOf(
80+
KeyBoardData("4", numberColor(), KeyIndex_4),
81+
KeyBoardData("5", numberColor(), KeyIndex_5),
82+
KeyBoardData("6", numberColor(), KeyIndex_6),
83+
KeyBoardData(Operator.MINUS.showText, functionColor(), KeyIndex_Minus),
84+
),
85+
listOf(
86+
KeyBoardData("1", numberColor(), KeyIndex_1),
87+
KeyBoardData("2", numberColor(), KeyIndex_2),
88+
KeyBoardData("3", numberColor(), KeyIndex_3),
89+
KeyBoardData(Operator.ADD.showText, functionColor(), KeyIndex_Add),
90+
),
91+
listOf(
92+
KeyBoardData("+/-", functionColor(), KeyIndex_NegativeNumber),
93+
KeyBoardData("0", numberColor(), KeyIndex_0),
94+
KeyBoardData(".", functionColor(), KeyIndex_Point),
95+
KeyBoardData("=", equalColor(), KeyIndex_Equal),
96+
)
9497
)
95-
)
9698

97-
val ProgrammerLeftKeyBoardBtn = listOf(
99+
@Composable
100+
fun programmerLeftKeyBoardBtn(): List<List<KeyBoardData>> = listOf(
98101
listOf(
99-
KeyBoardData("D", NumberColor, KeyIndex_D),
100-
KeyBoardData("E", NumberColor, KeyIndex_E),
101-
KeyBoardData("F", NumberColor, KeyIndex_F)
102+
KeyBoardData("D", numberColor(), KeyIndex_D),
103+
KeyBoardData("E", numberColor(), KeyIndex_E),
104+
KeyBoardData("F", numberColor(), KeyIndex_F)
102105
),
103106
listOf(
104-
KeyBoardData("A", NumberColor, KeyIndex_A),
105-
KeyBoardData("B", NumberColor, KeyIndex_B),
106-
KeyBoardData("C", NumberColor, KeyIndex_C)
107-
),
107+
KeyBoardData("A", numberColor(), KeyIndex_A),
108+
KeyBoardData("B", numberColor(), KeyIndex_B),
109+
KeyBoardData("C", numberColor(), KeyIndex_C)
110+
),
108111
listOf(
109-
KeyBoardData("7", NumberColor, KeyIndex_7),
110-
KeyBoardData("8", NumberColor, KeyIndex_8),
111-
KeyBoardData("9", NumberColor, KeyIndex_9)
112+
KeyBoardData("7", numberColor(), KeyIndex_7),
113+
KeyBoardData("8", numberColor(), KeyIndex_8),
114+
KeyBoardData("9", numberColor(), KeyIndex_9)
112115
),
113116
listOf(
114-
KeyBoardData("4", NumberColor, KeyIndex_4),
115-
KeyBoardData("5", NumberColor, KeyIndex_5),
116-
KeyBoardData("6", NumberColor, KeyIndex_6)
117+
KeyBoardData("4", numberColor(), KeyIndex_4),
118+
KeyBoardData("5", numberColor(), KeyIndex_5),
119+
KeyBoardData("6", numberColor(), KeyIndex_6)
117120
),
118121
listOf(
119-
KeyBoardData("1", NumberColor, KeyIndex_1),
120-
KeyBoardData("2", NumberColor, KeyIndex_2),
121-
KeyBoardData("3", NumberColor, KeyIndex_3)
122+
KeyBoardData("1", numberColor(), KeyIndex_1),
123+
KeyBoardData("2", numberColor(), KeyIndex_2),
124+
KeyBoardData("3", numberColor(), KeyIndex_3)
122125
),
123126
listOf(
124-
KeyBoardData("<<", FunctionColor, KeyIndex_Lsh),
125-
KeyBoardData("0", NumberColor, KeyIndex_0),
126-
KeyBoardData(">>", FunctionColor, KeyIndex_Rsh)
127+
KeyBoardData("<<", functionColor(), KeyIndex_Lsh),
128+
KeyBoardData("0", numberColor(), KeyIndex_0),
129+
KeyBoardData(">>", functionColor(), KeyIndex_Rsh)
127130
)
128131
)
129132

130-
val ProgrammerRightKeyBoardBtn = listOf(
133+
@Composable
134+
fun programmerRightKeyBoardBtn(): List<List<KeyBoardData>> = listOf(
131135
listOf(
132-
KeyBoardData("C", FunctionColor, KeyIndex_Clear),
133-
KeyBoardData("", FunctionColor, KeyIndex_Back)
136+
KeyBoardData("C", functionColor(), KeyIndex_Clear),
137+
KeyBoardData("", functionColor(), KeyIndex_Back)
134138
),
135139
listOf(
136-
KeyBoardData("CE", FunctionColor, KeyIndex_CE),
137-
KeyBoardData(Operator.Divide.showText, FunctionColor, KeyIndex_Divide)
140+
KeyBoardData("CE", functionColor(), KeyIndex_CE),
141+
KeyBoardData(Operator.Divide.showText, functionColor(), KeyIndex_Divide)
138142
),
139143
listOf(
140-
KeyBoardData("NOT", FunctionColor, KeyIndex_Not),
141-
KeyBoardData(Operator.MULTIPLY.showText, FunctionColor, KeyIndex_Multiply)
144+
KeyBoardData("NOT", functionColor(), KeyIndex_Not),
145+
KeyBoardData(Operator.MULTIPLY.showText, functionColor(), KeyIndex_Multiply)
142146
),
143147
listOf(
144-
KeyBoardData("XOR", FunctionColor, KeyIndex_XOr),
145-
KeyBoardData(Operator.MINUS.showText, FunctionColor, KeyIndex_Minus)
148+
KeyBoardData("XOR", functionColor(), KeyIndex_XOr),
149+
KeyBoardData(Operator.MINUS.showText, functionColor(), KeyIndex_Minus)
146150
),
147151
listOf(
148-
KeyBoardData("AND", FunctionColor, KeyIndex_And),
149-
KeyBoardData(Operator.ADD.showText, FunctionColor, KeyIndex_Add)
152+
KeyBoardData("AND", functionColor(), KeyIndex_And),
153+
KeyBoardData(Operator.ADD.showText, functionColor(), KeyIndex_Add)
150154
),
151155
listOf(
152-
KeyBoardData("OR", FunctionColor, KeyIndex_Or),
153-
KeyBoardData("=", FunctionColor, KeyIndex_Equal)
156+
KeyBoardData("OR", functionColor(), KeyIndex_Or),
157+
KeyBoardData("=", equalColor(), KeyIndex_Equal)
154158
)
155159
)
156160

app/src/main/java/com/equationl/calculator_compose/ui/theme/Color.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package com.equationl.calculator_compose.ui.theme
22

33
import androidx.compose.ui.graphics.Color
44

5-
val Purple200 = Color(0xFFBB86FC)
6-
val Purple500 = Color(0xFF6200EE)
7-
val Purple700 = Color(0xFF3700B3)
8-
val Teal200 = Color(0xFF03DAC5)
5+
val Amber200 = Color(0xFFFFE082)
6+
val Amber500 = Color(0xFFFFC107)
7+
val Amber700 = Color(0xFFFFA000)
8+
val AmberA200 = Color(0xFFFFD740)
9+
10+
val Grey200 = Color(0xFFEEEEEE)
11+
val Grey500 = Color(0xFF9E9E9E)
12+
val Grey700 = Color(0xFF616161)

app/src/main/java/com/equationl/calculator_compose/ui/theme/Theme.kt

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,20 @@ import androidx.compose.material.MaterialTheme
55
import androidx.compose.material.darkColors
66
import androidx.compose.material.lightColors
77
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.graphics.Color
89

910
private val DarkColorPalette = darkColors(
10-
primary = Purple200,
11-
primaryVariant = Purple700,
12-
secondary = Teal200
11+
primary = Grey500,
12+
primaryVariant = Grey700,
13+
secondary = Grey200,
14+
background = Color.LightGray
1315
)
1416

1517
private val LightColorPalette = lightColors(
16-
primary = Purple500,
17-
primaryVariant = Purple700,
18-
secondary = Teal200
19-
20-
/* Other default colors to override
21-
background = Color.White,
22-
surface = Color.White,
23-
onPrimary = Color.White,
24-
onSecondary = Color.Black,
25-
onBackground = Color.Black,
26-
onSurface = Color.Black,
27-
*/
18+
primary = Amber500,
19+
primaryVariant = Amber700,
20+
secondary = AmberA200,
21+
background = Amber200,
2822
)
2923

3024
@Composable

app/src/main/java/com/equationl/calculator_compose/view/HIstoryWidget.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ import androidx.compose.foundation.layout.*
88
import androidx.compose.foundation.lazy.LazyColumn
99
import androidx.compose.foundation.lazy.items
1010
import androidx.compose.material.Icon
11+
import androidx.compose.material.MaterialTheme
1112
import androidx.compose.material.Text
1213
import androidx.compose.material.icons.Icons
1314
import androidx.compose.material.icons.outlined.Delete
1415
import androidx.compose.runtime.Composable
1516
import androidx.compose.ui.Alignment
1617
import androidx.compose.ui.Modifier
17-
import androidx.compose.ui.graphics.Color
1818
import androidx.compose.ui.text.font.FontWeight
1919
import androidx.compose.ui.tooling.preview.Preview
2020
import androidx.compose.ui.unit.dp
2121
import androidx.compose.ui.unit.sp
2222
import com.equationl.calculator_compose.dataModel.HistoryData
2323
import com.equationl.calculator_compose.dataModel.Operator
24+
import com.equationl.calculator_compose.ui.theme.CalculatorComposeTheme
2425

2526
/**
2627
* @param onDelete 如果 item 为 null 则表示删除所有历史记录,否则删除指定的 item
@@ -33,7 +34,7 @@ fun HistoryWidget(
3334
onDelete: (item: HistoryData?) -> Unit
3435
) {
3536

36-
Column(Modifier.fillMaxSize().background(Color.LightGray)) {
37+
Column(Modifier.fillMaxSize().background(MaterialTheme.colors.primaryVariant)) {
3738
LazyColumn(modifier = Modifier.weight(9f)) {
3839
items(
3940
items = historyList,
@@ -108,9 +109,12 @@ fun HistoryPreview() {
108109
HistoryData(29, "1+1=", "1", "1", Operator.ADD, "2"),
109110
HistoryData(30, "1+1=", "1", "1", Operator.ADD, "2"),
110111
)
111-
HistoryWidget(
112-
historyList = testList,
113-
onClick = {},
114-
onDelete = {}
115-
)
112+
113+
CalculatorComposeTheme(false) {
114+
HistoryWidget(
115+
historyList = testList,
116+
onClick = {},
117+
onDelete = {}
118+
)
119+
}
116120
}

0 commit comments

Comments
 (0)