[Android] Avoid using app context from static call

Geoffrey Métais git at videolan.org
Fri Mar 30 16:51:05 CEST 2018


vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar  9 10:51:40 2018 +0100| [7ac64ace5804e4893385c45889a79ad7d8889222] | committer: Geoffrey Métais

Avoid using app context from static call

(cherry picked from commit 5924da80144392d92a80863943115471af54c739)

> https://code.videolan.org/videolan/vlc-android/commit/7ac64ace5804e4893385c45889a79ad7d8889222
---

 vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index ad013e3e7..26d76d61b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -223,14 +223,13 @@ public class UiTools {
     }
 
     public static void setKeyboardVisibility(final View v, final boolean show) {
-        final InputMethodManager inputMethodManager = (InputMethodManager) VLCApplication.getAppContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
+        if (v == null) return;
+        final InputMethodManager inputMethodManager = (InputMethodManager) v.getContext().getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
         sHandler.post(new Runnable() {
             @Override
             public void run() {
-                if (show)
-                    inputMethodManager.showSoftInput(v, InputMethodManager.SHOW_FORCED);
-                else
-                    inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
+                if (show) inputMethodManager.showSoftInput(v, InputMethodManager.SHOW_FORCED);
+                else inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
             }
         });
     }



More information about the Android mailing list