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 
17 package androidx.appcompat.widget;
18 
19 import android.content.Context;
20 import android.graphics.Canvas;
21 import android.util.AttributeSet;
22 import android.widget.SeekBar;
23 
24 import androidx.appcompat.R;
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  */
34 public class AppCompatSeekBar extends SeekBar {
35 
36     private final AppCompatSeekBarHelper mAppCompatSeekBarHelper;
37 
AppCompatSeekBar(Context context)38     public AppCompatSeekBar(Context context) {
39         this(context, null);
40     }
41 
AppCompatSeekBar(Context context, AttributeSet attrs)42     public AppCompatSeekBar(Context context, AttributeSet attrs) {
43         this(context, attrs, R.attr.seekBarStyle);
44     }
45 
AppCompatSeekBar(Context context, AttributeSet attrs, int defStyleAttr)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
onDraw(Canvas canvas)54     protected synchronized void onDraw(Canvas canvas) {
55         super.onDraw(canvas);
56         mAppCompatSeekBarHelper.drawTickMarks(canvas);
57     }
58 
59     @Override
drawableStateChanged()60     protected void drawableStateChanged() {
61         super.drawableStateChanged();
62         mAppCompatSeekBarHelper.drawableStateChanged();
63     }
64 
65     @Override
jumpDrawablesToCurrentState()66     public void jumpDrawablesToCurrentState() {
67         super.jumpDrawablesToCurrentState();
68         mAppCompatSeekBarHelper.jumpDrawablesToCurrentState();
69     }
70 }
71