Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
6f563f0d
Commit
6f563f0d
authored
Feb 07, 2019
by
Jonathan Almeida
Committed by
Jonathan Almeida
Feb 11, 2019
Browse files
Closes #1876: Tint all icon resources in custom tab
parent
c7ec850e
Changes
4
Hide whitespace changes
Inline
Side-by-side
components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt
View file @
6f563f0d
...
...
@@ -82,7 +82,7 @@ class BrowserToolbar @JvmOverloads constructor(
autocompleteExceptionHandler
/**
* Set/Get whether a site security icon (usually a lock or globe icon) should be next to the URL.
* Set/Get whether a site security icon (usually a lock or globe icon) should be
visible
next to the URL.
*/
var
displaySiteSecurityIcon
:
Boolean
get
()
=
displayToolbar
.
siteSecurityIconView
.
isVisible
()
...
...
@@ -90,6 +90,14 @@ class BrowserToolbar @JvmOverloads constructor(
displayToolbar
.
siteSecurityIconView
.
visibility
=
if
(
value
)
View
.
VISIBLE
else
View
.
GONE
}
/**
* Set/Get the site security icon colours (usually a lock or globe icon). It uses a pair of integers
* which represent the insecure and secure colours respectively.
*/
var
siteSecurityColor
:
Pair
<
Int
,
Int
>
get
()
=
displayToolbar
.
securityIconColor
set
(
value
)
{
displayToolbar
.
securityIconColor
=
value
}
/**
* Gets/Sets a custom view that will be drawn as behind the URL and page actions in display mode.
*/
...
...
@@ -97,6 +105,10 @@ class BrowserToolbar @JvmOverloads constructor(
get
()
=
displayToolbar
.
urlBoxView
set
(
value
)
{
displayToolbar
.
urlBoxView
=
value
}
var
menuViewColor
:
Int
get
()
=
displayToolbar
.
menuViewColor
set
(
value
)
{
displayToolbar
.
menuViewColor
=
value
}
/**
* Gets/Sets the margin to be used between browser actions.
*/
...
...
@@ -238,7 +250,7 @@ class BrowserToolbar @JvmOverloads constructor(
R
.
styleable
.
BrowserToolbar_browserToolbarTextSize
,
textSize
)
/
resources
.
displayMetrics
.
density
displayToolbar
.
menuViewColor
=
getColor
(
menuViewColor
=
getColor
(
R
.
styleable
.
BrowserToolbar_browserToolbarMenuColor
,
displayToolbar
.
menuViewColor
)
...
...
@@ -250,7 +262,7 @@ class BrowserToolbar @JvmOverloads constructor(
R
.
styleable
.
BrowserToolbar_browserToolbarSecureColor
,
displayToolbar
.
securityIconColor
.
second
)
displayToolbar
.
s
ecurity
Icon
Color
=
Pair
(
inSecure
,
secure
)
siteS
ecurityColor
=
Pair
(
inSecure
,
secure
)
}
recycle
()
}
...
...
components/feature/customtabs/src/main/java/mozilla/components/feature/customtabs/CustomTabsToolbarFeature.kt
View file @
6f563f0d
...
...
@@ -37,6 +37,7 @@ class CustomTabsToolbarFeature(
)
:
LifecycleAwareFeature
,
BackHandler
{
private
val
context
=
toolbar
.
context
private
var
initialized
=
false
internal
var
readableColor
=
Color
.
WHITE
override
fun
start
()
{
if
(
initialized
)
{
...
...
@@ -50,6 +51,10 @@ class CustomTabsToolbarFeature(
session
.
customTabConfig
?.
let
{
config
->
// Don't allow clickable toolbar so a custom tab can't switch to edit mode.
toolbar
.
onUrlClicked
=
{
false
}
// If it's available, hold on to the readable colour for other assets.
config
.
toolbarColor
?.
let
{
readableColor
=
getReadableTextColor
(
it
)
}
// Change the toolbar colour
updateToolbarColor
(
config
.
toolbarColor
)
// Add navigation close action
...
...
@@ -69,7 +74,9 @@ class CustomTabsToolbarFeature(
internal
fun
updateToolbarColor
(
toolbarColor
:
Int
?)
{
toolbarColor
?.
let
{
color
->
toolbar
.
setBackgroundColor
(
color
)
toolbar
.
textColor
=
getReadableTextColor
(
color
)
toolbar
.
textColor
=
readableColor
toolbar
.
siteSecurityColor
=
Pair
(
readableColor
,
readableColor
)
toolbar
.
menuViewColor
=
readableColor
}
}
...
...
@@ -80,7 +87,9 @@ class CustomTabsToolbarFeature(
R
.
drawable
.
mozac_ic_close
)
drawableIcon
?.
let
{
drawableIcon
?.
apply
{
setTint
(
readableColor
)
}.
also
{
val
button
=
Toolbar
.
ActionButton
(
it
,
context
.
getString
(
R
.
string
.
mozac_feature_customtabs_exit_button
)
)
{
closeListener
.
invoke
()
}
...
...
@@ -102,10 +111,11 @@ class CustomTabsToolbarFeature(
@VisibleForTesting
internal
fun
addShareButton
(
session
:
Session
)
{
val
button
=
Toolbar
.
ActionButton
(
ContextCompat
.
getDrawable
(
context
,
R
.
drawable
.
mozac_ic_share
),
context
.
getString
(
R
.
string
.
mozac_feature_customtabs_share_link
)
)
{
val
drawable
=
ContextCompat
.
getDrawable
(
context
,
R
.
drawable
.
mozac_ic_share
)
?.
apply
{
setTint
(
readableColor
)
}
val
button
=
Toolbar
.
ActionButton
(
drawable
,
context
.
getString
(
R
.
string
.
mozac_feature_customtabs_share_link
))
{
val
listener
=
shareListener
?:
{
context
.
share
(
session
.
url
)
}
listener
.
invoke
()
}
...
...
@@ -117,14 +127,10 @@ class CustomTabsToolbarFeature(
internal
fun
addMenuItems
(
menuItems
:
List
<
CustomTabMenuItem
>)
{
menuItems
.
map
{
SimpleBrowserMenuItem
(
it
.
name
)
{
it
.
pendingIntent
.
send
()
}
}.
also
{
val
items
=
if
(
menuBuilder
!=
null
)
{
menuBuilder
.
items
+
it
}
else
{
it
}
}.
also
{
items
->
val
combinedItems
=
menuBuilder
?.
let
{
builder
->
builder
.
items
+
items
}
?:
items
toolbar
.
setMenuBuilder
(
BrowserMenuBuilder
(
i
tems
))
toolbar
.
setMenuBuilder
(
BrowserMenuBuilder
(
combinedI
tems
))
}
}
...
...
@@ -134,14 +140,10 @@ class CustomTabsToolbarFeature(
* Removes the current Custom Tabs session when the back button is pressed and returns true.
* Should be called when the back button is pressed.
*/
override
fun
onBackPressed
():
Boolean
{
val
result
=
sessionManager
.
runWithSession
(
sessionId
)
{
closeListener
.
invoke
()
remove
(
it
)
true
}
return
result
override
fun
onBackPressed
()
=
sessionManager
.
runWithSession
(
sessionId
)
{
closeListener
.
invoke
()
remove
(
it
)
true
}
companion
object
{
...
...
components/feature/customtabs/src/test/java/mozilla/components/feature/customtabs/CustomTabsToolbarFeatureTest.kt
View file @
6f563f0d
...
...
@@ -340,4 +340,28 @@ class CustomTabsToolbarFeatureTest {
assertFalse
(
result
)
assertFalse
(
closeExecuted
)
}
@Test
fun
`keep
readableColor
if
toolbarColor
is
provided`
()
{
val
sessionManager
:
SessionManager
=
mock
()
val
toolbar
=
BrowserToolbar
(
RuntimeEnvironment
.
application
)
val
session
:
Session
=
mock
()
val
customTabConfig
:
CustomTabConfig
=
mock
()
val
feature
=
spy
(
CustomTabsToolbarFeature
(
sessionManager
,
toolbar
,
""
)
{})
assertEquals
(
Color
.
WHITE
,
feature
.
readableColor
)
`when`
(
sessionManager
.
findSessionById
(
anyString
())).
thenReturn
(
session
)
`when`
(
session
.
customTabConfig
).
thenReturn
(
customTabConfig
)
feature
.
initialize
(
session
)
assertEquals
(
Color
.
WHITE
,
feature
.
readableColor
)
`when`
(
customTabConfig
.
toolbarColor
).
thenReturn
(
Color
.
WHITE
)
feature
.
initialize
(
session
)
assertEquals
(
Color
.
BLACK
,
feature
.
readableColor
)
}
}
components/feature/toolbar/src/main/java/mozilla/components/feature/toolbar/ToolbarPresenter.kt
View file @
6f563f0d
...
...
@@ -41,8 +41,6 @@ class ToolbarPresenter(
toolbar
.
url
=
session
.
url
updateToolbarSecurity
(
session
.
securityInfo
)
// TODO Apply remaining configurations: https://github.com/mozilla-mobile/android-components/issues/306
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment