summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kolb <kolby@google.com>2011-06-01 09:54:20 -0700
committerMichael Kolb <kolby@google.com>2011-06-01 10:40:00 -0700
commit0f91e03b5e614bfd1bae969652172a933faf23c5 (patch)
tree2d10fc730ba6d39d4f107ef05f4c84a5caeb2ee5
parentdb343c57c970bb2e3b8f269fc4cbe90546357257 (diff)
downloadpackages_apps_Browser-0f91e03b5e614bfd1bae969652172a933faf23c5.zip
packages_apps_Browser-0f91e03b5e614bfd1bae969652172a933faf23c5.tar.gz
packages_apps_Browser-0f91e03b5e614bfd1bae969652172a933faf23c5.tar.bz2
use webview proxy in nav screen
Change-Id: If5c914dfad48cd4b13cd5fe81374e8adc35060f9
-rw-r--r--src/com/android/browser/BrowserWebView.java57
-rw-r--r--src/com/android/browser/NavTabScroller.java18
-rw-r--r--src/com/android/browser/NavTabView.java81
-rw-r--r--src/com/android/browser/PhoneUi.java1
4 files changed, 95 insertions, 62 deletions
diff --git a/src/com/android/browser/BrowserWebView.java b/src/com/android/browser/BrowserWebView.java
index 6cdc063..5a40b3c 100644
--- a/src/com/android/browser/BrowserWebView.java
+++ b/src/com/android/browser/BrowserWebView.java
@@ -22,9 +22,10 @@ import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
-import android.view.ViewConfiguration;
import android.webkit.WebView;
+import com.android.browser.NavTabView.WebProxyView;
+
import java.util.Map;
/**
@@ -39,10 +40,7 @@ public class BrowserWebView extends WebView implements Runnable {
private TitleBarBase mTitleBar;
private int mCaptureSize;
private Bitmap mCapture;
- private boolean mNavMode;
- private boolean mTracking;
- private int mSlop;
- float mDownX, mDownY;
+ private WebProxyView mProxyView;
/**
* @param context
@@ -84,15 +82,21 @@ public class BrowserWebView extends WebView implements Runnable {
}
private void init() {
- mNavMode = false;
- mSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
mCaptureSize = mContext.getResources().getDimensionPixelSize(R.dimen.tab_capture_size);
mCapture = Bitmap.createBitmap(mCaptureSize, mCaptureSize,
Bitmap.Config.RGB_565);
}
- protected void setNavMode(boolean enabled) {
- mNavMode = enabled;
+ protected void setProxyView(WebProxyView p) {
+ mProxyView = p;
+ }
+
+ @Override
+ public void invalidate() {
+ super.invalidate();
+ if (mProxyView != null) {
+ mProxyView.invalidate();
+ }
}
@Override
@@ -127,36 +131,13 @@ public class BrowserWebView extends WebView implements Runnable {
@Override
public boolean onTouchEvent(MotionEvent evt) {
- if (mNavMode) {
- if (MotionEvent.ACTION_DOWN == evt.getActionMasked()) {
- mDownX = evt.getX();
- mDownY = evt.getY();
- mTracking = true;
- return true;
- } else if (mTracking && MotionEvent.ACTION_MOVE == evt.getActionMasked()) {
- if (mSlop < Math.abs(evt.getX() - mDownX)
- || mSlop < Math.abs(evt.getY() - mDownY)) {
- mTracking = false;
- }
- return mTracking;
- } else if (mTracking && MotionEvent.ACTION_UP == evt.getActionMasked()) {
- performClick();
- mTracking = false;
- return true;
- } else if (mTracking && MotionEvent.ACTION_CANCEL == evt.getActionMasked()) {
- mTracking = false;
- return true;
- }
- return super.onTouchEvent(evt);
- } else {
- if (MotionEvent.ACTION_DOWN == evt.getActionMasked()) {
- mUserInitiated = true;
- } else if (MotionEvent.ACTION_UP == evt.getActionMasked()
- || (MotionEvent.ACTION_CANCEL == evt.getActionMasked())) {
- mUserInitiated = false;
- }
- return super.onTouchEvent(evt);
+ if (MotionEvent.ACTION_DOWN == evt.getActionMasked()) {
+ mUserInitiated = true;
+ } else if (MotionEvent.ACTION_UP == evt.getActionMasked()
+ || (MotionEvent.ACTION_CANCEL == evt.getActionMasked())) {
+ mUserInitiated = false;
}
+ return super.onTouchEvent(evt);
}
@Override
diff --git a/src/com/android/browser/NavTabScroller.java b/src/com/android/browser/NavTabScroller.java
index 9434ff0..bd26df7 100644
--- a/src/com/android/browser/NavTabScroller.java
+++ b/src/com/android/browser/NavTabScroller.java
@@ -192,10 +192,22 @@ public class NavTabScroller extends FrameLayout {
int midy = getScrollY() + getHeight() / 2;
int sel = -1;
for (int i = 0; i < mContentView.getChildCount(); i++) {
- View child = mContentView.getChildAt(i);
- if (child.getTop() <= midy && child.getBottom() >= midy) {
+ NavTabView child = (NavTabView) mContentView.getChildAt(i);
+ int top = child.getTop();
+ int bottom = child.getBottom();
+ if (top <= midy && bottom >= midy) {
sel = i;
- break;
+ } else {
+ // check if on screen
+ if (top > getScrollY() + getHeight() || bottom < getScrollY()) {
+ if (!child.isPaused()) {
+ child.pause();
+ }
+ } else {
+ if (child.isPaused()) {
+ child.resume();
+ }
+ }
}
}
if (sel != -1) {
diff --git a/src/com/android/browser/NavTabView.java b/src/com/android/browser/NavTabView.java
index ec42c94..061e024 100644
--- a/src/com/android/browser/NavTabView.java
+++ b/src/com/android/browser/NavTabView.java
@@ -18,6 +18,7 @@ package com.android.browser;
import android.content.Context;
import android.content.res.Resources;
+import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
@@ -32,21 +33,23 @@ import android.widget.TextView;
public class NavTabView extends LinearLayout {
- Tab mTab;
- BrowserWebView mWebView;
- ImageButton mForward;
- ImageButton mRefresh;
- ImageView mFavicon;
- ImageButton mClose;
- FrameLayout mContainer;
- TextView mTitle;
- View mTitleBar;
- OnClickListener mClickListener;
- boolean mHighlighted;
- Drawable mTitleBg;
- Drawable mUrlBg;
- float mMediumTextSize;
- float mSmallTextSize;
+ private Tab mTab;
+ private BrowserWebView mWebView;
+ private WebProxyView mProxy;
+ private ImageButton mForward;
+ private ImageButton mRefresh;
+ private ImageView mFavicon;
+ private ImageButton mClose;
+ private FrameLayout mContainer;
+ private TextView mTitle;
+ private View mTitleBar;
+ private OnClickListener mClickListener;
+ private boolean mHighlighted;
+ private Drawable mTitleBg;
+ private Drawable mUrlBg;
+ private float mMediumTextSize;
+ private float mSmallTextSize;
+ private boolean mPaused;
public NavTabView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@@ -82,6 +85,20 @@ public class NavTabView extends LinearLayout {
setState(false);
}
+ protected void pause() {
+ mPaused = true;
+ mWebView.onPause();
+ }
+
+ protected void resume() {
+ mPaused = false;
+ mWebView.onResume();
+ }
+
+ protected boolean isPaused() {
+ return mPaused;
+ }
+
protected boolean isRefresh(View v) {
return v == mRefresh;
}
@@ -99,7 +116,7 @@ public class NavTabView extends LinearLayout {
}
protected boolean isWebView(View v) {
- return v == mWebView;
+ return v == mProxy;
}
protected void setHighlighted(boolean highlighted) {
@@ -153,8 +170,8 @@ public class NavTabView extends LinearLayout {
if (web == null) return;
mWebView = web;
removeFromParent(mWebView);
- mWebView.setNavMode(true);
- mContainer.addView(mWebView, 0);
+ mProxy = new WebProxyView(mContext, mWebView);
+ mContainer.addView(mProxy, 0);
if (mWebView != null) {
mForward.setVisibility(mWebView.canGoForward()
? View.VISIBLE : View.GONE);
@@ -174,15 +191,39 @@ public class NavTabView extends LinearLayout {
mRefresh.setOnClickListener(mClickListener);
mForward.setOnClickListener(mClickListener);
mClose.setOnClickListener(mClickListener);
- if (mWebView != null) {
- mWebView.setOnClickListener(mClickListener);
+ if (mProxy != null) {
+ mProxy.setOnClickListener(mClickListener);
}
}
+ @Override
+ public void onDetachedFromWindow() {
+ mWebView.setProxyView(null);
+ }
+
private static void removeFromParent(View v) {
if (v.getParent() != null) {
((ViewGroup) v.getParent()).removeView(v);
}
}
+ static class WebProxyView extends View {
+
+ private BrowserWebView mWeb;
+
+ public WebProxyView(Context context, BrowserWebView web) {
+ super(context);
+ setWillNotDraw(false);
+ mWeb = web;
+ mWeb.setProxyView(this);
+
+ }
+
+ public void onDraw(Canvas c) {
+ c.translate(-mWeb.getScrollX(), -mWeb.getScrollY());
+ mWeb.onDraw(c);
+ }
+
+ }
+
}
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index ce993fd..f94a8ab 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -167,7 +167,6 @@ public class PhoneUi extends BaseUi {
Log.e(LOGTAG, "active tab with no webview detected");
return;
}
- view.setNavMode(false);
// Request focus on the top window.
if (mUseQuickControls) {
mPieControl.forceToTop(mContentView);