|
|
@ -43,8 +43,7 @@ import java.util.Set;
|
|
|
|
public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
|
|
|
public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
|
|
|
private static final String TAG = KeyboardAwareLinearLayout.class.getSimpleName();
|
|
|
|
private static final String TAG = KeyboardAwareLinearLayout.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
private final Rect oldRect = new Rect();
|
|
|
|
private final Rect rect = new Rect();
|
|
|
|
private final Rect newRect = new Rect();
|
|
|
|
|
|
|
|
private final Set<OnKeyboardHiddenListener> hiddenListeners = new HashSet<>();
|
|
|
|
private final Set<OnKeyboardHiddenListener> hiddenListeners = new HashSet<>();
|
|
|
|
private final Set<OnKeyboardShownListener> shownListeners = new HashSet<>();
|
|
|
|
private final Set<OnKeyboardShownListener> shownListeners = new HashSet<>();
|
|
|
|
private final int minKeyboardSize;
|
|
|
|
private final int minKeyboardSize;
|
|
|
@ -87,26 +86,29 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
|
|
|
int oldRotation = rotation;
|
|
|
|
int oldRotation = rotation;
|
|
|
|
rotation = getDeviceRotation();
|
|
|
|
rotation = getDeviceRotation();
|
|
|
|
if (oldRotation != rotation) {
|
|
|
|
if (oldRotation != rotation) {
|
|
|
|
|
|
|
|
Log.w(TAG, "rotation changed");
|
|
|
|
onKeyboardClose();
|
|
|
|
onKeyboardClose();
|
|
|
|
oldRect.setEmpty();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateKeyboardState() {
|
|
|
|
private void updateKeyboardState() {
|
|
|
|
|
|
|
|
if (isLandscape()) {
|
|
|
|
|
|
|
|
if (keyboardOpen) onKeyboardClose();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (viewInset == 0 && Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) viewInset = getViewInset();
|
|
|
|
if (viewInset == 0 && Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) viewInset = getViewInset();
|
|
|
|
final int availableHeight = this.getRootView().getHeight() - statusBarHeight - viewInset;
|
|
|
|
final int availableHeight = this.getRootView().getHeight() - statusBarHeight - viewInset;
|
|
|
|
getWindowVisibleDisplayFrame(newRect);
|
|
|
|
getWindowVisibleDisplayFrame(rect);
|
|
|
|
|
|
|
|
|
|
|
|
final int oldKeyboardHeight = availableHeight - (oldRect.bottom - oldRect.top);
|
|
|
|
final int keyboardHeight = availableHeight - (rect.bottom - rect.top);
|
|
|
|
final int keyboardHeight = availableHeight - (newRect.bottom - newRect.top);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (keyboardHeight - oldKeyboardHeight > minKeyboardSize && !keyboardOpen) {
|
|
|
|
if (keyboardHeight > minKeyboardSize) {
|
|
|
|
onKeyboardOpen(keyboardHeight);
|
|
|
|
if (getKeyboardHeight() != keyboardHeight) setKeyboardPortraitHeight(keyboardHeight);
|
|
|
|
} else if (oldKeyboardHeight - keyboardHeight > minKeyboardSize && keyboardOpen) {
|
|
|
|
if (!keyboardOpen) onKeyboardOpen(keyboardHeight);
|
|
|
|
|
|
|
|
} else if (keyboardOpen) {
|
|
|
|
onKeyboardClose();
|
|
|
|
onKeyboardClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
oldRect.set(newRect);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@TargetApi(VERSION_CODES.LOLLIPOP)
|
|
|
|
@TargetApi(VERSION_CODES.LOLLIPOP)
|
|
|
@ -130,15 +132,14 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void onKeyboardOpen(int keyboardHeight) {
|
|
|
|
protected void onKeyboardOpen(int keyboardHeight) {
|
|
|
|
|
|
|
|
Log.w(TAG, "onKeyboardOpen(" + keyboardHeight + ")");
|
|
|
|
keyboardOpen = true;
|
|
|
|
keyboardOpen = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (!isLandscape()) {
|
|
|
|
|
|
|
|
setKeyboardPortraitHeight(keyboardHeight);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyShownListeners();
|
|
|
|
notifyShownListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void onKeyboardClose() {
|
|
|
|
protected void onKeyboardClose() {
|
|
|
|
|
|
|
|
Log.w(TAG, "onKeyboardClose()");
|
|
|
|
keyboardOpen = false;
|
|
|
|
keyboardOpen = false;
|
|
|
|
notifyHiddenListeners();
|
|
|
|
notifyHiddenListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|