/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package androidx.wear.widget.drawer; import android.os.Handler; import android.os.Looper; import android.view.View; import android.view.View.OnScrollChangeListener; import android.widget.ScrollView; import androidx.annotation.RestrictTo; import androidx.annotation.RestrictTo.Scope; import androidx.wear.widget.drawer.FlingWatcherFactory.FlingListener; import androidx.wear.widget.drawer.FlingWatcherFactory.FlingWatcher; import java.lang.ref.WeakReference; /** * {@link FlingWatcher} implementation for {@link ScrollView ScrollViews}. *
* Because {@link ScrollView} does not provide a way to listen to the scroll state, there's no
* callback which definitely indicates the fling has finished. So, we instead listen for scroll
* events. If we reach the top or bottom of the view or if there are no events within {@link
* #MAX_WAIT_TIME_MS}, we assume the fling has finished.
*
* @hide
*/
@RestrictTo(Scope.LIBRARY)
class ScrollViewFlingWatcher implements FlingWatcher, OnScrollChangeListener {
static final int MAX_WAIT_TIME_MS = 100;
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
private final FlingListener mListener;
private final WeakReference