X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FCreateBookmark.java;h=5ac074b25f5369796e0da057a0270fa33e421e22;hp=77c58607777baa5282203f9c0c88be7c094a6ab2;hb=348acd7bd2c9ba9638ff87b34df4e7501214ca27;hpb=7ab2158319ff6d1e1b5087266e1c042e663452b3 diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java index 77c58607..5ac074b2 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/CreateBookmark.java @@ -1,5 +1,5 @@ -/** - * Copyright 2016 Soren Stoutner . +/* + * Copyright 2016-2017 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -20,6 +20,7 @@ package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; +import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; @@ -27,9 +28,7 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; -// If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard. -import android.support.v7.app.AlertDialog; -// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22. +// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <= 22. import android.support.v7.app.AppCompatDialogFragment; import android.view.KeyEvent; import android.view.View; @@ -56,7 +55,7 @@ public class CreateBookmark extends AppCompatDialogFragment { try { createBookmarkListener = (CreateBookmarkListener) context; } catch(ClassCastException exception) { - throw new ClassCastException(context.toString() + " must implement CreateBookmarkListener."); + throw new ClassCastException(context.toString() + " must implement `CreateBookmarkListener`."); } } @@ -99,7 +98,7 @@ public class CreateBookmark extends AppCompatDialogFragment { // Remove the warning below that `setSoftInputMode` might produce `java.lang.NullPointerException`. assert alertDialog.getWindow() != null; - // Show the keyboard when the `Dialog` is displayed on the screen. + // Show the keyboard when the `AlertDialog` is displayed on the screen. alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // We need to show the `AlertDialog` before we can call `setOnKeyListener()` below. @@ -109,9 +108,9 @@ public class CreateBookmark extends AppCompatDialogFragment { EditText createBookmarkNameEditText = (EditText) alertDialog.findViewById(R.id.create_bookmark_name_edittext); assert createBookmarkNameEditText != null; // Remove the warning below that `createBookmarkNameEditText` might be `null`. createBookmarkNameEditText.setOnKeyListener(new View.OnKeyListener() { - public boolean onKey(View v, int keyCode, KeyEvent event) { - // If the event is a key-down on the `enter` button, select the `PositiveButton` `Create`. - if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + public boolean onKey(View view, int keyCode, KeyEvent event) { + // If the event is a key-down on the `enter` key, select the `PositiveButton` `Create`. + if ((keyCode == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN)) { // Trigger `createBookmarkListener` and return the `DialogFragment` to the parent activity. createBookmarkListener.onCreateBookmark(CreateBookmark.this); // Manually dismiss the `AlertDialog`. @@ -132,8 +131,8 @@ public class CreateBookmark extends AppCompatDialogFragment { // Allow the `enter` key on the keyboard to create the bookmark from `create_bookmark_url_edittext`. createBookmarkUrlEditText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { - // If the event is a key-down on the "enter" button, select the PositiveButton "Create". - if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + // If the event is a key-down on the "enter" key, select the PositiveButton "Create". + if ((keyCode == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN)) { // Trigger `createBookmarkListener` and return the DialogFragment to the parent activity. createBookmarkListener.onCreateBookmark(CreateBookmark.this); // Manually dismiss the `AlertDialog`.