Browse Source

Fixed bug where rotating device caused webview height to be incorrect

master
Anthony Restaino 9 years ago
parent
commit
e0ace14029
  1. 49
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

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

@ -5,7 +5,6 @@
package acr.browser.lightning.activity; package acr.browser.lightning.activity;
import android.animation.ArgbEvaluator; import android.animation.ArgbEvaluator;
import android.animation.LayoutTransition;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener; import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity; import android.app.Activity;
@ -132,6 +131,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private static final String INTENT_PANIC_TRIGGER = "info.guardianproject.panic.action.TRIGGER"; private static final String INTENT_PANIC_TRIGGER = "info.guardianproject.panic.action.TRIGGER";
// Static Layout // Static Layout
@Bind(R.id.main_layout)
View mRootLayout;
@Bind(R.id.drawer_layout) @Bind(R.id.drawer_layout)
DrawerLayout mDrawerLayout; DrawerLayout mDrawerLayout;
@ -1031,8 +1033,20 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(final Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
if (mFullScreen) {
showActionBar();
mBrowserFrame.setTranslationY(0);
mToolbarLayout.setTranslationY(0);
}
initializeTabHeight();
doOnLayout(mRootLayout, new Runnable() {
@Override
public void run() {
int toolbarSize; int toolbarSize;
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
toolbarSize = Utils.dpToPx(56); toolbarSize = Utils.dpToPx(56);
@ -1042,12 +1056,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mToolbar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, toolbarSize)); mToolbar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, toolbarSize));
mToolbar.setMinimumHeight(toolbarSize); mToolbar.setMinimumHeight(toolbarSize);
mToolbar.requestLayout(); mToolbar.requestLayout();
if (mFullScreen) {
showActionBar();
mBrowserFrame.setTranslationY(0);
mToolbarLayout.setTranslationY(0);
} }
});
} }
public void closeBrowser() { public void closeBrowser() {
@ -1798,28 +1808,35 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
private void initializeTabHeight() { private void initializeTabHeight() {
mUiLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { doOnLayout(mRootLayout, new Runnable() {
@Override @Override
public void onGlobalLayout() { public void run() {
setTabHeight(); setTabHeight();
}
});
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { private static void doOnLayout(@NonNull final View view, @NonNull final Runnable runnable) {
mUiLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else { } else {
mUiLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} }
runnable.run();
} }
}); });
} }
private void setTabHeight() { private void setTabHeight() {
if (mUiLayout.getHeight() == 0) { if (mRootLayout.getHeight() == 0) {
mUiLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); mRootLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
} }
if (mFullScreen) { if (mFullScreen) {
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mUiLayout.getHeight())); mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mRootLayout.getHeight()));
} else { } else {
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} }

Loading…
Cancel
Save