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

android support for focusing (better) on inputs #233

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.content.Context;
import android.content.Intent;
import android.provider.Browser;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -68,6 +70,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

@SuppressLint("SetJavaScriptEnabled")
Expand All @@ -88,6 +91,7 @@ public class InAppBrowser extends CordovaPlugin {
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
private static final String HARDWARE_BACK_BUTTON = "hardwareback";
private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction";
private static final String DISMISSABLE_WITH_BACK_BUTTON = "dismissablewithbackbutton";
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend";
private static final Boolean DEFAULT_HARDWARE_BACK = true;
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort";
Expand All @@ -103,6 +107,7 @@ public class InAppBrowser extends CordovaPlugin {
private boolean clearSessionCache = false;
private boolean hadwareBackButton = true;
private boolean mediaPlaybackRequiresUserGesture = false;
private boolean dismissableWithBackButton = true;
private boolean shouldPauseInAppBrowser = false;
private boolean useWideViewPort = true;
private ValueCallback<Uri> mUploadCallback;
Expand Down Expand Up @@ -477,6 +482,14 @@ public boolean hardwareBack() {
return hadwareBackButton;
}

/**
* Has the user set that back button can dismiss the dialog
* @return
*/
public boolean isDismissableWithBackButton() {
return dismissableWithBackButton;
}

/**
* Checks to see if it is possible to go forward one page in history, then does so.
*/
Expand Down Expand Up @@ -549,6 +562,10 @@ public String showWebPage(final String url, HashMap<String, Boolean> features) {
} else {
hadwareBackButton = DEFAULT_HARDWARE_BACK;
}
Boolean dismissable = features.get(DISMISSABLE_WITH_BACK_BUTTON);
if (dismissable != null) {
dismissableWithBackButton = dismissable.booleanValue();
}
Boolean mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
if (mediaPlayback != null) {
mediaPlaybackRequiresUserGesture = mediaPlayback.booleanValue();
Expand Down Expand Up @@ -943,7 +960,15 @@ public InAppBrowserClient(CordovaWebView webView, EditText mEditText) {
*/
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if (url.startsWith(WebView.SCHEME_TEL)) {
// handle back to application redirect without processing url by webView
final Intent customSchemeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
final PackageManager packageManager = cordova.getActivity().getApplicationContext().getPackageManager();
final List<ResolveInfo> resolvedActivities = packageManager.queryIntentActivities(customSchemeIntent, 0);

String newloc = "";
if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
newloc = url;
} else if (url.startsWith(WebView.SCHEME_TEL)) {
try {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url));
Expand Down Expand Up @@ -992,6 +1017,10 @@ else if (url.startsWith("sms:")) {
} catch (android.content.ActivityNotFoundException e) {
LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
}
} else if(resolvedActivities.size() > 0) {
cordova.getActivity().startActivity(customSchemeIntent);
closeDialog();
return true;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/android/InAppBrowserDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onBackPressed () {
// because it does a clean up
if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) {
this.inAppBrowser.goBack();
} else {
} else if (this.inAppBrowser.isDismissableWithBackButton()) {
this.inAppBrowser.closeDialog();
}
}
Expand Down
34 changes: 27 additions & 7 deletions src/ios/CDVInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Licensed to the Apache Software Foundation (ASF) under one

@interface CDVInAppBrowser () {
NSInteger _previousStatusBarStyle;
BOOL _retryFailingRequest;
}
@end

Expand All @@ -46,6 +47,7 @@ - (void)pluginInitialize
{
_previousStatusBarStyle = -1;
_callbackIdPattern = nil;
_retryFailingRequest = YES;
}

- (id)settingForKey:(NSString*)key
Expand Down Expand Up @@ -471,13 +473,21 @@ - (void)webViewDidFinishLoad:(UIWebView*)theWebView

- (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
if (self.callbackId != nil) {
NSString* url = [self.inAppBrowserViewController.currentURL absoluteString];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInteger:error.code], @"message": error.localizedDescription}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];

[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
if (_retryFailingRequest) {
_retryFailingRequest = NO;
NSURL *url =[NSURL URLWithString:error.userInfo[@"NSErrorFailingURLStringKey"]];
[self openInSystem:url];
return;
} else {
_retryFailingRequest = YES;
if (self.callbackId != nil) {
NSString* url = [self.inAppBrowserViewController.currentURL absoluteString];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInteger:error.code], @"message": error.localizedDescription}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];

[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
}
}

Expand Down Expand Up @@ -783,6 +793,16 @@ - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition

- (void)viewDidLoad
{
CGRect frame = [UIApplication sharedApplication].statusBarFrame;
UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:frame];
bgToolbar.barStyle = UIBarStyleDefault;
bgToolbar.tintColor = [UIColor whiteColor];
bgToolbar.barTintColor = [UIColor whiteColor];
// [[UIBarItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor whiteColor]}];


[self.view addSubview:bgToolbar];

[super viewDidLoad];
}

Expand Down