1 /*
2  * Copyright (C) 2009 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.android.imftest.samples;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.LinearLayout;
24 import android.widget.EditText;
25 import android.widget.Button;
26 import android.view.LayoutInflater;
27 import android.app.Dialog;
28 
29 public class DialogActivity extends Activity {
30 
31     private static final int DIALOG_WITHOUT_EDITTEXT = 0;
32     private static final int DIALOG_WITH_EDITTEXT = 1;
33 
34     private LinearLayout mLayout;
35     private LayoutInflater mInflater;
36     private Button mButton1;
37     private Button mButton2;
38     private EditText mEditText;
39 
40 
41     @Override
onCreate(Bundle icicle)42     protected void onCreate(Bundle icicle)
43     {
44         super.onCreate(icicle);
45 
46         mLayout = new LinearLayout(this);
47         mLayout.setOrientation(LinearLayout.VERTICAL);
48         mLayout.setLayoutParams(new ViewGroup.LayoutParams(
49                 ViewGroup.LayoutParams.MATCH_PARENT,
50                 ViewGroup.LayoutParams.MATCH_PARENT));
51 
52         mButton1 = new Button(this);
53         mButton1.setText("Dialog WITHOUT EditText");//(R.string.open_dialog_scrollable);
54         mButton1.setOnClickListener(new View.OnClickListener()
55         {
56             public void onClick(View v)
57             {
58                 showDialog(DIALOG_WITHOUT_EDITTEXT);
59             }
60         });
61 
62         mButton2 = new Button(this);
63         mButton2.setText("Dialog WITH EditText");//(R.string.open_dialog_nonscrollable);
64         mButton2.setOnClickListener(new View.OnClickListener()
65         {
66             public void onClick(View v)
67             {
68                 showDialog(DIALOG_WITH_EDITTEXT);
69             }
70         });
71 
72         mEditText = new EditText(this);
73         mLayout.addView(mEditText);
74         mLayout.addView(mButton1);
75         mLayout.addView(mButton2);
76 
77         setContentView(mLayout);
78     }
79 
80     @Override
onCreateDialog(int id)81     protected Dialog onCreateDialog(int id)
82     {
83         switch (id)
84         {
85             case DIALOG_WITHOUT_EDITTEXT:
86                 return createDialog(false);
87             case DIALOG_WITH_EDITTEXT:
88                 return createDialog(true);
89         }
90 
91         return super.onCreateDialog(id);
92     }
93 
createDialog(boolean bEditText)94     protected Dialog createDialog(boolean bEditText)
95     {
96         LinearLayout layout;
97         layout = new LinearLayout(this);
98         layout.setOrientation(LinearLayout.VERTICAL);
99 
100         if(bEditText)
101         {
102             EditText editText;
103             editText = new EditText(this);
104             layout.addView(editText);
105         }
106 
107         Dialog d = new Dialog(this);
108         d.setTitle("The DIALOG!!!");
109         d.setCancelable(true);
110         d.setContentView(layout);
111         return d;
112     }
113 
114  }
115