1/*
2 * Copyright (C) 2014 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.graphics.Canvas;
21import android.support.annotation.RequiresApi;
22import android.support.v7.appcompat.R;
23import android.util.AttributeSet;
24import android.widget.SeekBar;
25
26/**
27 * A {@link SeekBar} which supports compatible features on older versions of the platform.
28 *
29 * <p>This will automatically be used when you use {@link SeekBar} in your layouts
30 * and the top-level activity / dialog is provided by
31 * <a href="{@docRoot}topic/libraries/support-library/packages.html#v7-appcompat">appcompat</a>.
32 * You should only need to manually use this class when writing custom views.</p>
33 */
34public class AppCompatSeekBar extends SeekBar {
35
36    private final AppCompatSeekBarHelper mAppCompatSeekBarHelper;
37
38    public AppCompatSeekBar(Context context) {
39        this(context, null);
40    }
41
42    public AppCompatSeekBar(Context context, AttributeSet attrs) {
43        this(context, attrs, R.attr.seekBarStyle);
44    }
45
46    public AppCompatSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
47        super(context, attrs, defStyleAttr);
48
49        mAppCompatSeekBarHelper = new AppCompatSeekBarHelper(this);
50        mAppCompatSeekBarHelper.loadFromAttributes(attrs, defStyleAttr);
51    }
52
53    @Override
54    protected synchronized void onDraw(Canvas canvas) {
55        super.onDraw(canvas);
56        mAppCompatSeekBarHelper.drawTickMarks(canvas);
57    }
58
59    @Override
60    protected void drawableStateChanged() {
61        super.drawableStateChanged();
62        mAppCompatSeekBarHelper.drawableStateChanged();
63    }
64
65    @RequiresApi(11)
66    @Override
67    public void jumpDrawablesToCurrentState() {
68        super.jumpDrawablesToCurrentState();
69        mAppCompatSeekBarHelper.jumpDrawablesToCurrentState();
70    }
71}
72