Skip to content

Commit 1d03dbd

Browse files
author
wdl
committed
多语言切换
1 parent 4f9c1f2 commit 1d03dbd

28 files changed

+335
-32
lines changed

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
//apply plugin: 'com.android.application'
2-
apply plugin: 'com.android.library'
3-
1+
apply plugin: 'com.android.application'
42
android {
53
compileSdkVersion 29
64
buildToolsVersion "29.0.1"
75
defaultConfig {
8-
//applicationId "com.wdl.libcore"
6+
applicationId "com.wdl.libcore"
97
minSdkVersion 15
108
targetSdkVersion 29
119
versionCode 1
@@ -22,9 +20,10 @@ android {
2220

2321
dependencies {
2422
implementation fileTree(dir: 'libs', include: ['*.jar'])
25-
implementation 'androidx.appcompat:appcompat:1.0.2'
23+
implementation 'androidx.appcompat:appcompat:1.1.0'
2624
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
2725
testImplementation 'junit:junit:4.12'
2826
androidTestImplementation 'androidx.test:runner:1.2.0'
2927
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
28+
implementation project(path: ':core')
3029
}

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
package="com.wdl.libcore">
55

66
<application
7-
android:name=".App"
7+
android:name="com.wdl.core.App"
88
android:allowBackup="true"
99
android:icon="@mipmap/ic_launcher"
1010
android:label="@string/app_name"
1111
android:roundIcon="@mipmap/ic_launcher_round"
1212
android:supportsRtl="true"
1313
android:theme="@style/AppTheme"
1414
tools:ignore="GoogleAppIndexingWarning">
15+
<activity android:name=".MainActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
1522

1623
<provider
17-
android:name=".provider.ContextProvider"
24+
android:name="com.wdl.core.provider.ContextProvider"
1825
android:authorities="${applicationId}.context_provider"
1926
android:exported="false"
2027
android:multiprocess="true" />
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.wdl.libcore;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.view.View;
7+
8+
import com.wdl.core.prompt.WToast;
9+
import com.wdl.core.util.LanguageUtil;
10+
import com.wdl.core.util.WActivityStack;
11+
import com.wdl.core.util.WLogger;
12+
import com.wdl.core.util.WResUtil;
13+
14+
import java.util.Locale;
15+
16+
public class MainActivity extends AppCompatActivity
17+
{
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState)
21+
{
22+
super.onCreate(savedInstanceState);
23+
//LanguageUtil.applyLang(Locale.ENGLISH);
24+
setContentView(R.layout.activity_main);
25+
WLogger.e("MainActivity");
26+
WToast.show("MainActivity");
27+
WLogger.e("MainActivity" + WActivityStack.getInstance().getSize());
28+
WLogger.e("MainActivity" + WResUtil.dp2px(20) + " " + WResUtil.getScreenWidth() + " " + WResUtil.getScreenHeight());
29+
30+
findViewById(R.id.btn_en).setOnClickListener(new View.OnClickListener()
31+
{
32+
@Override
33+
public void onClick(View v)
34+
{
35+
LanguageUtil.applyLang(MainActivity.this,Locale.ENGLISH);
36+
}
37+
});
38+
39+
findViewById(R.id.btn_zh).setOnClickListener(new View.OnClickListener()
40+
{
41+
@Override
42+
public void onClick(View v)
43+
{
44+
LanguageUtil.applyLang(MainActivity.this,Locale.CHINESE);
45+
}
46+
});
47+
48+
}
49+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".MainActivity">
8+
9+
<Button
10+
android:id="@+id/btn_en"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:text="@string/en_name"
14+
app:layout_constraintTop_toTopOf="parent" />
15+
16+
<Button
17+
android:id="@+id/btn_zh"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:text="@string/zh_name"
21+
app:layout_constraintTop_toBottomOf="@id/btn_en" />
22+
23+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="en_name">En</string>
4+
<string name="zh_name">Zh</string>
5+
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="en_name">En</string>
4+
<string name="zh_name">Zh</string>
5+
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<string name="app_name">Libcore</string>
3-
<string name="lib_context_init_class">com.wdl.libcore.InitClass</string>
3+
<string name="en_name">英文</string>
4+
<string name="zh_name">中文</string>
45
</resources>

core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

core/build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "29.0.1"
6+
7+
8+
defaultConfig {
9+
minSdkVersion 15
10+
targetSdkVersion 29
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
consumerProguardFiles 'consumer-rules.pro'
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
}
26+
27+
dependencies {
28+
implementation fileTree(dir: 'libs', include: ['*.jar'])
29+
30+
implementation 'androidx.appcompat:appcompat:1.1.0'
31+
testImplementation 'junit:junit:4.12'
32+
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
33+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34+
}

0 commit comments

Comments
 (0)