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 version of the platform. 28 * 29 * <p>This will automatically be used when you use {@link SeekBar} in your layouts. 30 * You should only need to manually use this class when writing custom views.</p> 31 */ 32public class AppCompatSeekBar extends SeekBar { 33 34 private final AppCompatSeekBarHelper mAppCompatSeekBarHelper; 35 36 public AppCompatSeekBar(Context context) { 37 this(context, null); 38 } 39 40 public AppCompatSeekBar(Context context, AttributeSet attrs) { 41 this(context, attrs, R.attr.seekBarStyle); 42 } 43 44 public AppCompatSeekBar(Context context, AttributeSet attrs, int defStyleAttr) { 45 super(context, attrs, defStyleAttr); 46 47 mAppCompatSeekBarHelper = new AppCompatSeekBarHelper(this); 48 mAppCompatSeekBarHelper.loadFromAttributes(attrs, defStyleAttr); 49 } 50 51 @Override 52 protected synchronized void onDraw(Canvas canvas) { 53 super.onDraw(canvas); 54 mAppCompatSeekBarHelper.drawTickMarks(canvas); 55 } 56 57 @Override 58 protected void drawableStateChanged() { 59 super.drawableStateChanged(); 60 mAppCompatSeekBarHelper.drawableStateChanged(); 61 } 62 63 @RequiresApi(11) 64 @Override 65 public void jumpDrawablesToCurrentState() { 66 super.jumpDrawablesToCurrentState(); 67 mAppCompatSeekBarHelper.jumpDrawablesToCurrentState(); 68 } 69} 70