// Path: libK3bAndroidZip/src/main/java/de/k3b/android/zip/Global.java
// public class Global {
//     /** document tree supported since andrid-5.0. For older devices use folder picker */
//     public static final boolean USE_DOCUMENT_PROVIDER = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
// 
//     /** #6: local settings: which language should the gui use */
//     public static final String PREF_KEY_USER_LOCALE = "user_locale";
// 
//     public static final String LOG_CONTEXT = "toGoZip";
//     /**
//      * true: addToCompressQue several Log.d(...) to show what is going on.
//      * debugEnabled is updated by the SettingsActivity
//      */
//     public static boolean debugEnabled = false;
// 
//     /** Remember initial language settings. This allows setting "switch back to device language" after changing app locale */
//     public static Locale systemLocale = Locale.getDefault();
// 
//     /** if not null added files will be logged in this zip-entry-text-file */
//     public static boolean isWriteLogFile2Zip = false;
// }


import de.k3b.android.zip.Global;
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;
/*
 * 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;




/**
 * 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().equals(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, "");
// Path: libK3bAndroidZip/src/main/java/de/k3b/android/zip/Global.java
// public class Global {
//     /** document tree supported since andrid-5.0. For older devices use folder picker */
//     public static final boolean USE_DOCUMENT_PROVIDER = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
// 
//     /** #6: local settings: which language should the gui use */
//     public static final String PREF_KEY_USER_LOCALE = "user_locale";
// 
//     public static final String LOG_CONTEXT = "toGoZip";
//     /**
//      * true: addToCompressQue several Log.d(...) to show what is going on.
//      * debugEnabled is updated by the SettingsActivity
//      */
//     public static boolean debugEnabled = false;
// 
//     /** Remember initial language settings. This allows setting "switch back to device language" after changing app locale */
//     public static Locale systemLocale = Locale.getDefault();
// 
//     /** if not null added files will be logged in this zip-entry-text-file */
//     public static boolean isWriteLogFile2Zip = false;
// }


// Path: app/src/main/java/de/k3b/android/widget/LocalizedActivity.java
import de.k3b.android.zip.Global;
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;

/*
 * 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;




/**
 * 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().equals(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"