From 9bb5bb99381fc40cbbc60b97a5759683de72bdca Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 22 Jul 2021 20:12:21 +0800 Subject: Hide keyboard when clicking cancel button in dialogs for going to subreddit and user. --- .../infinityforreddit/activities/MainActivity.java | 12 ++++++++++-- .../infinityforreddit/activities/SearchResultActivity.java | 12 ++++++++++-- .../activities/ViewSubredditDetailActivity.java | 12 ++++++++++-- .../infinityforreddit/activities/ViewUserDetailActivity.java | 12 ++++++++++-- 4 files changed, 40 insertions(+), 8 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 7468655b..0969478e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -1477,7 +1477,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); startActivity(subredditIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); @@ -1518,7 +1522,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); startActivity(userIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index d1df8ca5..f2096b97 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -649,7 +649,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); startActivity(subredditIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); @@ -690,7 +694,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); startActivity(userIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 3926062d..04d34ab9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -1441,7 +1441,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); startActivity(subredditIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); @@ -1482,7 +1486,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); startActivity(userIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index da2216e4..d6fbb3d4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -1247,7 +1247,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); startActivity(subredditIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); @@ -1288,7 +1292,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); startActivity(userIntent); }) - .setNegativeButton(R.string.cancel, null) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) .setOnDismissListener(dialogInterface -> { if (imm != null) { imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); -- cgit v1.2.3