* For #345 #346 - Adds private browsing theme Co-authored-by: Sawyer Blatz <sdblatz@gmail.com> * Abstracts theme management * Theme browser toolbar * Remove unused imports * Begin work on sharedPreferences * fix lint * #346 - Refactors ThemeManager to take a callback * Adds clean status bar and nav bar * lint * Themes settings icons better * Small clean upnightly-build-test
parent
a29952a2c0
commit
d09dc149ed
@ -0,0 +1,79 @@
|
||||
/* 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 org.mozilla.fenix
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
interface ThemeManager {
|
||||
enum class Theme {
|
||||
Light, Private
|
||||
}
|
||||
|
||||
val currentTheme: Theme
|
||||
fun setTheme(theme: Theme)
|
||||
}
|
||||
|
||||
fun Activity.setTheme(theme: ThemeManager.Theme) {
|
||||
val themeCode = when (theme) {
|
||||
ThemeManager.Theme.Light -> R.style.LightTheme
|
||||
ThemeManager.Theme.Private -> R.style.PrivateTheme
|
||||
}
|
||||
|
||||
setTheme(themeCode)
|
||||
}
|
||||
|
||||
fun ThemeManager.Theme.isPrivate(): Boolean = this == ThemeManager.Theme.Private
|
||||
|
||||
private var temporaryThemeManagerStorage = ThemeManager.Theme.Light
|
||||
class DefaultThemeManager : ThemeManager {
|
||||
var onThemeChange: ((ThemeManager.Theme) -> Unit)? = null
|
||||
|
||||
override val currentTheme: ThemeManager.Theme
|
||||
get() = temporaryThemeManagerStorage
|
||||
|
||||
override fun setTheme(theme: ThemeManager.Theme) {
|
||||
temporaryThemeManagerStorage = theme
|
||||
|
||||
onThemeChange?.invoke(currentTheme)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun resolveAttribute(attribute: Int, context: Context): Int {
|
||||
val typedValue = TypedValue()
|
||||
val theme = context.theme
|
||||
theme.resolveAttribute(attribute, typedValue, true)
|
||||
|
||||
return typedValue.resourceId
|
||||
}
|
||||
|
||||
// Handles status bar theme change since the window does not dynamically recreate
|
||||
fun applyStatusBarTheme(window: Window, themeManager: ThemeManager, context: Context) {
|
||||
window.statusBarColor = ContextCompat
|
||||
.getColor(context, DefaultThemeManager
|
||||
.resolveAttribute(android.R.attr.statusBarColor, context))
|
||||
|
||||
window.navigationBarColor = ContextCompat
|
||||
.getColor(context, DefaultThemeManager
|
||||
.resolveAttribute(android.R.attr.navigationBarColor, context))
|
||||
|
||||
when (themeManager.currentTheme) {
|
||||
ThemeManager.Theme.Light -> {
|
||||
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or
|
||||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
}
|
||||
ThemeManager.Theme.Private -> {
|
||||
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility and
|
||||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() and
|
||||
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape>
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:startColor="?attr/homeBackgroundTopGradient"
|
||||
android:endColor="?attr/homeBackgroundBottomGradient"
|
||||
android:type="linear" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/searchPrivateBackground"/>
|
||||
|
||||
<stroke android:width="1dp"
|
||||
android:color="@color/searchStrokePrivate"/>
|
||||
|
||||
<corners android:radius="8dp"/>
|
||||
</shape>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/searchDarkPrivateBackground"/>
|
||||
|
||||
<stroke android:width="1dp"
|
||||
android:color="@color/searchStrokePrivate"/>
|
||||
|
||||
<corners android:radius="8dp"/>
|
||||
</shape>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/searchDarkPrivateBackgroundAlternative"/>
|
||||
|
||||
<corners android:bottomRightRadius="8dp"
|
||||
android:bottomLeftRadius="8dp"
|
||||
android:topLeftRadius="8dp"
|
||||
android:topRightRadius="8dp"/>
|
||||
</shape>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="m21.457,11.1228 l-8.75,-8.0208c-0.3905,-0.3579 -1.0235,-0.3579 -1.414,0l-8.75,8.0208c-0.379,0.3597 -0.3736,0.9314 0.0122,1.285 0.3857,0.3536 1.0094,0.3586 1.4018,0.0112l1.043,-0.9561v6.9538c0,1.5188 1.3431,2.75 3,2.75h8c1.6569,0 3,-1.2312 3,-2.75v-6.9538l1.043,0.9561c0.3924,0.3474 1.0161,0.3424 1.4018,-0.0112 0.3857,-0.3536 0.3912,-0.9253 0.0122,-1.285zM17,18.4167c0,0.5063 -0.4477,0.9167 -1,0.9167 0.6667,0 0.1667,0 -1.5,0s-3.3333,0 -5,0h-1.5c-0.5523,0 -1,-0.4104 -1,-0.9167v-8.7872l5,-4.5833 5,4.5833z"
|
||||
android:fillColor="@color/offwhite"/>
|
||||
</vector>
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape>
|
||||
<solid android:color="@color/private_browsing_primary" />
|
||||
<corners android:radius="32dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="@color/private_browsing_primary" />
|
||||
<corners android:radius="32dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape>
|
||||
<solid android:color="#000000" />
|
||||
<corners android:radius="32dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="@color/offwhite" />
|
||||
<corners android:radius="32dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
|
||||
<corners android:radius="60dp"/>
|
||||
<solid android:color="@color/private_browsing_primary" />
|
||||
</shape>
|
Loading…
Reference in New Issue