-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6: Made app localizable via settings menu. Bugfix: allow utf8 in abo…
…utbox
- Loading branch information
Showing
15 changed files
with
331 additions
and
31 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
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
107 changes: 107 additions & 0 deletions
107
app/src/main/java/de/k3b/android/widget/LocalizedActivity.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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2015-2017 by k3b. | ||
* | ||
* This file is part of AndroFotoFinder and of ToGoZip. | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package de.k3b.android.widget; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.content.res.Configuration; | ||
import android.content.res.Resources; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceManager; | ||
|
||
import java.util.Locale; | ||
|
||
import de.k3b.android.toGoZip.Global; | ||
|
||
/** | ||
* An activity that can change the locale (language) of its content. | ||
* | ||
* Inspired by http://stackoverflow.com/questions/13181847/change-the-locale-at-runtime | ||
* | ||
* Created by k3b on 07.01.2016. | ||
*/ | ||
public abstract class LocalizedActivity extends Activity { | ||
/** if myLocale != Locale.Default : activity must be recreated in on resume */ | ||
private Locale myLocale = null; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
fixLocale(this); | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
// Locale has changed by other Activity ? | ||
if ((myLocale != null) && (myLocale.getLanguage() != Locale.getDefault().getLanguage())) { | ||
myLocale = null; | ||
recreate(LocalizedActivity.this); | ||
} | ||
} | ||
|
||
/** | ||
* Set Activity-s locale to SharedPreferences-setting. | ||
* Must be called before | ||
*/ | ||
public static void fixLocale(Context context) | ||
{ | ||
final SharedPreferences prefs = PreferenceManager | ||
.getDefaultSharedPreferences(context); | ||
String language = prefs.getString(Global.PREF_KEY_USER_LOCALE, ""); | ||
Locale locale = Global.systemLocale; // in case that setting=="use android-locale" | ||
if ((language != null) && (language.length() > 0)) { | ||
locale = new Locale(language); // overwrite "use android-locale" | ||
} | ||
|
||
if (locale != null) { | ||
Locale.setDefault(locale); | ||
Configuration config = new Configuration(); | ||
config.locale = locale; | ||
Resources resources = context.getResources(); | ||
resources.updateConfiguration(config, resources.getDisplayMetrics()); | ||
// recreate(); | ||
|
||
if (context instanceof LocalizedActivity) { | ||
((LocalizedActivity) context).myLocale = locale; | ||
} | ||
} | ||
} | ||
|
||
/** force all open activity to recreate */ | ||
public static void recreate(Activity child) { | ||
Activity context = child; | ||
while (context != null) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | ||
context.recreate(); | ||
} else { | ||
// https://stackoverflow.com/questions/11495130/android-recreate-functions-in-api-7 | ||
context.startActivity(new Intent(context, context.getClass())); | ||
context.finish(); | ||
} | ||
context = context.getParent(); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.