Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.sync.setup.activities; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.BrowserLocaleManager; |
michael@0 | 8 | import org.mozilla.gecko.LocaleManager; |
michael@0 | 9 | |
michael@0 | 10 | import android.annotation.TargetApi; |
michael@0 | 11 | import android.app.Activity; |
michael@0 | 12 | import android.content.Context; |
michael@0 | 13 | import android.os.Build; |
michael@0 | 14 | import android.os.Bundle; |
michael@0 | 15 | import android.os.StrictMode; |
michael@0 | 16 | import android.support.v4.app.FragmentActivity; |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * This is a helper class to do typical locale switching operations |
michael@0 | 20 | * without hitting StrictMode errors or adding boilerplate to common |
michael@0 | 21 | * activity subclasses. |
michael@0 | 22 | * |
michael@0 | 23 | * Either call {@link LocaleAware#initializeLocale(Context)} in your |
michael@0 | 24 | * <code>onCreate</code> method, or inherit from <code>LocaleAwareFragmentActivity</code> |
michael@0 | 25 | * or <code>LocaleAwareActivity</code>. |
michael@0 | 26 | */ |
michael@0 | 27 | public class LocaleAware { |
michael@0 | 28 | @TargetApi(Build.VERSION_CODES.GINGERBREAD) |
michael@0 | 29 | public static void initializeLocale(Context context) { |
michael@0 | 30 | final LocaleManager localeManager = BrowserLocaleManager.getInstance(); |
michael@0 | 31 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { |
michael@0 | 32 | localeManager.getAndApplyPersistedLocale(context); |
michael@0 | 33 | } else { |
michael@0 | 34 | final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads(); |
michael@0 | 35 | StrictMode.allowThreadDiskWrites(); |
michael@0 | 36 | try { |
michael@0 | 37 | localeManager.getAndApplyPersistedLocale(context); |
michael@0 | 38 | } finally { |
michael@0 | 39 | StrictMode.setThreadPolicy(savedPolicy); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | public static class LocaleAwareFragmentActivity extends FragmentActivity { |
michael@0 | 45 | @Override |
michael@0 | 46 | protected void onCreate(Bundle savedInstanceState) { |
michael@0 | 47 | LocaleAware.initializeLocale(getApplicationContext()); |
michael@0 | 48 | super.onCreate(savedInstanceState); |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | public static class LocaleAwareActivity extends Activity { |
michael@0 | 53 | @Override |
michael@0 | 54 | protected void onCreate(Bundle savedInstanceState) { |
michael@0 | 55 | LocaleAware.initializeLocale(getApplicationContext()); |
michael@0 | 56 | super.onCreate(savedInstanceState); |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | } |