111a77446c575f420d8acc163ff1f9b1050853e27Jason Monk/* 211a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * Copyright (C) 2015 The Android Open Source Project 311a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * 411a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * Licensed under the Apache License, Version 2.0 (the "License"); 511a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * you may not use this file except in compliance with the License. 611a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * You may obtain a copy of the License at 711a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * 811a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * http://www.apache.org/licenses/LICENSE-2.0 911a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * 1011a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * Unless required by applicable law or agreed to in writing, software 1111a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * distributed under the License is distributed on an "AS IS" BASIS, 1211a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1311a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * See the License for the specific language governing permissions and 1411a77446c575f420d8acc163ff1f9b1050853e27Jason Monk * limitations under the License. 1511a77446c575f420d8acc163ff1f9b1050853e27Jason Monk */ 1611a77446c575f420d8acc163ff1f9b1050853e27Jason Monkpackage com.android.systemui.tuner; 1711a77446c575f420d8acc163ff1f9b1050853e27Jason Monk 1811a77446c575f420d8acc163ff1f9b1050853e27Jason Monkimport android.content.Context; 1911a77446c575f420d8acc163ff1f9b1050853e27Jason Monkimport android.util.AttributeSet; 2011a77446c575f420d8acc163ff1f9b1050853e27Jason Monkimport android.view.DragEvent; 2111a77446c575f420d8acc163ff1f9b1050853e27Jason Monkimport android.widget.ScrollView; 2211a77446c575f420d8acc163ff1f9b1050853e27Jason Monk 2311a77446c575f420d8acc163ff1f9b1050853e27Jason Monkpublic class AutoScrollView extends ScrollView { 2411a77446c575f420d8acc163ff1f9b1050853e27Jason Monk 2511a77446c575f420d8acc163ff1f9b1050853e27Jason Monk private static final float SCROLL_PERCENT = .10f; 2611a77446c575f420d8acc163ff1f9b1050853e27Jason Monk 2711a77446c575f420d8acc163ff1f9b1050853e27Jason Monk public AutoScrollView(Context context, AttributeSet attrs) { 2811a77446c575f420d8acc163ff1f9b1050853e27Jason Monk super(context, attrs); 2911a77446c575f420d8acc163ff1f9b1050853e27Jason Monk } 3011a77446c575f420d8acc163ff1f9b1050853e27Jason Monk 3111a77446c575f420d8acc163ff1f9b1050853e27Jason Monk public boolean onDragEvent(DragEvent event) { 3211a77446c575f420d8acc163ff1f9b1050853e27Jason Monk switch (event.getAction()) { 3311a77446c575f420d8acc163ff1f9b1050853e27Jason Monk case DragEvent.ACTION_DRAG_LOCATION: 3411a77446c575f420d8acc163ff1f9b1050853e27Jason Monk int y = (int) event.getY(); 3511a77446c575f420d8acc163ff1f9b1050853e27Jason Monk int height = getHeight(); 3611a77446c575f420d8acc163ff1f9b1050853e27Jason Monk int scrollPadding = (int) (height * SCROLL_PERCENT); 3711a77446c575f420d8acc163ff1f9b1050853e27Jason Monk if (y < scrollPadding) { 3811a77446c575f420d8acc163ff1f9b1050853e27Jason Monk scrollBy(0, y - scrollPadding); 3911a77446c575f420d8acc163ff1f9b1050853e27Jason Monk } else if (y > height - scrollPadding) { 4011a77446c575f420d8acc163ff1f9b1050853e27Jason Monk scrollBy(0, y - height + scrollPadding); 4111a77446c575f420d8acc163ff1f9b1050853e27Jason Monk } 4211a77446c575f420d8acc163ff1f9b1050853e27Jason Monk break; 4311a77446c575f420d8acc163ff1f9b1050853e27Jason Monk } 4411a77446c575f420d8acc163ff1f9b1050853e27Jason Monk return false; 4511a77446c575f420d8acc163ff1f9b1050853e27Jason Monk } 4611a77446c575f420d8acc163ff1f9b1050853e27Jason Monk} 47