Skip to content

Commit

Permalink
add warning for not configured adjustResize windowSoftInputMode in Ac…
Browse files Browse the repository at this point in the history
…tivity
  • Loading branch information
frogermcs committed Mar 21, 2016
1 parent c02c4ab commit 14abe0a
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
Expand All @@ -26,16 +27,24 @@ public static KeyboardWatcher initWith(Activity activity) {
public KeyboardWatcher bindKeyboardWatcher(OnKeyboardToggleListener onKeyboardToggleListener) {
this.onKeyboardToggleListener = onKeyboardToggleListener;
final View root = activity.findViewById(android.R.id.content);
int inputModeFlag = activity.getWindow().getAttributes().softInputMode & WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
if (root instanceof ViewGroup && inputModeFlag != 0) {
rootView = (ViewGroup) root;
viewTreeObserverListener = new GlobalLayoutListener();
rootView.getViewTreeObserver().addOnGlobalLayoutListener(viewTreeObserverListener);
if (hasAdjustResizeInputMode()) {
if (root instanceof ViewGroup) {
rootView = (ViewGroup) root;
viewTreeObserverListener = new GlobalLayoutListener();
rootView.getViewTreeObserver().addOnGlobalLayoutListener(viewTreeObserverListener);
}
} else {
Log.w("KeyboardWatcher", "Activity " + activity.getClass().getSimpleName() + " should have windowSoftInputMode=\"adjustResize\"" +
"to make KeyboardWatcher working. You can set it in AndroidManifest.xml");
}

return this;
}

private boolean hasAdjustResizeInputMode() {
return (activity.getWindow().getAttributes().softInputMode & WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) != 0;
}

public void unbindKeyboardWatcher() {
if (rootView != null && viewTreeObserverListener != null) {
if (Build.VERSION.SDK_INT >= 16) {
Expand Down

0 comments on commit 14abe0a

Please sign in to comment.