• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
20 import android.content.res.TypedArray;
21 import android.util.AttributeSet;
22 import android.util.Log;
23 import android.view.MotionEvent;
24 
25 import androidx.annotation.ColorRes;
26 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
27 
28 import com.android.documentsui.R;
29 
30 /**
31  * A {@link SwipeRefreshLayout} that does not intercept any touch events. This relies on its nested
32  * view to scroll in order to cause a refresh. It is possible that it gets disabled by
33  * {@link ListeningGestureDetector} .
34  */
35 public class DocumentsSwipeRefreshLayout extends SwipeRefreshLayout {
36     private static final String TAG = DocumentsSwipeRefreshLayout.class.getSimpleName();
37 
DocumentsSwipeRefreshLayout(Context context)38     public DocumentsSwipeRefreshLayout(Context context) {
39         this(context, null);
40     }
41 
DocumentsSwipeRefreshLayout(Context context, AttributeSet attrs)42     public DocumentsSwipeRefreshLayout(Context context, AttributeSet attrs) {
43         super(context, attrs);
44 
45         final int[] styledAttrs = {android.R.attr.colorPrimary};
46 
47         TypedArray a = context.obtainStyledAttributes(styledAttrs);
48         @ColorRes int colorId = a.getResourceId(0, -1);
49         if (colorId == -1) {
50             Log.w(TAG, "Retrive colorPrimary colorId from theme fail, assign R.color.primary");
51             colorId = R.color.primary;
52         }
53         a.recycle();
54         setColorSchemeResources(colorId);
55     }
56 
57     @Override
onInterceptTouchEvent(MotionEvent e)58     public boolean onInterceptTouchEvent(MotionEvent e) {
59         return false;
60     }
61 }