1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14package android.support.v17.leanback.widget;
15
16import android.graphics.Color;
17import android.graphics.drawable.ColorDrawable;
18import android.os.Build;
19import android.view.View;
20
21/**
22 * Helper for setting rounded rectangle backgrounds on a view.
23 */
24final class RoundedRectHelper {
25
26    private final static RoundedRectHelper sInstance = new RoundedRectHelper();
27    private Impl mImpl;
28
29    /**
30     * Returns an instance of the helper.
31     */
32    public static RoundedRectHelper getInstance() {
33        return sInstance;
34    }
35
36    /**
37     * Sets or removes a rounded rectangle outline on the given view.
38     */
39    public void setClipToRoundedOutline(View view, boolean clip) {
40        mImpl.setClipToRoundedOutline(view, clip);
41    }
42
43    static interface Impl {
44        public void setClipToRoundedOutline(View view, boolean clip);
45    }
46
47    /**
48     * Implementation used prior to L.
49     */
50    private static final class StubImpl implements Impl {
51        @Override
52        public void setClipToRoundedOutline(View view, boolean clip) {
53            // Not supported
54        }
55    }
56
57    /**
58     * Implementation used on api 21 (and above).
59     */
60    private static final class Api21Impl implements Impl {
61        @Override
62        public void setClipToRoundedOutline(View view, boolean clip) {
63            RoundedRectHelperApi21.setClipToRoundedOutline(view, clip);
64        }
65    }
66
67    private RoundedRectHelper() {
68        if (Build.VERSION.SDK_INT >= 21) {
69            mImpl = new Api21Impl();
70        } else {
71            mImpl = new StubImpl();
72        }
73    }
74}
75