Fixed bug where keyboard would cover text input on the webview
This commit is contained in:
parent
40cda1317a
commit
bd98619d4f
@ -35,7 +35,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/Theme.LightTheme"
|
||||
android:windowSoftInputMode="adjustResize|adjustPan">
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
|
@ -17,6 +17,7 @@ import android.database.sqlite.SQLiteException;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.MediaPlayer;
|
||||
@ -116,6 +117,7 @@ import acr.browser.lightning.react.Observable;
|
||||
import acr.browser.lightning.react.Schedulers;
|
||||
import acr.browser.lightning.receiver.NetworkReceiver;
|
||||
import acr.browser.lightning.utils.DrawableUtils;
|
||||
import acr.browser.lightning.utils.KeyboardHelper;
|
||||
import acr.browser.lightning.utils.ProxyUtils;
|
||||
import acr.browser.lightning.utils.ThemeUtils;
|
||||
import acr.browser.lightning.utils.UrlUtils;
|
||||
@ -154,7 +156,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
private ImageView mArrowImage;
|
||||
|
||||
// Current tab view being displayed
|
||||
private View mCurrentView;
|
||||
@Nullable private View mCurrentView;
|
||||
|
||||
// Full Screen Video Views
|
||||
private FrameLayout mFullscreenContainer;
|
||||
@ -250,6 +252,17 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
initialize();
|
||||
|
||||
KeyboardHelper keyboardHelper = new KeyboardHelper(mRoot);
|
||||
keyboardHelper.registerKeyboardListener(new KeyboardHelper.KeyboardListener() {
|
||||
@Override
|
||||
public void keyboardVisibilityChanged(boolean visible) {
|
||||
if (visible) {
|
||||
setTabHeightForKeyboard();
|
||||
} else {
|
||||
setTabHeight();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized void initialize() {
|
||||
@ -603,7 +616,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
initializeTabHeight();
|
||||
|
||||
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
|
||||
// Sets the tab height correctly if the status bar is hidden
|
||||
// Also ensures that tab is correct height on rotation
|
||||
mRoot.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
|
||||
@Override
|
||||
@ -1081,7 +1096,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
initializeToolbarHeight(newConfig);
|
||||
}
|
||||
|
||||
private void initializeToolbarHeight(@NonNull final Configuration configuration){
|
||||
private void initializeToolbarHeight(@NonNull final Configuration configuration) {
|
||||
// TODO externalize the dimensions
|
||||
doOnLayout(mUiLayout, new Runnable() {
|
||||
@Override
|
||||
@ -1308,7 +1323,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
|
||||
private int getSearchBarColor(int requestedColor, int defaultColor) {
|
||||
if (requestedColor == defaultColor) {
|
||||
return mDarkTheme ? DrawableUtils.mixColor(0.25f, defaultColor, Color.WHITE): Color.WHITE;
|
||||
return mDarkTheme ? DrawableUtils.mixColor(0.25f, defaultColor, Color.WHITE) : Color.WHITE;
|
||||
} else {
|
||||
return DrawableUtils.mixColor(0.25f, requestedColor, Color.WHITE);
|
||||
}
|
||||
@ -1948,7 +1963,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
private void setTabHeight() {
|
||||
Log.d(TAG, "setTabHeight");
|
||||
if (mRoot.getHeight() == 0) {
|
||||
mRoot.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
||||
mRoot.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
|
||||
}
|
||||
|
||||
Log.d(TAG, "UI Layout top: " + mUiLayout.getTop());
|
||||
@ -1957,12 +1972,28 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
int height = mRoot.getHeight() - mUiLayout.getTop();
|
||||
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
|
||||
} else {
|
||||
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
params.weight = 1;
|
||||
mBrowserFrame.setLayoutParams(params);
|
||||
}
|
||||
|
||||
mBrowserFrame.requestLayout();
|
||||
}
|
||||
|
||||
private void setTabHeightForKeyboard() {
|
||||
doOnLayout(mUiLayout, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Rect rect = new Rect();
|
||||
mRoot.getWindowVisibleDisplayFrame(rect);
|
||||
|
||||
int height = rect.bottom - mUiLayout.getTop();
|
||||
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
|
||||
mBrowserFrame.requestLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This method lets the search bar know that the page is currently loading
|
||||
* and that it should display the stop icon to indicate to the user that
|
||||
|
@ -0,0 +1,67 @@
|
||||
package acr.browser.lightning.utils;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
public class KeyboardHelper {
|
||||
|
||||
public interface KeyboardListener {
|
||||
/**
|
||||
* Called when the visibility of the keyboard changes.
|
||||
* Parameter tells whether the keyboard has been shown
|
||||
* or hidden.
|
||||
*
|
||||
* @param visible true if the keyboard has been shown,
|
||||
* false otherwise.
|
||||
*/
|
||||
void keyboardVisibilityChanged(boolean visible);
|
||||
}
|
||||
|
||||
@NonNull private View mView;
|
||||
private int mLastRight = -1;
|
||||
private int mLastBottom = -1;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param view the view to listen on, should be
|
||||
* the {@link android.R.id#content} view.
|
||||
*/
|
||||
public KeyboardHelper(@NonNull View view) {
|
||||
mView = view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a {@link KeyboardListener} to receive
|
||||
* callbacks when the keyboard is shown for the specific
|
||||
* view. The view used should be the content view as it
|
||||
* will receive resize events from the system.
|
||||
*
|
||||
* @param listener the listener to register to receive events.
|
||||
*/
|
||||
public void registerKeyboardListener(@NonNull final KeyboardListener listener) {
|
||||
mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
Rect rect = new Rect();
|
||||
if (mLastBottom == -1) {
|
||||
mLastBottom = rect.bottom;
|
||||
}
|
||||
if (mLastRight == -1) {
|
||||
mLastRight = rect.right;
|
||||
}
|
||||
mView.getWindowVisibleDisplayFrame(rect);
|
||||
if (mLastRight == rect.right && rect.bottom < mLastBottom) {
|
||||
listener.keyboardVisibilityChanged(true);
|
||||
} else if (mLastRight == rect.right && rect.bottom > mLastBottom) {
|
||||
listener.keyboardVisibilityChanged(false);
|
||||
}
|
||||
mLastBottom = rect.bottom;
|
||||
mLastRight = rect.right;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout
|
||||
android:id="@+id/content_frame"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@color/primary_color" />
|
||||
android:background="@color/primary_color"
|
||||
android:clipChildren="true"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user