Example usage for android.content Intent ACTION_LOCALE_CHANGED

List of usage examples for android.content Intent ACTION_LOCALE_CHANGED

Introduction

In this page you can find the example usage for android.content Intent ACTION_LOCALE_CHANGED.

Prototype

String ACTION_LOCALE_CHANGED

To view the source code for android.content Intent ACTION_LOCALE_CHANGED.

Click Source Link

Document

Broadcast Action: The current device's locale has changed.

Usage

From source file:im.vector.VectorApp.java

@Override
public void onCreate() {
    Log.d(LOG_TAG, "onCreate");
    super.onCreate();

    if (BuildConfig.DEBUG) {
        Stetho.initializeWithDefaults(this);
    }//w  w  w. j  a  va  2  s  .  c  o m

    instance = this;
    mCallsManager = new CallsManager(this);
    mActivityTransitionTimer = null;
    mActivityTransitionTimerTask = null;

    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        VERSION_BUILD = packageInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(LOG_TAG, "fails to retrieve the package info " + e.getMessage());
    }

    VECTOR_VERSION_STRING = Matrix.getInstance(this).getVersion(true, true);

    // not the first launch
    if (null != Matrix.getInstance(this).getDefaultSession()) {
        SDK_VERSION_STRING = Matrix.getInstance(this).getDefaultSession().getVersion(true);
    } else {
        SDK_VERSION_STRING = "";
    }

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        SHORT_VERSION = pInfo.versionName;
    } catch (Exception e) {
    }

    mLogsDirectoryFile = new File(getCacheDir().getAbsolutePath() + "/logs");

    org.matrix.androidsdk.util.Log.setLogDirectory(mLogsDirectoryFile);
    org.matrix.androidsdk.util.Log.init("RiotLog");

    // log the application version to trace update
    // useful to track backward compatibility issues

    Log.d(LOG_TAG, "----------------------------------------------------------------");
    Log.d(LOG_TAG, "----------------------------------------------------------------");
    Log.d(LOG_TAG, " Application version: " + VECTOR_VERSION_STRING);
    Log.d(LOG_TAG, " SDK version: " + SDK_VERSION_STRING);
    Log.d(LOG_TAG,
            " Local time: " + (new SimpleDateFormat("MM-dd HH:mm:ss.SSSZ", Locale.US)).format(new Date()));
    Log.d(LOG_TAG, "----------------------------------------------------------------");
    Log.d(LOG_TAG, "----------------------------------------------------------------\n\n\n\n");

    mRageShake = new RageShake(this);

    // init the REST client
    MXSession.initUserAgent(getApplicationContext());

    this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
        final Map<String, String> mLocalesByActivity = new HashMap<>();

        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            Log.d(LOG_TAG, "onActivityCreated " + activity);
            mCreatedActivities.add(activity.toString());
            ThemeUtils.setActivityTheme(activity);
            // piwik
            onNewScreen(activity);
        }

        @Override
        public void onActivityStarted(Activity activity) {
            Log.d(LOG_TAG, "onActivityStarted " + activity);
        }

        /**
         * Compute the locale status value
         * @param activity the activity
         * @return the local status value
         */
        private String getActivityLocaleStatus(Activity activity) {
            return getApplicationLocale().toString() + "_" + getFontScale() + "_"
                    + ThemeUtils.getApplicationTheme(activity);
        }

        @Override
        public void onActivityResumed(final Activity activity) {
            Log.d(LOG_TAG, "onActivityResumed " + activity);
            setCurrentActivity(activity);

            String activityKey = activity.toString();

            if (mLocalesByActivity.containsKey(activityKey)) {
                String prevActivityLocale = mLocalesByActivity.get(activityKey);

                if (!TextUtils.equals(prevActivityLocale, getActivityLocaleStatus(activity))) {
                    Log.d(LOG_TAG,
                            "## onActivityResumed() : restart the activity " + activity
                                    + " because of the locale update from " + prevActivityLocale + " to "
                                    + getActivityLocaleStatus(activity));
                    restartActivity(activity);
                    return;
                }
            }

            // it should never happen as there is a broadcast receiver (mLanguageReceiver)
            if (!TextUtils.equals(Locale.getDefault().toString(), getApplicationLocale().toString())) {
                Log.d(LOG_TAG,
                        "## onActivityResumed() : the locale has been updated to "
                                + Locale.getDefault().toString() + ", restore the expected value "
                                + getApplicationLocale().toString());
                updateApplicationSettings(getApplicationLocale(), getFontScale(),
                        ThemeUtils.getApplicationTheme(activity));
                restartActivity(activity);
            }

            listPermissionStatuses();
        }

        @Override
        public void onActivityPaused(Activity activity) {
            Log.d(LOG_TAG, "onActivityPaused " + activity);
            mLocalesByActivity.put(activity.toString(), getActivityLocaleStatus(activity));
            setCurrentActivity(null);
            onAppPause();
        }

        @Override
        public void onActivityStopped(Activity activity) {
            Log.d(LOG_TAG, "onActivityStopped " + activity);
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
            Log.d(LOG_TAG, "onActivitySaveInstanceState " + activity);
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            Log.d(LOG_TAG, "onActivityDestroyed " + activity);
            mCreatedActivities.remove(activity.toString());
            mLocalesByActivity.remove(activity.toString());

            if (mCreatedActivities.size() > 1) {
                Log.d(LOG_TAG, "onActivityDestroyed : \n" + mCreatedActivities);
            }
        }
    });

    // create the markdown parser
    try {
        mMarkdownParser = new VectorMarkdownParser(this);
    } catch (Exception e) {
        // reported by GA
        Log.e(LOG_TAG, "cannot create the mMarkdownParser " + e.getMessage());
    }

    // track external language updates
    // local update from the settings
    // or screen rotation !
    VectorApp.getInstance().registerReceiver(mLanguageReceiver, new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
    VectorApp.getInstance().registerReceiver(mLanguageReceiver,
            new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));

    PreferencesManager.fixMigrationIssues(this);
    initApplicationLocale();
}

From source file:com.mobileglobe.android.customdialer.common.model.AccountTypeManager.java

/**
 * Internal constructor that only performs initial parsing.
 *///from  w  w  w . j  av a  2 s .  c o  m
public AccountTypeManagerImpl(Context context) {
    mContext = context;
    mFallbackAccountType = new FallbackAccountType(context);

    mAccountManager = AccountManager.get(mContext);

    mListenerThread = new HandlerThread("AccountChangeListener");
    mListenerThread.start();
    mListenerHandler = new Handler(mListenerThread.getLooper()) {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case MESSAGE_LOAD_DATA:
                loadAccountsInBackground();
                break;
            case MESSAGE_PROCESS_BROADCAST_INTENT:
                processBroadcastIntent((Intent) msg.obj);
                break;
            }
        }
    };

    mInvitableAccountTypeCache = new InvitableAccountTypeCache();

    // Request updates when packages or accounts change
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    mContext.registerReceiver(mBroadcastReceiver, filter);
    IntentFilter sdFilter = new IntentFilter();
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mContext.registerReceiver(mBroadcastReceiver, sdFilter);

    // Request updates when locale is changed so that the order of each field will
    // be able to be changed on the locale change.
    filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiver(mBroadcastReceiver, filter);

    if (ActivityCompat.checkSelfPermission(mContext,
            Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    mAccountManager.addOnAccountsUpdatedListener(this, mListenerHandler, false);

    ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this);

    mListenerHandler.sendEmptyMessage(MESSAGE_LOAD_DATA);
}

From source file:com.android.contacts.model.AccountTypeManager.java

/**
 * Internal constructor that only performs initial parsing.
 *//* w ww.j av a  2 s. c om*/
public AccountTypeManagerImpl(Context context) {
    mContext = context;
    mLocalAccountLocator = DeviceLocalAccountLocator.create(context);
    mTypeProvider = new AccountTypeProvider(context);
    mFallbackAccountType = new FallbackAccountType(context);

    mAccountManager = AccountManager.get(mContext);

    mExecutor = ContactsExecutors.getDefaultThreadPoolExecutor();
    mMainThreadExecutor = ContactsExecutors.newHandlerExecutor(mMainThreadHandler);

    // Request updates when packages or accounts change
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    mContext.registerReceiver(mBroadcastReceiver, filter);
    IntentFilter sdFilter = new IntentFilter();
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mContext.registerReceiver(mBroadcastReceiver, sdFilter);

    // Request updates when locale is changed so that the order of each field will
    // be able to be changed on the locale change.
    filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiver(mBroadcastReceiver, filter);

    mAccountManager.addOnAccountsUpdatedListener(this, mMainThreadHandler, false);

    ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, this);

    if (Flags.getInstance().getBoolean(Experiments.CP2_DEVICE_ACCOUNT_DETECTION_ENABLED)) {
        // Observe changes to RAW_CONTACTS so that we will update the list of "Device" accounts
        // if a new device contact is added.
        mContext.getContentResolver().registerContentObserver(ContactsContract.RawContacts.CONTENT_URI,
                /* notifyDescendents */ true, new ContentObserver(mMainThreadHandler) {
                    @Override
                    public boolean deliverSelfNotifications() {
                        return true;
                    }

                    @Override
                    public void onChange(boolean selfChange) {
                        reloadLocalAccounts();
                    }

                    @Override
                    public void onChange(boolean selfChange, Uri uri) {
                        reloadLocalAccounts();
                    }
                });
    }
    loadAccountTypes();
}

From source file:com.android.leanlauncher.LauncherModel.java

/**
 * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
 * ACTION_PACKAGE_CHANGED.//from ww  w .  jav a  2  s . c  o  m
 */
@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG_RECEIVER)
        Log.d(TAG, "onReceive intent=" + intent);

    final String action = intent.getAction();
    if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
        // If we have changed locale we need to clear out the labels in all apps/workspace.
        forceReload();
    } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
        // Check if configuration change was an mcc/mnc change which would affect app resources
        // and we would need to clear out the labels in all apps/workspace. Same handling as
        // above for ACTION_LOCALE_CHANGED
        Configuration currentConfig = context.getResources().getConfiguration();
        if (mPreviousConfigMcc != currentConfig.mcc) {
            Log.d(TAG, "Reload apps on config change. curr_mcc:" + currentConfig.mcc + " prevmcc:"
                    + mPreviousConfigMcc);
            forceReload();
        }
        // Update previousConfig
        mPreviousConfigMcc = currentConfig.mcc;
    }
}

From source file:com.android.calendar.alerts.AlertService.java

void processMessage(Message msg) {
    Bundle bundle = (Bundle) msg.obj;/* w  w  w  .j a  v  a2  s. c  om*/

    // On reboot, update the notification bar with the contents of the
    // CalendarAlerts table.
    String action = bundle.getString("action");
    if (DEBUG) {
        Log.d(TAG, bundle.getLong(android.provider.CalendarContract.CalendarAlerts.ALARM_TIME) + " Action = "
                + action);
    }

    // Some OEMs had changed the provider's EVENT_REMINDER broadcast to their own event,
    // which broke our unbundled app's reminders.  So we added backup alarm scheduling to the
    // app, but we know we can turn it off if we ever receive the EVENT_REMINDER broadcast.
    boolean providerReminder = action.equals(android.provider.CalendarContract.ACTION_EVENT_REMINDER);
    if (providerReminder) {
        if (sReceivedProviderReminderBroadcast == null) {
            sReceivedProviderReminderBroadcast = Utils.getSharedPreference(this, PROVIDER_REMINDER_PREF_KEY,
                    false);
        }

        if (!sReceivedProviderReminderBroadcast) {
            sReceivedProviderReminderBroadcast = true;
            Log.d(TAG, "Setting key " + PROVIDER_REMINDER_PREF_KEY + " to: true");
            Utils.setSharedPreference(this, PROVIDER_REMINDER_PREF_KEY, true);
        }
    }

    if (providerReminder || action.equals(Intent.ACTION_PROVIDER_CHANGED)
            || action.equals(android.provider.CalendarContract.ACTION_EVENT_REMINDER)
            || action.equals(AlertReceiver.EVENT_REMINDER_APP_ACTION)
            || action.equals(Intent.ACTION_LOCALE_CHANGED)) {

        // b/7652098: Add a delay after the provider-changed event before refreshing
        // notifications to help issue with the unbundled app installed on HTC having
        // stale notifications.
        if (action.equals(Intent.ACTION_PROVIDER_CHANGED)) {
            try {
                Thread.sleep(5000);
            } catch (Exception e) {
                // Ignore.
            }
        }

        updateAlertNotification(this);
    } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
        // The provider usually initiates this setting up of alarms on startup,
        // but there was a bug (b/7221716) where a race condition caused this step to be
        // skipped, resulting in missed alarms.  This is a stopgap to minimize this bug
        // for devices that don't have the provider fix, by initiating this a 2nd time here.
        // However, it would still theoretically be possible to hit the race condition
        // the 2nd time and still miss alarms.
        //
        // TODO: Remove this when the provider fix is rolled out everywhere.
        Intent intent = new Intent();
        intent.setClass(this, InitAlarmsService.class);
        startService(intent);
    } else if (action.equals(Intent.ACTION_TIME_CHANGED)) {
        doTimeChanged();
    } else if (action.equals(AlertReceiver.ACTION_DISMISS_OLD_REMINDERS)) {
        dismissOldAlerts(this);
    } else {
        Log.w(TAG, "Invalid action: " + action);
    }

    // Schedule the alarm for the next upcoming reminder, if not done by the provider.
    if (sReceivedProviderReminderBroadcast == null || !sReceivedProviderReminderBroadcast) {
        Log.d(TAG, "Scheduling next alarm with AlarmScheduler. " + "sEventReminderReceived: "
                + sReceivedProviderReminderBroadcast);
        AlarmScheduler.scheduleNextAlarm(this);
    }
}