forked from finddreams/AndroidMultiLanguage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb3ad28
commit fa5bc8a
Showing
26 changed files
with
475 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 34 additions & 1 deletion
35
app/src/main/java/com/finddreams/multilanguage/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,46 @@ | ||
package com.finddreams.multilanguage; | ||
|
||
import android.content.Intent; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
import com.finddreams.languagelib.OnChangeLanguageEvent; | ||
|
||
import org.greenrobot.eventbus.EventBus; | ||
import org.greenrobot.eventbus.Subscribe; | ||
import org.greenrobot.eventbus.ThreadMode; | ||
|
||
public class MainActivity extends BaseActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
EventBus.getDefault().register(this); | ||
} | ||
public void openLandScape(View view){ | ||
startActivity(new Intent(this,LandScapeActivity.class)); | ||
|
||
} | ||
public void openWebView(View view){ | ||
startActivity(new Intent(this,WebViewActivity.class)); | ||
} | ||
public void openSettingLanguage(View view){ | ||
startActivity(new Intent(this,SetLanguageActivity.class)); | ||
} | ||
public void openOther(View view){ | ||
startActivity(new Intent(this,OtherActivity.class)); | ||
} | ||
@Subscribe(threadMode = ThreadMode.MAIN) | ||
public void onChangeLanguageEvent(OnChangeLanguageEvent event){ | ||
Log.d("onchange","ChangeLanguage"); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
super.onBackPressed(); | ||
android.os.Process.killProcess(android.os.Process.myPid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 111 additions & 2 deletions
113
app/src/main/java/com/finddreams/multilanguage/SetLanguageActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,122 @@ | ||
package com.finddreams.multilanguage; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.RelativeLayout; | ||
|
||
public class SetLanguageActivity extends AppCompatActivity { | ||
import com.finddreams.languagelib.LanguageType; | ||
import com.finddreams.languagelib.LanguageUtil; | ||
|
||
/** | ||
* 设置语言页面 | ||
*/ | ||
public class SetLanguageActivity extends BaseActivity implements View.OnClickListener { | ||
|
||
private RelativeLayout rl_followsytem; | ||
private RelativeLayout rl_simplified_chinese; | ||
private RelativeLayout rl_traditional_chinese; | ||
private RelativeLayout rl_english; | ||
private ImageView iv_english; | ||
private ImageView iv_followsystem; | ||
private ImageView iv_simplified_chinese; | ||
private ImageView iv_traditional_chinese; | ||
private int savedLanguageType; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_set_language); | ||
setTitle(R.string.setting_language_title); | ||
initViews(); | ||
} | ||
|
||
private void initViews() { | ||
rl_followsytem = findViewById(R.id.rl_followsytem); | ||
rl_simplified_chinese = findViewById(R.id.rl_simplified_chinese); | ||
rl_traditional_chinese = findViewById(R.id.rl_traditional_chinese); | ||
rl_english = findViewById(R.id.rl_english); | ||
iv_followsystem = findViewById(R.id.iv_followsystem); | ||
iv_english = findViewById(R.id.iv_english); | ||
iv_simplified_chinese = findViewById(R.id.iv_simplified_chinese); | ||
iv_traditional_chinese = findViewById(R.id.iv_traditional_chinese); | ||
rl_followsytem.setOnClickListener(this); | ||
rl_simplified_chinese.setOnClickListener(this); | ||
rl_traditional_chinese.setOnClickListener(this); | ||
rl_english.setOnClickListener(this); | ||
savedLanguageType = LanguageUtil.getInstance().getLanguageType(); | ||
if (savedLanguageType == LanguageType.LANGUAGE_FOLLOW_SYSTEM) { | ||
setFollowSytemVisible(); | ||
} else if (savedLanguageType == LanguageType.LANGUAGE_CHINESE_TRADITIONAL) { | ||
setTraditionalVisible(); | ||
} else if (savedLanguageType == LanguageType.LANGUAGE_EN) { | ||
setEnglishVisible(); | ||
} else if (savedLanguageType == LanguageType.LANGUAGE_CHINESE_SIMPLIFIED) { | ||
setSimplifiedVisible(); | ||
} else { | ||
setSimplifiedVisible(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
int id = view.getId(); | ||
int selectedLanguage = 0; | ||
switch (id) { | ||
case R.id.rl_followsytem: | ||
setFollowSytemVisible(); | ||
selectedLanguage = LanguageType.LANGUAGE_FOLLOW_SYSTEM; | ||
break; | ||
case R.id.rl_simplified_chinese: | ||
setSimplifiedVisible(); | ||
selectedLanguage = LanguageType.LANGUAGE_CHINESE_SIMPLIFIED; | ||
|
||
break; | ||
case R.id.rl_traditional_chinese: | ||
setTraditionalVisible(); | ||
selectedLanguage = LanguageType.LANGUAGE_CHINESE_TRADITIONAL; | ||
|
||
break; | ||
case R.id.rl_english: | ||
setEnglishVisible(); | ||
selectedLanguage = LanguageType.LANGUAGE_EN; | ||
break; | ||
} | ||
LanguageUtil.getInstance().updateLanguage(selectedLanguage); | ||
Intent intent = new Intent(SetLanguageActivity.this, MainActivity.class); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); | ||
startActivity(intent); | ||
if (selectedLanguage == LanguageType.LANGUAGE_FOLLOW_SYSTEM) { | ||
System.exit(0); | ||
} | ||
} | ||
|
||
private void setSimplifiedVisible() { | ||
iv_followsystem.setVisibility(View.GONE); | ||
iv_english.setVisibility(View.GONE); | ||
iv_simplified_chinese.setVisibility(View.VISIBLE); | ||
iv_traditional_chinese.setVisibility(View.GONE); | ||
} | ||
|
||
private void setEnglishVisible() { | ||
iv_followsystem.setVisibility(View.GONE); | ||
iv_english.setVisibility(View.VISIBLE); | ||
iv_simplified_chinese.setVisibility(View.GONE); | ||
iv_traditional_chinese.setVisibility(View.GONE); | ||
} | ||
|
||
private void setTraditionalVisible() { | ||
iv_followsystem.setVisibility(View.GONE); | ||
iv_english.setVisibility(View.GONE); | ||
iv_simplified_chinese.setVisibility(View.GONE); | ||
iv_traditional_chinese.setVisibility(View.VISIBLE); | ||
} | ||
|
||
private void setFollowSytemVisible() { | ||
iv_followsystem.setVisibility(View.VISIBLE); | ||
iv_english.setVisibility(View.GONE); | ||
iv_simplified_chinese.setVisibility(View.GONE); | ||
iv_traditional_chinese.setVisibility(View.GONE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.