Skip to content

Commit

Permalink
Merge branch 'develop' into polynomial-subject-test
Browse files Browse the repository at this point in the history
  • Loading branch information
theayushyadav11 authored Jan 28, 2025
2 parents 467d891 + 0717ce8 commit a0ca152
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/layout-land/resume_lesson_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/state_button_primary_background"
android:drawableTint="@color/component_color_shared_white_background_color"
app:drawableTint="@color/component_color_shared_white_background_color"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:minWidth="144dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/state_button_primary_background"
android:drawableTint="@color/component_color_shared_white_background_color"
app:drawableTint="@color/component_color_shared_white_background_color"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:minWidth="144dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:drawableTint="@color/component_color_shared_multipane_icon_color"
app:drawableTint="@color/component_color_shared_multipane_icon_color"
android:gravity="center_vertical"
android:minHeight="48dp"
android:text="@string/menu_options"
Expand All @@ -28,7 +28,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:drawableTint="@color/component_color_shared_multipane_icon_color"
app:drawableTint="@color/component_color_shared_multipane_icon_color"
android:gravity="center_vertical"
android:minHeight="48dp"
android:text="@string/menu_help"
Expand All @@ -41,7 +41,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:drawableTint="@color/component_color_shared_multipane_icon_color"
app:drawableTint="@color/component_color_shared_multipane_icon_color"
android:gravity="center_vertical"
android:minHeight="48dp"
android:text="@string/bottom_sheet_options_menu_close"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?><!-- TODO(#59): Make this layout only accessible to tests. -->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand All @@ -20,13 +21,15 @@
android:layout_height="wrap_content"
android:max="@{viewModel.defaultMaximum}"
android:min="@{viewModel.defaultMinimum}"
tools:targetApi="26"
app:animatedProgress="@{viewModel.currentAutoProgress}" />

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/circular_progress_indicator_test_unbound_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="@{viewModel.defaultMaximum}"
android:min="@{viewModel.defaultMinimum}" />
android:min="@{viewModel.defaultMinimum}"
tools:targetApi="26"/>
</LinearLayout>
</layout>
4 changes: 3 additions & 1 deletion app/src/main/res/layout/content_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand Down Expand Up @@ -44,6 +45,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:breakStrategy="simple"
tools:targetApi="23"
android:fontFamily="sans-serif"
android:minWidth="48dp"
android:minHeight="48dp"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/feedback_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand Down Expand Up @@ -44,6 +45,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:breakStrategy="simple"
tools:targetApi="23"
android:fontFamily="sans-serif"
android:minWidth="48dp"
android:minHeight="48dp"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/profile_list_control_buttons.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand Down Expand Up @@ -52,6 +53,7 @@
android:layout_height="wrap_content"
android:max="@{viewModel.forceUploadProgress.totalEventsToUpload}"
android:min="0"
tools:targetApi="26"
app:animatedProgress="@{viewModel.forceUploadProgress.eventsUploaded}"
android:visibility="@{viewModel.forceUploadProgress.hasEventsToUpload() ? View.VISIBLE : View.GONE, default=gone}"
app:layout_constraintBottom_toBottomOf="@+id/learner_analytics_upload_logs_now_button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand Down Expand Up @@ -38,6 +39,7 @@
app:entityId="@{viewModel.promotedStory.storyId}"
app:entityType="@{viewModel.entityType}"
android:forceDarkAllowed="false"
tools:targetApi="29"
app:layout_constraintDimensionRatio="4:3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/promoted_story_card.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand Down Expand Up @@ -36,6 +37,7 @@
app:entityId="@{viewModel.promotedStory.storyId}"
app:entityType="@{viewModel.entityType}"
android:forceDarkAllowed="false"
tools:targetApi="29"
app:layout_constraintDimensionRatio="H, 16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/recently_played_story_card.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand Down Expand Up @@ -39,6 +40,7 @@
app:entityId="@{viewModel.promotedStory.storyId}"
app:entityType="@{viewModel.entityType}"
android:forceDarkAllowed="false"
tools:targetApi="29"
app:layout_constraintDimensionRatio="4:3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
9 changes: 8 additions & 1 deletion domain/src/main/assets/test_exp_id_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,14 @@
"denominator": 2
}
}
}],
},
{
"rule_type": "HasIntegerPartEqualTo",
"inputs": {
"x": 1
}
}
],
"outcome": {
"dest": "MultipleChoice",
"feedback": {
Expand Down
9 changes: 9 additions & 0 deletions domain/src/main/assets/test_exp_id_2.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,15 @@ states {
}
rule_type: "IsExactlyEqualTo"
}
rule_specs {
input {
key: "x"
value {
signed_int: 1
}
}
rule_type: "HasIntegerPartEqualTo"
}
}
solution {
answer_is_exclusive: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ class StateRetriever @Inject constructor() {
InteractionObject.newBuilder()
.setNonNegativeInt(inputJson.getInt(keyName))
.build()
"HasIntegerPartEqualTo" ->
InteractionObject.newBuilder()
.setSignedInt(inputJson.getInt(keyName))
.build()
else ->
InteractionObject.newBuilder()
.setFraction(parseFraction(inputJson.getJSONObject(keyName)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,32 @@ class StateRetrieverTest {
assertThat(state.linkedSkillId).isEqualTo("test_skill_id_2")
}

@Test
fun testParseState_withFractionInputInteraction_parsesRuleHasIntegerPartEqualToRuleSpec() {
val state = loadStateFromJson(
stateName = "Fractions",
explorationName = TEST_EXPLORATION_ID_2
)

val ruleSpecMap = state.interaction.answerGroupsList
.flatMap(AnswerGroup::getRuleSpecsList)
.associateBy(RuleSpec::getRuleType)
assertThat(ruleSpecMap).containsKey("HasIntegerPartEqualTo")
}

@Test
fun testParseState_withFractionInput_parsesRuleHasIntegerPartEqualToValueAtX() {
val state = loadStateFromJson(
stateName = "Fractions",
explorationName = TEST_EXPLORATION_ID_2
)

val ruleSpecMap = lookUpRuleSpec(state, "HasIntegerPartEqualTo")
val expectedInputInteractionObject =
InteractionObject.newBuilder().setSignedInt(1).build()
assertThat(ruleSpecMap.inputMap["x"]).isEqualTo(expectedInputInteractionObject)
}

/**
* Return the first [RuleSpec] in the specified [State] matching the specified rule type, or fails
* if one cannot be found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package org.oppia.android.util.parser.html

import android.app.Application
import android.content.res.AssetManager
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.drawable.Drawable
import android.text.Editable
import android.text.Spannable
import android.text.style.ImageSpan
Expand Down Expand Up @@ -60,12 +63,13 @@ class MathTagHandler(
}
is MathContent.MathAsLatex -> {
if (cacheLatexRendering) {
ImageSpan(
LatexImageSpan(
imageRetriever.loadMathDrawable(
content.rawLatex,
lineHeight,
type = if (useInlineRendering) INLINE_TEXT_IMAGE else BLOCK_IMAGE
)
),
useInlineRendering
)
} else {
MathExpressionSpan(
Expand Down Expand Up @@ -144,3 +148,87 @@ class MathTagHandler(
return mathVal?.let { "Math content $it" } ?: ""
}
}

/** An [ImageSpan] that vertically centers a LaTeX drawable within the surrounding text. */
private class LatexImageSpan(
imageDrawable: Drawable?,
private val isInlineMode: Boolean
) : ImageSpan(imageDrawable ?: createEmptyDrawable()) {

companion object {
private const val INLINE_VERTICAL_SHIFT_RATIO = 0.9f

private fun createEmptyDrawable(): Drawable {
return object : Drawable() {
override fun draw(canvas: Canvas) {}
override fun setAlpha(alpha: Int) {}
override fun setColorFilter(colorFilter: android.graphics.ColorFilter?) {}
override fun getOpacity(): Int = android.graphics.PixelFormat.TRANSPARENT

init {
setBounds(0, 0, 1, 1)
}
}
}
}

override fun getSize(
paint: Paint,
text: CharSequence,
start: Int,
end: Int,
fontMetrics: Paint.FontMetricsInt?
): Int {
val drawableBounds = drawable.bounds
val imageHeight = drawableBounds.height()
val textMetrics = paint.fontMetricsInt
val textHeight = textMetrics.descent - textMetrics.ascent

fontMetrics?.let { metrics ->
if (isInlineMode) {
val verticalShift = (imageHeight - textHeight) / 2 +
(textMetrics.descent * INLINE_VERTICAL_SHIFT_RATIO).toInt()
metrics.ascent = textMetrics.ascent - verticalShift
metrics.top = metrics.ascent
metrics.descent = textMetrics.descent + verticalShift
metrics.bottom = metrics.descent
} else {
val totalHeight = (imageHeight * 1.2).toInt()
metrics.ascent = -totalHeight / 2
metrics.top = metrics.ascent
metrics.descent = totalHeight / 2
metrics.bottom = metrics.descent
}
}
return drawableBounds.right
}

override fun draw(
canvas: Canvas,
text: CharSequence,
start: Int,
end: Int,
x: Float,
lineTop: Int,
baseline: Int,
lineBottom: Int,
paint: Paint
) {
canvas.save()

val imageHeight = drawable.bounds.height()
val yOffset = if (isInlineMode) {
val metrics = paint.fontMetricsInt
val ascent = metrics.ascent.toFloat()
val descent = metrics.descent.toFloat()
val expectedCenterY = baseline.toFloat() + (ascent + descent) / 2f
expectedCenterY - (imageHeight / 2f)
} else {
lineTop.toFloat() + (lineBottom - lineTop - imageHeight) / 2f
}

canvas.translate(x, yOffset)
drawable.draw(canvas)
canvas.restore()
}
}
Loading

0 comments on commit a0ca152

Please sign in to comment.