ConversationWebView.java revision b334c9035e9b7a38766bb66c29da2208525d1e11
1/* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package com.android.mail.browse; 19 20import android.content.Context; 21import android.util.AttributeSet; 22import android.view.MotionEvent; 23import android.webkit.WebView; 24 25import com.android.mail.utils.LogTag; 26import com.android.mail.utils.LogUtils; 27 28import java.util.Set; 29import java.util.concurrent.CopyOnWriteArraySet; 30 31public class ConversationWebView extends WebView implements ScrollNotifier { 32 33 private final Set<ScrollListener> mScrollListeners = 34 new CopyOnWriteArraySet<ScrollListener>(); 35 36 /** 37 * True when WebView is handling a touch-- in between POINTER_DOWN and 38 * POINTER_UP/POINTER_CANCEL. 39 */ 40 private boolean mHandlingTouch; 41 42 private static final String LOG_TAG = LogTag.getLogTag(); 43 44 public ConversationWebView(Context c) { 45 this(c, null); 46 } 47 48 public ConversationWebView(Context c, AttributeSet attrs) { 49 super(c, attrs); 50 } 51 52 @Override 53 public void addScrollListener(ScrollListener l) { 54 mScrollListeners.add(l); 55 } 56 57 @Override 58 public void removeScrollListener(ScrollListener l) { 59 mScrollListeners.remove(l); 60 } 61 62 @Override 63 protected void onScrollChanged(int l, int t, int oldl, int oldt) { 64 super.onScrollChanged(l, t, oldl, oldt); 65 66 for (ScrollListener listener : mScrollListeners) { 67 listener.onNotifierScroll(l, t); 68 } 69 } 70 71 @Override 72 public boolean onTouchEvent(MotionEvent ev) { 73 final int action = ev.getActionMasked(); 74 75 switch (action) { 76 case MotionEvent.ACTION_DOWN: 77 mHandlingTouch = true; 78 break; 79 case MotionEvent.ACTION_POINTER_DOWN: 80 LogUtils.d(LOG_TAG, "WebView disabling intercepts: POINTER_DOWN"); 81 requestDisallowInterceptTouchEvent(true); 82 break; 83 case MotionEvent.ACTION_CANCEL: 84 case MotionEvent.ACTION_UP: 85 mHandlingTouch = false; 86 break; 87 } 88 89 return super.onTouchEvent(ev); 90 } 91 92 public boolean isHandlingTouch() { 93 return mHandlingTouch; 94 } 95 96} 97