Skip to content

Commit 78d9459

Browse files
committed
Add some accessibility improvements
1 parent 0a239b1 commit 78d9459

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import android.content.Intent
1313
import android.content.pm.ActivityInfo
1414
import android.content.pm.LauncherApps
1515
import android.content.pm.PackageManager
16-
import android.content.pm.ShortcutInfo
1716
import android.content.res.Configuration
1817
import android.graphics.Bitmap
1918
import android.graphics.Color

app/src/main/kotlin/com/simplemobiletools/launcher/views/HomeScreenGrid.kt

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import android.view.animation.OvershootInterpolator
2626
import android.widget.RelativeLayout
2727
import androidx.core.graphics.drawable.toBitmap
2828
import androidx.core.graphics.drawable.toDrawable
29+
import androidx.core.graphics.toRect
2930
import androidx.core.graphics.withScale
3031
import androidx.core.graphics.withTranslation
3132
import androidx.core.view.ViewCompat
@@ -88,6 +89,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
8889
pageChangeStarted = {
8990
widgetViews.forEach { it.resetTouches() }
9091
closeFolder()
92+
accessibilityHelper.invalidateRoot()
9193
}
9294
)
9395

@@ -106,12 +108,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
106108
val appWidgetHost = MyAppWidgetHost(context, WIDGET_HOST_ID)
107109
private val appWidgetManager = AppWidgetManager.getInstance(context)
108110

111+
private val accessibilityHelper = HomeScreenGridTouchHelper(this)
109112
var itemClickListener: ((HomeScreenGridItem) -> Unit)? = null
110113
var itemLongClickListener: ((HomeScreenGridItem) -> Unit)? = null
111114

112115

113116
init {
114-
ViewCompat.setAccessibilityDelegate(this, HomeScreenGridTouchHelper(this))
117+
ViewCompat.setAccessibilityDelegate(this, accessibilityHelper)
115118

116119
textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
117120
color = Color.WHITE
@@ -1309,23 +1312,53 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
13091312
}
13101313

13111314
override fun getVisibleVirtualViews(virtualViewIds: MutableList<Int>?) {
1312-
val sorted = gridItems.filterVisibleOnCurrentPageOnly().sortedBy {
1313-
it.getDockAdjustedTop(rowCount) * 100 + it.left
1315+
val sorted = gridItems.filter { it.visibleOnCurrentPage() || (currentlyOpenFolder != null && it.parentId == currentlyOpenFolder?.item?.id) }.sortedBy {
1316+
(if (it.parentId == null) it.getDockAdjustedTop(rowCount) else 1) * 100 + it.left
13141317
}
13151318
sorted.forEachIndexed { index, homeScreenGridItem ->
13161319
virtualViewIds?.add(index, homeScreenGridItem.id?.toInt() ?: index)
13171320
}
13181321
}
13191322

13201323
override fun onPopulateNodeForVirtualView(virtualViewId: Int, node: AccessibilityNodeInfoCompat) {
1324+
val viewLocation = IntArray(2)
1325+
getLocationOnScreen(viewLocation)
1326+
1327+
// home screen
1328+
if (virtualViewId == -1) {
1329+
node.text = context.getString(R.string.app_name)
1330+
val viewBounds = Rect(left, top, right, bottom)
1331+
val onScreenBounds = Rect(viewBounds)
1332+
onScreenBounds.offset(viewLocation[0], viewLocation[1])
1333+
node.setBoundsInScreen(onScreenBounds)
1334+
node.setBoundsInParent(viewBounds)
1335+
1336+
node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK)
1337+
node.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK)
1338+
node.setParent(this@HomeScreenGrid)
1339+
}
1340+
13211341
val item = gridItems.firstOrNull { it.id?.toInt() == virtualViewId } ?: throw IllegalArgumentException("Unknown id")
13221342

1323-
node.text = item.title
1343+
node.text = if (item.type == ITEM_TYPE_WIDGET) {
1344+
item.providerInfo?.loadLabel(context.packageManager) ?: item.title
1345+
} else {
1346+
item.title
1347+
}
13241348

1325-
val viewLocation = IntArray(2)
1326-
getLocationOnScreen(viewLocation)
1349+
val viewBounds = if (item == currentlyOpenFolder?.item) {
1350+
currentlyOpenFolder?.getDrawingRect()?.toRect()
1351+
} else if (item.type == ITEM_TYPE_WIDGET) {
1352+
val widgetPos = calculateWidgetPos(item.getTopLeft())
1353+
val left = widgetPos.x
1354+
val top = widgetPos.y
1355+
val right = left + item.getWidthInCells() * cellWidth
1356+
val bottom = top + item.getHeightInCells() * cellHeight
13271357

1328-
val viewBounds = getClickableRect(item)
1358+
Rect(left, top, right, bottom)
1359+
} else {
1360+
getClickableRect(item)
1361+
}
13291362
val onScreenBounds = Rect(viewBounds)
13301363
onScreenBounds.offset(viewLocation[0], viewLocation[1])
13311364
node.setBoundsInScreen(onScreenBounds)
@@ -1340,7 +1373,11 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
13401373
val item = gridItems.firstOrNull { it.id?.toInt() == virtualViewId } ?: throw IllegalArgumentException("Unknown id")
13411374
when (action) {
13421375
AccessibilityNodeInfoCompat.ACTION_CLICK -> itemClickListener?.apply {
1343-
invoke(item)
1376+
if (item == currentlyOpenFolder?.item) {
1377+
closeFolder(true)
1378+
} else {
1379+
invoke(item)
1380+
}
13441381
return true
13451382
}
13461383

@@ -1401,6 +1438,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
14011438
} else if (currentlyOpenFolder?.item?.id != folder.id) {
14021439
closeFolder()
14031440
}
1441+
accessibilityHelper.invalidateRoot()
14041442
}
14051443

14061444
fun closeFolder(redraw: Boolean = false) {
@@ -1409,6 +1447,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
14091447
if (redraw) {
14101448
redrawGrid()
14111449
}
1450+
accessibilityHelper.invalidateRoot()
14121451
}
14131452
}
14141453

0 commit comments

Comments
 (0)