Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.documentsui.dirlist; |
| 18 | |
| 19 | import android.content.Context; |
Garfield, Tan | 8b6b35d | 2016-07-20 14:36:42 -0700 | [diff] [blame] | 20 | import android.content.res.TypedArray; |
| 21 | import android.support.annotation.ColorRes; |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 22 | import android.support.v4.widget.SwipeRefreshLayout; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.view.MotionEvent; |
| 25 | |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 26 | /** |
Ben Lin | 40f4488 | 2016-08-04 10:42:59 -0700 | [diff] [blame] | 27 | * A {@link SwipeRefreshLayout} that does not intercept any touch events. This relies on its nested |
Ben Lin | d79edd1 | 2017-03-14 17:39:36 -0700 | [diff] [blame] | 28 | * view to scroll in order to cause a refresh. It is possible that it gets disabled by |
| 29 | * {@link ListeningGestureDetector} . |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 30 | */ |
Ben Lin | 40f4488 | 2016-08-04 10:42:59 -0700 | [diff] [blame] | 31 | public class DocumentsSwipeRefreshLayout extends SwipeRefreshLayout { |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 32 | |
Garfield, Tan | 8b6b35d | 2016-07-20 14:36:42 -0700 | [diff] [blame] | 33 | private static final int[] COLOR_RES = new int[] { android.R.attr.colorAccent }; |
| 34 | private static int COLOR_ACCENT_INDEX = 0; |
| 35 | |
Ben Lin | 40f4488 | 2016-08-04 10:42:59 -0700 | [diff] [blame] | 36 | public DocumentsSwipeRefreshLayout(Context context) { |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 37 | this(context, null); |
| 38 | } |
| 39 | |
Ben Lin | 40f4488 | 2016-08-04 10:42:59 -0700 | [diff] [blame] | 40 | public DocumentsSwipeRefreshLayout(Context context, AttributeSet attrs) { |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 41 | super(context, attrs); |
Garfield, Tan | 8b6b35d | 2016-07-20 14:36:42 -0700 | [diff] [blame] | 42 | |
| 43 | TypedArray a = context.obtainStyledAttributes(COLOR_RES); |
| 44 | @ColorRes int colorId = a.getResourceId(COLOR_ACCENT_INDEX, -1); |
| 45 | a.recycle(); |
| 46 | setColorSchemeResources(colorId); |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public boolean onInterceptTouchEvent(MotionEvent e) { |
Ben Lin | 40f4488 | 2016-08-04 10:42:59 -0700 | [diff] [blame] | 51 | return false; |
Garfield, Tan | ca7c088 | 2016-07-18 16:45:27 -0700 | [diff] [blame] | 52 | } |
Ben Lin | d79edd1 | 2017-03-14 17:39:36 -0700 | [diff] [blame] | 53 | } |