// Path: library/src/main/java/com/oasisfeng/android/google/GooglePlayStore.java
// public class GooglePlayStore {
// 
//     public static final String PACKAGE_NAME = "com.android.vending";
//     private static final String APP_URL_PREFIX = "https://play.google.com/store/apps/details?id=";
// 
//     public static void showApp(final Context context, final String pkg) {
//         final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL_PREFIX + pkg)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//         updatePlayUrlIntent(context, intent);
//         try {
//             context.startActivity(intent);
//         } catch(final ActivityNotFoundException e) { /* In case of Google Play malfunction */ }
//     }
// 
//     public static void updatePreferenceIntent(final Context context, final Preference preference) {
//         final Intent intent = preference.getIntent();
//         updatePlayUrlIntent(context, intent);
//     }
// 
//     /** Modify intent to launch Google Play Store directly if possible (without activity chooser) */
//     private static void updatePlayUrlIntent(final Context context, final Intent intent) {
//         if (intent == null || intent.getPackage() != null) return;      // Skip intent with explicit target package
//         final Uri uri = intent.getData();
//         if (uri == null) return;
//         intent.setPackage(PACKAGE_NAME);
//         final ComponentName component = intent.resolveActivity(context.getPackageManager());
//         if (component != null) intent.setComponent(component);
//         else intent.setPackage(null);
//     }
// }
// 
// Path: library/src/main/java/com/oasisfeng/android/i18n/Locales.java
// public class Locales {
// 
//     public static Locale getFrom(final Context context) {
//         return context.getResources().getConfiguration().locale;
//     }
// 
//     /**
//      * Switch the locale of current app to explicitly specified or default one
//      *
//      * @param locale null for default
//      */
//     public static boolean switchTo(final Context context, final Locale locale) {
//         final Resources resources = context.getResources();
//         final Configuration configuration = resources.getConfiguration();
//         if (match(locale, configuration.locale)) return false;
//         setConfigurationLocale(configuration, locale);
//         resources.updateConfiguration(configuration, null);
//         return true;
//     }
// 
//     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
//     private static void setConfigurationLocale(final Configuration configuration, final Locale locale) {
//         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
//             configuration.locale = locale;
//         else configuration.setLocale(locale);
//     }
// 
//     private static boolean match(final Locale locale1, final Locale locale2) {
//     	return match(locale1.getLanguage(), locale2.getLanguage())
//     			&& match(locale1.getCountry(), locale2.getCountry())
//     			&& match(locale1.getVariant(), locale2.getVariant());
// 	}
// 
//     private static boolean match(final String value1, final String value2) {
//     	return (value1 == null && value2 == null) || "".equals(value1) || "".equals(value2)
//     			|| (value1 != null && value1.equals(value2));
//     }
// }


import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import com.oasisfeng.android.google.GooglePlayStore;
import com.oasisfeng.android.i18n.Locales;
import java.util.Locale;
import javax.annotation.ParametersAreNonnullByDefault;
import androidx.annotation.Nullable;
package com.oasisfeng.android.ui;






/**
 * A helper class to simply build an "About" dialog.
 *
 * <p>Declare the activity in AndroidManifest.xml:
 * <pre>
       &lt;activity android:name="com.oasisfeng.ui.About"
           android:theme="@android:style/Theme.Holo.DialogWhenLarge.NoActionBar" /&gt;
   </pre>
   Show the dialog in code: <pre>AboutActivity.show(context, R.xml.about);</pre>

 * @author Oasis
 */
@ParametersAreNonnullByDefault
public class AboutActivity extends PreferenceActivity {

    private static final String EXTRA_XML_RESOURCE_ID = "xml";

    /** Override to provide your own fragment implementation */
    @SuppressWarnings("MethodMayBeStatic") protected Fragment createAboutFragment() { return new AboutFragment(); }

    public static void show(final Context context, final int xml_res) {
        show(context, xml_res, AboutActivity.class);
    }

    /** Show about activity of your own implementation */
    public static void show(final Context context, final int xml_res, final Class<? extends Activity> activity) {
        context.startActivity(new Intent(context, activity).putExtra(EXTRA_XML_RESOURCE_ID, xml_res));
    }

    @Override protected void onCreate(final @Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getFragmentManager().beginTransaction().replace(android.R.id.content, createAboutFragment()).commit();
    }

    public static class AboutFragment extends PreferenceFragment {

        @Override public void onCreate(final @Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(getActivity().getIntent().getIntExtra(EXTRA_XML_RESOURCE_ID, 0));
            final Preference version_pref = getPreferenceScreen().findPreference("version");
            if (version_pref != null) try {
                final PackageInfo package_info = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
                version_pref.setTitle(version_pref.getTitle() + " " + package_info.versionName);
            } catch (final NameNotFoundException ignored) {}
        }

        @Override public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, final Preference preference) {
            if ("translation".equals(preference.getKey())) {
                final Locale default_locale = Locale.getDefault();
// Path: library/src/main/java/com/oasisfeng/android/google/GooglePlayStore.java
// public class GooglePlayStore {
// 
//     public static final String PACKAGE_NAME = "com.android.vending";
//     private static final String APP_URL_PREFIX = "https://play.google.com/store/apps/details?id=";
// 
//     public static void showApp(final Context context, final String pkg) {
//         final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_URL_PREFIX + pkg)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//         updatePlayUrlIntent(context, intent);
//         try {
//             context.startActivity(intent);
//         } catch(final ActivityNotFoundException e) { /* In case of Google Play malfunction */ }
//     }
// 
//     public static void updatePreferenceIntent(final Context context, final Preference preference) {
//         final Intent intent = preference.getIntent();
//         updatePlayUrlIntent(context, intent);
//     }
// 
//     /** Modify intent to launch Google Play Store directly if possible (without activity chooser) */
//     private static void updatePlayUrlIntent(final Context context, final Intent intent) {
//         if (intent == null || intent.getPackage() != null) return;      // Skip intent with explicit target package
//         final Uri uri = intent.getData();
//         if (uri == null) return;
//         intent.setPackage(PACKAGE_NAME);
//         final ComponentName component = intent.resolveActivity(context.getPackageManager());
//         if (component != null) intent.setComponent(component);
//         else intent.setPackage(null);
//     }
// }
// 
// Path: library/src/main/java/com/oasisfeng/android/i18n/Locales.java
// public class Locales {
// 
//     public static Locale getFrom(final Context context) {
//         return context.getResources().getConfiguration().locale;
//     }
// 
//     /**
//      * Switch the locale of current app to explicitly specified or default one
//      *
//      * @param locale null for default
//      */
//     public static boolean switchTo(final Context context, final Locale locale) {
//         final Resources resources = context.getResources();
//         final Configuration configuration = resources.getConfiguration();
//         if (match(locale, configuration.locale)) return false;
//         setConfigurationLocale(configuration, locale);
//         resources.updateConfiguration(configuration, null);
//         return true;
//     }
// 
//     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
//     private static void setConfigurationLocale(final Configuration configuration, final Locale locale) {
//         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
//             configuration.locale = locale;
//         else configuration.setLocale(locale);
//     }
// 
//     private static boolean match(final Locale locale1, final Locale locale2) {
//     	return match(locale1.getLanguage(), locale2.getLanguage())
//     			&& match(locale1.getCountry(), locale2.getCountry())
//     			&& match(locale1.getVariant(), locale2.getVariant());
// 	}
// 
//     private static boolean match(final String value1, final String value2) {
//     	return (value1 == null && value2 == null) || "".equals(value1) || "".equals(value2)
//     			|| (value1 != null && value1.equals(value2));
//     }
// }


// Path: library/src/main/java/com/oasisfeng/android/ui/AboutActivity.java
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import com.oasisfeng.android.google.GooglePlayStore;
import com.oasisfeng.android.i18n.Locales;
import java.util.Locale;
import javax.annotation.ParametersAreNonnullByDefault;
import androidx.annotation.Nullable;

package com.oasisfeng.android.ui;






/**
 * A helper class to simply build an "About" dialog.
 *
 * <p>Declare the activity in AndroidManifest.xml:
 * <pre>
       &lt;activity android:name="com.oasisfeng.ui.About"
           android:theme="@android:style/Theme.Holo.DialogWhenLarge.NoActionBar" /&gt;
   </pre>
   Show the dialog in code: <pre>AboutActivity.show(context, R.xml.about);</pre>

 * @author Oasis
 */
@ParametersAreNonnullByDefault
public class AboutActivity extends PreferenceActivity {

    private static final String EXTRA_XML_RESOURCE_ID = "xml";

    /** Override to provide your own fragment implementation */
    @SuppressWarnings("MethodMayBeStatic") protected Fragment createAboutFragment() { return new AboutFragment(); }

    public static void show(final Context context, final int xml_res) {
        show(context, xml_res, AboutActivity.class);
    }

    /** Show about activity of your own implementation */
    public static void show(final Context context, final int xml_res, final Class<? extends Activity> activity) {
        context.startActivity(new Intent(context, activity).putExtra(EXTRA_XML_RESOURCE_ID, xml_res));
    }

    @Override protected void onCreate(final @Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getFragmentManager().beginTransaction().replace(android.R.id.content, createAboutFragment()).commit();
    }

    public static class AboutFragment extends PreferenceFragment {

        @Override public void onCreate(final @Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(getActivity().getIntent().getIntExtra(EXTRA_XML_RESOURCE_ID, 0));
            final Preference version_pref = getPreferenceScreen().findPreference("version");
            if (version_pref != null) try {
                final PackageInfo package_info = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
                version_pref.setTitle(version_pref.getTitle() + " " + package_info.versionName);
            } catch (final NameNotFoundException ignored) {}
        }

        @Override public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, final Preference preference) {
            if ("translation".equals(preference.getKey())) {
                final Locale default_locale = Locale.getDefault();
                final Locale locale = Locales.getFrom(getActivity());