Skip to content

Commit

Permalink
support for showing/hiding location and controls
Browse files Browse the repository at this point in the history
+ style fixes
  • Loading branch information
reinberger authored and alunny committed Jun 11, 2012
1 parent d8c4cc0 commit a078a17
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 460 deletions.
20 changes: 20 additions & 0 deletions src/android/ChildBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.json.JSONException;
import org.json.JSONObject;

import android.R.bool;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
Expand Down Expand Up @@ -52,6 +53,8 @@ public class ChildBrowser extends Plugin {
private WebView webview;
private EditText edittext;
private boolean showLocationBar = true;
private boolean showAddress = true;
private boolean showNavigationBar = true;

/**
* Executes the request and returns PluginResult.
Expand Down Expand Up @@ -203,6 +206,8 @@ public String showWebPage(final String url, JSONObject options) {
// Determine if we should hide the location bar.
if (options != null) {
showLocationBar = options.optBoolean("showLocationBar", true);
showNavigationBar = options.optBoolean("showNavigationBar", true);
showAddress = options.optBoolean("showAddress", true);
}

// Create dialog in new thread
Expand Down Expand Up @@ -230,6 +235,12 @@ public void onDismiss(DialogInterface dialog) {
LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f);
LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
if (!showAddress) // larger buttons if address bar is not visible
{
backParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f);
forwardParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f);
closeParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f);
}

LinearLayout main = new LinearLayout((Context) ctx);
main.setOrientation(LinearLayout.VERTICAL);
Expand Down Expand Up @@ -325,6 +336,15 @@ public void onClick(View v) {
dialog.setContentView(main);
dialog.show();
dialog.getWindow().setAttributes(lp);

if (!showNavigationBar) {
back.setVisibility(View.GONE);
forward.setVisibility(View.GONE);
close.setVisibility(View.GONE);
}
if (!showAddress) {
edittext.setVisibility(View.GONE);
}
}

private Bitmap loadDrawable(String filename) throws java.io.IOException {
Expand Down
17 changes: 14 additions & 3 deletions src/ios/ChildBrowserCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ - (void) showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)o
childBrowser = [[ ChildBrowserViewController alloc ] initWithScale:FALSE ];
childBrowser.delegate = self;
}


//Show location bar
// if([options objectForKey:@"showLocationBar"]!=nil)
// [childBrowser showLocationBar:[[options objectForKey:@"showLocationBar"] boolValue]];
NSLog(@"showLocationBar %d",(int)[[options objectForKey:@"showLocationBar"] boolValue]);
/* // TODO: Work in progress
NSString* strOrientations = [ options objectForKey:@"supportedOrientations"];
NSArray* supportedOrientations = [strOrientations componentsSeparatedByString:@","];
Expand All @@ -56,9 +60,16 @@ - (void) showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)o

// object 1 is the callback id
NSString *url = (NSString*) [arguments objectAtIndex:1];


//NSLog(@"showWebPage showLocationBar %@", [options objectForKey:@"showLocationBar"]);
[childBrowser resetControls];
[childBrowser loadURL:url ];

if([options objectForKey:@"showAddress"]!=nil)
[childBrowser showAddress:[[options objectForKey:@"showAddress"] boolValue]];
if([options objectForKey:@"showLocationBar"]!=nil)
[childBrowser showLocationBar:[[options objectForKey:@"showLocationBar"] boolValue]];
if([options objectForKey:@"showNavigationBar"]!=nil)
[childBrowser showNavigationBar:[[options objectForKey:@"showNavigationBar"] boolValue]];
}

-(void) close:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options // args: url
Expand Down
17 changes: 13 additions & 4 deletions src/ios/ChildBrowserViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@end


@interface ChildBrowserViewController : UIViewController < UIWebViewDelegate > {
@interface ChildBrowserViewController : UIViewController < UIWebViewDelegate , UIGestureRecognizerDelegate> {
IBOutlet UIWebView* webView;
IBOutlet UIBarButtonItem* closeBtn;
IBOutlet UIBarButtonItem* refreshBtn;
Expand All @@ -32,23 +32,32 @@
IBOutlet UIBarButtonItem* fwdBtn;
IBOutlet UIBarButtonItem* safariBtn;
IBOutlet UIActivityIndicatorView* spinner;
IBOutlet UIToolbar* toolbar;
BOOL scaleEnabled;
BOOL isImage;

NSString* imageURL;
NSArray* supportedOrientations;
id <ChildBrowserDelegate> delegate;
}

@property (nonatomic, retain)id <ChildBrowserDelegate> delegate;
@property (nonatomic, retain) NSArray* supportedOrientations;
@property(retain) NSString* imageURL;
@property(assign) BOOL isImage;
@property (retain) NSString* imageURL;
@property (assign) BOOL isImage;


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation;
- (ChildBrowserViewController*)initWithScale:(BOOL)enabled;
- (IBAction)onDoneButtonPress:(id)sender;
- (IBAction)onSafariButtonPress:(id)sender;
- (void)loadURL:(NSString*)url;
-(void)closeBrowser;
- (void)closeBrowser;

//Disaplying Controls
- (void)resetControls;
- (void)showAddress:(BOOL)isShow; // display address bar
- (void)showLocationBar:(BOOL)isShow; // display the whole location bar
- (void)showNavigationBar:(BOOL)isShow; // display navigation buttons

@end
93 changes: 90 additions & 3 deletions src/ios/ChildBrowserViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

#import "ChildBrowserViewController.h"

@interface ChildBrowserViewController()

//Gesture Recognizer
- (void)addGestureRecognizer;

@end

@implementation ChildBrowserViewController

Expand Down Expand Up @@ -45,13 +51,17 @@ + (NSString*) resolveImageResource:(NSString*)resource
- (ChildBrowserViewController*)initWithScale:(BOOL)enabled
{
self = [super init];

if(self!=nil)
{
[self addGestureRecognizer];
}

scaleEnabled = enabled;

return self;
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
Expand All @@ -64,6 +74,7 @@ - (void)viewDidLoad {
webView.delegate = self;
webView.scalesPageToFit = TRUE;
webView.backgroundColor = [UIColor whiteColor];

NSLog(@"View did load");
}

Expand All @@ -86,7 +97,6 @@ - (void)viewDidUnload {


- (void)dealloc {

webView.delegate = nil;

[webView release];
Expand Down Expand Up @@ -118,8 +128,9 @@ -(void)closeBrowser

-(IBAction) onDoneButtonPress:(id)sender
{
[webView stopLoading];
[ self closeBrowser];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]];
[webView loadRequest:request];
}
Expand Down Expand Up @@ -228,5 +239,81 @@ - (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
addressLabel.text = @"Failed";
}

#pragma mark - Disaplying Controls

- (void)resetControls
{

CGRect rect = addressLabel.frame;
rect.origin.y = self.view.frame.size.height-(44+26);
[addressLabel setFrame:rect];
rect=webView.frame;
rect.size.height= self.view.frame.size.height-(44+26);
[webView setFrame:rect];
[addressLabel setHidden:NO];
[toolbar setHidden:NO];
}

- (void)showLocationBar:(BOOL)isShow
{
if(isShow)
return;
//the addreslabel heigth 21 toolbar 44
CGRect rect = webView.frame;
rect.size.height+=(26+44);
[webView setFrame:rect];
[addressLabel setHidden:YES];
[toolbar setHidden:YES];
}

- (void)showAddress:(BOOL)isShow
{
if(isShow)
return;
CGRect rect = webView.frame;
rect.size.height+=(26);
[webView setFrame:rect];
[addressLabel setHidden:YES];

}

- (void)showNavigationBar:(BOOL)isShow
{
if(isShow)
return;
CGRect rect = webView.frame;
rect.size.height+=(44);
[webView setFrame:rect];
[toolbar setHidden:YES];
rect = addressLabel.frame;
rect.origin.y+=44;
[addressLabel setFrame:rect];
}

#pragma mark - Gesture Recognizer

- (void)addGestureRecognizer
{
UISwipeGestureRecognizer* closeRG = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(closeBrowser)];
closeRG.direction = UISwipeGestureRecognizerDirectionLeft;
closeRG.delegate=self;
[self.view addGestureRecognizer:closeRG];
[closeRG release];
}

//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
//{
// return YES;
//}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return YES;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return YES;
}

@end
Loading

0 comments on commit a078a17

Please sign in to comment.