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