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 com.example.android.apis.R;
     20 
     21 import android.app.Activity;
     22 import android.widget.Button;
     23 import android.widget.ProgressBar;
     24 import android.os.Bundle;
     25 import android.view.View;
     26 import android.view.Window;
     27 
     28 
     29 /**
     30  * Demonstrates how to use progress bars as widgets and in the title bar.  The progress bar
     31  * in the title will be shown until the progress is complete, at which point it fades away.
     32  */
     33 public class ProgressBar1 extends Activity {
     34     @Override
     35     protected void onCreate(Bundle savedInstanceState) {
     36         super.onCreate(savedInstanceState);
     37 
     38         // Request the progress bar to be shown in the title
     39         requestWindowFeature(Window.FEATURE_PROGRESS);
     40         setContentView(R.layout.progressbar_1);
     41         setProgressBarVisibility(true);
     42 
     43         final ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal);
     44         setProgress(progressHorizontal.getProgress() * 100);
     45         setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100);
     46 
     47         Button button = (Button) findViewById(R.id.increase);
     48         button.setOnClickListener(new Button.OnClickListener() {
     49             public void onClick(View v) {
     50                 progressHorizontal.incrementProgressBy(1);
     51                 // Title progress is in range 0..10000
     52                 setProgress(100 * progressHorizontal.getProgress());
     53             }
     54         });
     55 
     56         button = (Button) findViewById(R.id.decrease);
     57         button.setOnClickListener(new Button.OnClickListener() {
     58             public void onClick(View v) {
     59                 progressHorizontal.incrementProgressBy(-1);
     60                 // Title progress is in range 0..10000
     61                 setProgress(100 * progressHorizontal.getProgress());
     62             }
     63         });
     64 
     65         button = (Button) findViewById(R.id.increase_secondary);
     66         button.setOnClickListener(new Button.OnClickListener() {
     67             public void onClick(View v) {
     68                 progressHorizontal.incrementSecondaryProgressBy(1);
     69                 // Title progress is in range 0..10000
     70                 setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
     71             }
     72         });
     73 
     74         button = (Button) findViewById(R.id.decrease_secondary);
     75         button.setOnClickListener(new Button.OnClickListener() {
     76             public void onClick(View v) {
     77                 progressHorizontal.incrementSecondaryProgressBy(-1);
     78                 // Title progress is in range 0..10000
     79                 setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
     80             }
     81         });
     82 
     83     }
     84 }
     85