Java tutorial
//package com.java2s; /* * Copyright 2011 Robert Theis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.content.SharedPreferences; public class Main { public static final String KEY_CHARACTER_WHITELIST_ARABIC = "preference_character_whitelist_arabic"; public static final String KEY_CHARACTER_WHITELIST_BULGARIAN = "preference_character_whitelist_bulgarian"; public static final String KEY_CHARACTER_WHITELIST_CATALAN = "preference_character_whitelist_catalan"; public static final String KEY_CHARACTER_WHITELIST_CHINESE_SIMPLIFIED = "preference_character_whitelist_chinese_simplified"; public static final String KEY_CHARACTER_WHITELIST_CHINESE_TRADITIONAL = "preference_character_whitelist_chinese_traditional"; public static final String KEY_CHARACTER_WHITELIST_CZECH = "preference_character_whitelist_czech"; public static final String KEY_CHARACTER_WHITELIST_DANISH = "preference_character_whitelist_danish"; public static final String KEY_CHARACTER_WHITELIST_DUTCH = "preference_character_whitelist_dutch"; public static final String KEY_CHARACTER_WHITELIST_ENGLISH = "preference_character_whitelist_english"; public static final String KEY_CHARACTER_WHITELIST_FINNISH = "preference_character_whitelist_finnish"; public static final String KEY_CHARACTER_WHITELIST_FRENCH = "preference_character_whitelist_french"; public static final String KEY_CHARACTER_WHITELIST_GERMAN = "preference_character_whitelist_german"; public static final String KEY_CHARACTER_WHITELIST_GREEK = "preference_character_whitelist_greek"; public static final String KEY_CHARACTER_WHITELIST_HEBREW = "preference_character_whitelist_hebrew"; public static final String KEY_CHARACTER_WHITELIST_HINDI = "preference_character_whitelist_hindi"; public static final String KEY_CHARACTER_WHITELIST_HUNGARIAN = "preference_character_whitelist_hungarian"; public static final String KEY_CHARACTER_WHITELIST_INDONESIAN = "preference_character_whitelist_indonesian"; public static final String KEY_CHARACTER_WHITELIST_ITALIAN = "preference_character_whitelist_italian"; public static final String KEY_CHARACTER_WHITELIST_JAPANESE = "preference_character_whitelist_japanese"; public static final String KEY_CHARACTER_WHITELIST_KOREAN = "preference_character_whitelist_korean"; public static final String KEY_CHARACTER_WHITELIST_LATVIAN = "preference_character_whitelist_latvian"; public static final String KEY_CHARACTER_WHITELIST_LITHUANIAN = "preference_character_whitelist_lithuanian"; public static final String KEY_CHARACTER_WHITELIST_NORWEGIAN = "preference_character_whitelist_norwegian"; public static final String KEY_CHARACTER_WHITELIST_POLISH = "preference_character_whitelist_polish"; public static final String KEY_CHARACTER_WHITELIST_PORTUGUESE = "preference_character_whitelist_portuguese"; public static final String KEY_CHARACTER_WHITELIST_ROMANIAN = "preference_character_whitelist_romanian"; public static final String KEY_CHARACTER_WHITELIST_RUSSIAN = "preference_character_whitelist_russian"; public static final String KEY_CHARACTER_WHITELIST_SERBIAN = "preference_character_whitelist_serbian"; public static final String KEY_CHARACTER_WHITELIST_SLOVAK = "preference_character_whitelist_slovak"; public static final String KEY_CHARACTER_WHITELIST_SLOVENIAN = "preference_character_whitelist_slovenian"; public static final String KEY_CHARACTER_WHITELIST_SPANISH = "preference_character_whitelist_spanish"; public static final String KEY_CHARACTER_WHITELIST_SWEDISH = "preference_character_whitelist_swedish"; public static final String KEY_CHARACTER_WHITELIST_TAGALOG = "preference_character_whitelist_tagalog"; public static final String KEY_CHARACTER_WHITELIST_THAI = "preference_character_whitelist_thai"; public static final String KEY_CHARACTER_WHITELIST_TURKISH = "preference_character_whitelist_turkish"; public static final String KEY_CHARACTER_WHITELIST_UKRAINIAN = "preference_character_whitelist_ukrainian"; public static final String KEY_CHARACTER_WHITELIST_VIETNAMESE = "preference_character_whitelist_vietnamese"; public static String getWhitelist(SharedPreferences prefs, String languageCode) { if (languageCode.equals("ara")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ARABIC, getDefaultWhitelist(languageCode)); } // Arabic else if (languageCode.equals("bul")) { return prefs.getString(KEY_CHARACTER_WHITELIST_BULGARIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("cat")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CATALAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("chi_sim")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CHINESE_SIMPLIFIED, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("chi_tra")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CHINESE_TRADITIONAL, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ces")) { return prefs.getString(KEY_CHARACTER_WHITELIST_CZECH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("dan")) { return prefs.getString(KEY_CHARACTER_WHITELIST_DANISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("nld")) { return prefs.getString(KEY_CHARACTER_WHITELIST_DUTCH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("eng")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ENGLISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("fin")) { return prefs.getString(KEY_CHARACTER_WHITELIST_FINNISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("fra")) { return prefs.getString(KEY_CHARACTER_WHITELIST_FRENCH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("deu")) { return prefs.getString(KEY_CHARACTER_WHITELIST_GERMAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ell")) { return prefs.getString(KEY_CHARACTER_WHITELIST_GREEK, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("heb")) { return prefs.getString(KEY_CHARACTER_WHITELIST_HEBREW, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("hin")) { return prefs.getString(KEY_CHARACTER_WHITELIST_HINDI, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("hun")) { return prefs.getString(KEY_CHARACTER_WHITELIST_HUNGARIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ind")) { return prefs.getString(KEY_CHARACTER_WHITELIST_INDONESIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ita")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ITALIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("jpn")) { return prefs.getString(KEY_CHARACTER_WHITELIST_JAPANESE, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("kor")) { return prefs.getString(KEY_CHARACTER_WHITELIST_KOREAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("lav")) { return prefs.getString(KEY_CHARACTER_WHITELIST_LATVIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("lit")) { return prefs.getString(KEY_CHARACTER_WHITELIST_LITHUANIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("nor")) { return prefs.getString(KEY_CHARACTER_WHITELIST_NORWEGIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("pol")) { return prefs.getString(KEY_CHARACTER_WHITELIST_POLISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("por")) { return prefs.getString(KEY_CHARACTER_WHITELIST_PORTUGUESE, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ron")) { return prefs.getString(KEY_CHARACTER_WHITELIST_ROMANIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("rus")) { return prefs.getString(KEY_CHARACTER_WHITELIST_RUSSIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("srp")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SERBIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("slk")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SLOVAK, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("slv")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SLOVENIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("spa")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SPANISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("swe")) { return prefs.getString(KEY_CHARACTER_WHITELIST_SWEDISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("tgl")) { return prefs.getString(KEY_CHARACTER_WHITELIST_TAGALOG, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("tha")) { return prefs.getString(KEY_CHARACTER_WHITELIST_THAI, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("tur")) { return prefs.getString(KEY_CHARACTER_WHITELIST_TURKISH, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("ukr")) { return prefs.getString(KEY_CHARACTER_WHITELIST_UKRAINIAN, getDefaultWhitelist(languageCode)); } else if (languageCode.equals("vie")) { return prefs.getString(KEY_CHARACTER_WHITELIST_VIETNAMESE, getDefaultWhitelist(languageCode)); } else { throw new IllegalArgumentException(); } } public static String getDefaultWhitelist(String languageCode) { if (languageCode.equals("ara")) { return ""; } // Arabic else if (languageCode.equals("bul")) { return ""; } // Bulgarian else if (languageCode.equals("cat")) { return ""; } // Catalan else if (languageCode.equals("chi_sim")) { return ""; } // Chinese (Simplified) else if (languageCode.equals("chi_tra")) { return ""; } // Chinese (Traditional) else if (languageCode.equals("ces")) { return ""; } // Czech else if (languageCode.equals("dan")) { return ""; } // Danish else if (languageCode.equals("nld")) { return ""; } // Dutch else if (languageCode.equals("eng")) { return "!?@#$%()<>_-+=/.,:;'\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; } // English else if (languageCode.equals("fin")) { return ""; } // Finnish else if (languageCode.equals("fra")) { return ""; } // French else if (languageCode.equals("deu")) { return ""; } // German else if (languageCode.equals("ell")) { return ""; } // Greek else if (languageCode.equals("heb")) { return ""; } // Hebrew else if (languageCode.equals("hin")) { return ""; } // Hindi else if (languageCode.equals("hun")) { return ""; } // Hungarian else if (languageCode.equals("ind")) { return ""; } // Indonesian else if (languageCode.equals("ita")) { return ""; } // Italian else if (languageCode.equals("jpn")) { return ""; } // Japanese else if (languageCode.equals("kor")) { return ""; } // Korean else if (languageCode.equals("lav")) { return ""; } // Latvian else if (languageCode.equals("lit")) { return ""; } // Lithuanian else if (languageCode.equals("nor")) { return ""; } // Norwegian else if (languageCode.equals("pol")) { return ""; } // Polish else if (languageCode.equals("por")) { return ""; } // Portuguese else if (languageCode.equals("ron")) { return ""; } // Romanian else if (languageCode.equals("rus")) { return ""; } // Russian else if (languageCode.equals("srp")) { return ""; } // Serbian (Latin) else if (languageCode.equals("slk")) { return ""; } // Slovak else if (languageCode.equals("slv")) { return ""; } // Slovenian else if (languageCode.equals("spa")) { return ""; } // Spanish else if (languageCode.equals("swe")) { return ""; } // Swedish else if (languageCode.equals("tgl")) { return ""; } // Tagalog else if (languageCode.equals("tha")) { return ""; } // Thai else if (languageCode.equals("tur")) { return ""; } // Turkish else if (languageCode.equals("ukr")) { return ""; } // Ukrainian else if (languageCode.equals("vie")) { return ""; } // Vietnamese else { throw new IllegalArgumentException(); } } }