├── .gitignore ├── README.md ├── app ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── fitem │ │ └── i18ndemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── fitem │ │ │ └── i18ndemo │ │ │ ├── base │ │ │ ├── AppApplication.java │ │ │ ├── AppConstants.java │ │ │ └── BaseActivity.java │ │ │ ├── ui │ │ │ └── MainActivity.java │ │ │ └── utils │ │ │ ├── LanguageUtils.java │ │ │ └── PopUtils.java │ └── res │ │ ├── anim │ │ ├── context_menu_right_in.xml │ │ └── context_menu_right_out.xml │ │ ├── drawable │ │ ├── pop_bg.xml │ │ └── pop_title_bg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── pop_select_language.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-en-rUS │ │ ├── dimens.xml │ │ └── strings.xml │ │ ├── values-th-rTH │ │ ├── dimens.xml │ │ └── strings.xml │ │ ├── values-zh-rCN │ │ ├── dimens.xml │ │ └── strings.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── fitem │ └── i18ndemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | local.properties 10 | .gradle/ 11 | .idea/ 12 | build/ 13 | *iml 14 | app/build/ 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android多语言切换完美解决方案 2 | 3 | 最近公司开始做多语言版本,由于之前没有做过,所以在网上搜寻了一番这方面的资料,最后经过实践、总结,写下了这篇文章。[源码Github](https://github.com/Fitem/I18NDemo/) 4 | 5 | ## 多语言的切换功能 6 | 7 | 首先,实现多语言的切换功能,参考[Android App 多语言切换](https://jaeger.itscoder.com/android/2016/05/14/switch-language-on-android-app.html)。 8 | 9 | 1.在res资源文件目录下添加不同语言的values,如图: 10 | 11 | ![添加多语言.png](http://upload-images.jianshu.io/upload_images/4759690-73a7d8c9faee176e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 12 | 13 | 2.通过修改Configuration中的locale来实现app语言的切换,具体代码如下: 14 | ``` 15 | Resources resources = context.getResources(); 16 | DisplayMetrics dm = resources.getDisplayMetrics(); 17 | Configuration config = resources.getConfiguration(); 18 | resources.updateConfiguration(config, dm); 19 | ``` 20 | 3.根据本地缓存的type获取对应的locale,其中7.0以上的系统需要另做处理,具体代码如下: 21 | ``` 22 | Locale locale; 23 | // 应用用户选择语言 24 | switch (type) { 25 | case 0: 26 | //由于API仅支持7.0,需要判断,否则程序会crash(解决7.0以上系统不能跟随系统语言问题) 27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 28 | LocaleList localeList = LocaleList.getDefault(); 29 | locale = localeList.get(localeList.size() - 1); 30 | } else { 31 | locale = Locale.getDefault(); 32 | } 33 | break; 34 | 、、、 35 | default: 36 | locale = thLocale; 37 | break; 38 | } 39 | ``` 40 | 4.在AppApplication中初始化时设置本地语言,用于每次启动APP后切换到本地缓存的语言 41 | 42 | // 设置本地化语言 43 | I18NUtils.setLocale(this); 44 | 45 | 5.在BaseActivity的OnCreate()方法中设置语言,用于处理每次切换系统语言后app语言会跟随系统变化的问题 46 | 47 | if(!I18NUtils.isSameLanguage(this)) { 48 | I18NUtils.setLocale(this); 49 | I18NUtils.toRestartMainActvity(this); 50 | } 51 | 52 | 6.手动切换语言时,先更新locale配置,然后通过跳转到主Activity实现。Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK通过清理掉进程中的所有activity重新配置。 53 | 54 | Intent intent = new Intent(activity, MainActivity.class); 55 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 56 | activity.startActivity(intent); 57 | // 杀掉进程,如果是跨进程则杀掉当前进程 58 | // android.os.Process.killProcess(android.os.Process.myPid()); 59 | // System.exit(0); 60 | 61 | ## 解决7.0以上系统存在的兼容问题 62 | 63 | 这个问题的解决参考了[Android 7.0 语言设置爬坑](http://www.jianshu.com/p/9a304c2047ff/)。由于Android7.0以上Configuration将通过LocaleList来管理语言,并且系统切换语言后,系统默认语言可能并不在LocaleList顶部[官方API说明](https://developer.android.com/reference/android/os/LocaleList.html#getDefault()/) 64 | 65 | 进测试得出结论,如果APP手动选择过语言则系统语言是第二个,否则是第一个。获取当前系统locale,代码如下: 66 | ``` 67 | //由于API仅支持7.0,需要判断,否则程序会crash(解决7.0以上系统不能跟随系统语言问题) 68 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 69 | LocaleList localeList = LocaleList.getDefault(); 70 | int spType = getLanguageType(AppApplication.getAppContext()); 71 | // 如果app已选择不跟随系统语言,则取第二个数据为系统默认语言 72 | if(spType != 0 && localeList.size() > 1) { 73 | locale = localeList.get(1); 74 | } else { 75 | locale = localeList.get(0); 76 | } 77 | } else { 78 | locale = Locale.getDefault(); 79 | } 80 | ``` 81 | 82 | ## 7.0以上系统WebView所在Activity没有跟随语言切换问题 83 | 更新日期:2017年12月14日15:56:47 84 | 85 | 在后续的测试发现,在有webView的activitiy中语言并没有随着语言进行切换。参考[多语言切换失效的问题](http://blog.csdn.net/xunmeng_93/article/details/78632210)以及[stackoverflow](https://stackoverflow.com/questions/40398528/android-webview-language-changes-abruptly-on-android-n)后,通过在切换语言之前执行new WebView(context).destroy()解决。代码: 86 | 87 | // 解决webview所在的activity语言没有切换问题 88 | new WebView(context).destroy(); 89 | // 切换语言 90 | Resources resources = context.getResources(); 91 | DisplayMetrics dm = resources.getDisplayMetrics(); 92 | Configuration config = resources.getConfiguration(); 93 | config.locale = getLocaleByType(type); 94 | LogUtils.logd("setLocale: " + config.locale.toString()); 95 | resources.updateConfiguration(config, dm); 96 | 97 | ## 总结 98 | 99 | 自此,多语言切换的问题已经完美解决了。经测试,完全兼容7.0以上系统的多语言切换。具体代码我已上传至[Github](https://github.com/Fitem/I18NDemo/) 100 | 101 | ## 后续 102 | 103 | 更新时间:2020年8月22日17:47:46 104 | 105 | 时隔两年,公司再次启动多语言版本,回头看当初的方案,发现很多问题。这次重新进行了更新,目前适用所有系统版本! 106 | 后续我也会对这次的新方案,整理成文章更新! 107 | 108 | 简书地址:http://www.jianshu.com/p/16efe98d4554/) 109 | 110 | E-mail:931675174@qq.com -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.1" 6 | defaultConfig { 7 | applicationId "com.example.asciidemo" 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | 15 | compileOptions { 16 | sourceCompatibility JavaVersion.VERSION_1_8 17 | targetCompatibility JavaVersion.VERSION_1_8 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation 'androidx.appcompat:appcompat:1.1.0' 31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 32 | testImplementation 'junit:junit:4.12' 33 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 35 | // retrofit和rxjava 36 | implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' 37 | implementation 'io.reactivex.rxjava3:rxjava:3.0.0' 38 | //view注解 39 | implementation "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion" 40 | annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion" 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/fitem/i18ndemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.fitem.i18ndemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/fitem/i18ndemo/base/AppApplication.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo.base; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | import android.content.Context; 6 | import android.os.Bundle; 7 | 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | 11 | import com.fitem.i18ndemo.utils.LanguageUtils; 12 | 13 | /** 14 | * Created by Fitem on 2017/12/8. 15 | */ 16 | 17 | public class AppApplication extends Application { 18 | private static Application mApplication; 19 | 20 | @Override 21 | public void onCreate() { 22 | super.onCreate(); 23 | mApplication = this; 24 | //监听activity生命周期 25 | registerActivityLifecycleCallbacks(); 26 | } 27 | 28 | private void registerActivityLifecycleCallbacks() { 29 | mApplication.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { 30 | @Override 31 | public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { 32 | // 对Application和Activity更新上下文的语言环境 33 | LanguageUtils.applyAppLanguage(activity); 34 | } 35 | 36 | @Override 37 | public void onActivityStarted(@NonNull Activity activity) { 38 | 39 | } 40 | 41 | @Override 42 | public void onActivityResumed(@NonNull Activity activity) { 43 | 44 | } 45 | 46 | @Override 47 | public void onActivityPaused(@NonNull Activity activity) { 48 | 49 | } 50 | 51 | @Override 52 | public void onActivityStopped(@NonNull Activity activity) { 53 | 54 | } 55 | 56 | @Override 57 | public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) { 58 | 59 | } 60 | 61 | @Override 62 | public void onActivityDestroyed(@NonNull Activity activity) { 63 | 64 | } 65 | }); 66 | } 67 | 68 | public static Context getAppContext() { 69 | return mApplication; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/fitem/i18ndemo/base/AppConstants.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo.base; 2 | 3 | /** 4 | * Created by Fitem on 2017/12/8. 5 | */ 6 | 7 | public class AppConstants { 8 | 9 | public static final String I18N = "i18n"; 10 | public static final String LOCALE_LANGUAGE = "locale_language"; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/fitem/i18ndemo/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo.base; 2 | 3 | 4 | import android.os.Bundle; 5 | 6 | import androidx.appcompat.app.AppCompatActivity; 7 | 8 | import butterknife.ButterKnife; 9 | 10 | /** 11 | * 基类 12 | */ 13 | 14 | /***************使用例子*********************/ 15 | public abstract class BaseActivity extends AppCompatActivity { 16 | 17 | @Override 18 | public void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | // 兼容启动页没有布局的情况 21 | if (getLayoutId() > 0) { 22 | setContentView(getLayoutId()); 23 | } 24 | 25 | ButterKnife.bind(this); 26 | this.initView(); 27 | } 28 | 29 | /*********************子类实现*****************************/ 30 | //获取布局文件 31 | public abstract int getLayoutId(); 32 | 33 | //初始化view 34 | public abstract void initView(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/fitem/i18ndemo/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo.ui; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.drawable.ColorDrawable; 6 | import android.view.Gravity; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.PopupWindow; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import com.fitem.i18ndemo.R; 15 | import com.fitem.i18ndemo.base.AppApplication; 16 | import com.fitem.i18ndemo.base.BaseActivity; 17 | import com.fitem.i18ndemo.utils.LanguageUtils; 18 | import com.fitem.i18ndemo.utils.PopUtils; 19 | 20 | import java.util.Locale; 21 | 22 | import butterknife.OnClick; 23 | 24 | public class MainActivity extends BaseActivity { 25 | 26 | private PopupWindow mPopupWindow; 27 | 28 | public static void actionActivity(Context context){ 29 | Intent intent = new Intent(context, MainActivity.class); 30 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 31 | context.startActivity(intent); 32 | } 33 | 34 | @OnClick(R.id.tv_select_language) 35 | public void toSelectLanguage() { 36 | showSelectPop(); 37 | } 38 | 39 | @Override 40 | public int getLayoutId() { 41 | return R.layout.activity_main; 42 | } 43 | 44 | @Override 45 | public void initView() { 46 | TextView mTvApplicationName = findViewById(R.id.tv_application_name); 47 | TextView mTvActivityName = findViewById(R.id.tv_activity_name); 48 | mTvApplicationName.setText(AppApplication.getAppContext().getString(R.string.application_name)); 49 | mTvActivityName.setText(R.string.activity_name); 50 | } 51 | 52 | private void showSelectPop() { 53 | // 设置contentView 54 | View contentView = LayoutInflater.from(this) 55 | .inflate(R.layout.pop_select_language, null); 56 | mPopupWindow = new PopupWindow(contentView); 57 | mPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); 58 | mPopupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); 59 | //设置点击事件 60 | contentView.findViewById(R.id.tv_default_language).setOnClickListener(new View.OnClickListener() { 61 | @Override 62 | public void onClick(View v) { 63 | mPopupWindow.dismiss(); 64 | toSetLanguage(0); 65 | } 66 | }); 67 | contentView.findViewById(R.id.tv_english).setOnClickListener(new View.OnClickListener() { 68 | @Override 69 | public void onClick(View v) { 70 | mPopupWindow.dismiss(); 71 | toSetLanguage(1); 72 | } 73 | }); 74 | 75 | contentView.findViewById(R.id.tv_chinese).setOnClickListener(new View.OnClickListener() { 76 | @Override 77 | public void onClick(View v) { 78 | mPopupWindow.dismiss(); 79 | toSetLanguage(2); 80 | } 81 | }); 82 | 83 | contentView.findViewById(R.id.tv_thai).setOnClickListener(new View.OnClickListener() { 84 | @Override 85 | public void onClick(View v) { 86 | mPopupWindow.dismiss(); 87 | toSetLanguage(3); 88 | } 89 | }); 90 | 91 | // 外部是否可以点击 92 | mPopupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000)); 93 | mPopupWindow.setOutsideTouchable(true); 94 | mPopupWindow.setFocusable(true); 95 | //设置动画 96 | mPopupWindow.setAnimationStyle(R.style.betSharePopAnim); 97 | PopUtils.setBackgroundAlpha(this, 0.5f);//设置屏幕透明度 98 | // 显示PopupWindow 99 | mPopupWindow.showAtLocation(contentView, Gravity.BOTTOM | Gravity.LEFT, 0, 0); 100 | contentView.setOnClickListener(new View.OnClickListener() { 101 | @Override 102 | public void onClick(View v) { 103 | mPopupWindow.dismiss(); 104 | } 105 | }); 106 | mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { 107 | 108 | @Override 109 | public void onDismiss() { 110 | // popupWindow隐藏时恢复屏幕正常透明度 111 | PopUtils.setBackgroundAlpha(MainActivity.this, 1.0f); 112 | } 113 | }); 114 | } 115 | 116 | private void toSetLanguage(int type) { 117 | Locale locale; 118 | Context context = AppApplication.getAppContext(); 119 | if (type == 0) { 120 | locale = LanguageUtils.getSystemLocale(); 121 | LanguageUtils.saveAppLocaleLanguage(LanguageUtils.SYSTEM_LANGUAGE_TGA); 122 | } else if (type == 1) { 123 | locale = Locale.US; 124 | LanguageUtils.saveAppLocaleLanguage(locale.toLanguageTag()); 125 | }else if (type == 2) { 126 | locale = Locale.SIMPLIFIED_CHINESE; 127 | LanguageUtils.saveAppLocaleLanguage(locale.toLanguageTag()); 128 | }else if(type == 3){ 129 | locale = new Locale("th"); 130 | LanguageUtils.saveAppLocaleLanguage(locale.toLanguageTag()); 131 | } else { 132 | return; 133 | } 134 | if (LanguageUtils.isSimpleLanguage(context, locale)) { 135 | Toast.makeText(context, "选择的语言和当前语言相同", Toast.LENGTH_SHORT).show(); 136 | return; 137 | } 138 | LanguageUtils.updateLanguage(context, locale); 139 | MainActivity.actionActivity(context); 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /app/src/main/java/com/fitem/i18ndemo/utils/LanguageUtils.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo.utils; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | import android.content.Context; 6 | import android.content.ContextWrapper; 7 | import android.content.SharedPreferences; 8 | import android.content.res.Configuration; 9 | import android.content.res.Resources; 10 | import android.text.TextUtils; 11 | import android.util.DisplayMetrics; 12 | 13 | import androidx.annotation.NonNull; 14 | 15 | import com.fitem.i18ndemo.base.AppApplication; 16 | import com.fitem.i18ndemo.base.AppConstants; 17 | 18 | import java.lang.reflect.Field; 19 | import java.util.Locale; 20 | 21 | /** 22 | * 多语言工具类 23 | * Created by Fitem on 2020/03/20. 24 | */ 25 | 26 | public class LanguageUtils { 27 | 28 | public static final String SYSTEM_LANGUAGE_TGA = "systemLanguageTag"; 29 | 30 | /** 31 | * 更新该context的config语言配置,对于application进行反射更新 32 | * @param context 33 | * @param locale 34 | */ 35 | public static void updateLanguage(final Context context, Locale locale) { 36 | Resources resources = context.getResources(); 37 | Configuration config = resources.getConfiguration(); 38 | Locale contextLocale = config.locale; 39 | if (isSameLocale(contextLocale, locale)) { 40 | return; 41 | } 42 | DisplayMetrics dm = resources.getDisplayMetrics(); 43 | config.setLocale(locale); 44 | if (context instanceof Application) { 45 | Context newContext = context.createConfigurationContext(config); 46 | try { 47 | //noinspection JavaReflectionMemberAccess 48 | Field mBaseField = ContextWrapper.class.getDeclaredField("mBase"); 49 | mBaseField.setAccessible(true); 50 | mBaseField.set(context, newContext); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | resources.updateConfiguration(config, dm); 56 | } 57 | 58 | /** 59 | * 对Application上下文进行替换 60 | * 61 | * @param activity activity 62 | */ 63 | public static void applyAppLanguage(@NonNull Activity activity) { 64 | Locale appLocale = getCurrentAppLocale(); 65 | updateLanguage(AppApplication.getAppContext(), appLocale); 66 | updateLanguage(activity, appLocale); 67 | } 68 | 69 | /** 70 | * 获取系统Local 71 | * 72 | * @return 73 | */ 74 | public static Locale getSystemLocale() { 75 | return Resources.getSystem().getConfiguration().locale; 76 | } 77 | 78 | /** 79 | * 获取app缓存语言 80 | * 81 | * @return 82 | */ 83 | private static String getPrefAppLocaleLanguage() { 84 | SharedPreferences sp = AppApplication.getAppContext().getSharedPreferences(AppConstants.I18N, Context.MODE_PRIVATE); 85 | return sp.getString(AppConstants.LOCALE_LANGUAGE, ""); 86 | } 87 | 88 | /** 89 | * 获取app缓存Locale 90 | * 91 | * @return null则无 92 | */ 93 | public static Locale getPrefAppLocale() { 94 | String appLocaleLanguage = getPrefAppLocaleLanguage(); 95 | if (!TextUtils.isEmpty(appLocaleLanguage)) { 96 | if (SYSTEM_LANGUAGE_TGA.equals(appLocaleLanguage)) { //系统语言则返回null 97 | return null; 98 | } else { 99 | return Locale.forLanguageTag(appLocaleLanguage); 100 | } 101 | } 102 | return Locale.SIMPLIFIED_CHINESE; // 为空,默认是简体中文 103 | } 104 | 105 | /** 106 | * 获取当前需要使用的locale,用于activity上下文的生成 107 | * 108 | * @return 109 | */ 110 | public static Locale getCurrentAppLocale() { 111 | Locale prefAppLocale = getPrefAppLocale(); 112 | return prefAppLocale == null ? getSystemLocale() : prefAppLocale; 113 | } 114 | 115 | 116 | /** 117 | * 缓存app当前语言 118 | * 119 | * @param language 120 | */ 121 | public static void saveAppLocaleLanguage(String language) { 122 | SharedPreferences sp = AppApplication.getAppContext().getSharedPreferences(AppConstants.I18N, Context.MODE_PRIVATE); 123 | SharedPreferences.Editor edit = sp.edit(); 124 | edit.putString(AppConstants.LOCALE_LANGUAGE, language); 125 | edit.apply(); 126 | } 127 | 128 | /** 129 | * 判断是否是APP语言 130 | * 131 | * @param context 132 | * @param locale 133 | * @return 134 | */ 135 | public static boolean isSimpleLanguage(Context context, Locale locale) { 136 | Locale appLocale = context.getResources().getConfiguration().locale; 137 | return appLocale.equals(locale); 138 | } 139 | 140 | /** 141 | * 获取App当前语言 142 | * 143 | * @return 144 | */ 145 | public static String getAppLanguage() { 146 | Locale locale = AppApplication.getAppContext().getResources().getConfiguration().locale; 147 | String language = locale.getLanguage(); 148 | String country = locale.getCountry(); 149 | StringBuilder stringBuilder = new StringBuilder(); 150 | if (!TextUtils.isEmpty(language)) { //语言 151 | stringBuilder.append(language); 152 | } 153 | if (!TextUtils.isEmpty(country)) { //国家 154 | stringBuilder.append("-").append(country); 155 | } 156 | 157 | return stringBuilder.toString(); 158 | } 159 | 160 | /** 161 | * 是否是相同的locale 162 | * @param l0 163 | * @param l1 164 | * @return 165 | */ 166 | private static boolean isSameLocale(Locale l0, Locale l1) { 167 | return equals(l1.getLanguage(), l0.getLanguage()) 168 | && equals(l1.getCountry(), l0.getCountry()); 169 | } 170 | 171 | /** 172 | * Return whether string1 is equals to string2. 173 | * 174 | * @param s1 The first string. 175 | * @param s2 The second string. 176 | * @return {@code true}: yes
{@code false}: no 177 | */ 178 | public static boolean equals(final CharSequence s1, final CharSequence s2) { 179 | if (s1 == s2) return true; 180 | int length; 181 | if (s1 != null && s2 != null && (length = s1.length()) == s2.length()) { 182 | if (s1 instanceof String && s2 instanceof String) { 183 | return s1.equals(s2); 184 | } else { 185 | for (int i = 0; i < length; i++) { 186 | if (s1.charAt(i) != s2.charAt(i)) return false; 187 | } 188 | return true; 189 | } 190 | } 191 | return false; 192 | } 193 | 194 | } 195 | -------------------------------------------------------------------------------- /app/src/main/java/com/fitem/i18ndemo/utils/PopUtils.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo.utils; 2 | 3 | import android.app.Activity; 4 | import android.view.WindowManager; 5 | 6 | /** 7 | * Created by Fitem on 2017/10/31. 8 | */ 9 | 10 | public class PopUtils { 11 | /** 12 | * 设置添加屏幕的背景透明度 13 | * 14 | * @param bgAlpha 屏幕透明度0.0-1.0 1表示完全不透明 15 | */ 16 | public static void setBackgroundAlpha(Activity activity, float bgAlpha) { 17 | WindowManager.LayoutParams lp = activity.getWindow() 18 | .getAttributes(); 19 | lp.alpha = bgAlpha; 20 | activity.getWindow().setAttributes(lp); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/anim/context_menu_right_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/anim/context_menu_right_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/pop_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/pop_title_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 25 | 26 | 33 | 34 | 44 | 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/pop_select_language.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 23 | 24 | 32 | 33 | 37 | 38 | 46 | 47 | 51 | 52 | 60 | 61 | 65 | 66 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-en-rUS/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 120dp 4 | 30dp 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-en-rUS/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | I18NDemo 3 | Internationalization 4 | This is an internationalization app demo! 5 | Select Language 6 | Default Language 7 | English 8 | Chinese 9 | Please select app language 10 | thai 11 | Activity Name 12 | Application Name 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values-th-rTH/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 80dp 4 | 30dp 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-th-rTH/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ความเป็นสากล 3 | ความเป็นสากล 4 | นี่คือตัวอย่างความเป็นสากลของแอป! 5 | เลือกภาษา 6 | ภาษาดั้งเดิม 7 | ภาษาอังกฤษ 8 | ภาษาจีน 9 | กรุณาเลือกภาษาของแอป 10 | ภาษาไทย 11 | ชื่อกิจกรรม 12 | ชื่อผู้ใช้ 13 | -------------------------------------------------------------------------------- /app/src/main/res/values-zh-rCN/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 80dp 4 | 30dp 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 国际化Demo 3 | 国际化 4 | 这是一个国际化应用demo! 5 | 选择语言 6 | 默认语言 7 | 英语 8 | 中文 9 | 请选择app语言 10 | 泰语 11 | 活动名称 12 | 应用名称 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #FFFFFF 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 120dp 4 | 30dp 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | I18NDemo 3 | Internationalization 4 | This is an internationalization app demo! 5 | Select Language 6 | Default Language 7 | English 8 | Chinese 9 | Please select app language 10 | thai 11 | Activity Name 12 | Application Name 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/test/java/com/fitem/i18ndemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.fitem.i18ndemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.5.1' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | 29 | ext{ 30 | // Rx全家桶 31 | rxjavaVersion = '3.0.0' 32 | rxandroidVersion = '3.0.0' 33 | rxbindingVersion = '3.0.0' 34 | // butterknife 35 | butterknifeVersion = '10.2.1' 36 | } 37 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Fitem/I18NDemo/5ba1300dc12eaa1fe3bfc445a923b3571caa768d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Mar 17 16:12:10 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------