Skip to content

Commit

Permalink
Fix oppia#380: Hi fi input interaction views (oppia#405)
Browse files Browse the repository at this point in the history
* nit

* UI hi-fi for text,number,and fraction input views

* UI hi-fi for text,number,and fraction input views

* UI hi-fi for text,number,and fraction input views nit

* nit

* nit

* test cases update

* accent color

* input type in fraction input type

* input type in fraction input type

* Merge branches 'develop' and 'hi-fi-input-interaction-views' of https://github.com/oppia/oppia-android into hi-fi-input-interaction-views

# Conflicts:
#	app/src/main/res/layout/text_input_interaction_item.xml

* text color in input type views

* changed inputtype in edit text

* margin updated in input views

* nit

* keyboardhelper to handle softinoutkeyboard

* Edit text focus removed.
On click of input type interaction item, it requires two clicks to display keyboard, which should actually be just a single click.
thus preventing scroll due to edit text focus

* as per review suggestion added binding.stateRecyclerView.smoothScrollToPosition(0) in processEphemeralStateResult

* nit

* Fix-406

* nit changes and keybord helper class renamed.

* nit

* kdoc for keyboardhelper.nit changes

* kdoc for keyboardhelper

* nit

* nit

* nit

* nit
  • Loading branch information
nikitamarysolomanpvt committed Nov 19, 2019
1 parent fdef5b9 commit 7704741
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package org.oppia.app.customview.interaction
import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.KeyEvent.ACTION_UP
import android.view.KeyEvent.KEYCODE_BACK
import android.view.View
import android.widget.EditText
import org.oppia.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.app.utility.KeyboardHelper.Companion.showSoftKeyboard

// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
// digits="0123456789/-"
Expand All @@ -26,11 +31,19 @@ class FractionInputInteractionView @JvmOverloads constructor(
hintText = hint.toString()
}

override fun onFocusChange(v: View?, hasFocus: Boolean) = if (hasFocus) {
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hint = ""
typeface = Typeface.DEFAULT
showSoftKeyboard(v, context)
} else {
hint = hintText
setTypeface(typeface, Typeface.ITALIC)
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
hideSoftKeyboard(v, context)
}

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
if (event.keyCode == KEYCODE_BACK && event.action == ACTION_UP)
this.clearFocus()
return super.onKeyPreIme(keyCode, event)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package org.oppia.app.customview.interaction
import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.KeyEvent.ACTION_UP
import android.view.KeyEvent.KEYCODE_BACK
import android.view.View
import android.widget.EditText
import org.oppia.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.app.utility.KeyboardHelper.Companion.showSoftKeyboard

// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
// digits="0123456789."
Expand All @@ -26,11 +31,20 @@ class NumericInputInteractionView @JvmOverloads constructor(
hintText = hint.toString()
}

override fun onFocusChange(v: View?, hasFocus: Boolean) = if (hasFocus) {
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hint = ""
typeface = Typeface.DEFAULT
showSoftKeyboard(v, context)
} else {
hint = hintText
setTypeface(typeface, Typeface.ITALIC)
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
hideSoftKeyboard(v, context)
}

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
if (event.keyCode == KEYCODE_BACK && event.action == ACTION_UP)
this.clearFocus()
return super.onKeyPreIme(keyCode, event)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package org.oppia.app.customview.interaction
import android.content.Context
import android.graphics.Typeface
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.View
import android.widget.EditText
import org.oppia.app.utility.KeyboardHelper.Companion.hideSoftKeyboard
import org.oppia.app.utility.KeyboardHelper.Companion.showSoftKeyboard

// TODO(#249): These are the attributes which should be defined in XML, that are required for this interaction view to work correctly
// hint="Write here."
Expand All @@ -25,11 +28,20 @@ class TextInputInteractionView @JvmOverloads constructor(
hintText = hint.toString()
}

override fun onFocusChange(v: View?, hasFocus: Boolean) = if (hasFocus) {
override fun onFocusChange(v: View, hasFocus: Boolean) = if (hasFocus) {
hint = ""
typeface = Typeface.DEFAULT
showSoftKeyboard(v, context)
} else {
hint = hintText
setTypeface(typeface, Typeface.ITALIC)
if (text.isEmpty()) setTypeface(typeface, Typeface.ITALIC)
hideSoftKeyboard(v, context)
}

override fun onKeyPreIme(keyCode: Int, event: KeyEvent): Boolean {
if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP)
this.clearFocus()
return super.onKeyPreIme(keyCode, event)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ class StateFragmentPresenter @Inject constructor(
}

val ephemeralState = result.getOrThrow()

val scrollToTop = ::currentStateName.isInitialized && currentStateName != ephemeralState.state.name

currentStateName = ephemeralState.state.name
val pendingItemList = mutableListOf<StateItemViewModel>()
addContentItem(pendingItemList, ephemeralState)
Expand Down Expand Up @@ -315,6 +318,10 @@ class StateFragmentPresenter @Inject constructor(

viewModel.itemList.clear()
viewModel.itemList += pendingItemList

if (scrollToTop) {
binding.stateRecyclerView.smoothScrollToPosition(0)
}
}

/**
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/org/oppia/app/utility/KeyboardHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.oppia.app.utility

import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager

/** KeyboardHelper helps to change the visibility of softinputkeybord. */
class KeyboardHelper {
companion object {
/**
* This method hides softinputkeybord
* @param view is the input view
* @param context context of the activity
*/
fun hideSoftKeyboard(view: View, context: Context) {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_IMPLICIT_ONLY)
}

/**
* This method shows softinputkeybord
* @param view is the input view
* @param context context of the activity
*/
fun showSoftKeyboard(view: View, context: Context) {
if (view.requestFocus()) {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
<variable
name="numericInputViewModel"
type="org.oppia.app.player.state.itemviewmodel.NumericInputViewModel" />
<variable
name="textInputViewModel"
type="org.oppia.app.player.state.itemviewmodel.TextInputViewModel" />
<variable
name="fractionInteractionViewModel"
type="org.oppia.app.player.state.itemviewmodel.FractionInteractionViewModel" />
</data>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".testing.InputInteractionViewTestActivity">

Expand Down Expand Up @@ -42,6 +50,7 @@
android:focusable="true"
android:hint="Write here."
android:inputType="text"
android:text="@={textInputViewModel.answerText}"
android:longClickable="false"
android:maxLength="200"
android:padding="8dp"
Expand All @@ -54,6 +63,7 @@
android:layout_margin="8dp"
android:background="@drawable/edit_text_background"
android:digits="0123456789/- "
android:text="@={fractionInteractionViewModel.answerText}"
android:focusable="true"
android:hint="Write fraction here."
android:inputType="date"
Expand Down
72 changes: 32 additions & 40 deletions app/src/main/res/layout/fraction_interaction_item.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto">
<layout xmlns:android="http:https://schemas.android.com/apk/res/android">

<data>

Expand All @@ -9,46 +8,39 @@
type="org.oppia.app.player.state.itemviewmodel.FractionInteractionViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="24dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical">

<FrameLayout
<org.oppia.app.customview.interaction.FractionInputInteractionView
android:id="@+id/fraction_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
android:background="@color/oppiaLightGreen"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent">

<org.oppia.app.customview.interaction.FractionInputInteractionView
android:id="@+id/fraction_input_interaction_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_background"
android:digits="0123456789/- "
android:enabled="@{!viewModel.isReadOnly}"
android:focusable="true"
android:fontFamily="sans-serif"
android:hint="@string/fractions_hint_text"
android:imeOptions="actionDone"
android:inputType="date"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
android:background="@drawable/edit_text_background"
android:digits="0123456789/- "
android:enabled="@{!viewModel.isReadOnly}"
android:fontFamily="sans-serif"
android:hint="@string/fractions_hint_text"
android:imeOptions="actionDone"
android:inputType="date"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
</FrameLayout>
</layout>
11 changes: 6 additions & 5 deletions app/src/main/res/layout/numeric_input_interaction_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="28dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="28dp"
android:layout_marginBottom="24dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical">

<org.oppia.app.customview.interaction.NumericInputInteractionView
Expand All @@ -23,21 +25,20 @@
android:layout_height="wrap_content"
android:background="@drawable/edit_text_background"
android:digits="0123456789."
android:textColor="@color/oppiaPrimaryText"
android:enabled="@{!viewModel.isReadOnly}"
android:focusable="true"
android:fontFamily="sans-serif"
android:hint="@string/number_input_hint_text"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:longClickable="false"
android:imeOptions="actionDone"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/text_input_interaction_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="28dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="28dp"
android:background="@color/oppiaLightGreen"
android:layout_marginBottom="24dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical">

<org.oppia.app.customview.interaction.TextInputInteractionView
Expand All @@ -24,20 +25,19 @@
android:layout_height="wrap_content"
android:background="@drawable/edit_text_background"
android:enabled="@{!viewModel.isReadOnly}"
android:textColor="@color/oppiaPrimaryText"
android:focusable="true"
android:fontFamily="sans-serif"
android:hint="@string/text_input_hint_text"
android:imeOptions="actionDone"
android:inputType="text"
android:longClickable="false"
android:maxLength="200"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:text="@={viewModel.answerText}"
android:textColor="@color/oppiaPrimaryText"
android:textColorHint="@color/edit_text_hint"
android:textSize="16sp"
android:textStyle="italic" />
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Sep 13 18:15:04 IST 2019
#Tue Nov 19 15:14:08 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-5.4.1-all.zip

0 comments on commit 7704741

Please sign in to comment.