Use new toolbar API of AC 18.0.0.

nightly-build-test
Sebastian Kaspari 5 years ago committed by Jeff Boek
parent 2cba624609
commit 9543f38978

@ -222,11 +222,11 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
view = view view = view
) )
browserToolbarView.view.setOnSiteSecurityClickedListener { browserToolbarView.view.display.setOnSiteSecurityClickedListener {
showQuickSettingsDialog() showQuickSettingsDialog()
} }
browserToolbarView.view.setOnTrackingProtectionClickedListener { browserToolbarView.view.display.setOnTrackingProtectionClickedListener {
context.metrics.track(Event.TrackingProtectionIconPressed) context.metrics.track(Event.TrackingProtectionIconPressed)
showTrackingProtectionPanel() showTrackingProtectionPanel()
} }

@ -379,7 +379,7 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
val tpIcon = val tpIcon =
browserToolbarView browserToolbarView
.view .view
.findViewById<AppCompatImageView>(R.id.mozac_browser_toolbar_tracking_protection_icon_view) .findViewById<AppCompatImageView>(R.id.mozac_browser_toolbar_tracking_protection_indicator)
// Measure layout view // Measure layout view
val spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) val spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)

@ -17,8 +17,8 @@ import kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.*
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.display.DisplayToolbar
import mozilla.components.support.ktx.android.util.dpToFloat import mozilla.components.support.ktx.android.util.dpToFloat
import mozilla.components.support.ktx.android.util.dpToPx
import org.jetbrains.anko.dimen import org.jetbrains.anko.dimen
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.customtabs.CustomTabToolbarMenu import org.mozilla.fenix.customtabs.CustomTabToolbarMenu
@ -54,7 +54,7 @@ class BrowserToolbarView(
init { init {
val isCustomTabSession = customTabSession != null val isCustomTabSession = customTabSession != null
view.setOnUrlLongClickListener { view.display.setOnUrlLongClickListener {
val clipboard = view.context.components.clipboardHandler val clipboard = view.context.components.clipboardHandler
val customView = LayoutInflater.from(view.context) val customView = LayoutInflater.from(view.context)
.inflate(R.layout.browser_toolbar_popup_window, null) .inflate(R.layout.browser_toolbar_popup_window, null)
@ -109,34 +109,45 @@ class BrowserToolbarView(
view.apply { view.apply {
elevation = TOOLBAR_ELEVATION.dpToFloat(resources.displayMetrics) elevation = TOOLBAR_ELEVATION.dpToFloat(resources.displayMetrics)
onUrlClicked = { if (!isCustomTabSession) {
display.setUrlBackground(getDrawable(R.drawable.search_url_background))
}
display.onUrlClicked = {
interactor.onBrowserToolbarClicked() interactor.onBrowserToolbarClicked()
false false
} }
browserActionMargin = browserActionMarginDp.dpToPx(resources.displayMetrics) display.progressGravity = if (isCustomTabSession) {
DisplayToolbar.Gravity.BOTTOM
urlBoxView = if (isCustomTabSession) null else urlBackground } else {
progressBarGravity = if (isCustomTabSession) PROGRESS_BOTTOM else PROGRESS_TOP DisplayToolbar.Gravity.TOP
}
textColor = ContextCompat.getColor(context, R.color.photonGrey30)
hint = context.getString(R.string.search_hint)
suggestionBackgroundColor = ContextCompat.getColor(
container.context,
R.color.suggestion_highlight_color
)
textColor = ContextCompat.getColor( val primaryTextColor = ContextCompat.getColor(
container.context, container.context,
ThemeManager.resolveAttribute(R.attr.primaryText, container.context) ThemeManager.resolveAttribute(R.attr.primaryText, container.context)
) )
val secondaryTextColor = ContextCompat.getColor(
hintColor = ContextCompat.getColor(
container.context, container.context,
ThemeManager.resolveAttribute(R.attr.secondaryText, container.context) ThemeManager.resolveAttribute(R.attr.secondaryText, container.context)
) )
val separatorColor = ContextCompat.getColor(
container.context,
ThemeManager.resolveAttribute(R.attr.toolbarDivider, container.context)
)
display.colors = display.colors.copy(
text = primaryTextColor,
securityIconSecure = primaryTextColor,
securityIconInsecure = primaryTextColor,
menu = primaryTextColor,
hint = secondaryTextColor,
separator = separatorColor,
trackingProtection = primaryTextColor
)
display.hint = context.getString(R.string.search_hint)
} }
val menuToolbar = if (isCustomTabSession) { val menuToolbar = if (isCustomTabSession) {
@ -180,8 +191,5 @@ class BrowserToolbarView(
companion object { companion object {
private const val TOOLBAR_ELEVATION = 16 private const val TOOLBAR_ELEVATION = 16
private const val PROGRESS_BOTTOM = 0
private const val PROGRESS_TOP = 1
const val browserActionMarginDp = 8
} }
} }

@ -12,6 +12,7 @@ import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvide
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.runWithSession import mozilla.components.browser.session.runWithSession
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.display.DisplayToolbar
import mozilla.components.concept.storage.HistoryStorage import mozilla.components.concept.storage.HistoryStorage
import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
import mozilla.components.feature.toolbar.ToolbarFeature import mozilla.components.feature.toolbar.ToolbarFeature
@ -40,7 +41,7 @@ class ToolbarIntegration(
private var renderStyle: ToolbarFeature.RenderStyle = ToolbarFeature.RenderStyle.UncoloredUrl private var renderStyle: ToolbarFeature.RenderStyle = ToolbarFeature.RenderStyle.UncoloredUrl
init { init {
toolbar.setMenuBuilder(toolbarMenu.menuBuilder) toolbar.display.menuBuilder = toolbarMenu.menuBuilder
toolbar.private = isPrivate toolbar.private = isPrivate
run { run {
@ -60,18 +61,33 @@ class ToolbarIntegration(
task.addListener { result -> task.addListener { result ->
val lottieDrawable = LottieDrawable() val lottieDrawable = LottieDrawable()
lottieDrawable.composition = result lottieDrawable.composition = result
toolbar.displayTrackingProtectionIcon =
toolbar.display.indicators = if (
context.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories context.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories
toolbar.displaySeparatorView = ) {
listOf(
DisplayToolbar.Indicators.TRACKING_PROTECTION,
DisplayToolbar.Indicators.SECURITY,
DisplayToolbar.Indicators.EMPTY)
} else {
listOf(DisplayToolbar.Indicators.SECURITY, DisplayToolbar.Indicators.EMPTY)
}
toolbar.display.displayIndicatorSeparator =
context.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories context.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories
toolbar.setTrackingProtectionIcons( toolbar.display.icons = toolbar.display.icons.copy(
iconOnNoTrackersBlocked = AppCompatResources.getDrawable( emptyIcon = AppCompatResources.getDrawable(
context,
R.drawable.ic_bookmark_filled
)!!,
trackingProtectionTrackersBlocked = lottieDrawable,
trackingProtectionNothingBlocked = AppCompatResources.getDrawable(
context, context,
R.drawable.ic_tracking_protection_enabled R.drawable.ic_tracking_protection_enabled
)!!, )!!,
iconOnTrackersBlocked = lottieDrawable, trackingProtectionException = AppCompatResources.getDrawable(
iconDisabledForSite = AppCompatResources.getDrawable(
context, context,
R.drawable.ic_tracking_protection_disabled R.drawable.ic_tracking_protection_disabled
)!! )!!
@ -107,6 +123,7 @@ class ToolbarIntegration(
ThemeManager.resolveAttribute(R.attr.primaryText, context), renderStyle = renderStyle ThemeManager.resolveAttribute(R.attr.primaryText, context), renderStyle = renderStyle
) )
) )
private var menuPresenter = private var menuPresenter =
MenuPresenter(toolbar, context.components.core.sessionManager, sessionId) MenuPresenter(toolbar, context.components.core.sessionManager, sessionId)

@ -14,6 +14,7 @@ import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieDrawable import com.airbnb.lottie.LottieDrawable
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.display.DisplayToolbar
import mozilla.components.feature.customtabs.CustomTabsToolbarFeature import mozilla.components.feature.customtabs.CustomTabsToolbarFeature
import mozilla.components.support.base.feature.BackHandler import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.LifecycleAwareFeature import mozilla.components.support.base.feature.LifecycleAwareFeature
@ -63,17 +64,26 @@ class CustomTabsIntegration(
task.addListener { result -> task.addListener { result ->
val lottieDrawable = LottieDrawable() val lottieDrawable = LottieDrawable()
lottieDrawable.composition = result lottieDrawable.composition = result
toolbar.displayTrackingProtectionIcon =
activity.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories
toolbar.displaySeparatorView = false
toolbar.setTrackingProtectionIcons( toolbar.display.displayIndicatorSeparator = false
iconOnNoTrackersBlocked = AppCompatResources.getDrawable( if (activity.settings().shouldUseTrackingProtection && FeatureFlags.etpCategories) {
toolbar.display.indicators = listOf(
DisplayToolbar.Indicators.SECURITY,
DisplayToolbar.Indicators.TRACKING_PROTECTION
)
} else {
toolbar.display.indicators = listOf(
DisplayToolbar.Indicators.SECURITY
)
}
toolbar.display.icons = toolbar.display.icons.copy(
trackingProtectionTrackersBlocked = lottieDrawable,
trackingProtectionNothingBlocked = AppCompatResources.getDrawable(
activity, activity,
R.drawable.ic_tracking_protection_enabled R.drawable.ic_tracking_protection_enabled
)!!, )!!,
iconOnTrackersBlocked = lottieDrawable, trackingProtectionException = AppCompatResources.getDrawable(
iconDisabledForSite = AppCompatResources.getDrawable(
activity, activity,
R.drawable.ic_tracking_protection_disabled R.drawable.ic_tracking_protection_disabled
)!! )!!

@ -9,7 +9,6 @@ import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.graphics.Typeface.BOLD import android.graphics.Typeface.BOLD
import android.graphics.Typeface.ITALIC import android.graphics.Typeface.ITALIC
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle import android.os.Bundle
import android.text.style.StyleSpan import android.text.style.StyleSpan
import android.view.LayoutInflater import android.view.LayoutInflater
@ -30,7 +29,6 @@ import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.content.hasCamera import mozilla.components.support.ktx.android.content.hasCamera
import mozilla.components.support.ktx.android.content.isPermissionGranted import mozilla.components.support.ktx.android.content.isPermissionGranted
import org.jetbrains.anko.backgroundDrawable
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
@ -193,7 +191,6 @@ class SearchFragment : Fragment(), BackHandler {
consumeFrom(searchStore) { consumeFrom(searchStore) {
awesomeBarView.update(it) awesomeBarView.update(it)
toolbarView.update(it) toolbarView.update(it)
updateSearchEngineIcon(it)
updateSearchWithLabel(it) updateSearchWithLabel(it)
updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url) updateClipboardSuggestion(it, requireContext().components.clipboardHandler.url)
} }
@ -245,14 +242,6 @@ class SearchFragment : Fragment(), BackHandler {
} }
} }
private fun updateSearchEngineIcon(searchState: SearchFragmentState) {
val searchIcon = searchState.searchEngineSource.searchEngine.icon
val draw = BitmapDrawable(resources, searchIcon)
val iconSize = resources.getDimension(R.dimen.preference_icon_drawable_size).toInt()
draw.setBounds(0, 0, iconSize, iconSize)
searchEngineIcon?.backgroundDrawable = draw
}
private fun updateSearchWithLabel(searchState: SearchFragmentState) { private fun updateSearchWithLabel(searchState: SearchFragmentState) {
search_with_shortcuts.visibility = search_with_shortcuts.visibility =
if (searchState.showSearchShortcuts) View.VISIBLE else View.GONE if (searchState.showSearchShortcuts) View.VISIBLE else View.GONE

@ -4,6 +4,8 @@
package org.mozilla.fenix.search.toolbar package org.mozilla.fenix.search.toolbar
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -77,17 +79,21 @@ class ToolbarView(
layoutParams.height = CoordinatorLayout.LayoutParams.MATCH_PARENT layoutParams.height = CoordinatorLayout.LayoutParams.MATCH_PARENT
hint = context.getString(R.string.search_hint) edit.hint = context.getString(R.string.search_hint)
textColor = container.context.getColorFromAttr(R.attr.primaryText) edit.colors = edit.colors.copy(
text = container.context.getColorFromAttr(R.attr.primaryText),
hintColor = container.context.getColorFromAttr(R.attr.secondaryText) hint = container.context.getColorFromAttr(R.attr.secondaryText),
suggestionBackground = ContextCompat.getColor(
suggestionBackgroundColor = ContextCompat.getColor( container.context,
container.context, R.color.suggestion_highlight_color
R.color.suggestion_highlight_color ),
clear = container.context.getColorFromAttr(R.attr.primaryText)
) )
edit.setUrlBackground(
ContextCompat.getDrawable(container.context, R.drawable.search_url_background))
private = isPrivate private = isPrivate
setOnEditListener(object : mozilla.components.concept.toolbar.Toolbar.OnEditListener { setOnEditListener(object : mozilla.components.concept.toolbar.Toolbar.OnEditListener {
@ -122,6 +128,18 @@ class ToolbarView(
view.editMode() view.editMode()
isInitialized = true isInitialized = true
} }
val iconSize = container.resources.getDimensionPixelSize(R.dimen.preference_icon_drawable_size)
val scaledIcon = Bitmap.createScaledBitmap(
searchState.searchEngineSource.searchEngine.icon,
iconSize,
iconSize,
true)
val icon = BitmapDrawable(container.resources, scaledIcon)
view.edit.setIcon(icon, searchState.searchEngineSource.searchEngine.name)
} }
companion object { companion object {

@ -14,31 +14,21 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolbar_wrapper" android:id="@+id/toolbar_wrapper"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="40dp" android:layout_height="56dp"
android:layout_margin="8dp" android:layout_margin="0dp"
android:background="@drawable/search_url_background"
android:outlineProvider="paddedBounds" android:outlineProvider="paddedBounds"
android:transitionName="toolbar_wrapper_transition" android:transitionName="toolbar_wrapper_transition"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/searchEngineIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_margin="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout <FrameLayout
android:id="@+id/toolbar_component_wrapper" android:id="@+id/toolbar_component_wrapper"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/searchEngineIcon" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -52,7 +52,7 @@
<dimen name="bottom_sheet_top_padding">8dp</dimen> <dimen name="bottom_sheet_top_padding">8dp</dimen>
<!-- Browser Toolbar --> <!-- Browser Toolbar -->
<dimen name="browser_toolbar_height">57dp</dimen> <dimen name="browser_toolbar_height">56dp</dimen>
<dimen name="toolbar_and_qab_height">67dp</dimen> <dimen name="toolbar_and_qab_height">67dp</dimen>
<!-- SignIn Component --> <!-- SignIn Component -->

Loading…
Cancel
Save