Skip to content

Commit 37e7046

Browse files
committed
fix #36, allow changing the Bright Display color
1 parent 14e6b54 commit 37e7046

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ android {
4141
}
4242

4343
dependencies {
44-
implementation 'com.simplemobiletools:commons:3.18.6'
44+
implementation 'com.simplemobiletools:commons:3.18.8'
4545
implementation 'com.squareup:otto:1.3.8'
4646
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
4747
}

app/src/main/kotlin/com/simplemobiletools/flashlight/activities/BrightDisplayActivity.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package com.simplemobiletools.flashlight.activities
33
import android.graphics.drawable.ColorDrawable
44
import android.os.Bundle
55
import android.view.WindowManager
6-
6+
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
7+
import com.simplemobiletools.commons.extensions.applyColorFilter
8+
import com.simplemobiletools.commons.extensions.getContrastColor
79
import com.simplemobiletools.flashlight.R
810
import com.simplemobiletools.flashlight.extensions.config
911
import kotlinx.android.synthetic.main.activity_bright_display.*
@@ -13,7 +15,19 @@ class BrightDisplayActivity : SimpleActivity() {
1315
super.onCreate(savedInstanceState)
1416
setContentView(R.layout.activity_bright_display)
1517
supportActionBar?.hide()
16-
display_holder.background = ColorDrawable(config.brightDisplayColor)
18+
setBackgroundColor(config.brightDisplayColor)
19+
20+
bright_display_change_color.setOnClickListener {
21+
ColorPickerDialog(this, config.brightDisplayColor, true, currentColorCallback = {
22+
setBackgroundColor(it)
23+
}) { wasPositivePressed, color ->
24+
if (wasPositivePressed) {
25+
config.brightDisplayColor = color
26+
} else {
27+
setBackgroundColor(config.brightDisplayColor)
28+
}
29+
}
30+
}
1731
}
1832

1933
override fun onResume() {
@@ -28,6 +42,14 @@ class BrightDisplayActivity : SimpleActivity() {
2842
toggleBrightness(false)
2943
}
3044

45+
private fun setBackgroundColor(color: Int) {
46+
bright_display.background = ColorDrawable(color)
47+
48+
val contrastColor = config.brightDisplayColor.getContrastColor()
49+
bright_display_change_color.setTextColor(contrastColor)
50+
bright_display_change_color.background.applyColorFilter(contrastColor)
51+
}
52+
3153
private fun toggleBrightness(increase: Boolean) {
3254
val layout = window.attributes
3355
layout.screenBrightness = (if (increase) 1 else 0).toFloat()

app/src/main/kotlin/com/simplemobiletools/flashlight/activities/WidgetConfigureActivity.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ class WidgetConfigureActivity : SimpleActivity() {
6565
}
6666

6767
private fun pickBackgroundColor() {
68-
ColorPickerDialog(this, mWidgetColorWithoutTransparency) {
69-
mWidgetColorWithoutTransparency = it
70-
updateColors()
68+
ColorPickerDialog(this, mWidgetColorWithoutTransparency) { wasPositivePressed, color ->
69+
if (wasPositivePressed) {
70+
mWidgetColorWithoutTransparency = color
71+
updateColors()
72+
}
7173
}
7274
}
7375

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<FrameLayout
2+
<RelativeLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:id="@+id/display_holder"
4+
android:id="@+id/bright_display_holder"
55
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
android:background="@android:color/white"/>
6+
android:layout_height="match_parent">
7+
8+
<FrameLayout
9+
android:id="@+id/bright_display"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
android:background="@android:color/white"/>
13+
14+
<TextView
15+
android:id="@+id/bright_display_change_color"
16+
android:layout_width="wrap_content"
17+
android:layout_height="wrap_content"
18+
android:layout_centerInParent="true"
19+
android:alpha="0.5"
20+
android:background="@drawable/button_background"
21+
android:padding="@dimen/activity_margin"
22+
android:text="@string/change_color"
23+
android:textSize="@dimen/big_text_size"/>
24+
25+
</RelativeLayout>

0 commit comments

Comments
 (0)