Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2007 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 com.example.android.apis.view;
     18 
     19 import android.app.Activity;
     20 import android.os.Bundle;
     21 import android.widget.CheckBox;
     22 import android.widget.CompoundButton;
     23 import android.widget.CompoundButton.OnCheckedChangeListener;
     24 import android.widget.SeekBar;
     25 import android.widget.TextView;
     26 
     27 import com.example.android.apis.R;
     28 
     29 
     30 /**
     31  * Demonstrates how to use a seek bar
     32  */
     33 public class SeekBar1 extends Activity implements SeekBar.OnSeekBarChangeListener {
     34 
     35     SeekBar mSeekBar;
     36     TextView mProgressText;
     37     TextView mTrackingText;
     38 
     39     @Override
     40     protected void onCreate(Bundle savedInstanceState) {
     41         super.onCreate(savedInstanceState);
     42 
     43         setContentView(R.layout.seekbar_1);
     44 
     45         mSeekBar = (SeekBar) findViewById(R.id.seek);
     46         mSeekBar.setOnSeekBarChangeListener(this);
     47         mProgressText = (TextView) findViewById(R.id.progress);
     48         mTrackingText = (TextView) findViewById(R.id.tracking);
     49 
     50         ((CheckBox) findViewById(R.id.enabled)).setOnCheckedChangeListener(
     51                 new OnCheckedChangeListener() {
     52                     @Override
     53                     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
     54                         findViewById(R.id.seekMin).setEnabled(isChecked);
     55                         findViewById(R.id.seekMax).setEnabled(isChecked);
     56                         mSeekBar.setEnabled(isChecked);
     57                     }
     58                 });
     59     }
     60 
     61     public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
     62         mProgressText.setText(progress + " " +
     63                 getString(R.string.seekbar_from_touch) + "=" + fromTouch);
     64     }
     65 
     66     public void onStartTrackingTouch(SeekBar seekBar) {
     67         mTrackingText.setText(getString(R.string.seekbar_tracking_on));
     68     }
     69 
     70     public void onStopTrackingTouch(SeekBar seekBar) {
     71         mTrackingText.setText(getString(R.string.seekbar_tracking_off));
     72     }
     73 }
     74