Skip to content

Commit

Permalink
Apply flavored color to splash screen and dynamic task icon
Browse files Browse the repository at this point in the history
Remove legacy lightning icons.
Remove extra instance of user preferences.
  • Loading branch information
Slion committed Oct 2, 2023
1 parent cafd9f1 commit ea8ed5c
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 180 deletions.
4 changes: 4 additions & 0 deletions app/src/debug/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#3DDC84</color>
</resources>
4 changes: 4 additions & 0 deletions app/src/debug/res/values/ic_launcher_debug_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_debug_background">#3DDC84</color>
</resources>
48 changes: 20 additions & 28 deletions app/src/main/java/acr/browser/lightning/ThemedActivity.kt
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
package acr.browser.lightning

import acr.browser.lightning.di.HiltEntryPoint
import acr.browser.lightning.extensions.setTaskLabel
import acr.browser.lightning.extensions.getDrawable
import acr.browser.lightning.extensions.toBitmap
import acr.browser.lightning.locale.LocaleAwareActivity
import acr.browser.lightning.settings.preferences.UserPreferences
import acr.browser.lightning.utils.ThemeUtils
import android.app.ActivityManager
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.annotation.StyleRes
import androidx.core.content.res.ResourcesCompat
import com.google.android.material.color.MaterialColors
import dagger.hilt.android.EntryPointAccessors
import fulguris.app
import fulguris.app
import timber.log.Timber

//@AndroidEntryPoint
abstract class ThemedActivity : LocaleAwareActivity() {
/**
We need to get our Theme before calling onCreate for settings theme to work.
However onCreate does the Hilt injections so we did not have access to [LocaleAwareActivity.userPreferences] early enough.
Fortunately we can access our Hilt entry point early as shown below.
TODO: Move this in the base class after migrating it to Kotlin.
*/
private val hiltEntryPoint = EntryPointAccessors.fromApplication(app, HiltEntryPoint::class.java)
protected val quickUserPrefs: UserPreferences = hiltEntryPoint.userPreferences
// TODO reduce protected visibility
protected var accentId: AccentTheme = quickUserPrefs.useAccent
protected var themeId: AppTheme = quickUserPrefs.useTheme

// TODO: Do we still need those? Are they working? Do we want to fix them?
protected var accentId: AccentTheme = userPreferences.useAccent
protected var themeId: AppTheme = userPreferences.useTheme

/**
* Override this to provide an alternate theme that should be set for every instance of this
Expand Down Expand Up @@ -71,6 +57,17 @@ abstract class ThemedActivity : LocaleAwareActivity() {
// That's apparently not an issue specific to Fulguris
applyTheme(provideThemeOverride()?:themeId)
applyAccent()
// NOTE: https://github.com/Slion/Fulguris/issues/308
// Only now call on create which will do Hilt injections
super.onCreate(savedInstanceState)
setDefaultTaskDescriptor()
resetPreferences()
}

/**
*
*/
private fun setDefaultTaskDescriptor() {
// Make sure we reset task description when an activity is created
//setTaskLabel(getString(R.string.app_name))
// Looks like the new API has no effect Samsung on Tab S8 so weird
Expand All @@ -83,19 +80,14 @@ abstract class ThemedActivity : LocaleAwareActivity() {
// .build())
// }

if (quickUserPrefs.taskIcon) {
val color = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, Color.BLACK)
val icon = ResourcesCompat.getDrawable(resources, R.mipmap.ic_launcher, theme)!!.toBitmap(256,256)
if (userPreferences.taskIcon) {
//val color = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, Color.BLACK)
val color = getColor(R.color.ic_launcher_background)
val icon = getDrawable(R.drawable.ic_lightning_flavored, android.R.attr.state_enabled).toBitmap(aBackground = color)
setTaskDescription(ActivityManager.TaskDescription(getString(R.string.app_name),icon, color))
} else {
setTaskDescription(ActivityManager.TaskDescription(getString(R.string.app_name)))
}


// NOTE: https://github.com/Slion/Fulguris/issues/308
// Only now call on create which will do Hilt injections
super.onCreate(savedInstanceState)
resetPreferences()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3406,7 +3406,8 @@ abstract class BrowserActivity : ThemedBrowserActivity(), BrowserView, UIControl

tabsManager.currentTab?.let { tab ->
if (userPreferences.taskIcon) {
val color = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, Color.BLACK)
//val color = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, Color.BLACK)
val color = getColor(R.color.ic_launcher_background)
setTaskDescription(ActivityManager.TaskDescription(getHeaderInfoText(userPreferences.taskLabel),tab.favicon,color))
} else {
setTaskDescription(ActivityManager.TaskDescription(getHeaderInfoText(userPreferences.taskLabel)))
Expand Down

This file was deleted.

127 changes: 127 additions & 0 deletions app/src/main/java/acr/browser/lightning/locale/LocaleAwareActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package acr.browser.lightning.locale

import acr.browser.lightning.di.HiltEntryPoint
import acr.browser.lightning.di.UserPrefs
import acr.browser.lightning.settings.preferences.UserPreferences
import android.content.Intent
import android.content.SharedPreferences
import android.content.res.Configuration
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.text.TextUtilsCompat
import androidx.core.view.ViewCompat
import dagger.hilt.android.EntryPointAccessors
import fulguris.app
import timber.log.Timber
import java.util.Locale
import javax.inject.Inject

//@AndroidEntryPoint
abstract class LocaleAwareActivity :
AppCompatActivity() {
@Volatile
private var mLastLocale: Locale? = null

/**
We need to get our Theme before calling onCreate for settings theme to work.
However onCreate does the Hilt injections so we did not have access to [LocaleAwareActivity.userPreferences] early enough.
Fortunately we can access our Hilt entry point early as shown below.
*/
private val hiltEntryPoint = EntryPointAccessors.fromApplication(app, HiltEntryPoint::class.java)
val userPreferences: UserPreferences = hiltEntryPoint.userPreferences

@UserPrefs
@Inject
lateinit var userSharedPreferences: SharedPreferences

/**
* Is called whenever the application locale has changed. Your Activity must either update
* all localised Strings, or replace itself with an updated version.
*/
abstract fun onLocaleChanged()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mLastLocale = LocaleUtils.requestedLocale(userPreferences.locale)
LocaleUtils.updateLocale(this, mLastLocale)
setLayoutDirection(window.decorView, mLastLocale)
}

/**
* Upon configuration change our new config is reset to system locale.
* Locale.geDefault is also reset to system local apparently.
* That's also true if locale was previously change on the application context.
* Therefore we don't bother with application context for now.
*
* @param newConfig
*/
override fun onConfigurationChanged(newConfig: Configuration) {
val requestedLocale = LocaleUtils.requestedLocale(userPreferences.locale)
Timber.v("Config changed - Last locale: $mLastLocale")
Timber.v("Config changed - Requested locale: $requestedLocale")
Timber.v("Config changed - New config locale (ignored): " + newConfig.locale)

// Check if our request local was changed
if (requestedLocale == mLastLocale) {
// Requested locale is the same make sure we apply it anew as it was reset in our new config
LocaleUtils.updateLocale(this, mLastLocale)
setLayoutDirection(window.decorView, mLastLocale)
} else {
// Requested locale was changed, we will need to restart our activity then
localeChanged(requestedLocale)
}
super.onConfigurationChanged(newConfig)
}

/**
*
*/
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

//onConfigurationChanged(getResources().getConfiguration());
}

/**
*
* @param aNewLocale
*/
private fun localeChanged(aNewLocale: Locale) {
Timber.v("Apply locale: $aNewLocale")
mLastLocale = aNewLocale
onLocaleChanged()
}

override fun onResume() {
super.onResume()
val requestedLocale = LocaleUtils.requestedLocale(userPreferences.locale)
Timber.v("Resume - Last locale: $mLastLocale")
Timber.v("Resume - Requested locale: $requestedLocale")

// Check if locale was changed as we were paused, apply new locale as needed
if (requestedLocale != mLastLocale) {
localeChanged(requestedLocale)
}
}

companion object {
private const val TAG = "LocaleAwareActivity"

/**
* Force set layout direction to RTL or LTR by Locale.
*
* @param view
* @param locale
*/
fun setLayoutDirection(view: View?, locale: Locale?) {
when (TextUtilsCompat.getLayoutDirectionFromLocale(locale)) {
ViewCompat.LAYOUT_DIRECTION_RTL -> ViewCompat.setLayoutDirection(view!!, ViewCompat.LAYOUT_DIRECTION_RTL)
ViewCompat.LAYOUT_DIRECTION_LTR -> ViewCompat.setLayoutDirection(view!!, ViewCompat.LAYOUT_DIRECTION_LTR)
else -> ViewCompat.setLayoutDirection(view!!, ViewCompat.LAYOUT_DIRECTION_LTR)
}
}
}
}
Loading

0 comments on commit ea8ed5c

Please sign in to comment.