Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * the License at |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 7 | * |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.content.Context; |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 20 | import android.graphics.Canvas; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
| 22 | import android.view.View; |
| 23 | import android.webkit.WebView; |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 24 | import android.webkit.WebViewClassic; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 25 | |
| 26 | import java.util.Map; |
| 27 | |
| 28 | /** |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 29 | * Manage WebView scroll events |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 30 | */ |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 31 | public class BrowserWebView extends WebView implements WebViewClassic.TitleBarDelegate { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 32 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 33 | public interface OnScrollChangedListener { |
| 34 | void onScrollChanged(int l, int t, int oldl, int oldt); |
| 35 | } |
| 36 | |
Romain Guy | 860662a | 2011-01-10 12:57:22 -0800 | [diff] [blame] | 37 | private boolean mBackgroundRemoved = false; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 38 | private TitleBar mTitleBar; |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 39 | private OnScrollChangedListener mOnScrollChangedListener; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * @param context |
| 43 | * @param attrs |
| 44 | * @param defStyle |
| 45 | * @param javascriptInterfaces |
| 46 | */ |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 47 | public BrowserWebView(Context context, AttributeSet attrs, int defStyle, |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 48 | Map<String, Object> javascriptInterfaces, boolean privateBrowsing) { |
| 49 | super(context, attrs, defStyle, javascriptInterfaces, privateBrowsing); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param context |
| 54 | * @param attrs |
| 55 | * @param defStyle |
| 56 | */ |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 57 | public BrowserWebView( |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 58 | Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 59 | super(context, attrs, defStyle, privateBrowsing); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @param context |
| 64 | * @param attrs |
| 65 | */ |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 66 | public BrowserWebView(Context context, AttributeSet attrs) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 67 | super(context, attrs); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @param context |
| 72 | */ |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 73 | public BrowserWebView(Context context) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 74 | super(context); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 77 | // From TitleBarDelegate |
Michael Kolb | 08a687a | 2011-04-22 16:13:02 -0700 | [diff] [blame] | 78 | @Override |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 79 | public int getTitleHeight() { |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 80 | return (mTitleBar != null) ? mTitleBar.getEmbeddedHeight() : 0; |
| 81 | } |
| 82 | |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 83 | // From TitleBarDelegate |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 84 | @Override |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 85 | public void onSetEmbeddedTitleBar(final View title) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 86 | mTitleBar = (TitleBar) title; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 89 | public boolean hasTitleBar() { |
| 90 | return (mTitleBar != null); |
| 91 | } |
| 92 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 93 | @Override |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 94 | protected void onDraw(Canvas c) { |
Michael Kolb | f262892 | 2011-03-09 17:15:28 -0800 | [diff] [blame] | 95 | super.onDraw(c); |
| 96 | if (!mBackgroundRemoved && getRootView().getBackground() != null) { |
| 97 | mBackgroundRemoved = true; |
| 98 | post(new Runnable() { |
| 99 | public void run() { |
| 100 | getRootView().setBackgroundDrawable(null); |
| 101 | } |
| 102 | }); |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 106 | public void drawContent(Canvas c) { |
| 107 | onDraw(c); |
| 108 | } |
| 109 | |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 110 | @Override |
| 111 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
| 112 | super.onScrollChanged(l, t, oldl, oldt); |
| 113 | if (mOnScrollChangedListener != null) { |
| 114 | mOnScrollChangedListener.onScrollChanged(l, t, oldl, oldt); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | public void setOnScrollChangedListener(OnScrollChangedListener listener) { |
| 119 | mOnScrollChangedListener = listener; |
| 120 | } |
| 121 | |
John Reck | bd54631 | 2011-09-19 11:47:52 -0700 | [diff] [blame] | 122 | @Override |
| 123 | public boolean showContextMenuForChild(View originalView) { |
| 124 | return false; |
| 125 | } |
| 126 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 127 | } |