Java Code Examples for org.chromium.base.ApplicationStatus#hasVisibleActivities()

The following examples show how to use org.chromium.base.ApplicationStatus#hasVisibleActivities() . 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: LifecycleHook.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    Log.d(TAG, "onApplicationStateChange");
    ThreadUtils.assertOnUiThread();

    boolean newVisibility = ApplicationStatus.hasVisibleActivities();
    if (mIsApplicationVisible == newVisibility) return;

    Log.d(TAG, "Application visibilty changed to %s. Updating state of %d client(s).",
            newVisibility, mClientHelpers.size());

    mIsApplicationVisible = newVisibility;

    synchronized (mClientHelpers) {
        for (GoogleApiClientHelper clientHelper : mClientHelpers) {
            if (mIsApplicationVisible) clientHelper.restoreConnectedState();
            else clientHelper.scheduleDisconnection();
        }
    }
}
 
Example 2
Source File: LifecycleHook.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationStateChange(int newState) {
    Log.d(TAG, "onApplicationStateChange");
    ThreadUtils.assertOnUiThread();

    boolean newVisibility = ApplicationStatus.hasVisibleActivities();
    if (mIsApplicationVisible == newVisibility) return;

    Log.d(TAG, "Application visibilty changed to %s. Updating state of %d client(s).",
            newVisibility, mClientHelpers.size());

    mIsApplicationVisible = newVisibility;

    synchronized (mClientHelpers) {
        for (GoogleApiClientHelper clientHelper : mClientHelpers) {
            if (mIsApplicationVisible) clientHelper.restoreConnectedState();
            else clientHelper.scheduleDisconnection();
        }
    }
}
 
Example 3
Source File: AppBannerInfoBarDelegateAndroid.java    From delion with Apache License 2.0 5 votes vote down vote up
private ApplicationStatus.ApplicationStateListener createApplicationStateListener() {
    return new ApplicationStatus.ApplicationStateListener() {
        @Override
        public void onApplicationStateChange(int newState) {
            if (!ApplicationStatus.hasVisibleActivities()) return;
            nativeUpdateInstallState(mNativePointer);
        }
    };
}
 
Example 4
Source File: GoogleApiClientHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Tells the helper that we are going to use the connection. It should postpone disconnections
 * and make sure the client is connected.
 * This is useful if the client might be used when we are in the background.
 */
public void willUseConnection() {
    // Cancel and reschedule the disconnection if we are in the background. We do it early to
    // avoid race conditions between a disconnect on the UI thread and the connect below.
    if (!ApplicationStatus.hasVisibleActivities()) scheduleDisconnection();

    // The client might be disconnected if we were idle in the background for too long.
    if (!mClient.isConnected() && !mClient.isConnecting()) {
        Log.d(TAG, "Reconnecting the client.");
        mClient.connect();
    }
}
 
Example 5
Source File: UpgradeActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void continueApplicationLaunch() {
    if (mIsDestroyed) return;

    ApiCompatibilityUtils.finishAndRemoveTask(this);
    if (mIntentToFireAfterUpgrade != null && ApplicationStatus.hasVisibleActivities()) {
        startActivity(mIntentToFireAfterUpgrade);
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        mIntentToFireAfterUpgrade = null;
    }
}
 
Example 6
Source File: AccountsChangedReceiver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void continueHandleAccountChangeIfNeeded(final Context context, final Intent intent) {
    if (!AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(intent.getAction())) return;

    AccountTrackerService.get(context).invalidateAccountSeedStatus(
            false /* don't refresh right now */);
    boolean isChromeVisible = ApplicationStatus.hasVisibleActivities();
    if (isChromeVisible) {
        startBrowserIfNeededAndValidateAccounts(context);
    } else {
        // Notify SigninHelper of changed accounts (via shared prefs).
        SigninHelper.markAccountsChangedPref(context);
    }
    notifyAccountsChangedOnBrowserStartup(context, intent);
}
 
Example 7
Source File: PowerBroadcastReceiver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())
            && ApplicationStatus.hasVisibleActivities()) {
        mServiceRunnable.post();
        unregisterReceiver();
    }
}
 
Example 8
Source File: DownloadSnackbarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
public SnackbarManager getSnackbarManager() {
    Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (activity != null && ApplicationStatus.hasVisibleActivities()
            && activity instanceof SnackbarManager.SnackbarManageable) {
        return ((SnackbarManager.SnackbarManageable) activity).getSnackbarManager();
    }
    return null;
}
 
Example 9
Source File: PowerBroadcastReceiver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())
            && ApplicationStatus.hasVisibleActivities()) {
        mServiceRunnable.post();
        unregisterReceiver();
    }
}
 
Example 10
Source File: AppBannerInfoBarDelegateAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private ApplicationStatus.ApplicationStateListener createApplicationStateListener() {
    return new ApplicationStatus.ApplicationStateListener() {
        @Override
        public void onApplicationStateChange(int newState) {
            if (!ApplicationStatus.hasVisibleActivities()) return;
            nativeUpdateInstallState(mNativePointer);
        }
    };
}
 
Example 11
Source File: AccountsChangedReceiver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void continueHandleAccountChangeIfNeeded(final Context context) {
    AccountTrackerService.get().invalidateAccountSeedStatus(
            false /* don't refresh right now */);
    boolean isChromeVisible = ApplicationStatus.hasVisibleActivities();
    if (isChromeVisible) {
        startBrowserIfNeededAndValidateAccounts(context);
    } else {
        // Notify SigninHelper of changed accounts (via shared prefs).
        SigninHelper.markAccountsChangedPref(context);
    }
    notifyAccountsChangedOnBrowserStartup(context);
}
 
Example 12
Source File: OmahaClient.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether or not Chrome is currently being used actively.
 */
@VisibleForTesting
protected boolean isChromeBeingUsed() {
    boolean isChromeVisible = ApplicationStatus.hasVisibleActivities();
    boolean isScreenOn = ApiCompatibilityUtils.isInteractive(this);
    return isChromeVisible && isScreenOn;
}
 
Example 13
Source File: PowerBroadcastReceiver.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_SCREEN_ON.equals(intent.getAction())
            && ApplicationStatus.hasVisibleActivities()) {
        mServiceRunnable.post();
        unregisterReceiver();
    }
}
 
Example 14
Source File: DownloadSnackbarController.java    From delion with Apache License 2.0 5 votes vote down vote up
public SnackbarManager getSnackbarManager() {
    Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (activity != null && ApplicationStatus.hasVisibleActivities()
            && activity instanceof SnackbarManager.SnackbarManageable) {
        return ((SnackbarManager.SnackbarManageable) activity).getSnackbarManager();
    }
    return null;
}
 
Example 15
Source File: OfflinePageDownloadBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static ComponentName getComponentName() {
    if (!ApplicationStatus.hasVisibleActivities()) return null;

    Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (activity instanceof ChromeTabbedActivity) {
        return activity.getComponentName();
    }

    return null;
}
 
Example 16
Source File: DelayedInvalidationsController.java    From delion with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
boolean shouldNotifyInvalidation(Bundle extras) {
    return isManualRequest(extras) || ApplicationStatus.hasVisibleActivities();
}
 
Example 17
Source File: DelayedInvalidationsController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
boolean shouldNotifyInvalidation(Bundle extras) {
    return isManualRequest(extras) || ApplicationStatus.hasVisibleActivities();
}
 
Example 18
Source File: LifecycleHook.java    From delion with Apache License 2.0 4 votes vote down vote up
private LifecycleHook() {
    mClientHelpers = new HashSet<GoogleApiClientHelper>();
    mIsApplicationVisible = ApplicationStatus.hasVisibleActivities();
    ApplicationStatus.registerApplicationStateListener(this);
    Log.d(TAG, "lifecycle hook registered.");
}
 
Example 19
Source File: InvalidationClientService.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether Chrome is in the foreground. Local method so it can be overridden in tests.
 */
@VisibleForTesting
boolean isChromeInForeground() {
    return ApplicationStatus.hasVisibleActivities();
}
 
Example 20
Source File: LifecycleHook.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private LifecycleHook() {
    mClientHelpers = new HashSet<GoogleApiClientHelper>();
    mIsApplicationVisible = ApplicationStatus.hasVisibleActivities();
    ApplicationStatus.registerApplicationStateListener(this);
    Log.d(TAG, "lifecycle hook registered.");
}