mirror of
				https://github.com/SimpleMobileTools/Simple-Flashlight.git
				synced 2025-06-05 21:59:19 +02:00 
			
		
		
		
	fix #36, allow changing the Bright Display color
This commit is contained in:
		| @@ -41,7 +41,7 @@ android { | |||||||
| } | } | ||||||
|  |  | ||||||
| dependencies { | dependencies { | ||||||
|     implementation 'com.simplemobiletools:commons:3.18.6' |     implementation 'com.simplemobiletools:commons:3.18.8' | ||||||
|     implementation 'com.squareup:otto:1.3.8' |     implementation 'com.squareup:otto:1.3.8' | ||||||
|     implementation 'com.android.support.constraint:constraint-layout:1.0.2' |     implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,7 +3,9 @@ package com.simplemobiletools.flashlight.activities | |||||||
| import android.graphics.drawable.ColorDrawable | import android.graphics.drawable.ColorDrawable | ||||||
| import android.os.Bundle | import android.os.Bundle | ||||||
| import android.view.WindowManager | import android.view.WindowManager | ||||||
|  | import com.simplemobiletools.commons.dialogs.ColorPickerDialog | ||||||
|  | import com.simplemobiletools.commons.extensions.applyColorFilter | ||||||
|  | import com.simplemobiletools.commons.extensions.getContrastColor | ||||||
| import com.simplemobiletools.flashlight.R | import com.simplemobiletools.flashlight.R | ||||||
| import com.simplemobiletools.flashlight.extensions.config | import com.simplemobiletools.flashlight.extensions.config | ||||||
| import kotlinx.android.synthetic.main.activity_bright_display.* | import kotlinx.android.synthetic.main.activity_bright_display.* | ||||||
| @@ -13,7 +15,19 @@ class BrightDisplayActivity : SimpleActivity() { | |||||||
|         super.onCreate(savedInstanceState) |         super.onCreate(savedInstanceState) | ||||||
|         setContentView(R.layout.activity_bright_display) |         setContentView(R.layout.activity_bright_display) | ||||||
|         supportActionBar?.hide() |         supportActionBar?.hide() | ||||||
|         display_holder.background = ColorDrawable(config.brightDisplayColor) |         setBackgroundColor(config.brightDisplayColor) | ||||||
|  |  | ||||||
|  |         bright_display_change_color.setOnClickListener { | ||||||
|  |             ColorPickerDialog(this, config.brightDisplayColor, true, currentColorCallback = { | ||||||
|  |                 setBackgroundColor(it) | ||||||
|  |             }) { wasPositivePressed, color -> | ||||||
|  |                 if (wasPositivePressed) { | ||||||
|  |                     config.brightDisplayColor = color | ||||||
|  |                 } else { | ||||||
|  |                     setBackgroundColor(config.brightDisplayColor) | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun onResume() { |     override fun onResume() { | ||||||
| @@ -28,6 +42,14 @@ class BrightDisplayActivity : SimpleActivity() { | |||||||
|         toggleBrightness(false) |         toggleBrightness(false) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private fun setBackgroundColor(color: Int) { | ||||||
|  |         bright_display.background = ColorDrawable(color) | ||||||
|  |  | ||||||
|  |         val contrastColor = config.brightDisplayColor.getContrastColor() | ||||||
|  |         bright_display_change_color.setTextColor(contrastColor) | ||||||
|  |         bright_display_change_color.background.applyColorFilter(contrastColor) | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private fun toggleBrightness(increase: Boolean) { |     private fun toggleBrightness(increase: Boolean) { | ||||||
|         val layout = window.attributes |         val layout = window.attributes | ||||||
|         layout.screenBrightness = (if (increase) 1 else 0).toFloat() |         layout.screenBrightness = (if (increase) 1 else 0).toFloat() | ||||||
|   | |||||||
| @@ -65,11 +65,13 @@ class WidgetConfigureActivity : SimpleActivity() { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun pickBackgroundColor() { |     private fun pickBackgroundColor() { | ||||||
|         ColorPickerDialog(this, mWidgetColorWithoutTransparency) { |         ColorPickerDialog(this, mWidgetColorWithoutTransparency) { wasPositivePressed, color -> | ||||||
|             mWidgetColorWithoutTransparency = it |             if (wasPositivePressed) { | ||||||
|  |                 mWidgetColorWithoutTransparency = color | ||||||
|                 updateColors() |                 updateColors() | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private fun requestWidgetUpdate() { |     private fun requestWidgetUpdate() { | ||||||
|         Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java).apply { |         Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java).apply { | ||||||
|   | |||||||
| @@ -1,7 +1,25 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <FrameLayout | <RelativeLayout | ||||||
|     xmlns:android="http://schemas.android.com/apk/res/android" |     xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|     android:id="@+id/display_holder" |     android:id="@+id/bright_display_holder" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="match_parent"> | ||||||
|  |  | ||||||
|  |     <FrameLayout | ||||||
|  |         android:id="@+id/bright_display" | ||||||
|         android:layout_width="match_parent" |         android:layout_width="match_parent" | ||||||
|         android:layout_height="match_parent" |         android:layout_height="match_parent" | ||||||
|         android:background="@android:color/white"/> |         android:background="@android:color/white"/> | ||||||
|  |  | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/bright_display_change_color" | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_centerInParent="true" | ||||||
|  |         android:alpha="0.5" | ||||||
|  |         android:background="@drawable/button_background" | ||||||
|  |         android:padding="@dimen/activity_margin" | ||||||
|  |         android:text="@string/change_color" | ||||||
|  |         android:textSize="@dimen/big_text_size"/> | ||||||
|  |  | ||||||
|  | </RelativeLayout> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user