Skip to content

Commit 9e50b37

Browse files
renattelerenattele
authored andcommitted
added color theming based on system but demo
1 parent 7c60ecf commit 9e50b37

21 files changed

+174
-53
lines changed

app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ android {
3535

3636
dependencies {
3737

38-
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.31"
3938
implementation 'androidx.core:core-ktx:1.3.2'
4039
implementation 'androidx.appcompat:appcompat:1.2.0'
4140
implementation 'com.google.android.material:material:1.3.0'
@@ -48,7 +47,7 @@ dependencies {
4847
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4948
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
5049
implementation 'org.reactivestreams:reactive-streams:1.0.3'
51-
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
50+
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'
5251
implementation 'com.google.android.gms:play-services-location:18.0.0'
5352
implementation 'com.google.android.material:material:1.3.0'
5453

app/src/main/java/com/colorata/st/MainActivity.kt

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.colorata.st
1+
package com.colorata.st
22

33
import android.annotation.SuppressLint
44
import android.app.*
@@ -8,25 +8,29 @@ import android.content.Intent
88
import android.content.SharedPreferences
99
import android.content.pm.PackageManager
1010
import android.content.pm.ResolveInfo
11+
import android.content.res.ColorStateList
1112
import android.content.res.Configuration
13+
import android.graphics.Color
1214
import android.graphics.drawable.Drawable
1315
import android.net.Uri
1416
import android.os.Build
1517
import android.os.Bundle
1618
import android.provider.Settings
1719
import android.util.DisplayMetrics
20+
import android.util.TypedValue
21+
import android.view.ContextThemeWrapper
1822
import android.view.View
1923
import android.view.animation.AlphaAnimation
2024
import android.view.animation.AnimationSet
2125
import android.view.animation.DecelerateInterpolator
2226
import android.widget.Button
2327
import android.widget.ImageView
28+
import android.widget.TextView
2429
import androidx.annotation.RequiresApi
2530
import androidx.appcompat.app.AppCompatActivity
2631
import androidx.core.app.NotificationCompat
2732
import androidx.core.app.NotificationManagerCompat
2833
import androidx.core.app.Person
29-
import androidx.core.content.ContextCompat
3034
import androidx.core.content.pm.ShortcutInfoCompat
3135
import androidx.core.content.pm.ShortcutManagerCompat
3236
import androidx.core.graphics.drawable.IconCompat
@@ -48,7 +52,7 @@ import kotlinx.android.synthetic.main.help_alert.*
4852
import java.util.*
4953

5054

51-
class MainActivity : AppCompatActivity() {
55+
class MainActivity : AppCompatActivity() {
5256

5357
//Init values
5458
private var nightMode = true
@@ -125,6 +129,23 @@ class MainActivity : AppCompatActivity() {
125129
settings.setOnClickListener { settings() }
126130
bubble_manager.setOnClickListener { bubbleManager()}
127131
weather_director.setOnClickListener { weatherDirector() }
132+
133+
//Changing COLOR TO ELEMENTS
134+
text_main.setTextColor(getButtonColor())
135+
help.setTextColor(getButtonColor())
136+
137+
about.setTextColor(getButtonColor())
138+
139+
settings.setTextColor(getButtonColor())
140+
141+
bubble_manager.setTextColor(getButtonColor())
142+
143+
weather_director.setTextColor(getButtonColor())
144+
145+
main_layout.setBackgroundColor(getBackground())
146+
147+
window.navigationBarColor = getBackground()
148+
window.statusBarColor = getBackground()
128149
}
129150

130151
//Fun for creating ANIMATIONS
@@ -287,6 +308,14 @@ class MainActivity : AppCompatActivity() {
287308
val source = dialogLayout.findViewById<Button>(R.id.sourcecode)
288309
val support = dialogLayout.findViewById<Button>(R.id.support)
289310
val version = dialogLayout.findViewById<Button>(R.id.version)
311+
val text = dialogLayout.findViewById<TextView>(R.id.text_about)
312+
313+
//Changing COLORS FOR ELEMENTS
314+
cancel.setTextColor(getButtonColor())
315+
source.setTextColor(getButtonColor())
316+
support.setTextColor(getButtonColor())
317+
version.setTextColor(getButtonColor())
318+
text.setTextColor(getButtonColor())
290319

291320
//Configuring BACKGROUND
292321
configBack(dialogLayout)
@@ -355,6 +384,7 @@ class MainActivity : AppCompatActivity() {
355384
val settings = dialogLayout.findViewById<Button>(R.id.settings_app)
356385
val clear = dialogLayout.findViewById<Button>(R.id.clear_data)
357386

387+
358388
//Configuring BACKGROUND
359389
configBack(dialogLayout)
360390

@@ -702,10 +732,10 @@ class MainActivity : AppCompatActivity() {
702732
private fun configBack(dialogLayout: View){
703733
when(nightMode){
704734
false -> {
705-
dialogLayout.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.light_background))
735+
dialogLayout.setBackgroundColor(getBackground())
706736
}
707737
true -> {
708-
dialogLayout.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.dark_background))
738+
dialogLayout.setBackgroundColor(getBackground())
709739
}
710740
}
711741
dialogLayout.rootView.fitsSystemWindows = true
@@ -991,4 +1021,100 @@ class MainActivity : AppCompatActivity() {
9911021

9921022
return userIcon
9931023
}
1024+
1025+
//Fun for get Phone THEME
1026+
private fun getColor(): Int {
1027+
val typedValue = TypedValue()
1028+
val contextThemeWrapper = ContextThemeWrapper(this,
1029+
android.R.style.Theme_DeviceDefault)
1030+
contextThemeWrapper.theme.resolveAttribute(android.R.attr.colorAccent,
1031+
typedValue, true)
1032+
return typedValue.data
1033+
}
1034+
1035+
//Fun for get COLOR THEME BACKGROUND
1036+
private fun getBackground(): Int {
1037+
var color = ""
1038+
when(nightMode){
1039+
true -> {
1040+
when(getColor()) {
1041+
-7686920 -> { color = "#162A49" }
1042+
-4359937 -> { color = "#2F1845" }
1043+
-3625836 -> { color = "#34271C" }
1044+
-3955038 -> { color = "#543C38" }
1045+
-942723 -> { color = "#4D3830" }
1046+
-15007797 -> { color = "#2C4F47" }
1047+
-2629914 -> { color = "#242527" }
1048+
-8076920 -> { color = "#3D523E" }
1049+
-14107177 -> { color = "#395458" }
1050+
-6705972 -> { color = "#374151" }
1051+
-18727 -> { color = "#503D46" }
1052+
-12722945 -> { color = "#2B4449" }
1053+
-1668371 -> { color = "#594B5A" }
1054+
-4871684 -> { color = "#3D3953" }
1055+
}
1056+
} false -> {
1057+
when(getColor()) {
1058+
-7686920 -> { color = "#8AB4F8" }
1059+
-4359937 -> { color = "#C89EF1" }
1060+
-3625836 -> { color = "#C8AC94" }
1061+
-3955038 -> { color = "#C3A6A2" }
1062+
-942723 -> { color = "#E3AF9A" }
1063+
-15007797 -> { color = "#95D4C6" }
1064+
-2629914 -> { color = "#D7DEE6" }
1065+
-8076920 -> { color = "#A1C7A3" }
1066+
-14107177 -> { color = "#91CBD4" }
1067+
-6705972 -> { color = "#A4B4CE" }
1068+
-18727 -> { color = "#FFD6E9" }
1069+
-12722945 -> { color = "#B8F2FF" }
1070+
-1668371 -> { color = "#EAC1ED" }
1071+
-4871684 -> { color = "#C5BBFE" }
1072+
}
1073+
}
1074+
}
1075+
return Color.parseColor(color)
1076+
}
1077+
1078+
//Fun for get COLOR THEME BUTTON
1079+
private fun getButtonColor(): Int {
1080+
var color = "#ffffff"
1081+
when(nightMode){
1082+
true -> {
1083+
when(getColor()) {
1084+
-7686920 -> { color = "#8AB4F8" }
1085+
-4359937 -> { color = "#C89EF1" }
1086+
-3625836 -> { color = "#C8AC94" }
1087+
-3955038 -> { color = "#C3A6A2" }
1088+
-942723 -> { color = "#E3AF9A" }
1089+
-15007797 -> { color = "#95D4C6" }
1090+
-2629914 -> { color = "#D7DEE6" }
1091+
-8076920 -> { color = "#A1C7A3" }
1092+
-14107177 -> { color = "#91CBD4" }
1093+
-6705972 -> { color = "#A4B4CE" }
1094+
-18727 -> { color = "#FFD6E9" }
1095+
-12722945 -> { color = "#B8F2FF" }
1096+
-1668371 -> { color = "#EAC1ED" }
1097+
-4871684 -> { color = "#C5BBFE" }
1098+
}
1099+
} false -> {
1100+
when(getColor()) {
1101+
-7686920 -> { color = "#162A49" }
1102+
-4359937 -> { color = "#2F1845" }
1103+
-3625836 -> { color = "#34271C" }
1104+
-3955038 -> { color = "#543C38" }
1105+
-942723 -> { color = "#4D3830" }
1106+
-15007797 -> { color = "#2C4F47" }
1107+
-2629914 -> { color = "#242527" }
1108+
-8076920 -> { color = "#3D523E" }
1109+
-14107177 -> { color = "#395458" }
1110+
-6705972 -> { color = "#374151" }
1111+
-18727 -> { color = "#503D46" }
1112+
-12722945 -> { color = "#2B4449" }
1113+
-1668371 -> { color = "#594B5A" }
1114+
-4871684 -> { color = "#3D3953" }
1115+
}
1116+
}
1117+
}
1118+
return Color.parseColor(color)
1119+
}
9941120
}

app/src/main/java/com/colorata/st/bubble/BubbleAdapter.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ class BubbleAdapter(private val values: MutableList<String>, private val icon: M
3333
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
3434

3535
holder.textView?.text = values[position]
36-
/*if (drawable[0] == null){
37-
holder.fab?.setImageResource(icon[position])
38-
} else {
39-
holder.fab?.setImageDrawable(drawable[position])
40-
}*/
4136

4237
holder.fab?.setImageResource(icon[position])
4338

app/src/main/res/layout/about_alert.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
android:layout_margin="@dimen/margin_text"/>
2020

2121
<!-- Button SOURCE CODE -->
22-
<Button
22+
<com.google.android.material.button.MaterialButton
2323
android:id="@+id/sourcecode"
2424
android:layout_width="@dimen/width"
2525
android:layout_height="wrap_content"
@@ -30,7 +30,7 @@
3030
android:text="@string/source_code"/>
3131

3232
<!-- Button SUPPORT US -->
33-
<Button
33+
<com.google.android.material.button.MaterialButton
3434
android:id="@+id/support"
3535
android:layout_width="@dimen/width"
3636
android:layout_height="@dimen/height"
@@ -41,7 +41,7 @@
4141
android:text="@string/support_us"/>
4242

4343
<!-- Button VERSION -->
44-
<Button
44+
<com.google.android.material.button.MaterialButton
4545
android:id="@+id/version"
4646
android:layout_width="@dimen/width"
4747
android:layout_height="@dimen/height"
@@ -52,7 +52,7 @@
5252
android:text="@string/version_sunray"/>
5353

5454
<!-- Button CANCEL -->
55-
<Button
55+
<com.google.android.material.button.MaterialButton
5656
android:id="@+id/cancel_version"
5757
android:layout_width="match_parent"
5858
android:layout_height="wrap_content"

app/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@
4949
android:text="@string/app_name"/>
5050

5151
<!-- Button to CHANGE POSITION -->
52-
<Button
52+
<com.google.android.material.button.MaterialButton
5353
android:id="@+id/weather_director"
5454
android:layout_width="wrap_content"
5555
android:layout_height="wrap_content"
5656
app:layout_constraintBottom_toTopOf="@id/bubble_manager"
5757
app:layout_constraintEnd_toEndOf="parent"
5858
app:layout_constraintStart_toStartOf="parent"
5959
app:layout_constraintTop_toTopOf="@id/guideline_one_handed_main"
60-
android:text="@string/weather_director"/>
60+
android:text="@string/weather_director" />
6161

6262
<!-- Button to ADD BUTTON -->
63-
<Button
63+
<com.google.android.material.button.MaterialButton
6464
android:id="@+id/bubble_manager"
6565
android:layout_width="wrap_content"
6666
android:layout_height="wrap_content"
@@ -71,7 +71,7 @@
7171
android:text="@string/add_buttons"/>
7272

7373
<!-- Button SETTINGS -->
74-
<Button
74+
<com.google.android.material.button.MaterialButton
7575
android:id="@+id/settings"
7676
android:layout_width="wrap_content"
7777
android:layout_height="wrap_content"
@@ -82,18 +82,18 @@
8282
android:text="@string/settings"/>
8383

8484
<!-- Button HELP -->
85-
<Button
85+
<com.google.android.material.button.MaterialButton
8686
android:id="@+id/help"
8787
android:layout_width="wrap_content"
8888
android:layout_height="wrap_content"
8989
app:layout_constraintBottom_toTopOf="@id/about"
9090
app:layout_constraintEnd_toEndOf="parent"
9191
app:layout_constraintStart_toStartOf="parent"
9292
app:layout_constraintTop_toBottomOf="@id/settings"
93-
android:text="@string/help"/>
93+
android:text="@string/help" />
9494

9595
<!-- Button ABOUT -->
96-
<Button
96+
<com.google.android.material.button.MaterialButton
9797
android:id="@+id/about"
9898
android:layout_width="wrap_content"
9999
android:layout_height="wrap_content"

app/src/main/res/layout/add_button_alert.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
android:layout_marginHorizontal="@dimen/margin_recycler"/>
3535

3636
<!-- Button CANCEL -->
37-
<Button
37+
<com.google.android.material.button.MaterialButton
3838
android:id="@+id/cancel_add_button"
3939
android:layout_width="@dimen/width"
4040
android:layout_height="wrap_content"

app/src/main/res/layout/bubble_item.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
android:id="@+id/bubble_button"
1212
android:layout_width="wrap_content"
1313
android:layout_height="wrap_content"
14-
app:backgroundTint="@color/bubble_item"
14+
app:borderWidth="1dp"
15+
android:backgroundTint="@android:color/transparent"
1516
android:src="@drawable/ic_baseline_flash_on_24"
1617
app:tint="#ffffff"
1718
android:contentDescription="@string/bubble_item"

app/src/main/res/layout/bubble_manager_alert.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
android:layout_margin="@dimen/margin_text"/>
1919

2020
<!-- Button ENABLE -->
21-
<Button
21+
<com.google.android.material.button.MaterialButton
2222
android:id="@+id/enable"
2323
android:layout_width="@dimen/width"
2424
android:layout_height="@dimen/height"
@@ -29,7 +29,7 @@
2929
android:text="@string/enable"/>
3030

3131
<!-- Button CHANGE POSITION -->
32-
<Button
32+
<com.google.android.material.button.MaterialButton
3333
android:id="@+id/change_position"
3434
android:layout_width="0dp"
3535
android:layout_height="wrap_content"
@@ -40,7 +40,7 @@
4040
android:text="@string/change_position"/>
4141

4242
<!-- Button ADD BUTTON -->
43-
<Button
43+
<com.google.android.material.button.MaterialButton
4444
android:id="@+id/add_button"
4545
android:layout_width="0dp"
4646
android:layout_height="@dimen/height"
@@ -51,7 +51,7 @@
5151
android:text="@string/add_button"/>
5252

5353
<!-- Button CANCEL -->
54-
<Button
54+
<com.google.android.material.button.MaterialButton
5555
android:id="@+id/cancel_bubble_manager"
5656
android:layout_width="match_parent"
5757
android:layout_height="wrap_content"

app/src/main/res/layout/bubble_manager_first_alert.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
android:layout_margin="@dimen/margin_paragraph_small_horizontal"
3737
android:layout_marginBottom="@dimen/margin_paragraph_small_bottom"/>
3838

39-
<Button
39+
<com.google.android.material.button.MaterialButton
4040
android:id="@+id/enable_first"
4141
android:layout_width="match_parent"
4242
android:layout_height="wrap_content"
@@ -123,7 +123,7 @@
123123
android:adjustViewBounds="true"/>
124124

125125
<!-- Button CANCEL -->
126-
<Button
126+
<com.google.android.material.button.MaterialButton
127127
android:id="@+id/cancel_bubble_manager_first"
128128
android:layout_width="@dimen/width"
129129
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)