diff --git a/src/corelib/time/qtimezoneprivate_android.cpp b/src/corelib/time/qtimezoneprivate_android.cpp index 43a4593104d..c4ca0e42146 100644 --- a/src/corelib/time/qtimezoneprivate_android.cpp +++ b/src/corelib/time/qtimezoneprivate_android.cpp @@ -10,6 +10,11 @@ QT_BEGIN_NAMESPACE +Q_DECLARE_JNI_CLASS(TimeZone, "java/util/TimeZone"); +Q_DECLARE_JNI_CLASS(Locale, "java/util/Locale"); +Q_DECLARE_JNI_CLASS(Date, "java/util/Date"); +Q_DECLARE_JNI_TYPE(StringArray, "[Ljava/lang/String;") + /* Private @@ -25,9 +30,9 @@ QAndroidTimeZonePrivate::QAndroidTimeZonePrivate() : QTimeZonePrivate() { // Keep in sync with systemTimeZoneId(): - androidTimeZone = QJniObject::callStaticObjectMethod( - "java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;"); - const QJniObject id = androidTimeZone.callObjectMethod("getID", "()Ljava/lang/String;"); + androidTimeZone = QJniObject::callStaticMethod( + QtJniTypes::className(), "getDefault"); + const QJniObject id = androidTimeZone.callMethod("getID"); m_id = id.toString().toUtf8(); } @@ -53,20 +58,19 @@ static QString getDisplayName(QJniObject zone, jint style, jboolean dst, const QLocale &locale) { QJniObject jbcpTag = QJniObject::fromString(locale.bcp47Name()); - QJniObject jlocale = QJniObject::callStaticObjectMethod( - "java/util/Locale", "forLanguageTag", "(Ljava/lang/String;)Ljava/util/Locale;", + QJniObject jlocale = QJniObject::callStaticMethod( + QtJniTypes::className(), "forLanguageTag", jbcpTag.object()); - return zone.callObjectMethod("getDisplayName", - "(ZILjava/util/Locale;)Ljava/lang/String;", - dst, style, jlocale.object()).toString(); + return zone.callMethod("getDisplayName", dst, style, + jlocale.object()).toString(); } void QAndroidTimeZonePrivate::init(const QByteArray &ianaId) { const QString iana = QString::fromUtf8(ianaId); - androidTimeZone = QJniObject::callStaticObjectMethod( - "java.util.TimeZone", "getTimeZone", "(Ljava/lang/String;)Ljava/util/TimeZone;", + androidTimeZone = QJniObject::callStaticMethod( + QtJniTypes::className(), "getTimeZone", QJniObject::fromString(iana).object()); // The ID or display name of the zone we've got, if it looks like what we asked for: @@ -81,7 +85,7 @@ void QAndroidTimeZonePrivate::init(const QByteArray &ianaId) // recognize the name; so check for whether ianaId is a recognized name of // the zone object we got and ignore the zone if not. // Try checking ianaId against getID(), getDisplayName(): - m_id = match(androidTimeZone.callObjectMethod("getID", "()Ljava/lang/String;").toString()); + m_id = match(androidTimeZone.callMethod("getID").toString()); for (int style = 1; m_id.isEmpty() && style >= 0; --style) { for (int dst = 1; m_id.isEmpty() && dst >= 0; --dst) { for (int pick = 2; m_id.isEmpty() && pick >= 0; --pick) { @@ -128,11 +132,13 @@ int QAndroidTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const { // offsetFromUtc( ) is invoked when androidTimeZone may not yet be set at startup, // so a validity test is needed here - if ( androidTimeZone.isValid() ) + if ( androidTimeZone.isValid() ) { // the java method getOffset() returns milliseconds, but QTimeZone returns seconds - return androidTimeZone.callMethod( "getOffset", "(J)I", static_cast(atMSecsSinceEpoch) ) / 1000; - else + return androidTimeZone.callMethod( + "getOffset", static_cast(atMSecsSinceEpoch) ) / 1000; + } else { return 0; + } } int QAndroidTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const @@ -163,8 +169,10 @@ bool QAndroidTimeZonePrivate::hasDaylightTime() const bool QAndroidTimeZonePrivate::isDaylightTime(qint64 atMSecsSinceEpoch) const { if ( androidTimeZone.isValid() ) { - QJniObject jDate( "java/util/Date", "(J)V", static_cast(atMSecsSinceEpoch) ); - return androidTimeZone.callMethod("inDaylightTime", "(Ljava/util/Date;)Z", jDate.object() ); + QJniObject jDate = QJniObject::construct( + static_cast(atMSecsSinceEpoch)); + return androidTimeZone.callMethod("inDaylightTime", + jDate.object()); } else return false; @@ -191,16 +199,17 @@ QTimeZonePrivate::Data QAndroidTimeZonePrivate::data(qint64 forMSecsSinceEpoch) QByteArray QAndroidTimeZonePrivate::systemTimeZoneId() const { // Keep in sync with default constructor: - QJniObject androidSystemTimeZone = QJniObject::callStaticObjectMethod( - "java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;"); - const QJniObject id = androidSystemTimeZone.callObjectMethod("getID"); + QJniObject androidSystemTimeZone = QJniObject::callStaticMethod( + QtJniTypes::className(), "getDefault"); + const QJniObject id = androidSystemTimeZone.callMethod("getID"); return id.toString().toUtf8(); } QList QAndroidTimeZonePrivate::availableTimeZoneIds() const { QList availableTimeZoneIdList; - QJniObject androidAvailableIdList = QJniObject::callStaticObjectMethod("java.util.TimeZone", "getAvailableIDs", "()[Ljava/lang/String;"); + QJniObject androidAvailableIdList = QJniObject::callStaticMethod( + QtJniTypes::className(), "getAvailableIDs"); QJniEnvironment jniEnv; int androidTZcount = jniEnv->GetArrayLength(androidAvailableIdList.object());