diff --git a/MultiLanguages.apk b/MultiLanguages.apk
index efebef3..0d9bc9f 100644
Binary files a/MultiLanguages.apk and b/MultiLanguages.apk differ
diff --git a/README.md b/README.md
index f916208..d8774ac 100644
--- a/README.md
+++ b/README.md
@@ -10,11 +10,12 @@
```groovy
buildscript {
- ......
+ repositories {
+ maven { url 'https://jitpack.io' }
+ }
}
allprojects {
repositories {
- // JitPack 远程仓库:https://jitpack.io
maven { url 'https://jitpack.io' }
}
}
@@ -25,7 +26,7 @@ allprojects {
```groovy
dependencies {
// 语种切换框架:https://github.com/getActivity/MultiLanguages
- implementation 'com.github.getActivity:MultiLanguages:6.6'
+ implementation 'com.github.getActivity:MultiLanguages:6.8'
}
```
diff --git a/app/build.gradle b/app/build.gradle
index 0a5c9d7..900235c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -7,8 +7,8 @@ android {
applicationId "com.hjq.language.demo"
minSdkVersion 16
targetSdkVersion 30
- versionCode 66
- versionName "6.6"
+ versionCode 68
+ versionName "6.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
@@ -30,11 +30,16 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':library')
- implementation 'androidx.appcompat:appcompat:1.2.0'
- implementation 'com.google.android.material:material:1.2.1'
+ // AppCompat 库:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn
+ implementation 'androidx.appcompat:appcompat:1.3.0'
+ // Material 库:https://github.com/material-components/material-components-android
+ implementation 'com.google.android.material:material:1.3.0'
// 标题栏框架:https://github.com/getActivity/TitleBar
- implementation 'com.github.getActivity:TitleBar:8.5'
+ implementation 'com.github.getActivity:TitleBar:8.6'
+
+ // 吐司框架:https://github.com/getActivity/ToastUtils
+ implementation 'com.github.getActivity:ToastUtils:9.5'
// 内存泄漏检测:https://github.com/square/leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7969e75..a0927c2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,8 +11,8 @@
android:name=".AppApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
android:networkSecurityConfig="@xml/network_security_config"
+ android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme"
tools:targetApi="q">
diff --git a/app/src/main/java/com/hjq/language/demo/AppApplication.java b/app/src/main/java/com/hjq/language/demo/AppApplication.java
index e8fcc04..ccae0be 100644
--- a/app/src/main/java/com/hjq/language/demo/AppApplication.java
+++ b/app/src/main/java/com/hjq/language/demo/AppApplication.java
@@ -6,6 +6,7 @@
import com.hjq.language.MultiLanguages;
import com.hjq.language.OnLanguageListener;
+import com.hjq.toast.ToastUtils;
import java.util.Locale;
@@ -21,6 +22,9 @@ public final class AppApplication extends Application {
public void onCreate() {
super.onCreate();
+ // 初始化 Toast 框架
+ ToastUtils.init(this);
+
// 初始化多语种框架
MultiLanguages.init(this);
// 设置语种变化监听器
diff --git a/app/src/main/java/com/hjq/language/demo/MainActivity.java b/app/src/main/java/com/hjq/language/demo/MainActivity.java
index 8936930..032e801 100644
--- a/app/src/main/java/com/hjq/language/demo/MainActivity.java
+++ b/app/src/main/java/com/hjq/language/demo/MainActivity.java
@@ -2,13 +2,17 @@
import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RadioGroup;
import android.widget.TextView;
+import com.hjq.bar.OnTitleBarListener;
+import com.hjq.bar.TitleBar;
import com.hjq.language.MultiLanguages;
+import com.hjq.toast.ToastUtils;
import java.util.Locale;
@@ -19,39 +23,43 @@
* desc : 多语种切换演示
*/
public final class MainActivity extends BaseActivity
- implements RadioGroup.OnCheckedChangeListener {
+ implements RadioGroup.OnCheckedChangeListener, OnTitleBarListener {
+ private TitleBar mTitleBar;
private WebView mWebView;
private RadioGroup mRadioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_language);
+ setContentView(R.layout.activity_main);
- mWebView = findViewById(R.id.wv_language_web);
- mRadioGroup = findViewById(R.id.rg_language_languages);
+ mTitleBar = findViewById(R.id.tb_main_bar);
+ mWebView = findViewById(R.id.wv_main_web);
+ mRadioGroup = findViewById(R.id.rg_main_languages);
+
+ mTitleBar.setOnTitleBarListener(this);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.loadUrl("https://developer.android.google.cn/index.html");
//((TextView) findViewById(R.id.tv_language_activity)).setText(this.getResources().getString(R.string.current_language));
- ((TextView) findViewById(R.id.tv_language_application)).setText(getApplication().getResources().getString(R.string.current_language));
- ((TextView) findViewById(R.id.tv_language_system)).setText(MultiLanguages.getLanguageString(this, MultiLanguages.getSystemLanguage(), R.string.current_language));
+ ((TextView) findViewById(R.id.tv_main_language_application)).setText(getApplication().getResources().getString(R.string.current_language));
+ ((TextView) findViewById(R.id.tv_main_language_system)).setText(MultiLanguages.getLanguageString(this, MultiLanguages.getSystemLanguage(), R.string.current_language));
if (MultiLanguages.isSystemLanguage()) {
- mRadioGroup.check(R.id.rb_language_auto);
+ mRadioGroup.check(R.id.rb_main_language_auto);
} else {
Locale locale = MultiLanguages.getAppLanguage();
if (Locale.CHINA.equals(locale)) {
- mRadioGroup.check(R.id.rb_language_cn);
+ mRadioGroup.check(R.id.rb_main_language_cn);
} else if (Locale.TAIWAN.equals(locale)) {
- mRadioGroup.check(R.id.rb_language_tw);
+ mRadioGroup.check(R.id.rb_main_language_tw);
} else if (Locale.ENGLISH.equals(locale)) {
- mRadioGroup.check(R.id.rb_language_en);
+ mRadioGroup.check(R.id.rb_main_language_en);
} else {
- mRadioGroup.check(R.id.rb_language_auto);
+ mRadioGroup.check(R.id.rb_main_language_auto);
}
}
@@ -66,16 +74,16 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
// 是否需要重启
boolean restart = false;
- if (checkedId == R.id.rb_language_auto) {
+ if (checkedId == R.id.rb_main_language_auto) {
// 跟随系统
restart = MultiLanguages.setSystemLanguage(this);
- } else if (checkedId == R.id.rb_language_cn) {
+ } else if (checkedId == R.id.rb_main_language_cn) {
// 简体中文
restart = MultiLanguages.setAppLanguage(this, Locale.CHINA);
- } else if (checkedId == R.id.rb_language_tw) {
+ } else if (checkedId == R.id.rb_main_language_tw) {
// 繁体中文
restart = MultiLanguages.setAppLanguage(this, Locale.TAIWAN);
- } else if (checkedId == R.id.rb_language_en) {
+ } else if (checkedId == R.id.rb_main_language_en) {
// 英语
restart = MultiLanguages.setAppLanguage(this, Locale.ENGLISH);
}
@@ -125,4 +133,15 @@ protected void onDestroy() {
//销毁此的WebView的内部状态
mWebView.destroy();
}
+
+ @Override
+ public void onLeftClick(View view) {}
+
+ @Override
+ public void onTitleClick(View view) {
+ ToastUtils.show(R.string.app_name);
+ }
+
+ @Override
+ public void onRightClick(View view) {}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_language.xml b/app/src/main/res/layout/activity_main.xml
similarity index 88%
rename from app/src/main/res/layout/activity_language.xml
rename to app/src/main/res/layout/activity_main.xml
index 320e140..5a559dc 100644
--- a/app/src/main/res/layout/activity_language.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -10,13 +10,14 @@
tools:context=".MainActivity">
@@ -115,7 +116,7 @@
android:text="当前 System 语种:" />
diff --git a/build.gradle b/build.gradle
index 5b71af8..eeeecec 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,18 +1,32 @@
buildscript {
repositories {
- jcenter()
+ // 阿里云云效仓库:https://maven.aliyun.com/mvn/guide
+ maven { url 'https://maven.aliyun.com/repository/jcenter' }
+ maven { url 'https://maven.aliyun.com/repository/google' }
+ // 华为开源镜像:https://mirrors.huaweicloud.com/
+ maven { url 'https://repo.huaweicloud.com/repository/maven/' }
+ // JitPack 远程仓库:https://jitpack.io
+ maven { url 'https://jitpack.io' }
+ mavenCentral()
google()
+ // noinspection JcenterRepositoryObsolete
+ jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.4.0'
+ classpath 'com.android.tools.build:gradle:4.1.2'
}
}
allprojects {
repositories {
- maven {url "https://jitpack.io"}
- jcenter()
+ maven { url 'https://maven.aliyun.com/repository/jcenter' }
+ maven { url 'https://maven.aliyun.com/repository/google' }
+ maven { url 'https://repo.huaweicloud.com/repository/maven/' }
+ maven { url 'https://jitpack.io' }
+ mavenCentral()
google()
+ // noinspection JcenterRepositoryObsolete
+ jcenter()
}
}
diff --git a/gradle.properties b/gradle.properties
index 3530b01..07610dd 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,3 +15,8 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
+
+# 表示使用 AndroidX
+android.useAndroidX = true
+# 表示将第三方库迁移到 AndroidX
+android.enableJetifier = true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 2aa45d6..947be17 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Wed Jul 18 11:21:06 CST 2018
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
+zipStoreBase = GRADLE_USER_HOME
+zipStorePath = wrapper/dists
+distributionBase = GRADLE_USER_HOME
+distributionPath = wrapper/dists
+distributionUrl = https\://services.gradle.org/distributions/gradle-6.5-all.zip
\ No newline at end of file
diff --git a/library/build.gradle b/library/build.gradle
index 818df75..bc39586 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -5,8 +5,15 @@ android {
defaultConfig {
minSdkVersion 14
- versionCode 66
- versionName "6.6"
+ versionCode 68
+ versionName "6.8"
+ }
+
+ android.libraryVariants.all { variant ->
+ // aar 输出文件名配置
+ variant.outputs.all { output ->
+ outputFileName = "language-${android.defaultConfig.versionName}.aar"
+ }
}
}
diff --git a/library/src/main/java/com/hjq/language/LanguagesObserver.java b/library/src/main/java/com/hjq/language/LanguagesObserver.java
index 2237aa6..e659df0 100644
--- a/library/src/main/java/com/hjq/language/LanguagesObserver.java
+++ b/library/src/main/java/com/hjq/language/LanguagesObserver.java
@@ -53,6 +53,12 @@ public void onConfigurationChanged(Configuration newConfig) {
return;
}
sSystemLanguage = newLocale;
+
+ // 如果当前的语种是跟随系统变化的,那么就需要重置一下当前 App 的语种
+ if (LanguagesConfig.isSystemLanguage(MultiLanguages.getApplication())) {
+ LanguagesConfig.clearLanguage(MultiLanguages.getApplication());
+ }
+
OnLanguageListener listener = MultiLanguages.getOnLanguagesListener();
if (listener != null) {
listener.onSystemLocaleChange(oldLocale, newLocale);
diff --git a/library/src/main/java/com/hjq/language/MultiLanguages.java b/library/src/main/java/com/hjq/language/MultiLanguages.java
index ad183e0..d9b5493 100644
--- a/library/src/main/java/com/hjq/language/MultiLanguages.java
+++ b/library/src/main/java/com/hjq/language/MultiLanguages.java
@@ -12,6 +12,7 @@
* time : 2019/05/03
* desc : 语种切换框架
*/
+@SuppressWarnings("unused")
public final class MultiLanguages {
/** 应用上下文对象 */