mirror of
https://gitee.com/shuto-github/phonegap-mobile-accessibility.git
synced 2026-05-26 00:00:06 +08:00
Refactor to MobileAccessibility.postNotification to accept other notification types
MobileAccessibility.postNotification now allows you to send UIAccessibilityScreenChangedNotification, UIAccessibilityLayoutChangedNotification, and UIAccessibilityPageScrolledNotification in addition to UIAccessibilityAnnouncementNotification. Refactor isVoiceOverRunning and “voiceoverstatuschanged” to the more platform agnostic isScreenReaderRunning and “screenreaderstatuschanged” in anticipation of Android support.
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
NSString* callbackId;
|
||||
NSString* commandCallbackId;
|
||||
BOOL voiceOverRunning;
|
||||
BOOL closeCaptioningEnabled;
|
||||
BOOL closedCaptioningEnabled;
|
||||
BOOL guidedAccessEnabled;
|
||||
BOOL invertColorsEnabled;
|
||||
BOOL monoAudioEnabled;
|
||||
@@ -32,17 +32,17 @@
|
||||
@property (strong) NSString* callbackId;
|
||||
@property (strong) NSString* commandCallbackId;
|
||||
@property BOOL voiceOverRunning;
|
||||
@property BOOL closeCaptioningEnabled;
|
||||
@property BOOL closedCaptioningEnabled;
|
||||
@property BOOL guidedAccessEnabled;
|
||||
@property BOOL invertColorsEnabled;
|
||||
@property BOOL monoAudioEnabled;
|
||||
|
||||
- (void) isVoiceOverRunning:(CDVInvokedUrlCommand*)command;
|
||||
- (void) isScreenReaderRunning:(CDVInvokedUrlCommand*)command;
|
||||
- (void) isClosedCaptioningEnabled:(CDVInvokedUrlCommand*)command;
|
||||
- (void) isGuidedAccessEnabled:(CDVInvokedUrlCommand*)command;
|
||||
- (void) isInvertColorsEnabled:(CDVInvokedUrlCommand*)command;
|
||||
- (void) isMonoAudioEnabled:(CDVInvokedUrlCommand*)command;
|
||||
- (void) postAnnouncementNotification:(CDVInvokedUrlCommand*)command;
|
||||
- (void) postNotification:(CDVInvokedUrlCommand*)command;
|
||||
- (void) start:(CDVInvokedUrlCommand*)command;
|
||||
- (void) stop:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
@synthesize callbackId;
|
||||
@synthesize commandCallbackId;
|
||||
@synthesize voiceOverRunning;
|
||||
@synthesize closeCaptioningEnabled;
|
||||
@synthesize closedCaptioningEnabled;
|
||||
@synthesize guidedAccessEnabled;
|
||||
@synthesize invertColorsEnabled;
|
||||
@synthesize monoAudioEnabled;
|
||||
@@ -93,7 +93,7 @@
|
||||
|
||||
#pragma Plugin interface
|
||||
|
||||
- (void)isVoiceOverRunning:(CDVInvokedUrlCommand*)command
|
||||
- (void)isScreenReaderRunning:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
[self.commandDelegate runInBackground:^{
|
||||
self.voiceOverRunning = UIAccessibilityIsVoiceOverRunning();
|
||||
@@ -105,8 +105,8 @@
|
||||
- (void)isClosedCaptioningEnabled:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
[self.commandDelegate runInBackground:^{
|
||||
self.closeCaptioningEnabled = [self getClosedCaptioningEnabledStatus];
|
||||
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:self.closeCaptioningEnabled];
|
||||
self.closedCaptioningEnabled = [self getClosedCaptioningEnabledStatus];
|
||||
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:self.closedCaptioningEnabled];
|
||||
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
||||
}];
|
||||
}
|
||||
@@ -138,17 +138,33 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)postAnnouncementNotification:(CDVInvokedUrlCommand *)command
|
||||
- (void)postNotification:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
CDVPluginResult* result = nil;
|
||||
NSString* notificationString = [command.arguments objectAtIndex:0];
|
||||
uint32_t notificationType = [[command.arguments objectAtIndex:0] intValue];
|
||||
NSString* notificationString = [command.arguments objectAtIndex:1];
|
||||
|
||||
if (notificationString == nil) {
|
||||
notificationString = @"";
|
||||
}
|
||||
|
||||
if (UIAccessibilityIsVoiceOverRunning() &&
|
||||
notificationString != nil && [notificationString length] > 0) {
|
||||
self.commandCallbackId = command.callbackId;
|
||||
[self isValidNotificationType:notificationType]) {
|
||||
[self.commandDelegate runInBackground:^{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mobileAccessibilityAnnouncementDidFinish:) name:UIAccessibilityAnnouncementDidFinishNotification object:nil];
|
||||
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, notificationString);
|
||||
if (notificationType == UIAccessibilityAnnouncementNotification) {
|
||||
self.commandCallbackId = command.callbackId;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mobileAccessibilityAnnouncementDidFinish:) name:UIAccessibilityAnnouncementDidFinishNotification object:nil];
|
||||
}
|
||||
|
||||
UIAccessibilityPostNotification(notificationType, notificationString);
|
||||
|
||||
if (notificationType != UIAccessibilityAnnouncementNotification) {
|
||||
NSMutableDictionary* data = [NSMutableDictionary dictionaryWithCapacity:2];
|
||||
[data setObject:notificationString forKey:@"stringValue"];
|
||||
[data setObject:@"true" forKey:@"wasSuccessful"];
|
||||
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:data];
|
||||
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
||||
@@ -156,6 +172,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isValidNotificationType:(uint32_t)notificationType
|
||||
{
|
||||
return (notificationType == UIAccessibilityScreenChangedNotification
|
||||
|| notificationType == UIAccessibilityLayoutChangedNotification
|
||||
|| notificationType == UIAccessibilityAnnouncementNotification
|
||||
|| notificationType == UIAccessibilityPageScrolledNotification);
|
||||
}
|
||||
|
||||
- (void)mobileAccessibilityAnnouncementDidFinish:(NSNotification *)dict
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityAnnouncementDidFinishNotification object:nil];
|
||||
@@ -203,14 +227,14 @@
|
||||
- (NSDictionary*)getMobileAccessibilityStatus
|
||||
{
|
||||
self.voiceOverRunning = UIAccessibilityIsVoiceOverRunning();
|
||||
self.closeCaptioningEnabled = [self getClosedCaptioningEnabledStatus];
|
||||
self.closedCaptioningEnabled = [self getClosedCaptioningEnabledStatus];
|
||||
self.guidedAccessEnabled = UIAccessibilityIsGuidedAccessEnabled();
|
||||
self.invertColorsEnabled = UIAccessibilityIsInvertColorsEnabled();
|
||||
self.monoAudioEnabled = UIAccessibilityIsMonoAudioEnabled();
|
||||
|
||||
NSMutableDictionary* mobileAccessibilityData = [NSMutableDictionary dictionaryWithCapacity:5];
|
||||
[mobileAccessibilityData setObject:[NSNumber numberWithBool:self.voiceOverRunning] forKey:@"isVoiceOverRunning"];
|
||||
[mobileAccessibilityData setObject:[NSNumber numberWithBool:self.closeCaptioningEnabled] forKey:@"isClosedCaptioningEnabled"];
|
||||
[mobileAccessibilityData setObject:[NSNumber numberWithBool:self.voiceOverRunning] forKey:@"isScreenReaderRunning"];
|
||||
[mobileAccessibilityData setObject:[NSNumber numberWithBool:self.closedCaptioningEnabled] forKey:@"isClosedCaptioningEnabled"];
|
||||
[mobileAccessibilityData setObject:[NSNumber numberWithBool:self.guidedAccessEnabled] forKey:@"isGuidedAccessEnabled"];
|
||||
[mobileAccessibilityData setObject:[NSNumber numberWithBool:self.invertColorsEnabled] forKey:@"isInvertColorsEnabled"];
|
||||
[mobileAccessibilityData setObject:[NSNumber numberWithBool:self.monoAudioEnabled] forKey:@"isMonoAudioEnabled"];
|
||||
|
||||
Reference in New Issue
Block a user