Android: Send locale/language change events on system locale changes
This enables applications to retranslate or otherwise update their UI when the Android system locale/language settings are changed during their runtime. Change-Id: Id482ca146080d9f3e74990f64e686f6b3504887c Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 83483b8b200ab5cedf659f418c7296719902ddc4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
a012e558d5
commit
768c49a7e9
@ -8,6 +8,7 @@ import android.app.Activity;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -29,6 +30,7 @@ public class QtActivityBase extends Activity
|
|||||||
private String m_applicationParams = "";
|
private String m_applicationParams = "";
|
||||||
private boolean m_isCustomThemeSet = false;
|
private boolean m_isCustomThemeSet = false;
|
||||||
private boolean m_retainNonConfigurationInstance = false;
|
private boolean m_retainNonConfigurationInstance = false;
|
||||||
|
private Configuration m_prevConfig;
|
||||||
|
|
||||||
private QtActivityDelegate m_delegate;
|
private QtActivityDelegate m_delegate;
|
||||||
|
|
||||||
@ -122,6 +124,8 @@ public class QtActivityBase extends Activity
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
showErrorDialog();
|
showErrorDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_prevConfig = new Configuration(getResources().getConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -183,6 +187,12 @@ public class QtActivityBase extends Activity
|
|||||||
{
|
{
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
m_delegate.handleUiModeChange(newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK);
|
m_delegate.handleUiModeChange(newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK);
|
||||||
|
|
||||||
|
int diff = newConfig.diff(m_prevConfig);
|
||||||
|
if ((diff & ActivityInfo.CONFIG_LOCALE) != 0)
|
||||||
|
QtNative.updateLocale();
|
||||||
|
|
||||||
|
m_prevConfig = new Configuration(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -435,6 +435,7 @@ public class QtNative
|
|||||||
|
|
||||||
// application methods
|
// application methods
|
||||||
static native void updateApplicationState(int state);
|
static native void updateApplicationState(int state);
|
||||||
|
static native void updateLocale();
|
||||||
|
|
||||||
// menu methods
|
// menu methods
|
||||||
static native boolean onPrepareOptionsMenu(Menu menu);
|
static native boolean onPrepareOptionsMenu(Menu menu);
|
||||||
|
@ -633,6 +633,12 @@ static void updateApplicationState(JNIEnv */*env*/, jobject /*thiz*/, jint state
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void updateLocale(JNIEnv */*env*/, jobject /*thiz*/)
|
||||||
|
{
|
||||||
|
QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::LocaleChange));
|
||||||
|
QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::LanguageChange));
|
||||||
|
}
|
||||||
|
|
||||||
static void handleOrientationChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newRotation, jint nativeOrientation)
|
static void handleOrientationChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newRotation, jint nativeOrientation)
|
||||||
{
|
{
|
||||||
// Array of orientations rotated in 90 degree increments, counterclockwise
|
// Array of orientations rotated in 90 degree increments, counterclockwise
|
||||||
@ -736,7 +742,8 @@ static JNINativeMethod methods[] = {
|
|||||||
{ "updateApplicationState", "(I)V", (void *)updateApplicationState },
|
{ "updateApplicationState", "(I)V", (void *)updateApplicationState },
|
||||||
{ "onActivityResult", "(IILandroid/content/Intent;)V", (void *)onActivityResult },
|
{ "onActivityResult", "(IILandroid/content/Intent;)V", (void *)onActivityResult },
|
||||||
{ "onNewIntent", "(Landroid/content/Intent;)V", (void *)onNewIntent },
|
{ "onNewIntent", "(Landroid/content/Intent;)V", (void *)onNewIntent },
|
||||||
{ "onBind", "(Landroid/content/Intent;)Landroid/os/IBinder;", (void *)onBind }
|
{ "onBind", "(Landroid/content/Intent;)Landroid/os/IBinder;", (void *)onBind },
|
||||||
|
{ "updateLocale", "()V", (void *)updateLocale },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FIND_AND_CHECK_CLASS(CLASS_NAME) \
|
#define FIND_AND_CHECK_CLASS(CLASS_NAME) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user