forked from extern/Unexpected-Keyboard
Fix gravity of keyboard in full screen (#363)
Set keyboard bottom gravity and adjust inputArea height so it doesn't appear on top in fullscreen.
This commit is contained in:
parent
649aea8c79
commit
62943ba4d3
@ -9,11 +9,7 @@ import android.os.IBinder;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.util.LogPrinter;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.view.*;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
@ -23,6 +19,8 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class Keyboard2 extends InputMethodService
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
@ -288,6 +286,61 @@ public class Keyboard2 extends InputMethodService
|
||||
if (parent != null && parent instanceof ViewGroup)
|
||||
((ViewGroup)parent).removeView(v);
|
||||
super.setInputView(v);
|
||||
updateSoftInputWindowLayoutParams();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateFullscreenMode() {
|
||||
super.updateFullscreenMode();
|
||||
updateSoftInputWindowLayoutParams();
|
||||
}
|
||||
|
||||
private void updateSoftInputWindowLayoutParams() {
|
||||
final Window window = getWindow().getWindow();
|
||||
updateLayoutHeightOf(window, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
final View inputArea = window.findViewById(android.R.id.inputArea);
|
||||
|
||||
updateLayoutHeightOf(
|
||||
(View) inputArea.getParent(),
|
||||
isFullscreenMode()
|
||||
? ViewGroup.LayoutParams.MATCH_PARENT
|
||||
: ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
updateLayoutGravityOf((View) inputArea.getParent(), Gravity.BOTTOM);
|
||||
|
||||
}
|
||||
|
||||
private static void updateLayoutHeightOf(final Window window, final int layoutHeight) {
|
||||
final WindowManager.LayoutParams params = window.getAttributes();
|
||||
if (params != null && params.height != layoutHeight) {
|
||||
params.height = layoutHeight;
|
||||
window.setAttributes(params);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLayoutHeightOf(final View view, final int layoutHeight) {
|
||||
final ViewGroup.LayoutParams params = view.getLayoutParams();
|
||||
if (params != null && params.height != layoutHeight) {
|
||||
params.height = layoutHeight;
|
||||
view.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLayoutGravityOf(final View view, final int layoutGravity) {
|
||||
final ViewGroup.LayoutParams lp = view.getLayoutParams();
|
||||
if (lp instanceof LinearLayout.LayoutParams) {
|
||||
final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lp;
|
||||
if (params.gravity != layoutGravity) {
|
||||
params.gravity = layoutGravity;
|
||||
view.setLayoutParams(params);
|
||||
}
|
||||
} else if (lp instanceof FrameLayout.LayoutParams) {
|
||||
final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lp;
|
||||
if (params.gravity != layoutGravity) {
|
||||
params.gravity = layoutGravity;
|
||||
view.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user