Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app accessibility #6725

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,14 @@ class MainActivity : SplashActivity<ActivityMainMd2Binding>() {
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> onBackPressed()
else -> return super.onOptionsItemSelected(item)
}
override fun onSupportNavigateUp(): Boolean {
onBackPressed()
return true
}

fun setDisplayHomeAsUpEnabled(isEnabled: Boolean) {
binding.mainToolbar.startAnimations()
when {
isEnabled -> binding.mainToolbar.setNavigationIcon(R.drawable.ic_back_md2)
else -> binding.mainToolbar.navigationIcon = null
}
supportActionBar?.setDisplayHomeAsUpEnabled(isEnabled)
}

internal fun requestNavigationHidden(hide: Boolean = true, requiresAnimation: Boolean = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return viewModel.onMenuItemClicked(item)
when (item.itemId) {
R.id.action_save -> viewModel.savePressed()
else -> return super.onOptionsItemSelected(item)
}
return true
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,7 @@ class FlashViewModel : BaseViewModel() {
_state.value = if (success) State.SUCCESS else State.FAILED
}

fun onMenuItemClicked(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_save -> savePressed()
}
return true
}

private fun savePressed() = withExternalRW {
fun savePressed() = withExternalRW {
viewModelScope.launch(Dispatchers.IO) {
val name = "magisk_install_log_%s.log".format(
System.currentTimeMillis().toTime(timeFormatStandard)
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/topjohnwu/magisk/ui/home/DeveloperItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.ui.home

import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.di.AppContext
import com.topjohnwu.magisk.databinding.RvItem

interface Dev {
Expand Down Expand Up @@ -66,14 +67,16 @@ sealed class DeveloperItem : Dev {
sealed class IconLink : RvItem() {

abstract val icon: Int
abstract val title: Int
abstract val titleRes: Int
abstract val link: String

val title: String get() = AppContext.getString(titleRes)

override val layoutRes get() = R.layout.item_icon_link

abstract class PayPal : IconLink(), Dev {
override val icon get() = R.drawable.ic_paypal
override val title get() = R.string.paypal
override val titleRes get() = R.string.paypal
override val link get() = "https://paypal.me/$name"

object Project : PayPal() {
Expand All @@ -83,19 +86,19 @@ sealed class IconLink : RvItem() {

object Patreon : IconLink() {
override val icon get() = R.drawable.ic_patreon
override val title get() = R.string.patreon
override val titleRes get() = R.string.patreon
override val link get() = Const.Url.PATREON_URL
}

abstract class Twitter : IconLink(), Dev {
override val icon get() = R.drawable.ic_twitter
override val title get() = R.string.twitter
override val titleRes get() = R.string.twitter
override val link get() = "https://twitter.com/$name"
}

abstract class Github : IconLink() {
override val icon get() = R.drawable.ic_github
override val title get() = R.string.github
override val titleRes get() = R.string.github

abstract class User : Github(), Dev {
override val link get() = "https://github.com/$name"
Expand All @@ -108,7 +111,7 @@ sealed class IconLink : RvItem() {

abstract class Sponsor : IconLink(), Dev {
override val icon get() = R.drawable.ic_favorite
override val title get() = R.string.github
override val titleRes get() = R.string.github
override val link get() = "https://github.com/sponsors/$name"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.topjohnwu.magisk.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;

import androidx.annotation.NonNull;

import com.google.android.material.card.MaterialCardView;

public class CheckableMaterialCardView extends MaterialCardView {
private boolean checkable;
private boolean checked;
public CheckableMaterialCardView(Context context) {
super(context);
}

public CheckableMaterialCardView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public CheckableMaterialCardView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override public void setCheckable(boolean checkable) {
this.checkable = checkable;
}

@Override public void setChecked(boolean checked) {
this.checked = checked;
}

@Override public CharSequence getAccessibilityClassName() {
return CheckableMaterialCardView.class.getName();
}

@Override public void onInitializeAccessibilityNodeInfo(@NonNull AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setCheckable(checkable);
info.setChecked(checked);
}

@Override public void onInitializeAccessibilityEvent(@NonNull AccessibilityEvent accessibilityEvent) {
accessibilityEvent.setChecked(checked);
super.onInitializeAccessibilityEvent(accessibilityEvent);
}
}
9 changes: 8 additions & 1 deletion app/src/main/res/layout/include_home_magisk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@

<LinearLayout
android:id="@+id/home_magisk_installed_version"
android:focusable="true"
android:focusableInTouchMode="false"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand All @@ -129,6 +131,8 @@

<LinearLayout
android:id="@+id/home_device_details_zygisk"
android:focusable="true"
android:focusableInTouchMode="false"
style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="@+id/home_magisk_installed_version"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_installed_version">
Expand All @@ -146,13 +150,16 @@

<LinearLayout
android:id="@+id/home_device_details_ramdisk"
android:focusable="true"
android:focusableInTouchMode="false"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="@+id/home_magisk_installed_version"
app:layout_constraintTop_toBottomOf="@+id/home_device_details_zygisk">

<TextView
style="@style/W.Home.ItemContent"
android:text="Ramdisk" />
android:text="Ramdisk"
tools:ignore="HardcodedText" />

<TextView
style="@style/W.Home.ItemContent.Right"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/include_home_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@

<LinearLayout
android:id="@+id/home_manager_latest_version"
android:focusable="true"
android:focusableInTouchMode="false"
style="@style/W.Home.Item.Top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand All @@ -130,6 +132,8 @@

<LinearLayout
android:id="@+id/home_manager_installed_version"
android:focusable="true"
android:focusableInTouchMode="false"
style="@style/W.Home.Item"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_latest_version">
Expand All @@ -147,6 +151,8 @@

<LinearLayout
android:id="@+id/home_manager_internal_connection"
android:focusable="true"
android:focusableInTouchMode="false"
style="@style/W.Home.Item.Bottom"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/home_manager_installed_version">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_developer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
android:text="@{item.handle}"
android:textAppearance="@style/AppearanceFoundation.Caption"
android:textStyle="bold"
android:contentDescription="@{item.name}"
tools:text="\@topjohnwu" />

<androidx.recyclerview.widget.RecyclerView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_icon_link.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
android:minWidth="48dp"
android:onClick="@{() -> viewModel.onLinkPressed(item.link)}"
android:padding="@dimen/l_50"
android:contentDescription="@{item.title}"
tools:layout_gravity="center">

<ImageView
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/res/layout/item_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@

</data>

<com.google.android.material.card.MaterialCardView
<com.topjohnwu.magisk.widget.CheckableMaterialCardView
style="@style/WidgetFoundation.Card"
isEnabled="@{item.enabled}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="@{item.enabled ? 1f : .5f}"
android:clickable="@{item.enabled}"
android:focusable="@{item.enabled}"
android:checkable="@{item.showSwitch}"
android:checked="@{item.checked}"
android:onClick="@{(view) -> item.onPressed(view, handler)}"
tools:layout_gravity="center">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="@{item.icon == 0 ? @dimen/l1 : 0}"
Expand Down Expand Up @@ -59,8 +62,10 @@
android:text="@{item.title}"
android:textAppearance="@style/AppearanceFoundation.Body"
android:textStyle="bold"
android:accessibilityHeading="true"
tools:lines="1"
tools:text="@tools:sample/lorem/random" />
tools:text="@tools:sample/lorem/random"
tools:targetApi="p" />

<TextView
gone="@{item.description.empty}"
Expand All @@ -81,10 +86,11 @@
android:layout_height="wrap_content"
android:checked="@{item.checked}"
android:focusable="@{item.enabled}"
android:importantForAccessibility="no"
android:onCheckedChanged="@{(v, c) -> item.onToggle(v, handler, c)}" />

</LinearLayout>

</com.google.android.material.card.MaterialCardView>
</com.topjohnwu.magisk.widget.CheckableMaterialCardView>

</layout>