Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Closes #3824: Adding the site tracking protection icon on the toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 committed Jul 31, 2019
1 parent 99ed80a commit 2ee9d45
Show file tree
Hide file tree
Showing 16 changed files with 641 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.view.View
import android.view.View.OnFocusChangeListener
import android.view.ViewGroup
import android.widget.ImageButton
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.annotation.VisibleForTesting
import androidx.core.view.forEach
Expand Down Expand Up @@ -210,6 +211,37 @@ class BrowserToolbar @JvmOverloads constructor(
editToolbar.urlView.setTextColor(value)
}

/**
* Sets the icon of the tracking protection the site has tracking protection enabled, but none
* trackers have been blocked or detected.
*/
var trackingProtectionONIcon: Drawable
get() = displayToolbar.trackingProtectionONIcon
set(value) {
displayToolbar.trackingProtectionONIcon = value
}

/**
* Sets the icon of the tracking protection icon when is active
* e.g (Trackers have been blocked or detected)
*/
var trackingProtectionActiveIcon: Drawable
get() = displayToolbar.trackingProtectionActiveIcon
set(value) {
displayToolbar.trackingProtectionActiveIcon = value
}

/**
* Sets the colour of the vertical separator between the tracking protection icon and the
* security indicator icon.
*/
@get:ColorInt
var trackingProtectionAndSecurityIndicatorSeparatorColor: Int
get() = displayToolbar.trackingProtectionAndSecurityIndicatorSeparatorColor
set(@ColorInt value) {
displayToolbar.trackingProtectionAndSecurityIndicatorSeparatorColor = value
}

/**
* Sets the size of the text for the title displayed in the toolbar.
*/
Expand Down Expand Up @@ -285,6 +317,29 @@ class BrowserToolbar @JvmOverloads constructor(
}
}

/**
* Sets a listener to be invoked when the site tracking protection indicator icon is clicked.
*/
fun setOnTrackingProtectionClickedListener(listener: (() -> Unit)?) {
if (listener == null) {
displayToolbar.trackingProtectionIconView.setOnClickListener(null)
displayToolbar.trackingProtectionIconView.background = null
} else {
displayToolbar.trackingProtectionIconView.setOnClickListener {
listener.invoke()
}

val outValue = TypedValue()

context.theme.resolveAttribute(
android.R.attr.selectableItemBackgroundBorderless,
outValue,
true)

displayToolbar.trackingProtectionIconView.setBackgroundResource(outValue.resourceId)
}
}

override fun setOnEditListener(listener: Toolbar.OnEditListener) {
editToolbar.editListener = listener
}
Expand Down Expand Up @@ -336,6 +391,25 @@ class BrowserToolbar @JvmOverloads constructor(
field = value
}

override var siteTrackingProtection: Toolbar.SiteTrackingProtection =
Toolbar.SiteTrackingProtection.OFF
set(value) {
if (field != value) {
displayToolbar.setTrackingProtectionState(value)
field = value
}
}

/**
* Set/Get whether a tracking protection icon (usually a shield icon) should be visible.
*/
var displayTrackingProtectionIcon: Boolean = displayToolbar.displayTrackingProtectionIcon
get() = displayToolbar.displayTrackingProtectionIcon
set(value) {
displayToolbar.displayTrackingProtectionIcon = value
field = value
}

init {
context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbar, defStyleAttr, 0).run {
attrs?.let {
Expand Down Expand Up @@ -363,6 +437,12 @@ class BrowserToolbar @JvmOverloads constructor(
R.styleable.BrowserToolbar_browserToolbarClearColor,
editToolbar.clearViewColor
)

trackingProtectionAndSecurityIndicatorSeparatorColor = getColor(
R.styleable.BrowserToolbar_browserToolbarTrackingProtectionAndSecurityIndicatorSeparatorColor,
displayToolbar.trackingProtectionAndSecurityIndicatorSeparatorColor
)

if (peekValue(R.styleable.BrowserToolbar_browserToolbarSuggestionForegroundColor) != null) {
suggestionForegroundColor = getColor(
R.styleable.BrowserToolbar_browserToolbarSuggestionForegroundColor,
Expand Down
Loading

0 comments on commit 2ee9d45

Please sign in to comment.