Skip to content
Permalink
Browse files

Add password dialog option to Notifier (#1550)

Closes #1431
  • Loading branch information...
kuan9611 authored and ewpatton committed Feb 22, 2019
1 parent 4cfd02b commit d75ffca771a0198b9c7118174901f7a6be9298d4
@@ -3964,6 +3964,10 @@ String newerVersionComponentException(String componentType, int srcCompVersion,
@Description("")
String ShowTextDialogMethods();

@DefaultMessage("ShowPasswordDialog")
@Description("")
String ShowPasswordDialogMethods();

@DefaultMessage("ShowProgressDialog")
@Description("")
String ShowProgressDialogMethods();
@@ -1368,6 +1368,10 @@ private static int upgradeNotifierProperties(Map<String, JSONValue> componentPro
// Added TextInputCanceled & ChoosingCanceled event
srcCompVersion = 5;
}
if (srcCompVersion < 6) {
// Added PasswordDialog
srcCompVersion = 6;
}
return srcCompVersion;
}

@@ -1915,7 +1915,10 @@ Blockly.Versioning.AllUpgradeMaps =
4: "noUpgrade",

// Added TextInputCanceled & ChoosingCanceled event
5: "noUpgrade"
5: "noUpgrade",

// Added a PasswordDialog for masked text input.
6: "noUpgrade"

}, // End Notifier upgraders

@@ -440,8 +440,10 @@ private YaVersion() {
// For YOUNG_ANDROID_VERSION 176:
// - PHONECALL_COMPONENT_VERSION was incremented to 3
// - TEXTING_COMPONENT_VERSION was incremented to 4
// For YOUNG_ANDROID_VERSION 177:
// - NOTIFIER_COMPONENT_VERSION was incremented to 6

public static final int YOUNG_ANDROID_VERSION = 176;
public static final int YOUNG_ANDROID_VERSION = 177;

// ............................... Blocks Language Version Number ...............................

@@ -906,7 +908,9 @@ private YaVersion() {
// - Added a ShowProgressDialog method, and a DismissProgressDialog method
// For NOTIFIER_COMPONENT_VERSION 5:
// - Added TextInputCanceled & ChoosingCanceled event
public static final int NOTIFIER_COMPONENT_VERSION = 5;
// For NOTIFIER_COMPONENT_VERSION 6:
// - Added a ShowPasswordDialog method
public static final int NOTIFIER_COMPONENT_VERSION = 6;

public static final int NXT_COLORSENSOR_COMPONENT_VERSION = 1;

@@ -15,6 +15,7 @@
import android.graphics.Typeface;
import android.os.Handler;
import android.text.Html;
import android.text.InputType;
import android.text.SpannableString;
import android.util.Log;
import android.view.Gravity;
@@ -45,6 +46,8 @@
* for example, yes or no, after which the AfterChoosing event is raised.
* <li> ShowTextDialog: lets the user enter text in response to the message, after
* which the AfterTextInput event is raised.
* <li> ShowPasswordDialog: lets the user enter password in response to the message, after
* which the AfterTextInput event is raised.
* <li> ShowAlert: displays an alert that goes away by itself after
* a short time.
* <li> ShowProgressDialog: displays an alert with a loading spinner that cannot be dismissed by
@@ -68,6 +71,8 @@
"for example, yes or no, after which the AfterChoosing event is raised.</li>" +
"<li> ShowTextDialog: lets the user enter text in response to the message, after " +
"which the AfterTextInput event is raised. " +
"<li> ShowPasswordDialog: lets the user enter password in response to the message, after " +
"which the AfterTextInput event is raised. " +
"<li> ShowAlert: displays a temporary alert that goes away by itself after a short time.</li>" +
"<li> ShowProgressDialog: displays an alert with a loading spinner that cannot be dismissed by " +
"the user. It can only be dismissed by using the DismissProgressDialog block.</li>" +
@@ -144,7 +149,7 @@ public void DismissProgressDialog() {
/**
* This method creates the actual ProgressDialog. If one is already being
* displayed, then it dismisses it, and creates this new one.
* @param message the message for the dialog
* @param message the message for the dialog
* @param title the title for the dialog
*/
public void progressDialog(String message, String title) {
@@ -241,7 +246,7 @@ public static void twoButtonDialog(Activity activity, String message, String ti

// Warning: The SDK button names are confusing. If there are
// three buttons, they go in the order POSITIVE | NEUTRAL | NEGATIVE
// In our notifier, we want choices like YES | NO | CANCEL, so NO maps to
// In our notifier, we want choices like YES | NO | CANCEL, so NO maps to
// neutral and CANCEL maps to NEGATIVE.
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, button1Text,
new DialogInterface.OnClickListener() {
@@ -305,7 +310,25 @@ public void ChoosingCanceled() {
+ "will be the text that was entered, or \"Cancel\" if the CANCEL button was pressed.")

public void ShowTextDialog(String message, String title, boolean cancelable) {
textInputDialog(message, title, cancelable);
textInputDialog(message, title, cancelable, false);
}

/**
* Shows a dialog box in which the user can enter password (input is masked),
* after which the AfterTextInput event is raised.
* @param message the text in the alert box
* @param title the title for the alert box
* @param cancelable indicates whether the user should be able to cancel out of dialog.
* When true, an additional CANCEL button will be added allowing user to cancel
* out of dialog. If selected, it will raise AfterTextInput with text of CANCEL.
*/
@SimpleFunction(description = "Shows a dialog box where the user can enter password (input is masked), "
+ "after which the AfterTextInput event will be raised. If cancelable is true there will be an "
+ "additional CANCEL button. Entering password will raise the AfterTextInput event. The \"response\" "
+ "parameter to AfterTextInput will be the entered password, or \"Cancel\" if CANCEL button was pressed.")

public void ShowPasswordDialog(String message, String title, boolean cancelable) {
textInputDialog(message, title, cancelable, true);
}

/**
@@ -319,16 +342,20 @@ public void ShowTextDialog(String message, String title, boolean cancelable) {
* @param cancelable indicates whether the user should be able to cancel out of dialog.
* When true, an additional CANCEL button will be added allowing user to cancel
* out of dialog. On selection, will raise AfterTextInput with text of CANCEL.
* @param maskInput When true, input text is masked. Suitable for sensitive information like passwords.
*/
// TODO(hal): It would be cleaner to define this in terms of oneButtonAlert and generalize
// oneButtonAlert so it can be used both for messages and text input. We could have merged
// this method into ShowTextDialog, but that would make it harder to do the generalization.
private void textInputDialog(String message, String title, boolean cancelable) {
private void textInputDialog(String message, String title, boolean cancelable, boolean maskInput) {
final AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setTitle(title);
alertDialog.setMessage(stringToHTML(message));
// Set an EditText view to get user input
final EditText input = new EditText(activity);
if (maskInput) {
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
alertDialog.setView(input);
// prevents the user from escaping the dialog by hitting the Back button
alertDialog.setCancelable(false);
@@ -835,7 +835,7 @@ <h3>Methods</h3>

<h2 id="Notifier">Notifier</h2>

<p>The Notifier component displays alert dialogs, messages, and temporary alerts, and creates Android log entries through the following methods: <ul><li> ShowMessageDialog: displays a message which the user must dismiss by pressing a button.</li><li> ShowChooseDialog: displays a message two buttons to let the user choose one of two responses, for example, yes or no, after which the AfterChoosing event is raised.</li><li> ShowTextDialog: lets the user enter text in response to the message, after which the AfterTextInput event is raised. <li> ShowAlert: displays a temporary alert that goes away by itself after a short time.</li><li> ShowProgressDialog: displays an alert with a loading spinner that cannot be dismissed by the user. It can only be dismissed by using the DismissProgressDialog block.</li><li> DismissProgressDialog: Dismisses the progress dialog displayed by ShowProgressDialog.</li><li> LogError: logs an error message to the Android log. </li><li> LogInfo: logs an info message to the Android log.</li><li> LogWarning: logs a warning message to the Android log.</li><li>The messages in the dialogs (but not the alert) can be formatted using the following HTML tags:&lt;b&gt;, &lt;big&gt;, &lt;blockquote&gt;, &lt;br&gt;, &lt;cite&gt;, &lt;dfn&gt;, &lt;div&gt;, &lt;em&gt;, &lt;small&gt;, &lt;strong&gt;, &lt;sub&gt;, &lt;sup&gt;, &lt;tt&gt;. &lt;u&gt;</li><li>You can also use the font tag to specify color, for example, &lt;font color="blue"&gt;. Some of the available color names are aqua, black, blue, fuchsia, green, grey, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow</li></ul></p>
<p>The Notifier component displays alert dialogs, messages, and temporary alerts, and creates Android log entries through the following methods: <ul><li> ShowMessageDialog: displays a message which the user must dismiss by pressing a button.</li><li> ShowChooseDialog: displays a message two buttons to let the user choose one of two responses, for example, yes or no, after which the AfterChoosing event is raised.</li><li> ShowTextDialog: lets the user enter text in response to the message, after which the AfterTextInput event is raised.</li><li> ShowPasswordDialog: lets the user enter password in response to the message, after which the AfterTextInput event is raised.</li><li> ShowAlert: displays a temporary alert that goes away by itself after a short time.</li><li> ShowProgressDialog: displays an alert with a loading spinner that cannot be dismissed by the user. It can only be dismissed by using the DismissProgressDialog block.</li><li> DismissProgressDialog: Dismisses the progress dialog displayed by ShowProgressDialog.</li><li> LogError: logs an error message to the Android log. </li><li> LogInfo: logs an info message to the Android log.</li><li> LogWarning: logs a warning message to the Android log.</li><li>The messages in the dialogs (but not the alert) can be formatted using the following HTML tags:&lt;b&gt;, &lt;big&gt;, &lt;blockquote&gt;, &lt;br&gt;, &lt;cite&gt;, &lt;dfn&gt;, &lt;div&gt;, &lt;em&gt;, &lt;small&gt;, &lt;strong&gt;, &lt;sub&gt;, &lt;sup&gt;, &lt;tt&gt;. &lt;u&gt;</li><li>You can also use the font tag to specify color, for example, &lt;font color="blue"&gt;. Some of the available color names are aqua, black, blue, fuchsia, green, grey, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow</li></ul></p>

<h3>Properties</h3>
<dl>
@@ -879,6 +879,8 @@ <h3>Methods</h3>
<dd>Shows a dialog box with an optional title and message (use empty strings if they are not wanted). This dialog box contains a spinning artifact to indicate that the program is working. It cannot be canceled by the user but must be dismissed by the App Inventor Program by using the DismissProgressDialog block.</dd>
<dt><code>ShowTextDialog(text message, text title, boolean cancelable)</code></dt>
<dd>Shows a dialog box where the user can enter text, after which the AfterTextInput event will be raised. If cancelable is true there will be an additional CANCEL button. Entering text will raise the AfterTextInput event. The "response" parameter to AfterTextInput will be the text that was entered, or "Cancel" if the CANCEL button was pressed.</dd>
<dt><code>ShowPasswordDialog(text message, text title, boolean cancelable)</code></dt>
<dd>Shows a dialog box where the user can enter password (input is masked), after which the AfterTextInput event will be raised. If cancelable is true there will be an additional CANCEL button. AfterTextInput event behaves the same way as ShowTextDialog.</dd>
</dl>

<h2 id="PasswordTextBox"> PasswordTextBox </h2>

0 comments on commit d75ffca

Please sign in to comment.
You can’t perform that action at this time.