InputTypeActivity.java revision 076357b8567458d4b6dfdcf839ef751634cd2bfb
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 /* Normal Edit Text w/Search Flag*/ 87 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL|EditorInfo.TYPE_TEXT_FLAG_SEARCH, 88 R.string.search_edit_text_label)); 89 90 /* Uri Edit Text */ 91 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_URI, 92 R.string.uri_edit_text_label)); 93 94 /* Email Address Edit Text */ 95 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS, 96 R.string.email_address_edit_text_label)); 97 98 /* Email Subject Text */ 99 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_EMAIL_SUBJECT, 100 R.string.email_subject_edit_text_label)); 101 102 /* Email Content Edit Text */ 103 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_LONG_MESSAGE, 104 R.string.email_content_edit_text_label)); 105 106 /* Person Name Edit Text */ 107 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_PERSON_NAME, 108 R.string.person_name_edit_text_label)); 109 110 /* Postal Address Edit Text */ 111 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_POSTAL_ADDRESS, 112 R.string.postal_address_edit_text_label)); 113 114 /* Password Edit Text */ 115 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_PASSWORD, 116 R.string.password_edit_text_label)); 117 118 /* Web Edit Text */ 119 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT, 120 R.string.web_edit_text_label)); 121 122 /* Signed Number Edit Text */ 123 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_NUMBER|EditorInfo.TYPE_NUMBER_FLAG_SIGNED, 124 R.string.signed_number_edit_text_label)); 125 126 /* Decimal Number Edit Text */ 127 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_NUMBER|EditorInfo.TYPE_NUMBER_FLAG_DECIMAL, 128 R.string.decimal_number_edit_text_label)); 129 130 /* Phone Number Edit Text */ 131 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_PHONE, 132 R.string.phone_number_edit_text_label)); 133 134 /* Normal Datetime Edit Text */ 135 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_DATETIME|EditorInfo.TYPE_DATETIME_VARIATION_NORMAL, 136 R.string.normal_datetime_edit_text_label)); 137 138 /* Date Edit Text */ 139 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_DATETIME|EditorInfo.TYPE_DATETIME_VARIATION_DATE, 140 R.string.date_edit_text_label)); 141 142 /* Time Edit Text */ 143 mLayout.addView(buildEntryView(EditorInfo.TYPE_CLASS_DATETIME|EditorInfo.TYPE_DATETIME_VARIATION_TIME, 144 R.string.time_edit_text_label)); 145 146 mScrollView.addView(mLayout); 147 setContentView(mScrollView); 148 } 149 150 private View buildEntryView(int inputType, int label) { 151 152 153 View view = mInflater.inflate(R.layout.sample_edit_text, mParent, false); 154 155 EditText editText = (EditText) view.findViewById(R.id.data); 156 editText.setInputType(inputType); 157 158 TextView textView = (TextView) view.findViewById(R.id.label); 159 textView.setText(label); 160 161 return view; 162 } 163 164} 165