1/* 2 * Copyright (C) 2014 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.ui; 19 20import android.content.Context; 21import android.database.Observable; 22import android.util.AttributeSet; 23import android.widget.ListView; 24 25import com.android.mail.browse.ScrollNotifier; 26 27/** 28 * Ordinary list view with extra boilerplate to notify on scrollbar-related events (unrelated to 29 * {@link android.widget.AbsListView.OnScrollListener}!) 30 */ 31public class ScrollNotifyingListView extends ListView implements ScrollNotifier { 32 33 private final ScrollObservable mObservable = new ScrollObservable(); 34 35 public ScrollNotifyingListView(Context c) { 36 this(c, null); 37 } 38 39 public ScrollNotifyingListView(Context c, AttributeSet attrs) { 40 super(c, attrs); 41 } 42 43 @Override 44 public void addScrollListener(ScrollListener l) { 45 mObservable.registerObserver(l); 46 } 47 48 @Override 49 public void removeScrollListener(ScrollListener l) { 50 mObservable.unregisterObserver(l); 51 } 52 53 @Override 54 protected void onScrollChanged(int l, int t, int oldl, int oldt) { 55 super.onScrollChanged(l, t, oldl, oldt); 56 mObservable.onScrollChanged(l, t, oldl, oldt); 57 } 58 59 @Override 60 public int computeVerticalScrollRange() { 61 return super.computeVerticalScrollRange(); 62 } 63 64 @Override 65 public int computeVerticalScrollOffset() { 66 return super.computeVerticalScrollOffset(); 67 } 68 69 @Override 70 public int computeVerticalScrollExtent() { 71 return super.computeVerticalScrollExtent(); 72 } 73 74 @Override 75 public int computeHorizontalScrollRange() { 76 return super.computeHorizontalScrollRange(); 77 } 78 79 @Override 80 public int computeHorizontalScrollOffset() { 81 return super.computeHorizontalScrollOffset(); 82 } 83 84 @Override 85 public int computeHorizontalScrollExtent() { 86 return super.computeHorizontalScrollExtent(); 87 } 88 89 private static class ScrollObservable extends Observable<ScrollListener> { 90 91 @SuppressWarnings("unused") 92 public void onScrollChanged(int l, int t, int oldl, int oldt) { 93 for (ScrollListener sl : mObservers) { 94 sl.onNotifierScroll(t); 95 } 96 } 97 98 } 99 100} 101