Unverified Commit 100cf21e authored by Bernardo Ferrari's avatar Bernardo Ferrari Committed by GitHub

Prefer enum over class. (#123312)

Convert `AndroidSemanticsAction` to enum.
parent 716d2524
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:meta/meta.dart';
/// Class name constants which correspond to the class names used by the
/// Android accessibility bridge.
class AndroidClassName {
......@@ -30,147 +28,97 @@ class AndroidClassName {
}
/// Action constants which correspond to `AccessibilityAction` in Android.
@immutable
class AndroidSemanticsAction {
const AndroidSemanticsAction._(this.id);
/// The Android id of the action.
final int id;
static const int _kFocusIndex = 1 << 0;
static const int _kClearFocusIndex = 1 << 1;
static const int _kSelectIndex = 1 << 2;
static const int _kClearSelectionIndex = 1 << 3;
static const int _kClickIndex = 1 << 4;
static const int _kLongClickIndex = 1 << 5;
static const int _kAccessibilityFocusIndex = 1 << 6;
static const int _kClearAccessibilityFocusIndex = 1 << 7;
static const int _kNextAtMovementGranularityIndex = 1 << 8;
static const int _kPreviousAtMovementGranularityIndex = 1 << 9;
static const int _kNextHtmlElementIndex = 1 << 10;
static const int _kPreviousHtmlElementIndex = 1 << 11;
static const int _kScrollForwardIndex = 1 << 12;
static const int _kScrollBackwardIndex = 1 << 13;
static const int _kCutIndex = 1 << 14;
static const int _kCopyIndex = 1 << 15;
static const int _kPasteIndex = 1 << 16;
static const int _kSetSelectionIndex = 1 << 17;
static const int _kExpandIndex = 1 << 18;
static const int _kCollapseIndex = 1 << 19;
static const int _kSetText = 1 << 21;
enum AndroidSemanticsAction {
/// Matches `AccessibilityAction.ACTION_FOCUS`.
static const AndroidSemanticsAction focus = AndroidSemanticsAction._(_kFocusIndex);
focus(_kFocusIndex),
/// Matches `AccessibilityAction.ACTION_CLEAR_FOCUS`.
static const AndroidSemanticsAction clearFocus = AndroidSemanticsAction._(_kClearFocusIndex);
clearFocus(_kClearFocusIndex),
/// Matches `AccessibilityAction.ACTION_SELECT`.
static const AndroidSemanticsAction select = AndroidSemanticsAction._(_kSelectIndex);
select(_kSelectIndex),
/// Matches `AccessibilityAction.ACTION_CLEAR_SELECTION`.
static const AndroidSemanticsAction clearSelection = AndroidSemanticsAction._(_kClearSelectionIndex);
clearSelection(_kClearSelectionIndex),
/// Matches `AccessibilityAction.ACTION_CLICK`.
static const AndroidSemanticsAction click = AndroidSemanticsAction._(_kClickIndex);
click(_kClickIndex),
/// Matches `AccessibilityAction.ACTION_LONG_CLICK`.
static const AndroidSemanticsAction longClick = AndroidSemanticsAction._(_kLongClickIndex);
longClick(_kLongClickIndex),
/// Matches `AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS`.
static const AndroidSemanticsAction accessibilityFocus = AndroidSemanticsAction._(_kAccessibilityFocusIndex);
accessibilityFocus(_kAccessibilityFocusIndex),
/// Matches `AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS`.
static const AndroidSemanticsAction clearAccessibilityFocus = AndroidSemanticsAction._(_kClearAccessibilityFocusIndex);
clearAccessibilityFocus(_kClearAccessibilityFocusIndex),
/// Matches `AccessibilityAction.ACTION_NEXT_AT_MOVEMENT_GRANULARITY`.
static const AndroidSemanticsAction nextAtMovementGranularity = AndroidSemanticsAction._(_kNextAtMovementGranularityIndex);
nextAtMovementGranularity(_kNextAtMovementGranularityIndex),
/// Matches `AccessibilityAction.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY`.
static const AndroidSemanticsAction previousAtMovementGranularity = AndroidSemanticsAction._(_kPreviousAtMovementGranularityIndex);
previousAtMovementGranularity(_kPreviousAtMovementGranularityIndex),
/// Matches `AccessibilityAction.ACTION_NEXT_HTML_ELEMENT`.
static const AndroidSemanticsAction nextHtmlElement = AndroidSemanticsAction._(_kNextHtmlElementIndex);
nextHtmlElement(_kNextHtmlElementIndex),
/// Matches `AccessibilityAction.ACTION_PREVIOUS_HTML_ELEMENT`.
static const AndroidSemanticsAction previousHtmlElement = AndroidSemanticsAction._(_kPreviousHtmlElementIndex);
previousHtmlElement(_kPreviousHtmlElementIndex),
/// Matches `AccessibilityAction.ACTION_SCROLL_FORWARD`.
static const AndroidSemanticsAction scrollForward = AndroidSemanticsAction._(_kScrollForwardIndex);
scrollForward(_kScrollForwardIndex),
/// Matches `AccessibilityAction.ACTION_SCROLL_BACKWARD`.
static const AndroidSemanticsAction scrollBackward = AndroidSemanticsAction._(_kScrollBackwardIndex);
scrollBackward(_kScrollBackwardIndex),
/// Matches `AccessibilityAction.ACTION_CUT`.
static const AndroidSemanticsAction cut = AndroidSemanticsAction._(_kCutIndex);
cut(_kCutIndex),
/// Matches `AccessibilityAction.ACTION_COPY`.
static const AndroidSemanticsAction copy = AndroidSemanticsAction._(_kCopyIndex);
copy(_kCopyIndex),
/// Matches `AccessibilityAction.ACTION_PASTE`.
static const AndroidSemanticsAction paste = AndroidSemanticsAction._(_kPasteIndex);
paste(_kPasteIndex),
/// Matches `AccessibilityAction.ACTION_SET_SELECTION`.
static const AndroidSemanticsAction setSelection = AndroidSemanticsAction._(_kSetSelectionIndex);
setSelection(_kSetSelectionIndex),
/// Matches `AccessibilityAction.ACTION_EXPAND`.
static const AndroidSemanticsAction expand = AndroidSemanticsAction._(_kExpandIndex);
expand(_kExpandIndex),
/// Matches `AccessibilityAction.ACTION_COLLAPSE`.
static const AndroidSemanticsAction collapse = AndroidSemanticsAction._(_kCollapseIndex);
collapse(_kCollapseIndex),
/// Matches `AccessibilityAction.SET_TEXT`.
static const AndroidSemanticsAction setText = AndroidSemanticsAction._(_kSetText);
@override
String toString() {
switch (id) {
case _kFocusIndex:
return 'AndroidSemanticsAction.focus';
case _kClearFocusIndex:
return 'AndroidSemanticsAction.clearFocus';
case _kSelectIndex:
return 'AndroidSemanticsAction.select';
case _kClearSelectionIndex:
return 'AndroidSemanticsAction.clearSelection';
case _kClickIndex:
return 'AndroidSemanticsAction.click';
case _kLongClickIndex:
return 'AndroidSemanticsAction.longClick';
case _kAccessibilityFocusIndex:
return 'AndroidSemanticsAction.accessibilityFocus';
case _kClearAccessibilityFocusIndex:
return 'AndroidSemanticsAction.clearAccessibilityFocus';
case _kNextAtMovementGranularityIndex:
return 'AndroidSemanticsAction.nextAtMovementGranularity';
case _kPreviousAtMovementGranularityIndex:
return 'AndroidSemanticsAction.previousAtMovementGranularity';
case _kNextHtmlElementIndex:
return 'AndroidSemanticsAction.nextHtmlElement';
case _kPreviousHtmlElementIndex:
return 'AndroidSemanticsAction.previousHtmlElement';
case _kScrollForwardIndex:
return 'AndroidSemanticsAction.scrollForward';
case _kScrollBackwardIndex:
return 'AndroidSemanticsAction.scrollBackward';
case _kCutIndex:
return 'AndroidSemanticsAction.cut';
case _kCopyIndex:
return 'AndroidSemanticsAction.copy';
case _kPasteIndex:
return 'AndroidSemanticsAction.paste';
case _kSetSelectionIndex:
return 'AndroidSemanticsAction.setSelection';
case _kExpandIndex:
return 'AndroidSemanticsAction.expand';
case _kCollapseIndex:
return 'AndroidSemanticsAction.collapse';
case _kSetText:
return 'AndroidSemanticsAction.setText';
default:
throw UnimplementedError();
}
}
setText(_kSetText);
const AndroidSemanticsAction(this.id);
/// The Android id of the action.
final int id;
static const int _kFocusIndex = 1 << 0;
static const int _kClearFocusIndex = 1 << 1;
static const int _kSelectIndex = 1 << 2;
static const int _kClearSelectionIndex = 1 << 3;
static const int _kClickIndex = 1 << 4;
static const int _kLongClickIndex = 1 << 5;
static const int _kAccessibilityFocusIndex = 1 << 6;
static const int _kClearAccessibilityFocusIndex = 1 << 7;
static const int _kNextAtMovementGranularityIndex = 1 << 8;
static const int _kPreviousAtMovementGranularityIndex = 1 << 9;
static const int _kNextHtmlElementIndex = 1 << 10;
static const int _kPreviousHtmlElementIndex = 1 << 11;
static const int _kScrollForwardIndex = 1 << 12;
static const int _kScrollBackwardIndex = 1 << 13;
static const int _kCutIndex = 1 << 14;
static const int _kCopyIndex = 1 << 15;
static const int _kPasteIndex = 1 << 16;
static const int _kSetSelectionIndex = 1 << 17;
static const int _kExpandIndex = 1 << 18;
static const int _kCollapseIndex = 1 << 19;
static const int _kSetText = 1 << 21;
static const Map<int, AndroidSemanticsAction> _kActionById = <int, AndroidSemanticsAction>{
_kFocusIndex: focus,
......@@ -196,18 +144,6 @@ class AndroidSemanticsAction {
_kSetText: setText,
};
@override
int get hashCode => id.hashCode;
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
return other is AndroidSemanticsAction
&& other.id == id;
}
/// Creates a new [AndroidSemanticsAction] from an integer `value`.
///
/// Returns `null` if the id is not a known Android accessibility action.
......
......@@ -1390,7 +1390,7 @@ abstract class RenderBox extends RenderObject {
} else {
debugTimelineArguments = <String, String>{};
}
debugTimelineArguments!['intrinsics dimension'] = describeEnum(dimension);
debugTimelineArguments!['intrinsics dimension'] = dimension.name;
debugTimelineArguments!['intrinsics argument'] = '$argument';
return true;
}());
......
......@@ -524,7 +524,7 @@ class _GlowController extends ChangeNotifier {
@override
String toString() {
return '_GlowController(color: $color, axis: ${describeEnum(axis)})';
return '_GlowController(color: $color, axis: ${axis.name})';
}
}
......
......@@ -2118,7 +2118,7 @@ mixin WidgetInspectorService {
if (parentData is FlexParentData) {
additionalJson['flexFactor'] = parentData.flex!;
additionalJson['flexFit'] =
describeEnum(parentData.fit ?? FlexFit.tight);
(parentData.fit ?? FlexFit.tight).name;
} else if (parentData is BoxParentData) {
final Offset offset = parentData.offset;
additionalJson['parentData'] = <String, Object>{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment