Skip to content

Commit eb0b93b

Browse files
committed
Android: accessiblity deprecation warnings
Pick-to: 6.10 Change-Id: Idebf0f6ecb8c9ae342932d4f8fd042f79d304693 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
1 parent 0ac09e2 commit eb0b93b

File tree

1 file changed

+59
-16
lines changed

1 file changed

+59
-16
lines changed

src/android/jar/src/org/qtproject/qt/android/QtAccessibilityDelegate.java

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void notifyValueChanged(int viewId, String value)
242242
}
243243

244244
final AccessibilityEvent event =
245-
AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
245+
obtainAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
246246

247247
event.setEnabled(true);
248248
event.setClassName(getNodeForVirtualViewId(viewId).getClassName());
@@ -285,7 +285,7 @@ void notifyAnnouncementEvent(int viewId, String message)
285285
}
286286

287287
final AccessibilityEvent event =
288-
AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
288+
obtainAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
289289
event.getText().add(message);
290290
event.setClassName(getNodeForVirtualViewId(viewId).getClassName());
291291
event.setPackageName(m_view.getContext().getPackageName());
@@ -349,7 +349,7 @@ private AccessibilityEvent getEventForVirtualViewId(int virtualViewId, int event
349349
if (m_layout == null || m_layout.getChildCount() == 0)
350350
return null;
351351

352-
final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
352+
final AccessibilityEvent event = obtainAccessibilityEvent(eventType);
353353

354354
event.setEnabled(true);
355355
event.setClassName(getNodeForVirtualViewId(virtualViewId).getClassName());
@@ -380,12 +380,12 @@ private void dumpNodes(int parentId)
380380
private AccessibilityNodeInfo getNodeForView()
381381
{
382382
if (m_view == null || m_layout == null)
383-
return AccessibilityNodeInfo.obtain();
383+
return obtainAccessibilityNodeInfo();
384384

385385
// Since we don't want the parent to be focusable, but we can't remove
386386
// actions from a node, copy over the necessary fields.
387-
final AccessibilityNodeInfo result = AccessibilityNodeInfo.obtain(m_view);
388-
final AccessibilityNodeInfo source = AccessibilityNodeInfo.obtain(m_view);
387+
final AccessibilityNodeInfo result = obtainAccessibilityNodeInfo(m_view);
388+
final AccessibilityNodeInfo source = obtainAccessibilityNodeInfo(m_view);
389389
m_view.onInitializeAccessibilityNodeInfo(source);
390390

391391
// Get the actual position on screen, taking the status bar into account.
@@ -395,8 +395,8 @@ private AccessibilityNodeInfo getNodeForView()
395395

396396
// Copy over parent and screen bounds.
397397
final Rect m_tempParentRect = new Rect();
398-
source.getBoundsInParent(m_tempParentRect);
399-
result.setBoundsInParent(m_tempParentRect);
398+
getBoundsInParent(source, m_tempParentRect);
399+
setBoundsInParent(result, m_tempParentRect);
400400

401401
final Rect m_tempScreenRect = new Rect();
402402
source.getBoundsInScreen(m_tempScreenRect);
@@ -444,9 +444,9 @@ private AccessibilityNodeInfo getNodeForView()
444444
private AccessibilityNodeInfo getNodeForVirtualViewId(int virtualViewId)
445445
{
446446
if (m_view == null || m_layout == null)
447-
return AccessibilityNodeInfo.obtain();
447+
return obtainAccessibilityNodeInfo();
448448

449-
final AccessibilityNodeInfo node = AccessibilityNodeInfo.obtain();
449+
final AccessibilityNodeInfo node = obtainAccessibilityNodeInfo();
450450

451451
node.setPackageName(m_view.getContext().getPackageName());
452452

@@ -471,7 +471,7 @@ private AccessibilityNodeInfo getNodeForVirtualViewId(int virtualViewId)
471471

472472
Rect parentScreenRect = QtNativeAccessibility.screenRect(parentId);
473473
screenRect.offset(-parentScreenRect.left, -parentScreenRect.top);
474-
node.setBoundsInParent(screenRect);
474+
setBoundsInParent(node, screenRect);
475475

476476
// Manage internal accessibility focus state.
477477
if (m_focusedVirtualViewId == virtualViewId) {
@@ -486,11 +486,7 @@ private AccessibilityNodeInfo getNodeForVirtualViewId(int virtualViewId)
486486
for (int id : ids)
487487
node.addChild(m_view, id);
488488
if (node.isScrollable()) {
489-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
490-
node.setCollectionInfo(new CollectionInfo(ids.length, 1, false));
491-
} else {
492-
node.setCollectionInfo(CollectionInfo.obtain(ids.length, 1, false));
493-
}
489+
setCollectionInfo(node, ids.length, 1, false);
494490
}
495491

496492
return node;
@@ -584,4 +580,51 @@ protected boolean performActionForVirtualViewId(int virtualViewId, int action)
584580
}
585581
return success;
586582
}
583+
584+
@SuppressWarnings("deprecation")
585+
private AccessibilityEvent obtainAccessibilityEvent(int eventType) {
586+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
587+
return new AccessibilityEvent(eventType);
588+
} else {
589+
return AccessibilityEvent.obtain(eventType);
590+
}
591+
}
592+
593+
@SuppressWarnings("deprecation")
594+
private AccessibilityNodeInfo obtainAccessibilityNodeInfo() {
595+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
596+
return new AccessibilityNodeInfo();
597+
} else {
598+
return AccessibilityNodeInfo.obtain();
599+
}
600+
}
601+
602+
@SuppressWarnings("deprecation")
603+
private AccessibilityNodeInfo obtainAccessibilityNodeInfo(View source) {
604+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
605+
return new AccessibilityNodeInfo(source);
606+
} else {
607+
return AccessibilityNodeInfo.obtain(source);
608+
}
609+
}
610+
611+
@SuppressWarnings("deprecation")
612+
private void getBoundsInParent(AccessibilityNodeInfo node, Rect outBounds) {
613+
node.getBoundsInParent(outBounds);
614+
}
615+
616+
@SuppressWarnings("deprecation")
617+
private void setBoundsInParent(AccessibilityNodeInfo node, Rect bounds) {
618+
node.setBoundsInParent(bounds);
619+
}
620+
621+
@SuppressWarnings("deprecation")
622+
private void setCollectionInfo(AccessibilityNodeInfo node, int rowCount, int columnCount,
623+
boolean hierarchical) {
624+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
625+
node.setCollectionInfo(new CollectionInfo(rowCount, columnCount, hierarchical));
626+
} else {
627+
node.setCollectionInfo(CollectionInfo.obtain(rowCount, columnCount, hierarchical));
628+
}
629+
}
587630
}

0 commit comments

Comments
 (0)