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