Skip to content

Commit

Permalink
Merge pull request #288 from aivanovski/feture/add-accessibility-tags
Browse files Browse the repository at this point in the history
Add accessibility tags
  • Loading branch information
aivanovski authored Dec 4, 2024
2 parents a5026ad + 6986c88 commit c1d798e
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ivanovsky.passnotes.presentation.core.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics

@Composable
fun contentDescription(description: String): Modifier {
return remember {
Modifier.semantics {
contentDescription = description
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class MaterialEditText(
this.hint = hint
}

val description = params.getString(R.styleable.MaterialEditText_description)
if (description != null) {
binding.textInput.contentDescription = description
}

val isEyeButtonEnabled = params.getBoolean(
R.styleable.MaterialEditText_isEyeButtonEnabled,
false
Expand All @@ -157,10 +162,12 @@ class MaterialEditText(
isEyeButtonEnabled && isClearButtonEnabled -> {
throw IllegalStateException()
}

isEyeButtonEnabled -> {
actionButton = ActionButton.EYE
isTextVisible = false
}

isClearButtonEnabled -> {
actionButton = ActionButton.CLEAR
}
Expand Down Expand Up @@ -272,19 +279,23 @@ class MaterialEditText(
InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_VARIATION_PASSWORD
}
}

TextInputType.DIGITS -> {
if (isTextVisible) {
InputType.TYPE_CLASS_NUMBER
} else {
InputType.TYPE_CLASS_NUMBER + InputType.TYPE_NUMBER_VARIATION_PASSWORD
}
}

TextInputType.TEXT_CAP_SENTENCES -> {
InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
}

TextInputType.URL -> {
InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_VARIATION_URI
}

TextInputType.EMAIL -> {
InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
}
Expand All @@ -300,11 +311,13 @@ class MaterialEditText(
binding.textInput.maxLines = 1
binding.textInput.isSingleLine = true
}

TextInputLines.MULTIPLE_LINES -> {
binding.textInput.isSingleLine = false
binding.textInput.minLines = 1
binding.textInput.maxLines = 25
}

else -> {}
}
setTextVisibleInternal(isTextVisible)
Expand All @@ -316,9 +329,11 @@ class MaterialEditText(
ImeOptions.ACTION_DONE -> {
binding.textInput.imeOptions = EditorInfo.IME_ACTION_DONE
}

ImeOptions.ACTION_NEXT -> {
binding.textInput.imeOptions = EditorInfo.IME_ACTION_NEXT
}

else -> {}
}
}
Expand Down Expand Up @@ -353,6 +368,7 @@ class MaterialEditText(
}
binding.editTextActionButton.setImageResource(getEyeIcon(isTextVisible))
}

ActionButton.CLEAR -> {
binding.editTextActionButton.setImageResource(R.drawable.ic_close_24dp)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.ivanovsky.passnotes.R
Expand All @@ -27,6 +28,7 @@ import com.ivanovsky.passnotes.presentation.core.compose.PrimaryTextStyle
import com.ivanovsky.passnotes.presentation.core.compose.ProgressIndicator
import com.ivanovsky.passnotes.presentation.core.compose.ThemedScreenPreview
import com.ivanovsky.passnotes.presentation.core.compose.cells.ui.InfoCell
import com.ivanovsky.passnotes.presentation.core.compose.contentDescription
import com.ivanovsky.passnotes.presentation.core.compose.model.InputType
import com.ivanovsky.passnotes.presentation.serverLogin.model.LoginType
import com.ivanovsky.passnotes.presentation.serverLogin.model.ServerLoginIntent.OnIgnoreSslValidationStateChanged
Expand Down Expand Up @@ -225,6 +227,7 @@ private fun UrlTextField(
end = dimensionResource(R.dimen.element_margin),
top = dimensionResource(R.dimen.element_margin)
)
.then(contentDescription(stringResource(R.string.url)))
)
}

Expand Down Expand Up @@ -302,6 +305,7 @@ private fun UsernameTextField(
end = dimensionResource(R.dimen.element_margin),
top = dimensionResource(R.dimen.element_margin)
)
.then(contentDescription(stringResource(R.string.username)))
)
}

Expand Down Expand Up @@ -332,6 +336,7 @@ private fun PasswordTextField(
end = dimensionResource(R.dimen.element_margin),
top = dimensionResource(R.dimen.element_margin)
)
.then(contentDescription(stringResource(R.string.password)))
)
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/dialog_change_password.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
android:layout_marginStart="@dimen/element_margin"
android:layout_marginTop="@dimen/group_margin"
android:layout_marginEnd="@dimen/element_margin"
app:description="@string/password"
app:hint="@string/password"
app:isEyeButtonEnabled="true"
app:layout_constraintBottom_toTopOf="@id/newPassword"
Expand All @@ -52,6 +53,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/element_margin"
app:description="@string/new_password"
app:hint="@string/new_password"
app:isEyeButtonEnabled="true"
app:layout_constraintBottom_toTopOf="@id/confirmation"
Expand All @@ -68,6 +70,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/element_margin"
app:description="@string/confirm_password"
app:hint="@string/confirm_password"
app:isEyeButtonEnabled="true"
app:layout_constraintBottom_toTopOf="@id/applyButton"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/layout/group_editor_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:screenState="@{viewModel.screenState}"
app:screenStateHandler="@{viewModel.screenStateHandler}" />
app:screenStateHandler="@{viewModel.screenStateHandler}"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" />

<com.ivanovsky.passnotes.presentation.core.widget.MaterialEditText
android:id="@+id/title"
Expand All @@ -39,6 +41,7 @@
android:layout_marginLeft="@dimen/element_margin"
android:layout_marginTop="@dimen/group_margin"
android:layout_marginRight="@dimen/element_margin"
app:description="@string/title"
app:hint="@string/title"
app:layout_constraintTop_toBottomOf="@id/errorPanelView"
app:screenState="@{viewModel.screenState}"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/groups_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
android:layout_marginStart="@dimen/element_margin"
android:layout_marginTop="@dimen/group_margin"
android:layout_marginEnd="@dimen/element_margin"
app:description="@string/query"
app:hint="@string/query"
app:isClearButtonEnabled="true"
app:layout_constraintTop_toBottomOf="@id/navigationPanelLayout"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/layout/new_database_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
app:layout_constraintEnd_toStartOf="@id/guidelineEnd"
app:layout_constraintTop_toTopOf="@id/addTemplatesCheckBox"
app:srcCompat="@drawable/ic_info_24dp"
app:tint="?attr/kpIconPrimaryColor"/>
app:tint="?attr/kpIconPrimaryColor" />

<com.ivanovsky.passnotes.presentation.core.widget.MaterialEditText
android:id="@+id/fileExtension"
Expand All @@ -151,6 +151,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/element_margin"
app:description="@string/file_name"
app:hint="@string/file_name"
app:isEnabled="@{viewModel.isFilenameEnabled}"
app:layout_constraintEnd_toStartOf="@id/fileExtension"
Expand All @@ -165,6 +166,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/element_margin"
app:description="@string/password"
app:hint="@string/password"
app:isEyeButtonEnabled="true"
app:layout_constraintEnd_toStartOf="@id/guidelineEnd"
Expand All @@ -179,6 +181,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/element_margin"
app:description="@string/confirm_password"
app:hint="@string/confirm"
app:isEyeButtonEnabled="true"
app:layout_constraintEnd_toStartOf="@id/guidelineEnd"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/password_generator_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/element_margin"
android:layout_marginTop="@dimen/element_margin"
app:description="@string/generated_password"
app:hint="@string/generated_password"
app:isEyeButtonEnabled="true"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/widget_material_edit_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/textInput"
android:saveEnabled="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:saveEnabled="false"
android:textColor="?attr/kpPrimaryTextColor"
android:textSize="@dimen/material_edit_text_primary_text_size" />

Expand All @@ -30,6 +30,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small_margin"
android:contentDescription="@string/eye_icon"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/widget_unlock_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/half_margin"
android:layout_marginEnd="@dimen/half_margin"
app:description="@string/password"
app:hint="@string/password"
app:isEyeButtonEnabled="true"
app:layout_constraintEnd_toStartOf="@id/unlockButton"
Expand All @@ -34,9 +35,9 @@
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="@dimen/small_margin"
android:contentDescription="@string/unlock_button"
android:foreground="?attr/selectableItemBackground"
android:minWidth="@dimen/unlock_button_size"
android:contentDescription="unlockButton"
app:layout_constraintBottom_toBottomOf="@id/password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/password" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<attr name="hint" format="string" />
<attr name="isEyeButtonEnabled" format="boolean" />
<attr name="isClearButtonEnabled" format="boolean" />
<attr name="description" format="string" />
</declare-styleable>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<string name="synchronize_with_source">Synchronize with source</string>
<string name="details">Details</string>

<!-- Accessibility descriptions -->
<string name="url">URL</string>
<string name="unlock_button">Unlock button</string>
<string name="eye_icon">Eye icon</string>

<!-- Lock notification -->
<string name="lock_notification_channel">Quick Lock</string>
<string name="lock_notification_channel_description">Button to lock opened database</string>
Expand Down

0 comments on commit c1d798e

Please sign in to comment.