Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5039 : Align policy text and symbols to the left, partial fix for list items #5573

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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 @@ -12,8 +12,8 @@ import org.oppia.android.app.model.PoliciesFragmentArguments
import org.oppia.android.app.model.PolicyPage
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.PoliciesFragmentBinding
import org.oppia.android.util.locale.LeftAlignedSymbolsSpan
import org.oppia.android.util.parser.html.HtmlParser
import org.oppia.android.util.parser.html.LeftAlignedSymbolsSpan
import org.oppia.android.util.parser.html.PolicyType
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ kt_android_library(
name = "list_item_leading_margin_span",
srcs = [
"ListItemLeadingMarginSpan.kt",
"LeftAlignedSymbolsSpan.kt",
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
],
visibility = [
"//app:__subpackages__",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.oppia.android.util.locale
package org.oppia.android.util.parser.html

import android.graphics.Canvas
import android.graphics.Paint
import android.text.style.ReplacementSpan

// Custom span to force LTR alignment for symbols as well
// Custom span to force LTR alignment for all text including symbols
/**
* Custom span to force LTR (left-to-right) alignment for all text,
* including symbols, regardless of the system's text direction.
*/
class LeftAlignedSymbolsSpan : ReplacementSpan() {
override fun getSize(
paint: Paint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package org.oppia.android.util.parser.html
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.text.Layout
import android.text.Spanned
import android.text.style.LeadingMarginSpan
import androidx.core.view.ViewCompat
import org.oppia.android.util.R
import org.oppia.android.util.R.dimen.spacing_before_bullet
import org.oppia.android.util.locale.OppiaLocale

// TODO(#562): Add screenshot tests to check whether the drawing logic works correctly on all devices.
Expand Down Expand Up @@ -40,7 +40,7 @@ sealed class ListItemLeadingMarginSpan : LeadingMarginSpan {
private val bulletRadius = resources.getDimensionPixelSize(R.dimen.bullet_radius)

private val bulletDiameter by lazy { bulletRadius * 2 }
private val baseMargin = (16f * context.resources.displayMetrics.density).toInt()
private val baseMargin = context.resources.getDimensionPixelSize((spacing_before_bullet))

private val isRtl by lazy {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable appears unused.

displayLocale.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL
Expand Down Expand Up @@ -119,7 +119,8 @@ sealed class ListItemLeadingMarginSpan : LeadingMarginSpan {
private val displayLocale: OppiaLocale.DisplayLocale
) : ListItemLeadingMarginSpan() {
private val resources = context.resources
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and displayLocale above are nolonger used.

private val baseMargin = (16f * context.resources.displayMetrics.density).toInt()
private val baseMargin =
context.resources.getDimensionPixelSize((R.dimen.spacing_before_number_prefix))

// Try to use a computed margin, but otherwise guess if there's no guaranteed spacing.
private var computedLeadingMargin =
Expand All @@ -143,15 +144,6 @@ sealed class ListItemLeadingMarginSpan : LeadingMarginSpan {
val isFirstCharacter = startCharOfSpan == start

if (isFirstCharacter) {
// Force left alignment
paint.textAlign = Paint.Align.LEFT

val textWidth = Rect().also {
paint.getTextBounds(
numberedItemPrefix, /* start= */ 0, /* end= */ numberedItemPrefix.length, it
)
}.width()

// Positioning calculation
val prefixStartX = x.toFloat() + baseMargin

Expand Down
Loading