Android examples for android.app:Instrumentation
locale From Instrumentation
import android.content.res.Configuration; import android.os.Build; import android.support.test.InstrumentationRegistry; import android.util.Log; import java.lang.reflect.Method; import java.util.Locale; public class Main{ private static Locale localeFromInstrumentation(String key) { String localeString = InstrumentationRegistry.getArguments() .getString(key);//from ww w . j a va 2 s . co m return LocaleUtil.localeFromParts(LocaleUtil .localePartsFrom(localeString)); } public static Locale localeFromParts(String[] localeParts) { if (localeParts == null || localeParts.length == 0) { return null; } else if (localeParts.length == 1) { return new Locale(localeParts[0]); } else if (localeParts.length == 2) { return new Locale(localeParts[0], localeParts[1]); } else { return new Locale(localeParts[0], localeParts[1], localeParts[2]); } } public static String[] localePartsFrom(String localeString) { if (localeString == null) { return null; } String[] localeParts = localeString.split("_"); if (localeParts.length < 1 || localeParts.length > 3) { return null; } return localeParts; } }