1
0
Fork 0

Use new toolbar API of AC 18.0.0.

master
Sebastian Kaspari 2019-10-15 17:54:04 +02:00 committed by Jeff Boek
parent 2cba624609
commit 9543f38978
9 changed files with 104 additions and 72 deletions

View File

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

View File

@ -379,7 +379,7 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
val tpIcon =
browserToolbarView
.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
val spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)

View File

@ -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.session.Session
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.dpToPx
import org.jetbrains.anko.dimen
import org.mozilla.fenix.R
import org.mozilla.fenix.customtabs.CustomTabToolbarMenu
@ -54,7 +54,7 @@ class BrowserToolbarView(
init {
val isCustomTabSession = customTabSession != null
view.setOnUrlLongClickListener {
view.display.setOnUrlLongClickListener {
val clipboard = view.context.components.clipboardHandler
val customView = LayoutInflater.from(view.context)
.inflate(R.layout.browser_toolbar_popup_window, null)
@ -109,34 +109,45 @@ class BrowserToolbarView(
view.apply {
elevation = TOOLBAR_ELEVATION.dpToFloat(resources.displayMetrics)
onUrlClicked = {
if (!isCustomTabSession) {
display.setUrlBackground(getDrawable(R.drawable.search_url_background))
}
display.onUrlClicked = {
interactor.onBrowserToolbarClicked()
false
}
browserActionMargin = browserActionMarginDp.dpToPx(resources.displayMetrics)
display.progressGravity = if (isCustomTabSession) {
DisplayToolbar.Gravity.BOTTOM
} else {
DisplayToolbar.Gravity.TOP
}
urlBoxView = if (isCustomTabSession) null else urlBackground
progressBarGravity = if (isCustomTabSession) PROGRESS_BOTTOM else PROGRESS_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,
ThemeManager.resolveAttribute(R.attr.primaryText, container.context)
)
hintColor = ContextCompat.getColor(
val secondaryTextColor = ContextCompat.getColor(
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) {
@ -180,8 +191,5 @@ class BrowserToolbarView(
companion object {
private const val TOOLBAR_ELEVATION = 16
private const val PROGRESS_BOTTOM = 0
private const val PROGRESS_TOP = 1
const val browserActionMarginDp = 8
}
}

View File

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

View File

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

View File

@ -9,7 +9,6 @@ import android.content.Context
import android.content.DialogInterface
import android.graphics.Typeface.BOLD
import android.graphics.Typeface.ITALIC
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import android.text.style.StyleSpan
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.ktx.android.content.hasCamera
import mozilla.components.support.ktx.android.content.isPermissionGranted
import org.jetbrains.anko.backgroundDrawable
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
@ -193,7 +191,6 @@ class SearchFragment : Fragment(), BackHandler {
consumeFrom(searchStore) {
awesomeBarView.update(it)
toolbarView.update(it)
updateSearchEngineIcon(it)
updateSearchWithLabel(it)
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) {
search_with_shortcuts.visibility =
if (searchState.showSearchShortcuts) View.VISIBLE else View.GONE

View File

@ -4,6 +4,8 @@
package org.mozilla.fenix.search.toolbar
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -77,17 +79,21 @@ class ToolbarView(
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)
hintColor = container.context.getColorFromAttr(R.attr.secondaryText)
suggestionBackgroundColor = ContextCompat.getColor(
container.context,
R.color.suggestion_highlight_color
edit.colors = edit.colors.copy(
text = container.context.getColorFromAttr(R.attr.primaryText),
hint = container.context.getColorFromAttr(R.attr.secondaryText),
suggestionBackground = ContextCompat.getColor(
container.context,
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
setOnEditListener(object : mozilla.components.concept.toolbar.Toolbar.OnEditListener {
@ -122,6 +128,18 @@ class ToolbarView(
view.editMode()
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 {

View File

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

View File

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