ViewCompat.java revision bc889e39e279fcf8c3d35fc11d8052c002eddf38
1bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell/*
2bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * Copyright (C) 2011 The Android Open Source Project
3bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell *
4bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
5bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * you may not use this file except in compliance with the License.
6bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * You may obtain a copy of the License at
7bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell *
8bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
9bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell *
10bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * Unless required by applicable law or agreed to in writing, software
11bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
12bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * See the License for the specific language governing permissions and
14bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * limitations under the License.
15bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell */
16bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
17bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellpackage android.support.v4.view;
18bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
19bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellimport android.view.View;
20bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
21bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell/**
22bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * Helper for accessing newer features in View.
23bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell */
24bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellpublic class ViewCompat {
25bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    interface ViewCompatImpl {
26bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollHorizontally(View v, int direction);
27bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollVertically(View v, int direction);
28bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
29bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
30bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    static class BaseViewCompatImpl implements ViewCompatImpl {
31bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollHorizontally(View v, int direction) {
32bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return false;
33bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
34bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollVertically(View v, int direction) {
35bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return false;
36bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
37bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
38bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
39bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    static class ICSViewCompatImpl implements ViewCompatImpl {
40bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollHorizontally(View v, int direction) {
41bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return ViewCompatICS.canScrollHorizontally(v, direction);
42bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
43bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollVertically(View v, int direction) {
44bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return ViewCompatICS.canScrollVertically(v, direction);
45bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
46bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
47bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
48bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    static final ViewCompatImpl IMPL;
49bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    static {
50bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        if (android.os.Build.VERSION.SDK_INT >= 14) {
51bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            IMPL = new ICSViewCompatImpl();
52bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        } else {
53bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            IMPL = new BaseViewCompatImpl();
54bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
55bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
56bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
57bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    public static boolean canScrollHorizontally(View v, int direction) {
58bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        return IMPL.canScrollHorizontally(v, direction);
59bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
60bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
61bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    public static boolean canScrollVertically(View v, int direction) {
62bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        return IMPL.canScrollVertically(v, direction);
63bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
64bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell}
65