+ // Add a text change listener to the URL edit text.
+ urlEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ // Do nothing.
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ // Do nothing.
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ // Update the create button.
+ updateCreateButton(createButton);
+ }
+ });
+
+ // Allow the enter key on the keyboard to create the shortcut when editing the name.
+ shortcutNameEditText.setOnKeyListener((View view, int keyCode, KeyEvent keyEvent) -> {
+ // Check to see if the enter key was pressed.
+ if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
+ // Check the status of the create button.
+ if (createButton.isEnabled()) { // The create button is enabled.
+ // Create the home screen shortcut.
+ createHomeScreenShortcut(favoriteIconBitmap);
+
+ // Manually dismiss the alert dialog.
+ alertDialog.dismiss();
+
+ // Consume the event.
+ return true;
+ } else { // The create button is disabled.
+ // Do not consume the event.
+ return false;
+ }
+ } else { // Some other key was pressed.
+ // Do not consume the event.
+ return false;
+ }
+ });
+
+ // Set the enter key on the keyboard to create the shortcut when editing the URL.
+ urlEditText.setOnKeyListener((View view, int keyCode, KeyEvent keyEvent) -> {
+ // Check to see if the enter key was pressed.
+ if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
+ // Check the status of the create button.
+ if (createButton.isEnabled()) { // The create button is enabled.
+ // Create the home screen shortcut.
+ createHomeScreenShortcut(favoriteIconBitmap);
+
+ // Manually dismiss the alert dialog.
+ alertDialog.dismiss();
+
+ // Consume the event.
+ return true;
+ } else { // The create button is disabled.
+ // Do not consume the event.
+ return false;
+ }
+ } else { // Some other key was pressed.
+ // Do not consume the event.