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.design.widget;
18
19import android.os.Build;
20import android.view.View;
21
22class ViewUtils {
23
24    static final ValueAnimatorCompat.Creator DEFAULT_ANIMATOR_CREATOR
25            = new ValueAnimatorCompat.Creator() {
26        @Override
27        public ValueAnimatorCompat createAnimator() {
28            return new ValueAnimatorCompat(Build.VERSION.SDK_INT >= 12
29                    ? new ValueAnimatorCompatImplHoneycombMr1()
30                    : new ValueAnimatorCompatImplEclairMr1());
31        }
32    };
33
34    private interface ViewUtilsImpl {
35        void setBoundsViewOutlineProvider(View view);
36    }
37
38    private static class ViewUtilsImplBase implements ViewUtilsImpl {
39        @Override
40        public void setBoundsViewOutlineProvider(View view) {
41            // no-op
42        }
43    }
44
45    private static class ViewUtilsImplLollipop implements ViewUtilsImpl {
46        @Override
47        public void setBoundsViewOutlineProvider(View view) {
48            ViewUtilsLollipop.setBoundsViewOutlineProvider(view);
49        }
50    }
51
52    private static final ViewUtilsImpl IMPL;
53
54    static {
55        final int version = Build.VERSION.SDK_INT;
56        if (version >= 21) {
57            IMPL = new ViewUtilsImplLollipop();
58        } else {
59            IMPL = new ViewUtilsImplBase();
60        }
61    }
62
63    static void setBoundsViewOutlineProvider(View view) {
64        IMPL.setBoundsViewOutlineProvider(view);
65    }
66
67    static ValueAnimatorCompat createAnimator() {
68        return DEFAULT_ANIMATOR_CREATOR.createAnimator();
69    }
70
71}
72