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
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,36 @@ public void onClick(DialogInterface dialog, int which) {
task.success(false);
}
});

alertBuilder.create().show();
}
});
});
}


public static void prompt(final ForgeTask task, @ForgeParam("title") final String title, @ForgeParam("body") final String body) {
task.performUI(new Runnable() {
@Override
public void run() {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(ForgeApp.getActivity());
alertBuilder.setTitle(title);
alertBuilder.setMessage(body);

final EditText input = new EditText(this);
alertBuilder.setView(input);

alertBuilder.setCancelable(false);
alertBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
task.success(input.getText());
}
});

alertBuilder.create().show();
}
});
}

public static void toast(final ForgeTask task, @ForgeParam("body") final String body) {
task.performUI(new Runnable() {
@Override
Expand All @@ -119,4 +143,74 @@ public void run() {
}
});
}

private static final int INPUT_FIELD_ID = 1001;
/***
* Shows an alert prompt with an input field. By default the input field will not be
* a multiline field
****/
public static void prompt(final ForgeTask task, @ForgeParam("title") final String title, @ForgeParam("defVal") final String defVal) {

task.performUI(new Runnable() {
@Override
public void run() {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(ForgeApp.getActivity());
alertBuilder.setTitle(title);
alertBuilder.setView(createView(defVal));
alertBuilder.setCancelable(false);
alertBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

String input = null;
if(dialog instanceof Dialog) {
Dialog parent =Dialog.class.cast(dialog);
EditText edit = (EditText) parent.findViewById(INPUT_FIELD_ID);

if(edit != null && edit.getText() != null) {
input = edit.getText().toString();
}
}

task.success(input);
}
});

alertBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
task.success();
}
});

AlertDialog dialog = alertBuilder.create();

dialog.show();
}
});
}

/***
* Creates a view with an input field
* The input field allows single line text.
****/
private static View createView(String defVal) {
Activity context = ForgeApp.getActivity();
ViewGroup ui = new LinearLayout(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
ui.setLayoutParams(params);

EditText input = new EditText(context);
input.setId(INPUT_FIELD_ID);
input.setSingleLine(true);
input.setLayoutParams(params);
if(defVal != null) {
input.setText(defVal);
input.setSelection(defVal.length()); // set the cursor to the end
}

ui.addView(input);

return ui;
}
}
11 changes: 11 additions & 0 deletions inspector/ios-inspector/ForgeModule/notification_API.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ + (void)confirm:(ForgeTask*)task title:(NSString*)title body:(NSString*)body pos
[[[UIAlertView alloc] initWithTitle:title message:body cancelButtonItem:negativeBtn otherButtonItems:positiveBtn, nil] show];
}

+ (void)prompt:(ForgeTask*)task title:(NSString*)title body:(NSString*)body {
RIButtonItem *ok = [RIButtonItem item];
ok.label = @"OK";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:body cancelButtonItem:ok otherButtonItems:nil];
UITextField *input = [alertView textFieldAtIndex:0];
ok.action = ^{
[task success:input.text];
};
[alertView show];
}

+ (void)toast:(ForgeTask*)task body:(NSString*)body {
[PCToastMessage toastWithDuration:5.0 andText:body inView:[[[ForgeApp sharedApp] viewController] view]];
[task success:nil];
Expand Down
20 changes: 20 additions & 0 deletions module/javascript/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ forge['notification'] = {
negative: negative
}, success, error);
},
'prompt': function (title, body, success, error) {
forge.internal.call("notification.prompt", {
title: title,
body: body
}, success, error);
},
'toast': function (body, success, error) {
forge.internal.call("notification.toast", {
body: body
Expand All @@ -65,5 +71,19 @@ forge['notification'] = {
},
'hideLoading': function (success, error) {
forge.internal.call("notification.hideLoading", {}, success, error);
},
/**
* Create a Android native input prompt dialog.
*
* @param {string} title
* @param {string} defVal
* @param {function()=} success
* @param {function({message: string}=} error
*/
'prompt': function (title, defVal, success, error) {
forge.internal.call("notification.prompt", {
title: title,
defVal: defVal
}, success, error);
}
};