Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ag 2069 ios doesn't open calendar pdf links using cms integrated calendars #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
179 changes: 98 additions & 81 deletions src/ios/ChildBrowserViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,40 @@ @implementation ChildBrowserViewController
@synthesize closeBtn, refreshBtn, backBtn, fwdBtn, safariBtn, closeButton;
@synthesize customNavigationBar, headerLogoUrl, backButtonUrl;

int toolBarHeight;

- (ChildBrowserViewController*)initWithScale:(BOOL)enabled
{
self = [super init];
if(self!=nil)
if(self!=nil)
{
[self addGestureRecognizer];
}
self.scaleEnabled = enabled;
return self;
self.scaleEnabled = enabled;
return self;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];

self.refreshBtn.image = [UIImage imageNamed:@"ChildBrowser.bundle/but_refresh"];
self.refreshBtn.image = [UIImage imageNamed:@"ChildBrowser.bundle/but_refresh"];
self.backBtn.image = [UIImage imageNamed:@"ChildBrowser.bundle/arrow_left.png"];
self.fwdBtn.image = [UIImage imageNamed:@"ChildBrowser.bundle/arrow_right.png"];
self.safariBtn.image = [UIImage imageNamed:@"ChildBrowser.bundle/compass.png"];
self.fwdBtn.image = [UIImage imageNamed:@"ChildBrowser.bundle/arrow_right.png"];
self.safariBtn.image = [UIImage imageNamed:@"ChildBrowser.bundle/compass.png"];

self.spinner.center = self.view.center;

self.webView.delegate = self;
self.webView.scalesPageToFit = YES;
self.webView.backgroundColor = [UIColor whiteColor];
self.webView.delegate = self;
self.webView.scalesPageToFit = YES;
self.webView.backgroundColor = [UIColor whiteColor];

self.customNavigationBar = [[[CustomNavigationView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [[UIScreen mainScreen] bounds].size.width, NavigationViewHeight()) andHeaderLogoUrl:self.headerLogoUrl] autorelease];
self.customNavigationBar.delegate = self;
[self.view addSubview:self.customNavigationBar];
toolBarHeight = 0;
}

- (void)viewWillAppear:(BOOL)animated
Expand All @@ -76,49 +79,57 @@ - (void)viewWillAppear:(BOOL)animated
}

// Toolbar
[self.toolbar setHidden:!self.showToolbar];
if (self.showToolbar) {
webViewFrame.size.height -= self.toolbar.frame.size.height;
[self.toolbar setHidden:!(self.showToolbar || IS_IPHONE_X())];
if (self.showToolbar || IS_IPHONE_X()) {
if (IS_IPHONE_X()) {
CGRect toolbarFrame = self.toolbar.frame;
toolbarFrame.origin.y = self.view.frame.size.height - 78;
[self.toolbar setFrame:toolbarFrame];
webViewFrame.size.height -= 42 + toolBarHeight;
} else {
webViewFrame.size.height -= self.toolbar.frame.size.height;
}
}

// Address
[self.addressLabel setHidden:!self.showAddress];

[self.webView setFrame:webViewFrame];
[self.view setNeedsLayout];
toolBarHeight = 32;
}

- (void)dealloc
{
self.webView.delegate = nil;
self.webView.delegate = nil;
self.delegate = nil;
self.orientationDelegate = nil;
#if !__has_feature(objc_arc)
[self.webView release];
[self.closeBtn release];
[self.refreshBtn release];
[self.addressLabel release];
[self.backBtn release];
[self.fwdBtn release];
[self.safariBtn release];
[self.spinner release];
[self.webView release];
[self.closeBtn release];
[self.refreshBtn release];
[self.addressLabel release];
[self.backBtn release];
[self.fwdBtn release];
[self.safariBtn release];
[self.spinner release];
[self.toolbar release];
[self.customNavigationBar release];
[self.headerLogoUrl release];
[self.backButtonUrl release];
[self.closeButton release];

[super dealloc];
[super dealloc];
#endif
}

- (void)closeBrowser
{
if (self.delegate != nil)
{
[self.delegate onClose];
}
if (self.delegate != nil)
{
[self.delegate onClose];
}

// Show status bar on close
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
Expand All @@ -145,7 +156,7 @@ - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))comp
- (IBAction)onDoneButtonPress:(id)sender
{
[self.webView stopLoading];
[self closeBrowser];
[self closeBrowser];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]];
[self.webView loadRequest:request];
Expand All @@ -154,48 +165,53 @@ - (IBAction)onDoneButtonPress:(id)sender

- (IBAction)onSafariButtonPress:(id)sender
{
if (self.delegate != nil)
{
[self.delegate onOpenInSafari];
}
if (isImage)
{
NSURL* pURL = [[[NSURL alloc] initWithString:imageURL] autorelease];
[[UIApplication sharedApplication] openURL:pURL];
}
else
{
NSURLRequest *request = webView.request;
[[UIApplication sharedApplication] openURL:request.URL];
}
if (self.delegate != nil)
{
[self.delegate onOpenInSafari];
}
if (isImage)
{
NSURL* pURL = [[[NSURL alloc] initWithString:imageURL] autorelease];
[[UIApplication sharedApplication] openURL:pURL];
}
else
{
NSURLRequest *request = webView.request;
[[UIApplication sharedApplication] openURL:request.URL];
}
}

- (void)loadURL:(NSString*)url
{
NSLog(@"Opening Url : %@",url);
if (self.isImage)
{
self.imageURL = url;
NSLog(@"Opening Url : %@",url);
if (self.isImage)
{
self.imageURL = url;
self.webView.backgroundColor = [UIColor blackColor];
self.webView.scrollView.bounces = NO;
self.spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;

NSString *htmlText = [NSString stringWithFormat:@"<html style='width:100%%;height:100%%'><body style='background-image:url(%@);background-size:contain;background-position:center;background-repeat:no-repeat;background-color:black;'></body></html>", url];
[webView loadHTMLString:htmlText baseURL:[NSURL URLWithString:@""]];
}
else
{
imageURL = @"";
NSString *htmlText = [NSString stringWithFormat:@"<html style='width:100%%;height:100%%'><body style='background-image:url(%@);background-size:contain;background-position:center;background-repeat:no-repeat;background-color:black;'></body></html>", url];
[webView loadHTMLString:htmlText baseURL:[NSURL URLWithString:@""]];
}
else
{
imageURL = @"";
self.webView.backgroundColor = [UIColor whiteColor];
self.webView.scrollView.bounces = YES;
self.spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.webView loadRequest:request];
}
self.webView.hidden = NO;
NSString *decoded = [url stringByRemovingPercentEncoding];
if ([url isEqualToString:decoded]) {
// The URL was not encoded yet
url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
}
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.webView loadRequest:request];
}
self.webView.hidden = NO;
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Expand All @@ -209,35 +225,35 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)

- (void)webViewDidStartLoad:(UIWebView *)sender
{
self.addressLabel.text = @"Loading...";
self.backBtn.enabled = webView.canGoBack;
self.fwdBtn.enabled = webView.canGoForward;
[self.spinner startAnimating];
self.addressLabel.text = @"Loading...";
self.backBtn.enabled = webView.canGoBack;
self.fwdBtn.enabled = webView.canGoForward;
[self.spinner startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)sender
- (void)webViewDidFinishLoad:(UIWebView *)sender
{
NSURLRequest *request = self.webView.request;
NSLog(@"New Address is : %@",request.URL.absoluteString);

self.addressLabel.text = request.URL.absoluteString;
self.backBtn.enabled = webView.canGoBack;
self.fwdBtn.enabled = webView.canGoForward;
[self.spinner stopAnimating];
if (self.delegate != nil)
NSURLRequest *request = self.webView.request;
NSLog(@"New Address is : %@",request.URL.absoluteString);
self.addressLabel.text = request.URL.absoluteString;
self.backBtn.enabled = webView.canGoBack;
self.fwdBtn.enabled = webView.canGoForward;
[self.spinner stopAnimating];
if (self.delegate != nil)
{
[self.delegate onChildLocationChange:request.URL.absoluteString];
}
[self.delegate onChildLocationChange:request.URL.absoluteString];
}
}

- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error
{
NSLog (@"webView:didFailLoadWithError");
NSLog (@"%@", [error localizedDescription]);
NSLog (@"%@", [error localizedFailureReason]);

[spinner stopAnimating];
addressLabel.text = @"Failed";
}
Expand Down Expand Up @@ -307,7 +323,7 @@ - (NSUInteger)supportedInterfaceOrientations
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.orientationDelegate supportedInterfaceOrientations];
}

// return UIInterfaceOrientationMaskPortrait; // NO - is IOS 6 only
return (1 << UIInterfaceOrientationPortrait);
}
Expand All @@ -319,7 +335,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) {
return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

return YES;
}

Expand All @@ -333,3 +349,4 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
}

@end

34 changes: 19 additions & 15 deletions src/ios/ChildBrowserViewController.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment version="768" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
<deployment version="2048" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="Helvetica.ttc">
<string>Helvetica</string>
</array>
</customFonts>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ChildBrowserViewController">
<connections>
Expand All @@ -27,10 +36,10 @@
<webView hidden="YES" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="4">
<rect key="frame" x="0.0" y="44" width="320" height="409"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</webView>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" barStyle="black" id="6">
<rect key="frame" x="0.0" y="436.00000010259578" width="320" height="44"/>
<rect key="frame" x="0.0" y="436" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<items>
<barButtonItem style="plain" systemItem="flexibleSpace" id="37"/>
Expand Down Expand Up @@ -63,9 +72,9 @@
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Loading..." lineBreakMode="tailTruncation" minimumFontSize="10" adjustsFontSizeToFit="NO" id="13">
<rect key="frame" x="5" y="410" width="277" height="21"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<color key="backgroundColor" white="0.66666669000000001" alpha="0.0" colorSpace="deviceWhite"/>
<color key="backgroundColor" red="0.60271537303924561" green="0.60271537303924561" blue="0.60271537303924561" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="13"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<activityIndicatorView hidden="YES" opaque="NO" clearsContextBeforeDrawing="NO" userInteractionEnabled="NO" contentMode="scaleToFill" hidesWhenStopped="YES" style="gray" id="32">
Expand All @@ -76,23 +85,18 @@
<rect key="frame" x="276" y="20" width="24" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<state key="normal" image="Close.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="onDoneButtonPress:" destination="-1" eventType="touchUpInside" id="ly6-wB-o8l"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
</view>
</objects>
<resources>
<image name="Close.png" width="24" height="24"/>
</resources>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>