InputTypeActivity.java revision 3dec7d563a2f3e1eb967ce2054a00b6620e3558c
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 17package com.android.imftest.samples; 18 19import com.android.imftest.R; 20 21import android.app.Activity; 22import android.widget.EditText; 23import android.widget.LinearLayout; 24import android.widget.Button; 25import android.widget.ScrollView; 26import android.widget.TextView; 27import android.os.Bundle; 28import android.view.LayoutInflater; 29import android.view.View; 30import android.view.ViewGroup; 31import android.view.ViewParent; 32import android.view.ViewRoot; 33import android.view.inputmethod.EditorInfo; 34import android.content.Context; 35 36public class InputTypeActivity extends Activity { 37 38 private LinearLayout mLayout; 39 private ScrollView mScrollView; 40 private LayoutInflater mInflater; 41 private ViewGroup mParent; 42 43 @Override 44 protected void onCreate(Bundle icicle) { 45 super.onCreate(icicle); 46 47 mScrollView = new ScrollView(this); 48 49 mLayout = new LinearLayout(this); 50 mLayout.setOrientation(LinearLayout.VERTICAL); 51 mLayout.setLayoutParams(new ViewGroup.LayoutParams( 52 ViewGroup.LayoutParams.FILL_PARENT, 53 ViewGroup.LayoutParams.FILL_PARENT)); 54 55 mInflater = getLayoutInflater(); 56 mParent = mLayout; 57 58 /* Normal Edit Text */ 59 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL, 60 R.string.normal_edit_text_label)); 61 62 /* Normal Edit Text w/Cap Chars Flag*/ 63 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL|EditorInfo.TYPE_TEXT_FLAG_CAP_CHARACTERS, 64 R.string.cap_chars_edit_text_label)); 65 66 /* Normal Edit Text w/Cap Words Flag*/ 67 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL|EditorInfo.TYPE_TEXT_FLAG_CAP_WORDS, 68 R.string.cap_words_edit_text_label)); 69 70 /* Normal Edit Text w/Cap Multiline Flag */ 71 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL|EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE, 72 R.string.multiline_edit_text_label)); 73 74 /* Normal Edit Text w/Cap Sentences Flag */ 75 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL|EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES, 76 R.string.cap_sentences_edit_text_label)); 77 78 /* Normal Edit Text w/Auto-complete Flag */ 79 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL|EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE, 80 R.string.auto_complete_edit_text_label)); 81 82 /* Normal Edit Text w/Auto-correct Flag */ 83 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL|EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT, 84 R.string.auto_correct_edit_text_label)); 85 86 /* Uri Edit Text */ 87 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_URI, 88 R.string.uri_edit_text_label)); 89 90 /* Email Address Edit Text */ 91 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS, 92 R.string.email_address_edit_text_label)); 93 94 /* Email Subject Text */ 95 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_EMAIL_SUBJECT, 96 R.string.email_subject_edit_text_label)); 97 98 /* Email Content Edit Text */ 99 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_LONG_MESSAGE, 100 R.string.email_content_edit_text_label)); 101 102 /* Person Name Edit Text */ 103 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_PERSON_NAME, 104 R.string.person_name_edit_text_label)); 105 106 /* Postal Address Edit Text */ 107 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_POSTAL_ADDRESS, 108 R.string.postal_address_edit_text_label)); 109 110 /* Password Edit Text */ 111 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_PASSWORD, 112 R.string.password_edit_text_label)); 113 114 /* Web Edit Text */ 115 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT, 116 R.string.web_edit_text_label)); 117 118 /* Signed Number Edit Text */ 119 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_NUMBER|EditorInfo.TYPE_NUMBER_FLAG_SIGNED, 120 R.string.signed_number_edit_text_label)); 121 122 /* Decimal Number Edit Text */ 123 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_NUMBER|EditorInfo.TYPE_NUMBER_FLAG_DECIMAL, 124 R.string.decimal_number_edit_text_label)); 125 126 /* Phone Number Edit Text */ 127 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_PHONE, 128 R.string.phone_number_edit_text_label)); 129 130 /* Normal Datetime Edit Text */ 131 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_DATETIME|EditorInfo.TYPE_DATETIME_VARIATION_NORMAL, 132 R.string.normal_datetime_edit_text_label)); 133 134 /* Date Edit Text */ 135 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_DATETIME|EditorInfo.TYPE_DATETIME_VARIATION_DATE, 136 R.string.date_edit_text_label)); 137 138 /* Time Edit Text */ 139 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_DATETIME|EditorInfo.TYPE_DATETIME_VARIATION_TIME, 140 R.string.time_edit_text_label)); 141 142 mScrollView.addView(mLayout); 143 setContentView(mScrollView); 144 } 145 146 private View buildEntryView(int inputType, int label) { 147 148 149 View view = mInflater.inflate(R.layout.sample_edit_text, mParent, false); 150 151 EditText editText = (EditText) view.findViewById(R.id.data); 152 editText.setInputType(inputType); 153 154 TextView textView = (TextView) view.findViewById(R.id.label); 155 textView.setText(label); 156 157 return view; 158 } 159 160} 161