Example usage for android.content Intent ACTION_CONFIGURATION_CHANGED

List of usage examples for android.content Intent ACTION_CONFIGURATION_CHANGED

Introduction

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

Prototype

String ACTION_CONFIGURATION_CHANGED

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

Click Source Link

Document

Broadcast Action: The current device android.content.res.Configuration (orientation, locale, etc) has changed.

Usage

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

private LauncherAppState() {
    if (sContext == null) {
        throw new IllegalStateException("LauncherAppState inited before app context set");
    }//from w  w  w. j  a v a  2  s.c  o  m

    Log.v(Launcher.TAG, "LauncherAppState inited");

    // set sIsScreenXLarge and mScreenDensity *before* creating icon cache
    mIsScreenLarge = isScreenLarge(sContext.getResources());
    mScreenDensity = sContext.getResources().getDisplayMetrics().density;

    recreateWidgetPreviewDb();
    mIconCache = new IconCache(sContext);
    mItemIdToViewId = new ArrayMap<>();

    mModel = new LauncherModel(this, mIconCache);
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
    launcherApps.addOnAppsChangedCallback(mModel);

    // Register intent receivers
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_LOCALE_CHANGED);
    filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    sContext.registerReceiver(mModel, filter);
}

From source file:com.chen.mail.browse.SendersView.java

private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) {
    if (sConfigurationChangedReceiver == null && resourceCachingRequired) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override/*from w  ww.  ja  v a  2s  . c  om*/
            public void onReceive(Context context, Intent intent) {
                sDraftSingularString = null;
                getSenderResources(context, true);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (sDraftSingularString == null) {
        Resources res = context.getResources();
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedString = res.getString(R.string.senders_elided);
        sDraftSingularString = res.getQuantityText(R.plurals.draft, 1);
        sDraftPluralString = res.getQuantityText(R.plurals.draft, 2);
        sDraftCountFormatString = res.getString(R.string.draft_count_format);
        sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance);
        sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance);
        sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance);
        sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersUnreadTextAppearance);
        sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance);
        sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersReadTextAppearance);
        sMessageCountSpacerString = res.getString(R.string.message_count_spacer);
        sSendingString = res.getString(R.string.sending);
        sBidiFormatter = BidiFormatter.getInstance();
    }
}

From source file:com.android.mail.browse.SendersView.java

private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) {
    if (sConfigurationChangedReceiver == null && resourceCachingRequired) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override/*from  w ww.j ava 2 s. co m*/
            public void onReceive(Context context, Intent intent) {
                sDraftSingularString = null;
                getSenderResources(context, true);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (sDraftSingularString == null) {
        Resources res = context.getResources();
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedString = res.getString(R.string.senders_elided);
        sDraftSingularString = res.getQuantityText(R.plurals.draft, 1);
        sDraftPluralString = res.getQuantityText(R.plurals.draft, 2);
        sDraftCountFormatString = res.getString(R.string.draft_count_format);
        sMeSubjectString = res.getString(R.string.me_subject_pronoun);
        sMeObjectString = res.getString(R.string.me_object_pronoun);
        sToHeaderString = res.getString(R.string.to_heading);
        sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance);
        sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance);
        sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance);
        sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceUnreadStyle);
        sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance);
        sRetryingStyleSpan = new TextAppearanceSpan(context, R.style.RetryingTextAppearance);
        sFailedStyleSpan = new TextAppearanceSpan(context, R.style.FailedTextAppearance);
        sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceReadStyle);
        sMessageCountSpacerString = res.getString(R.string.message_count_spacer);
        sSendingString = res.getString(R.string.sending);
        sRetryingString = res.getString(R.string.message_retrying);
        sFailedString = res.getString(R.string.message_failed);
        sBidiFormatter = BidiFormatter.getInstance();
    }
}

From source file:com.tct.mail.browse.SendersView.java

private static synchronized void getSenderResources(Context context, final boolean resourceCachingRequired) {
    if (sConfigurationChangedReceiver == null && resourceCachingRequired) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override/*  ww w  .ja  v a  2 s.  co m*/
            public void onReceive(Context context, Intent intent) {
                sDraftSingularString = null;
                getSenderResources(context, true);
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (sDraftSingularString == null) {
        Resources res = context.getResources();
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedString = res.getString(R.string.senders_elided);
        sDraftSingularString = res.getQuantityText(R.plurals.draft, 1);
        sDraftPluralString = res.getQuantityText(R.plurals.draft, 2);
        sDraftCountFormatString = res.getString(R.string.draft_count_format);
        sMeSubjectString = res.getString(R.string.me_subject_pronoun);
        sMeObjectString = res.getString(R.string.me_object_pronoun);
        sToHeaderString = res.getString(R.string.to_heading);
        sMessageInfoUnreadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoUnreadTextAppearance);
        sMessageInfoReadStyleSpan = new TextAppearanceSpan(context, R.style.MessageInfoReadTextAppearance);
        sDraftsStyleSpan = new TextAppearanceSpan(context, R.style.DraftTextAppearance);
        sUnreadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceUnreadStyle);
        sSendingStyleSpan = new TextAppearanceSpan(context, R.style.SendingTextAppearance);
        sQueuedStyleSpan = new TextAppearanceSpan(context, R.style.RetryingTextAppearance);
        sFailedStyleSpan = new TextAppearanceSpan(context, R.style.FailedTextAppearance);
        sReadStyleSpan = new TextAppearanceSpan(context, R.style.SendersAppearanceReadStyle);
        sMessageCountSpacerString = res.getString(R.string.message_count_spacer);
        sSendingString = res.getString(R.string.sending);
        sQueuedString = res.getString(R.string.message_retrying);
        sFailedString = res.getString(R.string.message_failed);
        sBidiFormatter = BidiFormatter.getInstance();
    }
}

From source file:com.achep.acdisplay.services.BathService.java

@Override
public void onCreate() {
    super.onCreate();

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mLanguage = getResources().getConfiguration().locale.getLanguage();

    // Listen for the config changes to update notification just
    // once locale has changed.
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    registerReceiver(mReceiver, intentFilter);

    synchronized (monitor) {
        sCreated = true;/* w  ww.  j  av a 2 s  . co m*/

        // Register for add / remove service events.
        intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_ADD_SERVICE);
        intentFilter.addAction(ACTION_REMOVE_SERVICE);
        mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
        mLocalBroadcastManager.registerReceiver(mReceiver, intentFilter);

        if (sServiceMap.isEmpty()) {
            stopSelf();
        } else {
            // Init all children
            Set<Map.Entry<Class, ChildService>> set = sServiceMap.entrySet();
            for (Map.Entry<Class, ChildService> entry : set) {
                ChildService child = entry.getValue();
                child.setContext(this);
                child.onCreate();

                mMap.put(entry.getKey(), child);
            }
            sServiceMap.clear();

            startForeground(App.ID_NOTIFY_BATH, buildNotification());
        }
    }
}

From source file:com.bullmobi.message.services.BathService.java

@Override
public void onCreate() {
    super.onCreate();

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mLanguage = getResources().getConfiguration().locale.getLanguage();

    // Listen for the config changes to update notification just
    // once locale has changed.
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    registerReceiver(mReceiver, intentFilter);

    synchronized (monitor) {
        sCreated = true;/*  ww w  .jav a 2  s.  c om*/
        //stop system Keyguard
        //          KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        //          KeyguardManager.KeyguardLock mKeyguardLock = km.newKeyguardLock("");
        //          mKeyguardLock.disableKeyguard();
        // Register for add / remove service events.
        intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_ADD_SERVICE);
        intentFilter.addAction(ACTION_REMOVE_SERVICE);
        mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
        mLocalBroadcastManager.registerReceiver(mReceiver, intentFilter);

        if (sServiceMap.isEmpty()) {
            stopSelf();
        } else {
            // Init all children
            Set<Map.Entry<Class, ChildService>> set = sServiceMap.entrySet();
            for (Map.Entry<Class, ChildService> entry : set) {
                ChildService child = entry.getValue();
                child.setContext(this);
                child.onCreate();

                mMap.put(entry.getKey(), child);
            }
            sServiceMap.clear();

            startForeground(App.ID_NOTIFY_BATH, buildNotification());
        }
    }
}

From source file:com.acrr.acdisplay.services.BathService.java

@Override
public void onCreate() {
    super.onCreate();
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mLanguage = getResources().getConfiguration().locale.getLanguage();

    // Listen for the config changes to update notification just
    // once locale has changed.
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    registerReceiver(mReceiver, intentFilter);

    synchronized (monitor) {
        sCreated = true;//from www.j a  va2s.c o m
        sRunning = true;

        // Register for add / remove service events.
        intentFilter = new IntentFilter();
        intentFilter.addAction(ACTION_ADD_SERVICE);
        intentFilter.addAction(ACTION_REMOVE_SERVICE);
        mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
        mLocalBroadcastManager.registerReceiver(mReceiver, intentFilter);

        if (sServiceMap.isEmpty()) {
            stopMySelf();
        } else {
            // Init all children
            Set<Map.Entry<Class, ChildService>> set = sServiceMap.entrySet();
            for (Map.Entry<Class, ChildService> entry : set) {
                ChildService child = entry.getValue();
                child.setContext(this);
                child.onCreate();

                mMap.put(entry.getKey(), child);
            }
            sServiceMap.clear();

            startForeground(App.ID_NOTIFY_BATH, buildNotification());
        }
    }
}

From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java

private synchronized void showInternal(@NonNull final Callback callback) {
    mHandler.post(new Runnable() {
        @Override//from w ww  .  j av  a 2  s  .c o  m
        public void run() {
            try {
                mPreview = new Preview(mContext);

                Point size = getDisplaySize();
                int pt = (int) (5 * getScaledDensity());
                WindowManager.LayoutParams l = new WindowManager.LayoutParams(pt, pt,
                        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                        PixelFormat.TRANSLUCENT);
                l.x = -size.x / 2;
                l.y = -size.y / 2;
                mWinMgr.addView(mPreview, l);

                mCamera = Camera.open(mCameraId);
                setRequestedPictureSize(mCamera);
                setRequestedPreviewSize(mCamera);
                mPreview.switchCamera(mCameraId, mCamera);
                mCamera.setPreviewCallback(CameraOverlay.this);
                mCamera.setErrorCallback(CameraOverlay.this);

                IntentFilter filter = new IntentFilter();
                filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
                mContext.registerReceiver(mOrientReceiver, filter);

                sendNotification();

                callback.onSuccess();
            } catch (Throwable t) {
                if (BuildConfig.DEBUG) {
                    Log.w("Overlay", "", t);
                }
                callback.onFail();
            }
        }
    });
}

From source file:org.ormma.controller.OrmmaDisplayController.java

public void startConfigurationListener() {
    try {// w  w  w  . j a  v  a 2  s  .  co m
        if (mBroadCastReceiver == null)
            mBroadCastReceiver = new OrmmaConfigurationBroadcastReceiver(this);
        mContext.registerReceiver(mBroadCastReceiver, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    } catch (Exception e) {
    }
}

From source file:org.apache.cordova.AndroidWebView.java

/**
 * Initialize webview./*from  ww  w. ja v  a  2  s  .co m*/
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setup() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    if (shouldRequestFocusOnInit()) {
        this.requestFocusFromTouch();
    }
    // Enable JavaScript
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2)
    try {
        Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class });

        String manufacturer = android.os.Build.MANUFACTURER;
        Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB
                && android.os.Build.MANUFACTURER.contains("HTC")) {
            gingerbread_getMethod.invoke(settings, true);
        }
    } catch (NoSuchMethodException e) {
        Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8");
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "Doing the NavDump failed with bad arguments");
    } catch (IllegalAccessException e) {
        Log.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore");
    } catch (InvocationTargetException e) {
        Log.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore.");
    }

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        Level16Apis.enableUniversalAccess(settings);
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = this.cordova.getActivity().getApplicationContext()
            .getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);

    //Determine whether we're in debug or release mode, and turn on Debugging!
    try {
        final String packageName = this.cordova.getActivity().getPackageName();
        final PackageManager pm = this.cordova.getActivity().getPackageManager();
        ApplicationInfo appInfo;

        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);

        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
                && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            setWebContentsDebuggingEnabled(true);
        }
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
        e.printStackTrace();
    } catch (NameNotFoundException e) {
        Log.d(TAG, "This should never happen: Your application's package can't be found.");
        e.printStackTrace();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    String pathToCache = this.cordova.getActivity().getApplicationContext()
            .getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setAppCachePath(pathToCache);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    this.updateUserAgentString();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                updateUserAgentString();
            }
        };
        this.cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405

    pluginManager = new PluginManager(this, this.cordova);
    jsMessageQueue = new NativeToJsMessageQueue(this, cordova);
    exposedJsApi = new AndroidExposedJsApi(pluginManager, jsMessageQueue);
    resourceApi = new CordovaResourceApi(this.getContext(), pluginManager);
    exposeJsInterface();
}