1/*
2 * Copyright (C) 2015 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
17package android.support.v7.widget;
18
19import android.content.Context;
20import android.support.v4.view.ViewCompat;
21import android.util.AttributeSet;
22
23/**
24 * RecyclerView wrapper used in tests. This class can fake behavior like layout direction w/o
25 * playing with framework support.
26 */
27public class WrappedRecyclerView extends RecyclerView {
28
29    Boolean mFakeRTL;
30
31    public void setFakeRTL(Boolean fakeRTL) {
32        mFakeRTL = fakeRTL;
33    }
34
35    public WrappedRecyclerView(Context context) {
36        super(context);
37        init(context);
38    }
39
40    public WrappedRecyclerView(Context context, AttributeSet attrs) {
41        super(context, attrs);
42        init(context);
43    }
44
45    public WrappedRecyclerView(Context context, AttributeSet attrs, int defStyle) {
46        super(context, attrs, defStyle);
47        init(context);
48    }
49
50    private void init(Context context) {
51        //initializeScrollbars(null);
52    }
53
54    @Override
55    public int getLayoutDirection() {
56        if (mFakeRTL == null) {
57            return super.getLayoutDirection();
58        }
59        return Boolean.TRUE.equals(mFakeRTL) ? ViewCompat.LAYOUT_DIRECTION_RTL
60                : ViewCompat.LAYOUT_DIRECTION_LTR;
61    }
62}