1
0
Fork 0

Import variables referred to by path

master
Tiger Oakes 2019-06-23 13:13:52 -04:00 committed by Emily Kager
parent 55f5c5d049
commit 30930cdc88
24 changed files with 89 additions and 73 deletions

View File

@ -6,6 +6,8 @@ package org.mozilla.fenix
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Application import android.app.Application
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import io.reactivex.plugins.RxJavaPlugins import io.reactivex.plugins.RxJavaPlugins
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
@ -197,41 +199,40 @@ open class FenixApplication : Application() {
@SuppressLint("WrongConstant") @SuppressLint("WrongConstant")
// Suppressing erroneous lint warning about using MODE_NIGHT_AUTO_BATTERY, a likely library bug // Suppressing erroneous lint warning about using MODE_NIGHT_AUTO_BATTERY, a likely library bug
private fun setDayNightTheme() { private fun setDayNightTheme() {
val settings = Settings.getInstance(this)
when { when {
Settings.getInstance(this).shouldUseLightTheme -> { settings.shouldUseLightTheme -> {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_NO AppCompatDelegate.MODE_NIGHT_NO
) )
} }
Settings.getInstance(this).shouldUseDarkTheme -> { settings.shouldUseDarkTheme -> {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES AppCompatDelegate.MODE_NIGHT_YES
) )
} }
android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.P && SDK_INT < Build.VERSION_CODES.P && settings.shouldUseAutoBatteryTheme -> {
Settings.getInstance(this).shouldUseAutoBatteryTheme -> {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
) )
} }
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P && SDK_INT >= Build.VERSION_CODES.P && settings.shouldFollowDeviceTheme -> {
Settings.getInstance(this).shouldFollowDeviceTheme -> {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
) )
} }
// First run of app no default set, set the default to Follow System for 28+ and Normal Mode otherwise // First run of app no default set, set the default to Follow System for 28+ and Normal Mode otherwise
else -> { else -> {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { if (SDK_INT >= Build.VERSION_CODES.P) {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
) )
Settings.getInstance(this).setFollowDeviceTheme(true) settings.setFollowDeviceTheme(true)
} else { } else {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_NO AppCompatDelegate.MODE_NIGHT_NO
) )
Settings.getInstance(this).setLightTheme(true) settings.setLightTheme(true)
} }
} }
} }

View File

@ -8,6 +8,8 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.util.TypedValue import android.util.TypedValue
import android.view.View import android.view.View
import android.view.Window import android.view.Window
@ -70,7 +72,7 @@ interface ThemeManager {
window: Window, window: Window,
context: Context context: Context
) { ) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { if (SDK_INT >= Build.VERSION_CODES.M) {
window.statusBarColor = ContextCompat window.statusBarColor = ContextCompat
.getColor( .getColor(
context, resolveAttribute(android.R.attr.statusBarColor, context) context, resolveAttribute(android.R.attr.statusBarColor, context)
@ -83,7 +85,7 @@ interface ThemeManager {
window.statusBarColor = Color.BLACK window.statusBarColor = Color.BLACK
} }
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { if (SDK_INT >= Build.VERSION_CODES.O) {
// API level can display handle light navigation bar color // API level can display handle light navigation bar color
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility =
window.decorView.systemUiVisibility or window.decorView.systemUiVisibility or

View File

@ -4,6 +4,7 @@ package org.mozilla.fenix.collections
License, v. 2.0. If a copy of the MPL was not distributed with this 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/. */ file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import android.graphics.PorterDuff.Mode.SRC_IN
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -89,7 +90,7 @@ class CollectionViewHolder(
view.context, view.context,
getIconColor(collection.id) getIconColor(collection.id)
), ),
android.graphics.PorterDuff.Mode.SRC_IN SRC_IN
) )
} }

View File

@ -12,6 +12,7 @@ import android.widget.FrameLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.widget.TextViewCompat import androidx.core.widget.TextViewCompat
import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.ContentViewCallback
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.fenix_snackbar.view.* import kotlinx.android.synthetic.main.fenix_snackbar.view.*
import org.mozilla.fenix.R import org.mozilla.fenix.R
@ -110,7 +111,7 @@ class FenixSnackbar private constructor(
private class FenixSnackbarCallback( private class FenixSnackbarCallback(
private val content: View private val content: View
) : com.google.android.material.snackbar.ContentViewCallback { ) : ContentViewCallback {
override fun animateContentIn(delay: Int, duration: Int) { override fun animateContentIn(delay: Int, duration: Int) {
content.translationY = (content.height).toFloat() content.translationY = (content.height).toFloat()

View File

@ -13,6 +13,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Build.VERSION.SDK_INT
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
@ -33,7 +34,7 @@ class NotificationManager(private val context: Context) {
init { init {
// Create the notification channels we are going to use, but only on API 26+ because the NotificationChannel // Create the notification channels we are going to use, but only on API 26+ because the NotificationChannel
// class is new and not in the support library. // class is new and not in the support library.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel( createNotificationChannel(
RECEIVE_TABS_CHANNEL_ID, RECEIVE_TABS_CHANNEL_ID,
// Pick 'high' because this is a user-triggered action that is expected to be part of a continuity flow. // Pick 'high' because this is a user-triggered action that is expected to be part of a continuity flow.
@ -68,7 +69,7 @@ class NotificationManager(private val context: Context) {
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_VIBRATE or Notification.DEFAULT_SOUND) .setDefaults(Notification.DEFAULT_VIBRATE or Notification.DEFAULT_SOUND)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (SDK_INT >= Build.VERSION_CODES.M) {
builder.setCategory(Notification.CATEGORY_REMINDER) builder.setCategory(Notification.CATEGORY_REMINDER)
} }

View File

@ -4,8 +4,10 @@
package org.mozilla.fenix.ext package org.mozilla.fenix.ext
import android.content.res.Configuration
import android.content.res.Resources import android.content.res.Resources
import android.os.Build import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.text.SpannableString import android.text.SpannableString
import android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE import android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
import androidx.annotation.StringRes import androidx.annotation.StringRes
@ -19,13 +21,19 @@ fun Resources.getSpannable(@StringRes id: Int, spanParts: List<Pair<Any, Iterabl
val resultCreator = SpannableStringCreator() val resultCreator = SpannableStringCreator()
Formatter( Formatter(
SpannableAppendable(resultCreator, spanParts), SpannableAppendable(resultCreator, spanParts),
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { getLocale(configuration)
configuration.locales[0]
} else configuration.locale
).format(getString(id), *spanParts.map { it.first }.toTypedArray()) ).format(getString(id), *spanParts.map { it.first }.toTypedArray())
return resultCreator.toSpannableString() return resultCreator.toSpannableString()
} }
@Suppress("Deprecation")
private fun getLocale(configuration: Configuration) =
if (SDK_INT >= Build.VERSION_CODES.N) {
configuration.locales[0]
} else {
configuration.locale
}
class SpannableStringCreator { class SpannableStringCreator {
private val parts = ArrayList<CharSequence>() private val parts = ArrayList<CharSequence>()
private var length = 0 private var length = 0

View File

@ -4,7 +4,7 @@
package org.mozilla.fenix.home package org.mozilla.fenix.home
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -13,10 +13,10 @@ import androidx.core.content.ContextCompat
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.session_bottom_sheet.view.* import kotlinx.android.synthetic.main.session_bottom_sheet.view.*
import org.mozilla.fenix.utils.ItsNotBrokenSnack
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ThemeManager import org.mozilla.fenix.ThemeManager
import org.mozilla.fenix.ext.getColorFromAttr import org.mozilla.fenix.ext.getColorFromAttr
import org.mozilla.fenix.utils.ItsNotBrokenSnack
class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer { class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer {
sealed class SessionType { sealed class SessionType {
@ -48,7 +48,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
ContextCompat.getColor( ContextCompat.getColor(
context!!, context!!,
ThemeManager.resolveAttribute(R.attr.accent, context!!) ThemeManager.resolveAttribute(R.attr.accent, context!!)
), PorterDuff.Mode.SRC_IN ), SRC_IN
) )
setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
setOnClickListener { setOnClickListener {
@ -59,7 +59,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
view.delete_session_button.apply { view.delete_session_button.apply {
val drawable = ContextCompat.getDrawable(context!!, R.drawable.ic_delete) val drawable = ContextCompat.getDrawable(context!!, R.drawable.ic_delete)
drawable?.setColorFilter( drawable?.setColorFilter(
R.attr.destructive.getColorFromAttr(context), PorterDuff.Mode.SRC_IN R.attr.destructive.getColorFromAttr(context), SRC_IN
) )
setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
} }
@ -70,7 +70,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
ContextCompat.getColor( ContextCompat.getColor(
context!!, context!!,
ThemeManager.resolveAttribute(R.attr.primaryText, context!!) ThemeManager.resolveAttribute(R.attr.primaryText, context!!)
), PorterDuff.Mode.SRC_IN ), SRC_IN
) )
setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
} }

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.home.sessioncontrol.viewholders package org.mozilla.fenix.home.sessioncontrol.viewholders
import android.content.Context import android.content.Context
import android.graphics.PorterDuff.Mode.SRC_IN
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -104,7 +105,7 @@ class CollectionViewHolder(
view.context, view.context,
getIconColor(collection.id) getIconColor(collection.id)
), ),
android.graphics.PorterDuff.Mode.SRC_IN SRC_IN
) )
} }

View File

@ -5,6 +5,8 @@
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
import android.content.Context import android.content.Context
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -29,7 +31,7 @@ class OnboardingThemePickerViewHolder(private val view: View) : RecyclerView.Vie
val radioDarkTheme = view.theme_dark_radio_button val radioDarkTheme = view.theme_dark_radio_button
val radioFollowDeviceTheme = view.theme_automatic_radio_button val radioFollowDeviceTheme = view.theme_automatic_radio_button
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { if (SDK_INT >= Build.VERSION_CODES.P) {
radioFollowDeviceTheme?.key = R.string.pref_key_follow_device_theme radioFollowDeviceTheme?.key = R.string.pref_key_follow_device_theme
} else { } else {
radioFollowDeviceTheme?.key = R.string.pref_key_auto_battery_theme radioFollowDeviceTheme?.key = R.string.pref_key_auto_battery_theme
@ -69,7 +71,7 @@ class OnboardingThemePickerViewHolder(private val view: View) : RecyclerView.Vie
} }
radioFollowDeviceTheme.onClickListener { radioFollowDeviceTheme.onClickListener {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { if (SDK_INT >= Build.VERSION_CODES.P) {
setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
} else { } else {
setNewTheme(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY) setNewTheme(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)

View File

@ -4,7 +4,7 @@
package org.mozilla.fenix.library package org.mozilla.fenix.library
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -97,6 +97,6 @@ class LibraryFragment : Fragment() {
toolbar.setBackgroundColor(backgroundColor) toolbar.setBackgroundColor(backgroundColor)
toolbar.setTitleTextColor(foregroundColor) toolbar.setTitleTextColor(foregroundColor)
toolbar.navigationIcon?.colorFilter = toolbar.navigationIcon?.colorFilter =
PorterDuffColorFilter(foregroundColor, PorterDuff.Mode.SRC_IN) PorterDuffColorFilter(foregroundColor, SRC_IN)
} }
} }

View File

@ -7,7 +7,7 @@ package org.mozilla.fenix.library.bookmarks
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -158,7 +158,7 @@ class BookmarkFragment : Fragment(), BackHandler, AccountObserver {
isVisible = mode.selectedItems.size == 1 isVisible = mode.selectedItems.size == 1
icon.colorFilter = PorterDuffColorFilter( icon.colorFilter = PorterDuffColorFilter(
ContextCompat.getColor(context!!, R.color.white_color), ContextCompat.getColor(context!!, R.color.white_color),
PorterDuff.Mode.SRC_IN SRC_IN
) )
} }
} }

View File

@ -4,7 +4,7 @@
package org.mozilla.fenix.library.bookmarks package org.mozilla.fenix.library.bookmarks
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
@ -90,7 +90,7 @@ class BookmarkUIView(
private fun setToolbarColors(foreground: Int, background: Int) { private fun setToolbarColors(foreground: Int, background: Int) {
val toolbar = activity?.findViewById<Toolbar>(R.id.navigationToolbar) val toolbar = activity?.findViewById<Toolbar>(R.id.navigationToolbar)
val colorFilter = PorterDuffColorFilter( val colorFilter = PorterDuffColorFilter(
ContextCompat.getColor(context, foreground), PorterDuff.Mode.SRC_IN ContextCompat.getColor(context, foreground), SRC_IN
) )
toolbar?.run { toolbar?.run {
setBackgroundColor(ContextCompat.getColor(context, background)) setBackgroundColor(ContextCompat.getColor(context, background))

View File

@ -4,7 +4,7 @@
package org.mozilla.fenix.library.bookmarks.addfolder package org.mozilla.fenix.library.bookmarks.addfolder
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -71,7 +71,7 @@ class AddBookmarkFolderFragment : Fragment() {
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.bookmarks_add_folder, menu) inflater.inflate(R.menu.bookmarks_add_folder, menu)
menu.findItem(R.id.confirm_add_folder_button).icon.colorFilter = menu.findItem(R.id.confirm_add_folder_button).icon.colorFilter =
PorterDuffColorFilter(R.attr.primaryText.getColorFromAttr(context!!), PorterDuff.Mode.SRC_IN) PorterDuffColorFilter(R.attr.primaryText.getColorFromAttr(context!!), SRC_IN)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {

View File

@ -6,7 +6,7 @@ package org.mozilla.fenix.library.bookmarks.edit
import android.content.Context import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -142,7 +142,7 @@ class EditBookmarkFragment : Fragment() {
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.bookmarks_edit, menu) inflater.inflate(R.menu.bookmarks_edit, menu)
menu.findItem(R.id.delete_bookmark_button).icon.colorFilter = menu.findItem(R.id.delete_bookmark_button).icon.colorFilter =
PorterDuffColorFilter(R.attr.primaryText.getColorFromAttr(context!!), PorterDuff.Mode.SRC_IN) PorterDuffColorFilter(R.attr.primaryText.getColorFromAttr(context!!), SRC_IN)
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {

View File

@ -5,7 +5,7 @@
package org.mozilla.fenix.library.bookmarks.selectfolder package org.mozilla.fenix.library.bookmarks.selectfolder
import android.content.Context import android.content.Context
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -131,7 +131,7 @@ class SelectBookmarkFolderFragment : Fragment(), AccountObserver {
if (!visitedAddBookmark) { if (!visitedAddBookmark) {
inflater.inflate(R.menu.bookmarks_select_folder, menu) inflater.inflate(R.menu.bookmarks_select_folder, menu)
menu.findItem(R.id.add_folder_button).icon.colorFilter = menu.findItem(R.id.add_folder_button).icon.colorFilter =
PorterDuffColorFilter(R.attr.primaryText.getColorFromAttr(context!!), PorterDuff.Mode.SRC_IN) PorterDuffColorFilter(R.attr.primaryText.getColorFromAttr(context!!), SRC_IN)
} }
} }

View File

@ -5,7 +5,7 @@
package org.mozilla.fenix.library.history package org.mozilla.fenix.library.history
import android.content.DialogInterface import android.content.DialogInterface
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
@ -107,7 +107,7 @@ class HistoryFragment : Fragment(), BackHandler {
isVisible = mode.selectedItems.isNotEmpty() isVisible = mode.selectedItems.isNotEmpty()
icon.colorFilter = PorterDuffColorFilter( icon.colorFilter = PorterDuffColorFilter(
ContextCompat.getColor(context!!, R.color.white_color), ContextCompat.getColor(context!!, R.color.white_color),
PorterDuff.Mode.SRC_IN SRC_IN
) )
} }
} }

View File

@ -4,14 +4,14 @@
package org.mozilla.fenix.library.history package org.mozilla.fenix.library.history
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import android.widget.ImageButton import android.widget.ImageButton
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -97,9 +97,7 @@ class HistoryUIView(
private fun setToolbarColors(foreground: Int, background: Int) { private fun setToolbarColors(foreground: Int, background: Int) {
val toolbar = (activity as AppCompatActivity).findViewById<Toolbar>(R.id.navigationToolbar) val toolbar = (activity as AppCompatActivity).findViewById<Toolbar>(R.id.navigationToolbar)
val colorFilter = PorterDuffColorFilter( val colorFilter = PorterDuffColorFilter(ContextCompat.getColor(context, foreground), SRC_IN)
ContextCompat.getColor(context, foreground), PorterDuff.Mode.SRC_IN
)
toolbar.setBackgroundColor(ContextCompat.getColor(context, background)) toolbar.setBackgroundColor(ContextCompat.getColor(context, background))
toolbar.setTitleTextColor(ContextCompat.getColor(context, foreground)) toolbar.setTitleTextColor(ContextCompat.getColor(context, foreground))

View File

@ -4,7 +4,7 @@ package org.mozilla.fenix.search.awesomebar
License, v. 2.0. If a copy of the MPL was not distributed with this 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/. */ file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -93,13 +93,13 @@ class AwesomeBarUIView(
init { init {
with(container.context) { with(container.context) {
val draw = getDrawable(R.drawable.ic_link) val primaryTextColor = ContextCompat.getColor(
draw?.setColorFilter( this,
ContextCompat.getColor( ThemeManager.resolveAttribute(R.attr.primaryText, this)
this,
ThemeManager.resolveAttribute(R.attr.primaryText, this)
), PorterDuff.Mode.SRC_IN
) )
val draw = getDrawable(R.drawable.ic_link)
draw?.setColorFilter(primaryTextColor, SRC_IN)
clipboardSuggestionProvider = ClipboardSuggestionProvider( clipboardSuggestionProvider = ClipboardSuggestionProvider(
this, this,
loadUrlUseCase, loadUrlUseCase,
@ -130,12 +130,7 @@ class AwesomeBarUIView(
if (Settings.getInstance(container.context).showSearchSuggestions) { if (Settings.getInstance(container.context).showSearchSuggestions) {
val searchDrawable = getDrawable(R.drawable.ic_search) val searchDrawable = getDrawable(R.drawable.ic_search)
searchDrawable?.setColorFilter( searchDrawable?.setColorFilter(primaryTextColor, SRC_IN)
ContextCompat.getColor(
this,
ThemeManager.resolveAttribute(R.attr.primaryText, this)
), PorterDuff.Mode.SRC_IN
)
defaultSearchSuggestionProvider = defaultSearchSuggestionProvider =
SearchSuggestionProvider( SearchSuggestionProvider(
searchEngine = components.search.searchEngineManager.getDefaultSearchEngine( searchEngine = components.search.searchEngineManager.getDefaultSearchEngine(
@ -199,7 +194,7 @@ class AwesomeBarUIView(
ContextCompat.getColor( ContextCompat.getColor(
this, this,
ThemeManager.resolveAttribute(R.attr.primaryText, this) ThemeManager.resolveAttribute(R.attr.primaryText, this)
), PorterDuff.Mode.SRC_IN ), SRC_IN
) )
searchSuggestionFromShortcutProvider = searchSuggestionFromShortcutProvider =

View File

@ -5,6 +5,8 @@
package org.mozilla.fenix.settings package org.mozilla.fenix.settings
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -27,9 +29,10 @@ class AboutFragment : Fragment() {
val appName = requireContext().resources.getString(R.string.app_name) val appName = requireContext().resources.getString(R.string.app_name)
(activity as AppCompatActivity).title = getString(R.string.preferences_about, appName) (activity as AppCompatActivity).title = getString(R.string.preferences_about, appName)
var maybeGecko = " \uD83E\uDD8E " val maybeGecko = if (SDK_INT < Build.VERSION_CODES.N) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) { "GV: "
maybeGecko = "GV: " } else {
" \uD83E\uDD8E "
} }
val aboutText = try { val aboutText = try {

View File

@ -11,12 +11,12 @@ import android.content.Context
import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.support.ktx.android.content.isPermissionGranted import mozilla.components.support.ktx.android.content.isPermissionGranted
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
import android.Manifest.permission.CAMERA as CAMERA_PERMISSION
const val ID_CAMERA_PERMISSION = 0 const val ID_CAMERA_PERMISSION = 0
const val ID_LOCATION_PERMISSION = 1 const val ID_LOCATION_PERMISSION = 1
const val ID_MICROPHONE_PERMISSION = 2 const val ID_MICROPHONE_PERMISSION = 2
const val ID_NOTIFICATION_PERMISSION = 3 const val ID_NOTIFICATION_PERMISSION = 3
private const val CAMERA_PERMISSION = android.Manifest.permission.CAMERA
enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>) { enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>) {
CAMERA(ID_CAMERA_PERMISSION, arrayOf(CAMERA_PERMISSION)), CAMERA(ID_CAMERA_PERMISSION, arrayOf(CAMERA_PERMISSION)),

View File

@ -9,6 +9,8 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle import android.os.Bundle
import android.provider.Settings import android.provider.Settings
import android.widget.Toast import android.widget.Toast
@ -86,7 +88,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener) preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener)
if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.M) { if (SDK_INT <= Build.VERSION_CODES.M) {
findPreference<DefaultBrowserPreference>(getString(R.string.pref_key_make_default_browser))?.apply { findPreference<DefaultBrowserPreference>(getString(R.string.pref_key_make_default_browser))?.apply {
isVisible = false isVisible = false
} }
@ -259,7 +261,7 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
} }
private fun getClickListenerForMakeDefaultBrowser(): OnPreferenceClickListener { private fun getClickListenerForMakeDefaultBrowser(): OnPreferenceClickListener {
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { return if (SDK_INT >= Build.VERSION_CODES.N) {
OnPreferenceClickListener { OnPreferenceClickListener {
val intent = Intent( val intent = Intent(
Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS

View File

@ -5,6 +5,8 @@
package org.mozilla.fenix.settings package org.mozilla.fenix.settings
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
@ -42,7 +44,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
radioDarkTheme.addToRadioGroup(radioLightTheme) radioDarkTheme.addToRadioGroup(radioLightTheme)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { if (SDK_INT >= Build.VERSION_CODES.P) {
radioLightTheme.addToRadioGroup(radioFollowDeviceTheme) radioLightTheme.addToRadioGroup(radioFollowDeviceTheme)
radioDarkTheme.addToRadioGroup(radioFollowDeviceTheme) radioDarkTheme.addToRadioGroup(radioFollowDeviceTheme)
@ -86,7 +88,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
private fun bindFollowDeviceTheme() { private fun bindFollowDeviceTheme() {
val keyDeviceTheme = getString(R.string.pref_key_follow_device_theme) val keyDeviceTheme = getString(R.string.pref_key_follow_device_theme)
radioFollowDeviceTheme = requireNotNull(findPreference(keyDeviceTheme)) radioFollowDeviceTheme = requireNotNull(findPreference(keyDeviceTheme))
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { if (SDK_INT >= Build.VERSION_CODES.P) {
radioFollowDeviceTheme.onClickListener { radioFollowDeviceTheme.onClickListener {
setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
} }

View File

@ -5,7 +5,7 @@
package org.mozilla.fenix.share package org.mozilla.fenix.share
import android.content.Context import android.content.Context
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -143,7 +143,7 @@ class AccountDeviceViewHolder(
itemView.device_icon.apply { itemView.device_icon.apply {
setImageResource(drawableRes) setImageResource(drawableRes)
background.setColorFilter(ContextCompat.getColor(context, colorRes), PorterDuff.Mode.SRC_IN) background.setColorFilter(ContextCompat.getColor(context, colorRes), SRC_IN)
drawable.setTint(ContextCompat.getColor(context, R.color.device_foreground)) drawable.setTint(ContextCompat.getColor(context, R.color.device_foreground))
} }
itemView.device_name.text = name itemView.device_name.text = name

View File

@ -6,7 +6,7 @@ package org.mozilla.fenix.utils
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.PorterDuff import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.AttributeSet import android.util.AttributeSet
@ -16,8 +16,7 @@ import androidx.core.content.ContextCompat.getColor
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ThemeManager import org.mozilla.fenix.ThemeManager
class ClearableEditText @JvmOverloads class ClearableEditText @JvmOverloads constructor(
constructor(
context: Context, context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.editTextStyle defStyleAttr: Int = R.attr.editTextStyle
@ -41,7 +40,7 @@ constructor(
setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_clear, 0) setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_clear, 0)
for (drawable: Drawable in compoundDrawables.filterNotNull()) { for (drawable: Drawable in compoundDrawables.filterNotNull()) {
val color = ThemeManager.resolveAttribute(R.attr.primaryText, context!!) val color = ThemeManager.resolveAttribute(R.attr.primaryText, context!!)
drawable.colorFilter = PorterDuffColorFilter(getColor(context, color), PorterDuff.Mode.SRC_IN) drawable.colorFilter = PorterDuffColorFilter(getColor(context, color), SRC_IN)
} }
} else { } else {
setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)