Skip to content

Commit 94ae8d9

Browse files
Giulio CarusoGiulio Caruso
authored andcommitted
Add Demo project
1 parent 6c4a18f commit 94ae8d9

File tree

1,101 files changed

+135974
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,101 files changed

+135974
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#ifdef DEBUG
21+
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
22+
#else
23+
#define DLog(...)
24+
#endif
25+
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
@interface NSArray (CDVJSONSerializingPrivate)
21+
- (NSString*)cdv_JSONString;
22+
@end
23+
24+
@interface NSDictionary (CDVJSONSerializingPrivate)
25+
- (NSString*)cdv_JSONString;
26+
@end
27+
28+
@interface NSString (CDVJSONSerializingPrivate)
29+
- (id)cdv_JSONObject;
30+
- (id)cdv_JSONFragment;
31+
@end
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import "CDVJSON_private.h"
21+
#import <Foundation/NSJSONSerialization.h>
22+
23+
@implementation NSArray (CDVJSONSerializingPrivate)
24+
25+
- (NSString*)cdv_JSONString
26+
{
27+
NSError* error = nil;
28+
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
29+
options:0
30+
error:&error];
31+
32+
if (error != nil) {
33+
NSLog(@"NSArray JSONString error: %@", [error localizedDescription]);
34+
return nil;
35+
} else {
36+
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
37+
}
38+
}
39+
40+
@end
41+
42+
@implementation NSDictionary (CDVJSONSerializingPrivate)
43+
44+
- (NSString*)cdv_JSONString
45+
{
46+
NSError* error = nil;
47+
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
48+
options:NSJSONWritingPrettyPrinted
49+
error:&error];
50+
51+
if (error != nil) {
52+
NSLog(@"NSDictionary JSONString error: %@", [error localizedDescription]);
53+
return nil;
54+
} else {
55+
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
56+
}
57+
}
58+
59+
@end
60+
61+
@implementation NSString (CDVJSONSerializingPrivate)
62+
63+
- (id)cdv_JSONObject
64+
{
65+
NSError* error = nil;
66+
id object = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding]
67+
options:NSJSONReadingMutableContainers
68+
error:&error];
69+
70+
if (error != nil) {
71+
NSLog(@"NSString JSONObject error: %@", [error localizedDescription]);
72+
}
73+
74+
return object;
75+
}
76+
77+
- (id)cdv_JSONFragment
78+
{
79+
NSError* error = nil;
80+
id object = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding]
81+
options:NSJSONReadingAllowFragments
82+
error:&error];
83+
84+
if (error != nil) {
85+
NSLog(@"NSString JSONObject error: %@", [error localizedDescription]);
86+
}
87+
88+
return object;
89+
}
90+
91+
@end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
@interface CDVPlugin (Private)
21+
22+
- (instancetype)initWithWebViewEngine:(id <CDVWebViewEngineProtocol>)theWebViewEngine;
23+
24+
@end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import "CDVPlugin.h"
21+
22+
@interface CDVGestureHandler : CDVPlugin
23+
24+
@property (nonatomic, strong) UILongPressGestureRecognizer* lpgr;
25+
26+
@end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import "CDVGestureHandler.h"
21+
22+
@implementation CDVGestureHandler
23+
24+
- (void)pluginInitialize
25+
{
26+
[self applyLongPressFix];
27+
}
28+
29+
- (void)applyLongPressFix
30+
{
31+
// You can't suppress 3D Touch and still have regular longpress,
32+
// so if this is false, let's not consider the 3D Touch setting at all.
33+
if (![self.commandDelegate.settings objectForKey:@"suppresseslongpressgesture"] ||
34+
![[self.commandDelegate.settings objectForKey:@"suppresseslongpressgesture"] boolValue]) {
35+
return;
36+
}
37+
38+
self.lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGestures:)];
39+
self.lpgr.minimumPressDuration = 0.45f;
40+
self.lpgr.allowableMovement = 100.0f;
41+
42+
// 0.45 is ok for 'regular longpress', 0.05-0.08 is required for '3D Touch longpress',
43+
// but since this will also kill onclick handlers (not ontouchend) it's optional.
44+
if ([self.commandDelegate.settings objectForKey:@"suppresses3dtouchgesture"] &&
45+
[[self.commandDelegate.settings objectForKey:@"suppresses3dtouchgesture"] boolValue]) {
46+
self.lpgr.minimumPressDuration = 0.05f;
47+
}
48+
49+
NSArray *views = self.webView.subviews;
50+
if (views.count == 0) {
51+
NSLog(@"No webview subviews found, not applying the longpress fix.");
52+
return;
53+
}
54+
for (int i=0; i<views.count; i++) {
55+
UIView *webViewScrollView = views[i];
56+
if ([webViewScrollView isKindOfClass:[UIScrollView class]]) {
57+
NSArray *webViewScrollViewSubViews = webViewScrollView.subviews;
58+
UIView *browser = webViewScrollViewSubViews[0];
59+
[browser addGestureRecognizer:self.lpgr];
60+
break;
61+
}
62+
}
63+
}
64+
65+
- (void)handleLongPressGestures:(UILongPressGestureRecognizer*)sender
66+
{
67+
if ([sender isEqual:self.lpgr]) {
68+
if (sender.state == UIGestureRecognizerStateBegan) {
69+
NSLog(@"Ignoring a longpress in order to suppress the magnifying glass.");
70+
}
71+
}
72+
}
73+
74+
@end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import "CDVPlugin.h"
21+
22+
@interface CDVHandleOpenURL : CDVPlugin
23+
24+
@property (nonatomic, strong) NSURL* url;
25+
@property (nonatomic, assign) BOOL pageLoaded;
26+
27+
@end
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import "CDVHandleOpenURL.h"
21+
#import "CDV.h"
22+
23+
@implementation CDVHandleOpenURL
24+
25+
- (void)pluginInitialize
26+
{
27+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationLaunchedWithUrl:) name:CDVPluginHandleOpenURLNotification object:nil];
28+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationPageDidLoad:) name:CDVPageDidLoadNotification object:nil];
29+
}
30+
31+
- (void)applicationLaunchedWithUrl:(NSNotification*)notification
32+
{
33+
NSURL* url = [notification object];
34+
35+
self.url = url;
36+
37+
// warm-start handler
38+
if (self.pageLoaded) {
39+
[self processOpenUrl:self.url pageLoaded:YES];
40+
self.url = nil;
41+
}
42+
}
43+
44+
- (void)applicationPageDidLoad:(NSNotification*)notification
45+
{
46+
// cold-start handler
47+
48+
self.pageLoaded = YES;
49+
50+
if (self.url) {
51+
[self processOpenUrl:self.url pageLoaded:YES];
52+
self.url = nil;
53+
}
54+
}
55+
56+
- (void)processOpenUrl:(NSURL*)url pageLoaded:(BOOL)pageLoaded
57+
{
58+
__weak __typeof(self) weakSelf = self;
59+
60+
dispatch_block_t handleOpenUrl = ^(void) {
61+
// calls into javascript global function 'handleOpenURL'
62+
NSString* jsString = [NSString stringWithFormat:@"document.addEventListener('deviceready',function(){if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}});", url.absoluteString];
63+
64+
[weakSelf.webViewEngine evaluateJavaScript:jsString completionHandler:nil];
65+
};
66+
67+
if (!pageLoaded) {
68+
NSString* jsString = @"document.readystate";
69+
[self.webViewEngine evaluateJavaScript:jsString
70+
completionHandler:^(id object, NSError* error) {
71+
if ((error == nil) && [object isKindOfClass:[NSString class]]) {
72+
NSString* readyState = (NSString*)object;
73+
BOOL ready = [readyState isEqualToString:@"loaded"] || [readyState isEqualToString:@"complete"];
74+
if (ready) {
75+
handleOpenUrl();
76+
} else {
77+
self.url = url;
78+
}
79+
}
80+
}];
81+
} else {
82+
handleOpenUrl();
83+
}
84+
}
85+
86+
@end

0 commit comments

Comments
 (0)