mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-08 20:28:34 -05:00
Use TitleBarDelegate otherwise clicking links won't work on Jelly Bean
This commit is contained in:
parent
70860b86ca
commit
d4c90ad2bb
14
src/android/webkit/WebViewClassic.java
Normal file
14
src/android/webkit/WebViewClassic.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package android.webkit;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trojan class for getting access to a hidden API level 16 interface
|
||||||
|
*/
|
||||||
|
public class WebViewClassic {
|
||||||
|
public interface TitleBarDelegate {
|
||||||
|
int getTitleHeight();
|
||||||
|
|
||||||
|
public void onSetEmbeddedTitleBar(final View title);
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebViewClassic.TitleBarDelegate;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +44,7 @@ import android.widget.FrameLayout;
|
|||||||
* Call {@link #setEmbeddedTitleBarCompat(View)} for setting a view as embedded
|
* Call {@link #setEmbeddedTitleBarCompat(View)} for setting a view as embedded
|
||||||
* title bar on top of the displayed WebView page.
|
* title bar on top of the displayed WebView page.
|
||||||
*/
|
*/
|
||||||
public class TitleBarWebView extends WebView {
|
public class TitleBarWebView extends WebView implements TitleBarDelegate {
|
||||||
/**
|
/**
|
||||||
* Internally used view wrapper for suppressing unwanted touch events on the
|
* Internally used view wrapper for suppressing unwanted touch events on the
|
||||||
* title bar view when WebView contents is being touched.
|
* title bar view when WebView contents is being touched.
|
||||||
@ -82,6 +83,13 @@ public class TitleBarWebView extends WebView {
|
|||||||
private Matrix mMatrix = new Matrix();
|
private Matrix mMatrix = new Matrix();
|
||||||
private Method mNativeGetVisibleTitleHeightMethod;
|
private Method mNativeGetVisibleTitleHeightMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will always contain a reference to the title bar view no matter if
|
||||||
|
* {@code setEmbeddedTitleBar()} or the Jelly Bean workaround is used. We use this in
|
||||||
|
* {@link #getTitleHeight()}.
|
||||||
|
*/
|
||||||
|
private View mTitleBarView;
|
||||||
|
|
||||||
public TitleBarWebView(Context context) {
|
public TitleBarWebView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init();
|
init();
|
||||||
@ -172,6 +180,8 @@ public class TitleBarWebView extends WebView {
|
|||||||
"Native setEmbeddedTitleBar not available. Starting workaround");
|
"Native setEmbeddedTitleBar not available. Starting workaround");
|
||||||
setEmbeddedTitleBarJellyBean(v);
|
setEmbeddedTitleBarJellyBean(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mTitleBarView = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -225,6 +235,11 @@ public class TitleBarWebView extends WebView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 16) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
|
|
||||||
if(mTitleBar != null) {
|
if(mTitleBar != null) {
|
||||||
@ -264,8 +279,25 @@ public class TitleBarWebView extends WebView {
|
|||||||
scrollBar.draw(canvas);
|
scrollBar.draw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTitleHeight() {
|
/**
|
||||||
if(mTitleBar != null) return mTitleBar.getHeight();
|
* Get the height of the title bar view.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* In the Jelly Bean workaround we need this method because we have to implement the
|
||||||
|
* {@link TitleBarDelegate} interface. But by implementing this method we override the hidden
|
||||||
|
* {@code getTitleHeight()} of the {@link WebView}s in older Android versions.
|
||||||
|
* <br>
|
||||||
|
* What we should do, is return the title height on Jelly Bean and call through to the parent
|
||||||
|
* parent class on older Android versions. But this would require even more trickery, so we
|
||||||
|
* just inline the parent functionality which simply calls {@link View#getHeight()}. This is
|
||||||
|
* exactly what we do on Jelly Bean anyway.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getTitleHeight() {
|
||||||
|
if (mTitleBarView != null) {
|
||||||
|
return mTitleBarView.getHeight();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,4 +347,7 @@ public class TitleBarWebView extends WebView {
|
|||||||
|
|
||||||
mTitleBar = v;
|
mTitleBar = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSetEmbeddedTitleBar(View title) { /* unused */ }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user