1 /* 2 * Copyright (C) 2006 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 android.text.method; 18 19 import android.view.KeyEvent; 20 import android.text.InputType; 21 22 /** 23 * For entering dates in a text field. 24 * <p></p> 25 * As for all implementations of {@link KeyListener}, this class is only concerned 26 * with hardware keyboards. Software input methods have no obligation to trigger 27 * the methods in this class. 28 */ 29 public class DateKeyListener extends NumberKeyListener 30 { getInputType()31 public int getInputType() { 32 return InputType.TYPE_CLASS_DATETIME 33 | InputType.TYPE_DATETIME_VARIATION_DATE; 34 } 35 36 @Override getAcceptedChars()37 protected char[] getAcceptedChars() 38 { 39 return CHARACTERS; 40 } 41 getInstance()42 public static DateKeyListener getInstance() { 43 if (sInstance != null) 44 return sInstance; 45 46 sInstance = new DateKeyListener(); 47 return sInstance; 48 } 49 50 /** 51 * The characters that are used. 52 * 53 * @see KeyEvent#getMatch 54 * @see #getAcceptedChars 55 */ 56 public static final char[] CHARACTERS = new char[] { 57 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 58 '/', '-', '.' 59 }; 60 61 private static DateKeyListener sInstance; 62 } 63