Skip to content
Open
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
12 changes: 6 additions & 6 deletions src/android/PinDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
import org.json.JSONObject;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.view.WindowManager;
import android.widget.EditText;


public class PinDialog extends CordovaPlugin {

public ProgressDialog spinnerDialog = null;

public PinDialog() {
}

Expand Down Expand Up @@ -108,9 +106,11 @@ public void onCancel(DialogInterface dialog){
}
});

dlg.create();
dlg.show();

AlertDialog instance = dlg.create();
instance.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
instance.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
instance.show();
promptInput.requestFocus();
};
};
this.cordova.getActivity().runOnUiThread(runnable);
Expand Down
2 changes: 1 addition & 1 deletion src/ios/CDVPinDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <Cordova/CDVPlugin.h>


@interface CDVPinDialog : CDVPlugin <UIAlertViewDelegate>{}
@interface CDVPinDialog : CDVPlugin {}
@property (nonatomic, copy) NSString* callbackId;

- (void)prompt:(CDVInvokedUrlCommand*)command;
Expand Down
65 changes: 26 additions & 39 deletions src/ios/CDVPinDialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,34 @@ - (void)prompt:(CDVInvokedUrlCommand*)command
NSString* message = [command argumentAtIndex:0];
NSString* title = [command argumentAtIndex:1];
NSArray* buttons = [command argumentAtIndex:2];

UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:title
message:message
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];

//alertView.callbackId = callbackId;

int count = [buttons count];

for (int n = 0; n < count; n++) {
[alertView addButtonWithTitle:[buttons objectAtIndex:n]];
}

alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
UITextField* textField = [alertView textFieldAtIndex:0];

[alertView show];

[textField resignFirstResponder];
[textField setKeyboardType:UIKeyboardTypeNumberPad];
[textField becomeFirstResponder];

dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController* alert = [UIAlertController alertControllerWithTitle:title
message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField* tf) {
tf.secureTextEntry = YES;
tf.keyboardType = UIKeyboardTypeNumberPad;
}];
__weak UIAlertController* weakAlert = alert; // avoid action-handler retain cycle
for (NSUInteger n = 0; n < buttons.count; n++) {
NSInteger oneBased = (NSInteger)n + 1;
UIAlertActionStyle style = (n == buttons.count - 1)
? UIAlertActionStyleCancel : UIAlertActionStyleDefault;
[alert addAction:[UIAlertAction actionWithTitle:buttons[n]
style:style handler:^(UIAlertAction* a) {
NSString* value0 = weakAlert.textFields.firstObject.text;
NSDictionary* info = @{ @"buttonIndex": @(oneBased),
@"input1": (value0 ?: [NSNull null]) };
CDVPluginResult* r = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info];
[self.commandDelegate sendPluginResult:r callbackId:self.callbackId];
}]];
}
UIViewController* top = self.viewController;
while (top.presentedViewController) top = top.presentedViewController;
[top presentViewController:alert animated:YES completion:nil];
});
}


- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
CDVPluginResult* result;

NSString* value0 = [[alertView textFieldAtIndex:0] text];
NSDictionary* info = @{
@"buttonIndex":@(buttonIndex + 1),
@"input1":(value0 ? value0 : [NSNull null])
};
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info];

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


@end