Skip to content

Commit

Permalink
多语言切换
Browse files Browse the repository at this point in the history
  • Loading branch information
wdl committed Oct 31, 2019
1 parent 4f9c1f2 commit 1d03dbd
Show file tree
Hide file tree
Showing 28 changed files with 335 additions and 32 deletions.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//apply plugin: 'com.android.application'
apply plugin: 'com.android.library'

apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
//applicationId "com.wdl.libcore"
applicationId "com.wdl.libcore"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
Expand All @@ -22,9 +20,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':core')
}
11 changes: 9 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
package="com.wdl.libcore">

<application
android:name=".App"
android:name="com.wdl.core.App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<provider
android:name=".provider.ContextProvider"
android:name="com.wdl.core.provider.ContextProvider"
android:authorities="${applicationId}.context_provider"
android:exported="false"
android:multiprocess="true" />
Expand Down
49 changes: 49 additions & 0 deletions app/src/main/java/com/wdl/libcore/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.wdl.libcore;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.wdl.core.prompt.WToast;
import com.wdl.core.util.LanguageUtil;
import com.wdl.core.util.WActivityStack;
import com.wdl.core.util.WLogger;
import com.wdl.core.util.WResUtil;

import java.util.Locale;

public class MainActivity extends AppCompatActivity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//LanguageUtil.applyLang(Locale.ENGLISH);
setContentView(R.layout.activity_main);
WLogger.e("MainActivity");
WToast.show("MainActivity");
WLogger.e("MainActivity" + WActivityStack.getInstance().getSize());
WLogger.e("MainActivity" + WResUtil.dp2px(20) + " " + WResUtil.getScreenWidth() + " " + WResUtil.getScreenHeight());

findViewById(R.id.btn_en).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
LanguageUtil.applyLang(MainActivity.this,Locale.ENGLISH);
}
});

findViewById(R.id.btn_zh).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
LanguageUtil.applyLang(MainActivity.this,Locale.CHINESE);
}
});

}
}
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btn_en"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/en_name"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn_zh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zh_name"
app:layout_constraintTop_toBottomOf="@id/btn_en" />

</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values-en-rUS/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="en_name">En</string>
<string name="zh_name">Zh</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="en_name">En</string>
<string name="zh_name">Zh</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<string name="app_name">Libcore</string>
<string name="lib_context_init_class">com.wdl.libcore.InitClass</string>
<string name="en_name">英文</string>
<string name="zh_name">中文</string>
</resources>
1 change: 1 addition & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"


defaultConfig {
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Empty file added core/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wdl.core" />
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wdl.libcore;
package com.wdl.core;

import com.wdl.libcore.util.WActivityStack;
import com.wdl.libcore.util.WLogger;
import com.wdl.core.util.WActivityStack;
import com.wdl.core.util.WLogger;

public class App extends WApp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wdl.libcore;
package com.wdl.core;

import android.util.Log;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.wdl.libcore;
package com.wdl.core;

import android.app.Application;

import com.wdl.libcore.util.WActivityStack;
import com.wdl.libcore.util.WProcessUtil;
import com.wdl.core.util.WActivityStack;
import com.wdl.core.util.WProcessUtil;

@SuppressWarnings("unused")
public abstract class WApp extends Application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.wdl.libcore.prompt;
package com.wdl.core.prompt;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.Toast;

import com.wdl.libcore.util.WLibrary;
import com.wdl.core.util.WLibrary;

@SuppressWarnings("unused")
public final class WToast extends WLibrary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.wdl.libcore.provider;
package com.wdl.core.provider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.wdl.libcore.util.WLibrary;
import com.wdl.core.util.WLibrary;


public class ContextProvider extends ContentProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wdl.libcore.util;
package com.wdl.core.util;

import android.app.Activity;
import android.content.Context;
Expand Down
Loading

0 comments on commit 1d03dbd

Please sign in to comment.