Browse Source

Fixed bug where keyboard would cover text input on the webview

master
Anthony Restaino 9 years ago
parent
commit
bd98619d4f
  1. 2
      app/src/main/AndroidManifest.xml
  2. 43
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  3. 67
      app/src/main/java/acr/browser/lightning/utils/KeyboardHelper.java
  4. 6
      app/src/main/res/layout/browser_content.xml

2
app/src/main/AndroidManifest.xml

@ -35,7 +35,7 @@
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTask"
android:theme="@style/Theme.LightTheme" android:theme="@style/Theme.LightTheme"
android:windowSoftInputMode="adjustResize|adjustPan"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

43
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -17,6 +17,7 @@ import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.media.MediaPlayer; import android.media.MediaPlayer;
@ -116,6 +117,7 @@ import acr.browser.lightning.react.Observable;
import acr.browser.lightning.react.Schedulers; import acr.browser.lightning.react.Schedulers;
import acr.browser.lightning.receiver.NetworkReceiver; import acr.browser.lightning.receiver.NetworkReceiver;
import acr.browser.lightning.utils.DrawableUtils; import acr.browser.lightning.utils.DrawableUtils;
import acr.browser.lightning.utils.KeyboardHelper;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.UrlUtils;
@ -154,7 +156,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private ImageView mArrowImage; private ImageView mArrowImage;
// Current tab view being displayed // Current tab view being displayed
private View mCurrentView; @Nullable private View mCurrentView;
// Full Screen Video Views // Full Screen Video Views
private FrameLayout mFullscreenContainer; private FrameLayout mFullscreenContainer;
@ -250,6 +252,17 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
initialize(); 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() { private synchronized void initialize() {
@ -603,7 +616,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
initializeTabHeight(); 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() { mRoot.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Override @Override
@ -1081,7 +1096,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
initializeToolbarHeight(newConfig); initializeToolbarHeight(newConfig);
} }
private void initializeToolbarHeight(@NonNull final Configuration configuration){ private void initializeToolbarHeight(@NonNull final Configuration configuration) {
// TODO externalize the dimensions // TODO externalize the dimensions
doOnLayout(mUiLayout, new Runnable() { doOnLayout(mUiLayout, new Runnable() {
@Override @Override
@ -1308,7 +1323,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private int getSearchBarColor(int requestedColor, int defaultColor) { private int getSearchBarColor(int requestedColor, int defaultColor) {
if (requestedColor == 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 { } else {
return DrawableUtils.mixColor(0.25f, requestedColor, Color.WHITE); return DrawableUtils.mixColor(0.25f, requestedColor, Color.WHITE);
} }
@ -1948,7 +1963,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private void setTabHeight() { private void setTabHeight() {
Log.d(TAG, "setTabHeight"); Log.d(TAG, "setTabHeight");
if (mRoot.getHeight() == 0) { 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()); Log.d(TAG, "UI Layout top: " + mUiLayout.getTop());
@ -1957,11 +1972,27 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
int height = mRoot.getHeight() - mUiLayout.getTop(); int height = mRoot.getHeight() - mUiLayout.getTop();
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height)); mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
} else { } 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(); mBrowserFrame.requestLayout();
} }
});
}
/** /**
* This method lets the search bar know that the page is currently loading * This method lets the search bar know that the page is currently loading

67
app/src/main/java/acr/browser/lightning/utils/KeyboardHelper.java

@ -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;
}
});
}
}

6
app/src/main/res/layout/browser_content.xml

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout
android:id="@+id/content_frame" android:id="@+id/content_frame"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:background="@color/primary_color" /> android:background="@color/primary_color"
android:clipChildren="true"/>

Loading…
Cancel
Save