Enable automatic UI adjustment

+ Now the colors are chosen automatically from the background image 
selected
+ This is just amazing and I am very excited (I will tell 2000 ppl about 
it, spread the word please ^^)
This commit is contained in:
Finn M Glas 2020-05-24 21:19:25 +02:00
parent 9681c7021f
commit 3bbfc5374c
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
9 changed files with 94 additions and 21 deletions

View file

@ -37,4 +37,5 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0' implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0' implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.palette:palette:1.0.0'
} }

View file

@ -33,6 +33,12 @@ class ChooseActivity : AppCompatActivity() {
) )
setContentView(R.layout.activity_choose) setContentView(R.layout.activity_choose)
if (getSavedTheme(this) == "custom") {
activity_choose_container.setBackgroundColor(dominantColor)
activity_choose_app_bar.setBackgroundColor(dominantColor)
activity_choose_close.setTextColor(vibrantColor)
}
// As older APIs somehow do not recognize the xml defined onClick // As older APIs somehow do not recognize the xml defined onClick
activity_choose_close.setOnClickListener() { finish() } activity_choose_close.setOnClickListener() { finish() }

View file

@ -6,9 +6,7 @@ import android.os.Bundle
import android.util.TypedValue import android.util.TypedValue
import android.view.* import android.view.*
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.finnmglas.launcher.extern.blink import com.finnmglas.launcher.extern.*
import com.finnmglas.launcher.extern.getSavedTheme
import com.finnmglas.launcher.extern.resetSettings
import kotlinx.android.synthetic.main.activity_firststartup.* import kotlinx.android.synthetic.main.activity_firststartup.*
@ -41,6 +39,12 @@ class FirstStartupActivity : AppCompatActivity(){
) )
setContentView(R.layout.activity_firststartup) setContentView(R.layout.activity_firststartup)
if (getSavedTheme(this) == "custom") {
activity_firststartup_app_bar.setBackgroundColor(dominantColor)
activity_firststartup_container.setBackgroundColor(dominantColor)
activity_firststartup_close.setTextColor(vibrantColor)
}
activity_firststartup_hint_text.blink() // animate activity_firststartup_hint_text.blink() // animate
loadMenu(this) loadMenu(this)

View file

@ -93,6 +93,10 @@ class MainActivity : AppCompatActivity(),
loadSettings(sharedPref) loadSettings(sharedPref)
if (currentTheme == "custom") {
activity_main_settings_icon.setTextColor(vibrantColor)
}
mDetector = GestureDetectorCompat(this, this) mDetector = GestureDetectorCompat(this, this)
mDetector.setOnDoubleTapListener(this) mDetector.setOnDoubleTapListener(this)

View file

@ -56,6 +56,19 @@ class SettingsActivity : AppCompatActivity() {
} }
} }
override fun onStart() {
super.onStart()
if (getSavedTheme(this) == "custom") {
activity_settings_container.setBackgroundColor(dominantColor)
activity_settings_app_bar.setBackgroundColor(dominantColor)
activity_settings_device_settings.setTextColor(vibrantColor)
activity_settings_close.setTextColor(vibrantColor)
activity_settings_tabs.setSelectedTabIndicatorColor(vibrantColor)
}
}
fun backHome(view: View) { finish() } fun backHome(view: View) { finish() }
/** Theme - related */ /** Theme - related */

View file

@ -37,6 +37,9 @@ var appsList : MutableList<ResolveInfo> = mutableListOf()
var background : Bitmap? = null var background : Bitmap? = null
var dominantColor = 0
var vibrantColor = 0
/** REQUEST CODES */ /** REQUEST CODES */
val REQUEST_PICK_IMAGE = 1 val REQUEST_PICK_IMAGE = 1
@ -218,6 +221,9 @@ fun loadSettings(sharedPref : SharedPreferences){
calendarApp = sharedPref.getString("action_calendarApp", "").toString() calendarApp = sharedPref.getString("action_calendarApp", "").toString()
clockApp = sharedPref.getString("action_clockApp", "").toString() clockApp = sharedPref.getString("action_clockApp", "").toString()
dominantColor = sharedPref.getInt("custom_dominant", 0)
vibrantColor = sharedPref.getInt("custom_vibrant", 0)
} }
fun resetSettings(sharedPref : SharedPreferences, context: Context) : MutableList<String>{ fun resetSettings(sharedPref : SharedPreferences, context: Context) : MutableList<String>{
@ -318,7 +324,7 @@ fun getDominantColor(bitmap: Bitmap?): Int {
fun setButtonColor(btn: Button, color: Int) { fun setButtonColor(btn: Button, color: Int) {
if (Build.VERSION.SDK_INT >= 29) if (Build.VERSION.SDK_INT >= 29)
btn.background.colorFilter = BlendModeColorFilter(color, BlendMode.DST_OVER) btn.background.colorFilter = BlendModeColorFilter(color, BlendMode.MULTIPLY)
else else
btn.background.setColorFilter(color, PorterDuff.Mode.MULTIPLY) btn.background.setColorFilter(color, PorterDuff.Mode.MULTIPLY)
} }

View file

@ -13,8 +13,7 @@ import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import com.finnmglas.launcher.ChooseActivity import com.finnmglas.launcher.ChooseActivity
import com.finnmglas.launcher.R import com.finnmglas.launcher.R
import com.finnmglas.launcher.extern.REQUEST_CHOOSE_APP import com.finnmglas.launcher.extern.*
import com.finnmglas.launcher.extern.loadSettings
import kotlinx.android.synthetic.main.fragment_settings_apps.* import kotlinx.android.synthetic.main.fragment_settings_apps.*
/** The 'Apps' Tab associated Fragment in Settings */ /** The 'Apps' Tab associated Fragment in Settings */
@ -32,6 +31,22 @@ class SettingsFragmentApps : Fragment() {
} }
override fun onStart() { override fun onStart() {
if (getSavedTheme(context!!) == "custom") {
fragment_settings_apps_container.setBackgroundColor(dominantColor)
setButtonColor(fragment_settings_apps_choose_up_btn, vibrantColor)
setButtonColor(fragment_settings_apps_choose_down_btn, vibrantColor)
setButtonColor(fragment_settings_apps_choose_left_btn, vibrantColor)
setButtonColor(fragment_settings_apps_choose_right_btn, vibrantColor)
setButtonColor(fragment_settings_apps_choose_vol_up_btn, vibrantColor)
setButtonColor(fragment_settings_apps_choose_vol_down_btn, vibrantColor)
setButtonColor(fragment_settings_apps_launch_btn, vibrantColor)
setButtonColor(fragment_settings_apps_install_btn, vibrantColor)
setButtonColor(fragment_settings_apps_remove_btn, vibrantColor)
}
// Action - selecting buttons // Action - selecting buttons
fragment_settings_apps_choose_up_btn.setOnClickListener{ chooseApp("upApp") } fragment_settings_apps_choose_up_btn.setOnClickListener{ chooseApp("upApp") }
fragment_settings_apps_choose_down_btn.setOnClickListener{ chooseApp("downApp") } fragment_settings_apps_choose_down_btn.setOnClickListener{ chooseApp("downApp") }

View file

@ -15,9 +15,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.finnmglas.launcher.FirstStartupActivity import com.finnmglas.launcher.FirstStartupActivity
import com.finnmglas.launcher.R import com.finnmglas.launcher.R
import com.finnmglas.launcher.extern.openAppSettings import com.finnmglas.launcher.extern.*
import com.finnmglas.launcher.extern.openNewTabWindow
import com.finnmglas.launcher.extern.resetSettings
import kotlinx.android.synthetic.main.fragment_settings_meta.* import kotlinx.android.synthetic.main.fragment_settings_meta.*
/** The 'Meta' Tab associated Fragment in Settings */ /** The 'Meta' Tab associated Fragment in Settings */
@ -34,6 +32,19 @@ class SettingsFragmentMeta : Fragment() {
} }
override fun onStart() { override fun onStart() {
if (getSavedTheme(context!!) == "custom") {
fragment_settings_meta_container.setBackgroundColor(dominantColor)
setButtonColor(fragment_settings_meta_select_launcher_btn, vibrantColor)
setButtonColor(fragment_settings_meta_view_tutorial_btn, vibrantColor)
setButtonColor(fragment_settings_meta_reset_settings_btn, vibrantColor)
fragment_settings_meta_footer_play_icon.setTextColor(vibrantColor)
fragment_settings_meta_footer_github_icon.setTextColor(vibrantColor)
fragment_settings_meta_footer_globe_icon.setTextColor(vibrantColor)
}
// Button onClicks // Button onClicks
fragment_settings_meta_select_launcher_btn.setOnClickListener { fragment_settings_meta_select_launcher_btn.setOnClickListener {

View file

@ -14,6 +14,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.palette.graphics.Palette
import com.finnmglas.launcher.R import com.finnmglas.launcher.R
import com.finnmglas.launcher.extern.* import com.finnmglas.launcher.extern.*
import kotlinx.android.synthetic.main.fragment_settings_theme.* import kotlinx.android.synthetic.main.fragment_settings_theme.*
@ -33,28 +34,32 @@ class SettingsFragmentTheme : Fragment() {
override fun onStart(){ override fun onStart(){
// Hide 'select' button for the selected theme or allow customisation // Hide 'select' button for the selected theme or allow customisation
when (getSavedTheme(this.context!!)) { when (getSavedTheme(context!!)) {
"dark" -> fragment_settings_theme_select_dark_btn.visibility = View.INVISIBLE "dark" -> fragment_settings_theme_select_dark_btn.visibility = View.INVISIBLE
"finn" -> fragment_settings_theme_select_finn_btn.visibility = View.INVISIBLE "finn" -> fragment_settings_theme_select_finn_btn.visibility = View.INVISIBLE
"custom" -> { "custom" -> {
fragment_settings_theme_select_custom_btn.text = getString(R.string.settings_select_image) fragment_settings_theme_select_custom_btn.text = getString(R.string.settings_select_image)
fragment_settings_theme_container.setBackgroundColor(dominantColor)
setButtonColor(fragment_settings_theme_select_finn_btn, vibrantColor)
setButtonColor(fragment_settings_theme_select_dark_btn, vibrantColor)
setButtonColor(fragment_settings_theme_select_custom_btn, vibrantColor)
} }
} }
// Theme changing buttons // Theme changing buttons
fragment_settings_theme_select_dark_btn.setOnClickListener { fragment_settings_theme_select_dark_btn.setOnClickListener {
saveTheme(this.context!!, "dark") saveTheme(context!!, "dark")
activity!!.recreate() activity!!.recreate()
} }
fragment_settings_theme_select_finn_btn.setOnClickListener { fragment_settings_theme_select_finn_btn.setOnClickListener {
saveTheme(this.context!!, "finn") saveTheme(context!!, "finn")
activity!!.recreate() activity!!.recreate()
} }
fragment_settings_theme_select_custom_btn.setOnClickListener { fragment_settings_theme_select_custom_btn.setOnClickListener {
// Request permission (on newer APIs) // Request permission (on newer APIs)
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
when { when {
ContextCompat.checkSelfPermission(this.context!!, ContextCompat.checkSelfPermission(context!!,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
-> letUserPickImage() -> letUserPickImage()
shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE) shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)
@ -94,17 +99,25 @@ class SettingsFragmentTheme : Fragment() {
if (data == null) return if (data == null) return
val imageUri = data.data val imageUri = data.data
background = MediaStore.Images.Media.getBitmap(context!!.contentResolver, imageUri)
/* Save image Uri as string */ Palette.Builder(background!!).generate {
val editor: SharedPreferences.Editor = context!!.getSharedPreferences( it?.let { palette ->
context!!.getString(R.string.preference_file_key), Context.MODE_PRIVATE).edit() dominantColor = palette.getDominantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
editor.putString("background_uri", imageUri.toString()) vibrantColor = palette.getVibrantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
editor.apply()
background = MediaStore.Images.Media.getBitmap(this.context!!.contentResolver, imageUri) /* Save image Uri as string */
val editor: SharedPreferences.Editor = context!!.getSharedPreferences(
context!!.getString(R.string.preference_file_key), Context.MODE_PRIVATE).edit()
editor.putString("background_uri", imageUri.toString())
editor.putInt("custom_dominant", dominantColor)
editor.putInt("custom_vibrant", vibrantColor)
editor.apply()
saveTheme(this.context!!, "custom") saveTheme(context!!, "custom")
activity!!.recreate() activity!!.recreate()
}
}
} }
} }
} }