Esempio n. 1
0
static jint NativePluralRules_forLocaleImpl(JNIEnv* env, jclass, jstring localeName) {
    Locale locale = Locale::createFromName(ScopedUtfChars(env, localeName).c_str());
    UErrorCode status = U_ZERO_ERROR;
    PluralRules* result = PluralRules::forLocale(locale, status);
    icu4jni_error(env, status);
    return reinterpret_cast<uintptr_t>(result);
}
status_t android_hardware_display_DisplayViewport_toNative(JNIEnv* env, jobject viewportObj,
        DisplayViewport* viewport) {
    viewport->displayId = env->GetIntField(viewportObj, gDisplayViewportClassInfo.displayId);
    viewport->orientation = env->GetIntField(viewportObj, gDisplayViewportClassInfo.orientation);
    viewport->deviceWidth = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceWidth);
    viewport->deviceHeight = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceHeight);

    jstring uniqueId =
            jstring(env->GetObjectField(viewportObj, gDisplayViewportClassInfo.uniqueId));
    if (uniqueId != nullptr) {
        viewport->uniqueId.setTo(ScopedUtfChars(env, uniqueId).c_str());
    }

    jobject logicalFrameObj =
            env->GetObjectField(viewportObj, gDisplayViewportClassInfo.logicalFrame);
    viewport->logicalLeft = env->GetIntField(logicalFrameObj, gRectClassInfo.left);
    viewport->logicalTop = env->GetIntField(logicalFrameObj, gRectClassInfo.top);
    viewport->logicalRight = env->GetIntField(logicalFrameObj, gRectClassInfo.right);
    viewport->logicalBottom = env->GetIntField(logicalFrameObj, gRectClassInfo.bottom);

    jobject physicalFrameObj =
            env->GetObjectField(viewportObj, gDisplayViewportClassInfo.physicalFrame);
    viewport->physicalLeft = env->GetIntField(physicalFrameObj, gRectClassInfo.left);
    viewport->physicalTop = env->GetIntField(physicalFrameObj, gRectClassInfo.top);
    viewport->physicalRight = env->GetIntField(physicalFrameObj, gRectClassInfo.right);
    viewport->physicalBottom = env->GetIntField(physicalFrameObj, gRectClassInfo.bottom);

    return OK;
}
Esempio n. 3
0
static jstring ICU_toUpperCase(JNIEnv* env, jclass, jstring javaString, jstring localeName) {
    ScopedJavaUnicodeString scopedString(env, javaString);
    UnicodeString& s(scopedString.unicodeString());
    UnicodeString original(s);
    s.toUpper(Locale::createFromName(ScopedUtfChars(env, localeName).c_str()));
    return s == original ? javaString : env->NewString(s.getBuffer(), s.length());
}
Esempio n. 4
0
extern "C" jstring Java_libcore_icu_ICU_toUpperCase(JNIEnv* env, jclass, jstring javaString, jstring localeName) {
  ScopedJavaUnicodeString scopedString(env, javaString);
  if (!scopedString.valid()) {
    return NULL;
  }
  UnicodeString& s(scopedString.unicodeString());
  UnicodeString original(s);
  s.toUpper(Locale::createFromName(ScopedUtfChars(env, localeName).c_str()));
  return s == original ? javaString : env->NewString(s.getBuffer(), s.length());
}
static jlong NativePluralRules_forLocaleImpl(JNIEnv* env, jclass, jstring javaLocaleName) {
    // The icu4c PluralRules returns a "other: n" default rule for the deprecated locales Java uses.
    // Work around this by translating back to the current language codes.
    std::string localeName(ScopedUtfChars(env, javaLocaleName).c_str());
    if (localeName[0] == 'i' && localeName[1] == 'w') {
        localeName[0] = 'h';
        localeName[1] = 'e';
    } else if (localeName[0] == 'i' && localeName[1] == 'n') {
        localeName[0] = 'i';
        localeName[1] = 'd';
    } else if (localeName[0] == 'j' && localeName[1] == 'i') {
        localeName[0] = 'y';
        localeName[1] = 'i';
    }

    icu::Locale locale = icu::Locale::createFromName(localeName.c_str());
    UErrorCode status = U_ZERO_ERROR;
    icu::PluralRules* result = icu::PluralRules::forLocale(locale, status);
    maybeThrowIcuException(env, "PluralRules::forLocale", status);
    return reinterpret_cast<uintptr_t>(result);
}
Esempio n. 6
0
Locale getLocale(JNIEnv* env, jstring localeName) {
    return Locale::createFromName(ScopedUtfChars(env, localeName).c_str());
}