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

Cleanup whitespaces #109

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
51 changes: 25 additions & 26 deletions src/android/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ Licensed to the Apache Software Foundation (ASF) under one
/**
* This class provides access to notifications on the device.
*
* Be aware that this implementation gets called on
* Be aware that this implementation gets called on
* navigator.notification.{alert|confirm|prompt}, and that there is a separate
* implementation in org.apache.cordova.CordovaChromeClient that gets
* called on a simple window.{alert|confirm|prompt}.
*/
public class Notification extends CordovaPlugin {

private static final String LOG_TAG = "Notification";

public int confirmResult = -1;
public ProgressDialog spinnerDialog = null;
public ProgressDialog progressDialog = null;
Expand All @@ -71,14 +71,14 @@ public Notification() {
* @return True when the action was valid, false otherwise.
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
/*
* Don't run any of these if the current activity is finishing
* in order to avoid android.view.WindowManager$BadTokenException
* crashing the app. Just return true here since false should only
* be returned in the event of an invalid action.
*/
if(this.cordova.getActivity().isFinishing()) return true;
/*
* Don't run any of these if the current activity is finishing
* in order to avoid android.view.WindowManager$BadTokenException
* crashing the app. Just return true here since false should only
* be returned in the event of an invalid action.
*/
if (this.cordova.getActivity().isFinishing()) return true;

if (action.equals("beep")) {
this.beep(args.getLong(0));
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public void run() {
* @param callbackContext The callback context
*/
public synchronized void alert(final String message, final String title, final String buttonLabel, final CallbackContext callbackContext) {
final CordovaInterface cordova = this.cordova;
final CordovaInterface cordova = this.cordova;

Runnable runnable = new Runnable() {
public void run() {
Expand Down Expand Up @@ -201,7 +201,7 @@ public void onCancel(DialogInterface dialog)
* @param callbackContext The callback context.
*/
public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) {
final CordovaInterface cordova = this.cordova;
final CordovaInterface cordova = this.cordova;

Runnable runnable = new Runnable() {
public void run() {
Expand Down Expand Up @@ -272,24 +272,23 @@ public void onCancel(DialogInterface dialog)
* Builds and shows a native Android prompt dialog with given title, message, buttons.
* This dialog only shows up to 3 buttons. Any labels after that will be ignored.
* The following results are returned to the JavaScript callback identified by callbackId:
* buttonIndex Index number of the button selected
* input1 The text entered in the prompt dialog box
* buttonIndex Index number of the button selected
* input1 The text entered in the prompt dialog box
*
* @param message The message the dialog should display
* @param title The title of the dialog
* @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
* @param callbackContext The callback context.
*/
public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) {

final CordovaInterface cordova = this.cordova;

Runnable runnable = new Runnable() {
public void run() {
final EditText promptInput = new EditText(cordova.getActivity());
/* CB-11677 - By default, prompt input text color is set according current theme.
But for some android versions is not visible (for example 5.1.1).

/* CB-11677 - By default, prompt input text color is set according current theme.
But for some android versions is not visible (for example 5.1.1).
android.R.color.primary_text_light will make text visible on all versions. */
Resources resources = cordova.getActivity().getResources();
int promptInputTextColor = resources.getColor(android.R.color.primary_text_light);
Expand All @@ -299,11 +298,11 @@ But for some android versions is not visible (for example 5.1.1).
dlg.setMessage(message);
dlg.setTitle(title);
dlg.setCancelable(true);

dlg.setView(promptInput);

final JSONObject result = new JSONObject();

// First button
if (buttonLabels.length() > 0) {
try {
Expand All @@ -313,7 +312,7 @@ public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
try {
result.put("buttonIndex",1);
result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText());
result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText());
} catch (JSONException e) {
LOG.d(LOG_TAG,"JSONException on first button.", e);
}
Expand Down Expand Up @@ -356,7 +355,7 @@ public void onClick(DialogInterface dialog, int which) {
try {
result.put("buttonIndex",3);
result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText());
} catch (JSONException e) {
} catch (JSONException e) {
LOG.d(LOG_TAG,"JSONException on third button.", e);
}
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
Expand Down Expand Up @@ -479,7 +478,7 @@ public synchronized void progressStop() {
this.progressDialog = null;
}
}

@SuppressLint("NewApi")
private AlertDialog.Builder createDialog(CordovaInterface cordova) {
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Expand All @@ -499,7 +498,7 @@ private ProgressDialog createProgressDialog(CordovaInterface cordova) {
return new ProgressDialog(cordova.getActivity());
}
}

@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Expand Down
31 changes: 11 additions & 20 deletions src/ios/CDVNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,21 @@ @implementation CDVNotification
*/
- (void)showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:(NSArray*)buttons defaultText:(NSString*)defaultText callbackId:(NSString*)callbackId dialogType:(NSString*)dialogType
{

int count = (int)[buttons count];
#ifdef __IPHONE_8_0
if (NSClassFromString(@"UIAlertController")) {

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.3) {

CGRect alertFrame = [UIScreen mainScreen].applicationFrame;

if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
// swap the values for the app frame since it is now in landscape
CGFloat temp = alertFrame.size.width;
alertFrame.size.width = alertFrame.size.height;
alertFrame.size.height = temp;
}

alertController.view.frame = alertFrame;
}

Expand Down Expand Up @@ -86,22 +83,21 @@ - (void)showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:
[weakNotif.commandDelegate sendPluginResult:result callbackId:callbackId];
}]];
}

if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {

[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text = defaultText;
}];
}

if(!alertList)
alertList = [[NSMutableArray alloc] init];
[alertList addObject:alertController];

if ([alertList count]==1) {
[self presentAlertcontroller];
}

}
else
{
Expand All @@ -113,26 +109,23 @@ - (void)showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];

alertView.callbackId = callbackId;




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

if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField* textField = [alertView textFieldAtIndex:0];
textField.text = defaultText;
}

[alertView show];
#ifdef __IPHONE_8_0
}
#endif

}

- (void)alert:(CDVInvokedUrlCommand*)command
Expand Down Expand Up @@ -239,15 +232,13 @@ -(UIViewController *)getTopPresentedViewController {
}

-(void)presentAlertcontroller {

__weak CDVNotification* weakNotif = self;
[self.getTopPresentedViewController presentViewController:[alertList firstObject] animated:YES completion:^{
[alertList removeObject:[alertList firstObject]];
if ([alertList count]>0) {
[weakNotif presentAlertcontroller];
}
}];

}

@end
Expand Down