@SuppressWarnings("deprecation") private void showActions() { String textColumn = CommandDao.Properties.Text.columnName; String orderBy = textColumn + " COLLATE LOCALIZED ASC"; String whereBy = CommandDao.Properties.Lang.columnName + "=\"" + prefs.getString(CommandActivity.PREFS_LANGUAGE, Locale.US.toString()) + "\""; cursor = db.query( commandDao.getTablename(), commandDao.getAllColumns(), whereBy, null, null, null, orderBy); String[] from = {textColumn, CommandDao.Properties.Lang.columnName}; int[] to = {android.R.id.text1, android.R.id.text2}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from, to); setListAdapter(adapter); }
/** @see DATADOC-130 */ @Test public void convertsMapTypeCorrectly() { Map<Locale, String> map = Collections.singletonMap(Locale.US, "Foo"); BasicDBObject dbObject = new BasicDBObject(); converter.write(map, dbObject); assertThat(dbObject.get(Locale.US.toString()).toString(), is("Foo")); }
private void recordVoiceCommand() { final Intent newCommandIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); newCommandIntent.putExtra( RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); newCommandIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak command phrase"); String languagePref = prefs.getString(CommandActivity.PREFS_LANGUAGE, Locale.US.toString()); newCommandIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, languagePref); newCommandIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, languagePref); newCommandIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, languagePref); startActivityForResult(newCommandIntent, VOICE_RECOGNITION_REQUEST_CODE); }
public void testMoreKeysOfEnterKey() { final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); final InputMethodSubtype subtype = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.US.toString(), SubtypeLocaleUtils.QWERTY); // Password field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // Email field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); // Url field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); // Phone number field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_PHONE, InputType.TYPE_CLASS_PHONE); // Number field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, InputType.TYPE_CLASS_NUMBER); // Date-time field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_NORMAL); // Date field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_DATE); // Time field. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME); // Text field. if (isPhone()) { // The enter key has an Emoji key as one of more keys. doTestNavigationWithEmojiMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT); } else { // Tablet has a dedicated Emoji key, so the Enter key has no Emoji more key. doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT); } // Short message field. if (isPhone()) { // Enter key is switched to Emoji key on a short message field. // Emoji key has no navigation more keys. doTestNoNavigationMoreKeysOf( Constants.CODE_EMOJI, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); } else { doTestNavigationMoreKeysOf( Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); } }
public class TypeAdapter { public enum DataType { BOOLEAN, DATE, DOUBLE, FLOAT, INTEGER, INT, LONG, SHORT, STRING } private DataType type = DataType.STRING; private String dateFormat = "MM/dd/yyyy hh:mm:ss aaa"; private String locale = Locale.US.toString(); private DateFormat format; public void setType(String type) { this.type = DataType.valueOf(type.trim().toUpperCase()); } public void setFormat(String format) { dateFormat = format; } public void setLocale(String locale) { this.locale = locale; } protected Object convertToPrimaryObject(String value) throws IllegalArgumentException { switch (type) { case BOOLEAN: return parseBoolean(value); case DATE: return parseDate(value); case DOUBLE: return parseDouble(value); case FLOAT: return parseFloat(value); case INTEGER: return parseInteger(value); case INT: return parseInteger(value); case LONG: return parseLong(value); case SHORT: return parseShort(value); case STRING: return value; } throw new IllegalStateException("Illegal primitive type '" + type + "' specified"); } private DateFormat getDateFormat() { if (format != null) { return format; } try { return format = new SimpleDateFormat(dateFormat, new Locale(locale)); } catch (Throwable e) { throw new BuildException("Incorrect time format/locale specified", e); } } private Boolean parseBoolean(String value) throws IllegalArgumentException { if (value == null || value.trim().isEmpty()) { throw new IllegalArgumentException("Can't convert null value to boolean"); } String val = value.trim().toLowerCase(); if (val.equals("false") || val.equals("no") || val.equals("0")) { return false; } if (val.equals("true") || val.equals("yes") || val.equals("1")) { return true; } throw new IllegalArgumentException("Invalid boolean value '" + value + "' specified"); } private Date parseDate(String value) throws IllegalArgumentException { if (value == null || value.trim().length() == 0) { return null; } try { return getDateFormat().parse(value); } catch (ParseException e) { } try { return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { } throw new IllegalArgumentException("Invalid date value '" + value + "' specified"); } private Double parseDouble(String value) throws IllegalArgumentException { if (value == null || value.trim().length() == 0) { return null; } try { return Double.parseDouble(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid double value '" + value + "' specified"); } } private Float parseFloat(String value) throws IllegalArgumentException { if (value == null || value.trim().length() == 0) { return null; } try { return Float.parseFloat(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid float value '" + value + "' specified"); } } private Integer parseInteger(String value) throws IllegalArgumentException { if (value == null || value.trim().length() == 0) { return null; } try { return Integer.parseInt(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid int value '" + value + "' specified"); } } private Long parseLong(String value) throws IllegalArgumentException { if (value == null || value.trim().length() == 0) { return null; } try { return Long.parseLong(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid long value '" + value + "' specified"); } } private Short parseShort(String value) throws IllegalArgumentException { if (value == null || value.trim().length() == 0) { return null; } try { return Short.parseShort(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid short value '" + value + "' specified"); } } }
public void timeToLowerCase_ICU(int reps) { for (int i = 0; i < reps; ++i) { libcore.icu.ICU.toLowerCase(s.value, Locale.US.toString()); } }