Skip to content

Commit

Permalink
Merge branch 'bullet-fix-2' into temp-integration-pt3
Browse files Browse the repository at this point in the history
Conflicts:
	utility/src/main/java/org/oppia/util/parser/HtmlParser.kt
  • Loading branch information
BenHenning committed Dec 5, 2019
2 parents dab0642 + a775f02 commit 613cc1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
10 changes: 7 additions & 3 deletions utility/src/main/java/org/oppia/util/parser/HtmlParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.text.style.BulletSpan
import android.text.style.ClickableSpan
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import org.xml.sax.Attributes
import javax.inject.Inject

Expand All @@ -23,6 +24,7 @@ private const val CUSTOM_CONCEPT_CARD_TAG = "oppia-concept-card-link"
class HtmlParser private constructor(
private val urlImageParserFactory: UrlImageParser.Factory,
private val gcsResourceName: String,
private val activity: AppCompatActivity,
private val entityType: String,
private val entityId: String,
private val imageCenterAlign: Boolean,
Expand Down Expand Up @@ -73,7 +75,7 @@ class HtmlParser private constructor(
val end = spannableBuilder.getSpanEnd(it)
spannableBuilder.removeSpan(it)
spannableBuilder.setSpan(
ImprovedBulletSpan(),
ImprovedBulletSpan(activity),
start,
end,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE
Expand Down Expand Up @@ -125,13 +127,15 @@ class HtmlParser private constructor(
}

/** Factory for creating new [HtmlParser]s. */
class Factory @Inject constructor(private val urlImageParserFactory: UrlImageParser.Factory) {
class Factory @Inject constructor(
private val urlImageParserFactory: UrlImageParser.Factory, private val activity: AppCompatActivity
) {
/**
* Returns a new [HtmlParser] with the specified entity type and ID for loading images, and an optionally specified
* [CustomOppiaTagActionListener] for handling custom Oppia tag events.
*/
fun create(gcsResourceName: String, entityType: String, entityId: String, imageCenterAlign: Boolean, customOppiaTagActionListener: CustomOppiaTagActionListener? = null): HtmlParser {
return HtmlParser(urlImageParserFactory, gcsResourceName, entityType, entityId, imageCenterAlign, customOppiaTagActionListener)
return HtmlParser(urlImageParserFactory, gcsResourceName, activity, entityType, entityId, imageCenterAlign, customOppiaTagActionListener)
}
}
}
19 changes: 10 additions & 9 deletions utility/src/main/java/org/oppia/util/parser/ImprovedBulletSpan.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package org.oppia.util.parser

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.graphics.Path.Direction
import android.text.Layout
import android.text.Spanned
import android.text.style.LeadingMarginSpan
import androidx.appcompat.app.AppCompatActivity
import org.oppia.util.R

/**
* Copy of [android.text.style.BulletSpan] from android SDK 28 with removed internal code.
*
* Reference: https://github.com/davidbilik/bullet-span-sample
*/
class ImprovedBulletSpan(
private val bulletRadius: Int = STANDARD_BULLET_RADIUS,
private val gapWidth: Int = STANDARD_GAP_WIDTH,
val color: Int = STANDARD_COLOR
) : LeadingMarginSpan {
class ImprovedBulletSpan(activity: AppCompatActivity) : LeadingMarginSpan {

companion object {
private const val STANDARD_BULLET_RADIUS = 8
private const val STANDARD_GAP_WIDTH = 32
private const val STANDARD_COLOR = 0
private var bulletRadius: Int = 0
private var gapWidth: Int = 0

init {
bulletRadius = (activity as Context).resources.getDimensionPixelSize(R.dimen.bullet_radius)
gapWidth = (activity as Context).resources.getDimensionPixelSize(R.dimen.bullet_gap_width)
}

private var mBulletPath: Path? = null
Expand Down
5 changes: 5 additions & 0 deletions utility/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="bullet_radius">4dp</dimen>
<dimen name="bullet_gap_width">16dp</dimen>
</resources>

0 comments on commit 613cc1b

Please sign in to comment.