Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

For #5356 Improved private browsing "common myths" link accessibility #5479

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders

import android.text.SpannableString
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan
import android.text.style.UnderlineSpan
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer
Expand All @@ -24,26 +23,21 @@ class PrivateBrowsingDescriptionViewHolder(

init {
val resources = view.context.resources
// Format the description text to include a hyperlink
val appName = resources.getString(R.string.app_name)
view.private_session_description.text = resources.getString(R.string.private_browsing_placeholder, appName)
val descriptionText = String
.format(view.private_session_description.text.toString(), System.getProperty("line.separator"))
val linkStartIndex = descriptionText.indexOf("\n\n") + 2
val linkAction = object : ClickableSpan() {
override fun onClick(widget: View?) {
view.private_session_description.text = resources.getString(
R.string.private_browsing_placeholder_description, appName
)
val commonMythsText = view.private_session_common_myths.text.toString()
val textWithLink = SpannableString(commonMythsText).apply {
setSpan(UnderlineSpan(), 0, commonMythsText.length, 0)
}
with(view.private_session_common_myths) {
movementMethod = LinkMovementMethod.getInstance()
text = textWithLink
setOnClickListener {
actionEmitter.onNext(TabAction.PrivateBrowsingLearnMore)
}
}
val textWithLink = SpannableString(descriptionText).apply {
setSpan(linkAction, linkStartIndex, descriptionText.length, 0)

val colorSpan = ForegroundColorSpan(view.private_session_description.currentTextColor)
setSpan(colorSpan, linkStartIndex, descriptionText.length, 0)
}

view.private_session_description.movementMethod = LinkMovementMethod.getInstance()
view.private_session_description.text = textWithLink
}

companion object {
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/res/layout/private_browsing_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@
android:id="@+id/private_session_description_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_margin="12dp"
android:importantForAccessibility="no"
android:orientation="vertical">
<TextView
android:id="@+id/private_session_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:padding="4dp"
android:gravity="center_vertical"
android:scrollHorizontally="false"
tools:text="@string/private_browsing_placeholder"
tools:text="@string/private_browsing_placeholder_description"
android:textColor="?primaryText"
android:textSize="14sp" />
<TextView
android:id="@+id/private_session_common_myths"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:ellipsize="none"
android:gravity="center_vertical"
android:scrollHorizontally="false"
android:text="@string/private_browsing_common_myths"
android:textColor="?primaryText"
android:textSize="14sp" />
</LinearLayout>
8 changes: 5 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
<string name="private_browsing_title">You’re in a private session</string>
<!-- Explanation for private browsing displayed to users on home view when they first enable private mode
The first parameter is the name of the app defined in app_name (for example: Fenix) -->
<string name="private_browsing_placeholder">
<string name="private_browsing_placeholder_description">
%1$s clears your search and browsing history when you quit the app or close all private tabs. While this doesn’t make you anonymous to websites or your internet service provider, it makes it
easier to keep what you do online private from anyone else who uses this device.\n\nCommon myths about private
browsing
easier to keep what you do online private from anyone else who uses this device.
</string>
<string name="private_browsing_common_myths">
Common myths about private browsing
</string>
<!-- Delete session button to erase your history in a private session -->
<string name="private_browsing_delete_session">Delete session</string>
Expand Down