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.app.Dialog;
     23 import android.app.ProgressDialog;
     24 import android.os.Bundle;
     25 import android.view.View;
     26 import android.widget.Button;
     27 
     28 /**
     29  * Demonstrates the use of progress dialogs.  Uses {@link Activity#onCreateDialog}
     30  * and {@link Activity#showDialog} to ensure the dialogs will be properly saved
     31  * and restored.
     32  */
     33 public class ProgressBar3 extends Activity {
     34 
     35     ProgressDialog mDialog1;
     36     ProgressDialog mDialog2;
     37 
     38     private static final int DIALOG1_KEY = 0;
     39     private static final int DIALOG2_KEY = 1;
     40 
     41 
     42     @Override
     43     protected void onCreate(Bundle savedInstanceState) {
     44         super.onCreate(savedInstanceState);
     45 
     46         setContentView(R.layout.progressbar_3);
     47 
     48         Button button = (Button) findViewById(R.id.showIndeterminate);
     49         button.setOnClickListener(new View.OnClickListener() {
     50             public void onClick(View v) {
     51                 showDialog(DIALOG1_KEY);
     52             }
     53         });
     54 
     55         button = (Button) findViewById(R.id.showIndeterminateNoTitle);
     56         button.setOnClickListener(new View.OnClickListener() {
     57             public void onClick(View v) {
     58                 showDialog(DIALOG2_KEY);
     59             }
     60         });
     61     }
     62 
     63     @Override
     64     protected Dialog onCreateDialog(int id) {
     65         switch (id) {
     66             case DIALOG1_KEY: {
     67                 ProgressDialog dialog = new ProgressDialog(this);
     68                 dialog.setTitle("Indeterminate");
     69                 dialog.setMessage("Please wait while loading...");
     70                 dialog.setIndeterminate(true);
     71                 dialog.setCancelable(true);
     72                 return dialog;
     73             }
     74             case DIALOG2_KEY: {
     75                 ProgressDialog dialog = new ProgressDialog(this);
     76                 dialog.setMessage("Please wait while loading...");
     77                 dialog.setIndeterminate(true);
     78                 dialog.setCancelable(true);
     79                 return dialog;
     80             }
     81         }
     82         return null;
     83     }
     84 }
     85