1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.fmradio.views; 18 19 import android.content.Context; 20 import android.os.Parcelable; 21 import android.util.AttributeSet; 22 import android.view.MotionEvent; 23 import android.widget.ScrollView; 24 25 /** 26 * A {@link ScrollView} that doesn't respond or intercept touch events. 27 * This is used in combination with {@link com.android.FmScroller.widget.MultiShrinkScroller} 28 * so that MultiShrinkScroller can handle all scrolling & saving. 29 */ 30 public class FmTouchlessScrollView extends ScrollView { 31 32 /** 33 * Constructor method 34 * 35 * @param context The context instance 36 */ FmTouchlessScrollView(Context context)37 public FmTouchlessScrollView(Context context) { 38 this(context, null); 39 } 40 41 /** 42 * Constructor method 43 * 44 * @param context The context instance 45 * @param attrs The attribute set for this view 46 */ FmTouchlessScrollView(Context context, AttributeSet attrs)47 public FmTouchlessScrollView(Context context, AttributeSet attrs) { 48 this(context, attrs, 0); 49 } 50 51 /** 52 * Constructor method 53 * 54 * @param context The context instance 55 * @param attrs The attribute set for this view 56 * @param defStyleAttr The default style for this view 57 */ FmTouchlessScrollView(Context context, AttributeSet attrs, int defStyleAttr)58 public FmTouchlessScrollView(Context context, AttributeSet attrs, int defStyleAttr) { 59 super(context, attrs, defStyleAttr); 60 } 61 62 @Override onSaveInstanceState()63 protected Parcelable onSaveInstanceState() { 64 // Do not save the current scroll position. Always store scrollY=0 and delegate 65 // responsibility of saving state to the MultiShrinkScroller. 66 final int scrollY = getScrollY(); 67 setScrollY(0); 68 final Parcelable returnValue = super.onSaveInstanceState(); 69 setScrollY(scrollY); 70 return returnValue; 71 } 72 73 /** 74 * {@inheritDoc} 75 */ 76 @Override onInterceptTouchEvent(MotionEvent ev)77 public boolean onInterceptTouchEvent(MotionEvent ev) { 78 return false; 79 } 80 81 /** 82 * {@inheritDoc} 83 */ 84 @Override onTouchEvent(MotionEvent event)85 public boolean onTouchEvent(MotionEvent event) { 86 return false; 87 } 88 } 89