Skip to content

Commit

Permalink
Make SurveyOnboardingBackgroundView generic for reuse.
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes committed Mar 27, 2024
1 parent 5d86f13 commit a17713d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ VIEWS_WITH_RESOURCE_IMPORTS = [
"src/main/java/org/oppia/android/app/customview/LessonThumbnailImageView.kt",
"src/main/java/org/oppia/android/app/customview/PromotedStoryCardView.kt",
"src/main/java/org/oppia/android/app/customview/SegmentedCircularProgressView.kt",
"src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt",
"src/main/java/org/oppia/android/app/customview/OppiaCurveBackgroundView.kt",
"src/main/java/org/oppia/android/app/customview/VerticalDashedLineView.kt",
"src/main/java/org/oppia/android/app/survey/SurveyMultipleChoiceOptionView.kt",
"src/main/java/org/oppia/android/app/survey/SurveyNpsItemOptionView.kt",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.oppia.android.app.customview

import android.content.Context
import android.content.res.TypedArray
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
Expand All @@ -18,33 +18,38 @@ import org.oppia.android.app.view.ViewComponentImpl
import javax.inject.Inject

/**
* CustomView to add a background to [SurveyWelcomeDialogFragment] and [SurveyOutroDialogFragment].
* Without chaptersFinished and totalChapters values this custom-view cannot be created.
* CustomView to add a background to views that require a bezier curve background.
*
* Reference: // https://proandroiddev.com/how-i-drew-custom-shapes-in-bottom-bar-c4539d86afd7 and
* // https://ciechanow.ski/drawing-bezier-curves/
*/
class SurveyOnboardingBackgroundView : View {
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler
class OppiaCurveBackgroundView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
/**
* Used to retrieve the layout direction that should be used to mirror the direction of the
* curve based on locale.
*/
@Inject lateinit var resourceHandler: AppLanguageResourceHandler

private val isRtl by lazy {
resourceHandler.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL
}

private var customBackgroundColor = Color.WHITE // Default color

private lateinit var paint: Paint
private lateinit var path: Path
private var strokeWidth = 2f

constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)

init {
val typedArray: TypedArray =
context.obtainStyledAttributes(attrs, R.styleable.OppiaCurveBackgroundView)
customBackgroundColor =
typedArray.getColor(R.styleable.OppiaCurveBackgroundView_customBackgroundColor, Color.WHITE)
typedArray.recycle()
setupCurvePaint()
}

Expand All @@ -61,10 +66,10 @@ class SurveyOnboardingBackgroundView : View {
val width = this.width.toFloat()
val height = this.height.toFloat()

val controlPoint1X = width * 0.5f
val controlPoint1X = width * 0.55f
val controlPoint1Y = 0f

val controlPoint2X = width * 0.5f
val controlPoint2X = width * 0.52f
val controlPoint2Y = height * 0.2f

val controlPoint3X = width * 1f
Expand All @@ -91,11 +96,8 @@ class SurveyOnboardingBackgroundView : View {
paint = Paint(Paint.ANTI_ALIAS_FLAG)
paint.apply {
style = Paint.Style.FILL_AND_STROKE
strokeWidth = this@SurveyOnboardingBackgroundView.strokeWidth
color = ContextCompat.getColor(
context,
R.color.component_color_survey_popup_background_color
)
strokeWidth = this@OppiaCurveBackgroundView.strokeWidth
color = customBackgroundColor
}
setBackgroundColor(Color.TRANSPARENT)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.oppia.android.app.customview.ContinueButtonView
import org.oppia.android.app.customview.LessonThumbnailImageView
import org.oppia.android.app.customview.PromotedStoryCardView
import org.oppia.android.app.customview.SegmentedCircularProgressView
import org.oppia.android.app.customview.SurveyOnboardingBackgroundView
import org.oppia.android.app.customview.OppiaCurveBackgroundView
import org.oppia.android.app.home.promotedlist.ComingSoonTopicsListView
import org.oppia.android.app.home.promotedlist.PromotedStoryListView
import org.oppia.android.app.player.state.DragDropSortInteractionView
Expand Down Expand Up @@ -42,7 +42,7 @@ interface ViewComponentImpl : ViewComponent {
fun inject(promotedStoryCardView: PromotedStoryCardView)
fun inject(promotedStoryListView: PromotedStoryListView)
fun inject(segmentedCircularProgressView: SegmentedCircularProgressView)
fun inject(surveyOnboardingBackgroundView: SurveyOnboardingBackgroundView)
fun inject(oppiaCurveBackgroundView: OppiaCurveBackgroundView)
fun inject(surveyMultipleChoiceOptionView: SurveyMultipleChoiceOptionView)
fun inject(surveyNpsItemOptionView: SurveyNpsItemOptionView)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.10" />

<org.oppia.android.app.customview.SurveyOnboardingBackgroundView
<org.oppia.android.app.customview.OppiaCurveBackgroundView
android:id="@+id/survey_onboarding_background"
android:layout_width="match_parent"
android:layout_height="0dp"
app:customBackgroundColor="@color/component_color_survey_popup_background_color"
app:layout_constraintTop_toBottomOf="@id/survey_onboarding_title_guide" />

<androidx.constraintlayout.widget.Guideline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.10" />

<org.oppia.android.app.customview.SurveyOnboardingBackgroundView
<org.oppia.android.app.customview.OppiaCurveBackgroundView
android:id="@+id/survey_onboarding_background"
android:layout_width="match_parent"
android:layout_height="0dp"
app:customBackgroundColor="@color/component_color_survey_popup_background_color"
app:layout_constraintTop_toBottomOf="@id/survey_onboarding_title_guide" />

<androidx.constraintlayout.widget.Guideline
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/survey_outro_dialog_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.15" />

<org.oppia.android.app.customview.SurveyOnboardingBackgroundView
<org.oppia.android.app.customview.OppiaCurveBackgroundView
android:id="@+id/survey_onboarding_background"
android:layout_width="match_parent"
android:layout_height="0dp"
app:customBackgroundColor="@color/component_color_survey_popup_background_color"
app:layout_constraintTop_toBottomOf="@id/survey_onboarding_title_guide" />

<androidx.constraintlayout.widget.Guideline
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/survey_welcome_dialog_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.15" />

<org.oppia.android.app.customview.SurveyOnboardingBackgroundView
<org.oppia.android.app.customview.OppiaCurveBackgroundView
android:id="@+id/survey_onboarding_background"
android:layout_width="match_parent"
android:layout_height="0dp"
app:customBackgroundColor="@color/component_color_survey_popup_background_color"
app:layout_constraintTop_toBottomOf="@id/survey_onboarding_title_guide" />

<androidx.constraintlayout.widget.Guideline
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<attr name="isPasswordInput" format="boolean" />
<attr name="inputLength" format="integer" />
</declare-styleable>

<declare-styleable name="OppiaCurveBackgroundView">
<attr name="customBackgroundColor" format="color" />
</declare-styleable>
</resources>
2 changes: 1 addition & 1 deletion scripts/assets/kdoc_validity_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ exempted_file_path: "app/src/main/java/org/oppia/android/app/application/Applica
exempted_file_path: "app/src/main/java/org/oppia/android/app/application/ApplicationInjectorProvider.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/application/ApplicationStartupListenerModule.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/administratorcontrols/RouteToProfileListListener.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/OppiaCurveBackgroundView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/notice/AutomaticAppDeprecationNoticeDialogFragmentPresenter.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsActivityPresenter.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/devoptions/DeveloperOptionsFragment.kt"
Expand Down
2 changes: 1 addition & 1 deletion scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ exempted_file_path: "app/src/main/java/org/oppia/android/app/completedstorylist/
exempted_file_path: "app/src/main/java/org/oppia/android/app/completedstorylist/CompletedStoryListViewModel.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/ChapterNotStartedContainerConstraintLayout.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/ContinueButtonView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/OppiaCurveBackgroundView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/PromotedStoryCardView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/SegmentedCircularProgressView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/SurveyOnboardingBackgroundView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/VerticalDashedLineView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/interaction/FractionInputInteractionView.kt"
exempted_file_path: "app/src/main/java/org/oppia/android/app/customview/interaction/NumericInputInteractionView.kt"
Expand Down

0 comments on commit a17713d

Please sign in to comment.