org.chromium.base.ApplicationStatus.ActivityStateListener Java Examples

The following examples show how to use org.chromium.base.ApplicationStatus.ActivityStateListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChromeBrowserInitializer.java    From delion with Apache License 2.0 6 votes vote down vote up
private ActivityStateListener createActivityStateListener() {
    return new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) {
                // Android destroys Activities at some point after a locale change, but doesn't
                // kill the process.  This can lead to a bug where Chrome is halfway RTL, where
                // stale natively-loaded resources are not reloaded (http://crbug.com/552618).
                if (!mInitialLocale.equals(Locale.getDefault())) {
                    Log.e(TAG, "Killing process because of locale change.");
                    Process.killProcess(Process.myPid());
                }

                DeviceFormFactor.resetValuesIfNeeded(mApplication);
            }
        }
    };
}
 
Example #2
Source File: ChromeBrowserInitializer.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private ActivityStateListener createActivityStateListener() {
    return new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) {
                // Android destroys Activities at some point after a locale change, but doesn't
                // kill the process.  This can lead to a bug where Chrome is halfway RTL, where
                // stale natively-loaded resources are not reloaded (http://crbug.com/552618).
                if (!mInitialLocale.equals(Locale.getDefault())) {
                    Log.e(TAG, "Killing process because of locale change.");
                    Process.killProcess(Process.myPid());
                }

                DeviceFormFactor.resetValuesIfNeeded(mApplication);
            }
        }
    };
}
 
Example #3
Source File: ChromeBrowserInitializer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private ActivityStateListener createActivityStateListener() {
    return new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) {
                // Android destroys Activities at some point after a locale change, but doesn't
                // kill the process.  This can lead to a bug where Chrome is halfway RTL, where
                // stale natively-loaded resources are not reloaded (http://crbug.com/552618).
                if (!mInitialLocale.equals(Locale.getDefault())) {
                    Log.e(TAG, "Killing process because of locale change.");
                    Process.killProcess(Process.myPid());
                }

                DeviceFormFactor.resetValuesIfNeeded(mApplication);
            }
        }
    };
}
 
Example #4
Source File: OfflinePageTabObserver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static void ensureObserverMapInitialized() {
    if (sObservers != null) return;
    sObservers = new HashMap<>();
    ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState != ActivityState.DESTROYED) return;
            OfflinePageTabObserver observer = sObservers.remove(activity);
            if (observer == null) return;
            observer.destroy();
        }
    });
}
 
Example #5
Source File: SyncController.java    From delion with Apache License 2.0 4 votes vote down vote up
private SyncController(Context context) {
    mContext = context;
    mChromeSigninController = ChromeSigninController.get(mContext);
    AndroidSyncSettings.registerObserver(context, this);
    mProfileSyncService = ProfileSyncService.get();
    mProfileSyncService.addSyncStateChangedListener(this);
    mProfileSyncService.setMasterSyncEnabledProvider(
            new ProfileSyncService.MasterSyncEnabledProvider() {
                public boolean isMasterSyncEnabled() {
                    return AndroidSyncSettings.isMasterSyncEnabled(mContext);
                }
            });

    setSessionsId();

    // Create the SyncNotificationController.
    mSyncNotificationController = new SyncNotificationController(
            mContext, PassphraseActivity.class, AccountManagementFragment.class);
    mProfileSyncService.addSyncStateChangedListener(mSyncNotificationController);

    updateSyncStateFromAndroid();

    // When the application gets paused, tell sync to flush the directory to disk.
    ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.PAUSED) {
                mProfileSyncService.flushDirectory();
            }
        }
    });

    GmsCoreSyncListener gmsCoreSyncListener =
            ((ChromeApplication) context.getApplicationContext()).createGmsCoreSyncListener();
    if (gmsCoreSyncListener != null) {
        mProfileSyncService.addSyncStateChangedListener(gmsCoreSyncListener);
    }

    SigninManager.get(mContext).addSignInStateObserver(new SigninManager.SignInStateObserver() {
        @Override
        public void onSignedIn() {
            mProfileSyncService.requestStart();
        }

        @Override
        public void onSignedOut() {}
    });
}
 
Example #6
Source File: SyncController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private SyncController(Context context) {
    mContext = context;
    mChromeSigninController = ChromeSigninController.get(mContext);
    AndroidSyncSettings.registerObserver(context, this);
    mProfileSyncService = ProfileSyncService.get();
    mProfileSyncService.addSyncStateChangedListener(this);
    mProfileSyncService.setMasterSyncEnabledProvider(
            new ProfileSyncService.MasterSyncEnabledProvider() {
                public boolean isMasterSyncEnabled() {
                    return AndroidSyncSettings.isMasterSyncEnabled(mContext);
                }
            });

    setSessionsId();

    // Create the SyncNotificationController.
    mSyncNotificationController = new SyncNotificationController(
            mContext, PassphraseActivity.class, AccountManagementFragment.class);
    mProfileSyncService.addSyncStateChangedListener(mSyncNotificationController);

    updateSyncStateFromAndroid();

    // When the application gets paused, tell sync to flush the directory to disk.
    ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.PAUSED) {
                mProfileSyncService.flushDirectory();
            }
        }
    });

    GmsCoreSyncListener gmsCoreSyncListener =
            ((ChromeApplication) context.getApplicationContext()).createGmsCoreSyncListener();
    if (gmsCoreSyncListener != null) {
        mProfileSyncService.addSyncStateChangedListener(gmsCoreSyncListener);
    }

    SigninManager.get(mContext).addSignInStateObserver(new SigninManager.SignInStateObserver() {
        @Override
        public void onSignedIn() {
            mProfileSyncService.requestStart();
        }

        @Override
        public void onSignedOut() {}
    });
}
 
Example #7
Source File: SyncController.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private SyncController(Context context) {
    mContext = context;
    mChromeSigninController = ChromeSigninController.get();
    AndroidSyncSettings.registerObserver(context, this);
    mProfileSyncService = ProfileSyncService.get();
    mProfileSyncService.addSyncStateChangedListener(this);
    mProfileSyncService.setMasterSyncEnabledProvider(
            new ProfileSyncService.MasterSyncEnabledProvider() {
                @Override
                public boolean isMasterSyncEnabled() {
                    return AndroidSyncSettings.isMasterSyncEnabled(mContext);
                }
            });

    setSessionsId();

    // Create the SyncNotificationController.
    mSyncNotificationController = new SyncNotificationController(
            mContext, PassphraseActivity.class, AccountManagementFragment.class);
    mProfileSyncService.addSyncStateChangedListener(mSyncNotificationController);

    updateSyncStateFromAndroid();

    // When the application gets paused, tell sync to flush the directory to disk.
    ApplicationStatus.registerStateListenerForAllActivities(new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.PAUSED) {
                mProfileSyncService.flushDirectory();
            }
        }
    });

    GmsCoreSyncListener gmsCoreSyncListener = AppHooks.get().createGmsCoreSyncListener();
    if (gmsCoreSyncListener != null) {
        mProfileSyncService.addSyncStateChangedListener(gmsCoreSyncListener);
    }

    SigninManager.get(mContext).addSignInStateObserver(new SigninManager.SignInStateObserver() {
        @Override
        public void onSignedIn() {
            mProfileSyncService.requestStart();
        }

        @Override
        public void onSignedOut() {}
    });
}