Java Code Examples for org.chromium.chrome.browser.preferences.ChromePreferenceManager#getInstance()

The following examples show how to use org.chromium.chrome.browser.preferences.ChromePreferenceManager#getInstance() . 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: SigninPromoUtil.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance();
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get().isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startIfAllowed(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example 2
Source File: SigninPromoUtil.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(activity);
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get(activity).isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startAccountSigninActivity(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example 3
Source File: SigninPromoUtil.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(activity);
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get(activity).isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startIfAllowed(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example 4
Source File: NewTabPageRecyclerView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * To be triggered when a snippet is bound to a ViewHolder.
 */
public void onSnippetBound(View cardView) {
    // We only run if the feature is enabled and once per NTP.
    if (!SnippetsConfig.isIncreasedCardVisibilityEnabled() || mFirstCardAnimationRun) return;
    mFirstCardAnimationRun = true;

    // We only want an animation to run if we are not scrolled.
    if (computeVerticalScrollOffset() != 0) return;

    // We only show the animation a certain number of times to a user.
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(getContext());
    int animCount = manager.getNewTabPageFirstCardAnimationRunCount();
    if (animCount > CardsVariationParameters.getFirstCardAnimationMaxRuns()) return;
    manager.setNewTabPageFirstCardAnimationRunCount(animCount + 1);

    // We do not show the animation if the user has previously seen it then scrolled.
    if (manager.getCardsImpressionAfterAnimation()) return;

    // The peeking card bounces up twice from its position.
    ObjectAnimator animator = ObjectAnimator.ofFloat(cardView, View.TRANSLATION_Y,
            0f, -mPeekingCardBounceDistance, 0f, -mPeekingCardBounceDistance, 0f);
    animator.setStartDelay(PEEKING_CARD_ANIMATION_START_DELAY_MS);
    animator.setDuration(PEEKING_CARD_ANIMATION_TIME_MS);
    animator.setInterpolator(PEEKING_CARD_INTERPOLATOR);
    animator.start();
}
 
Example 5
Source File: ChromeWebApkHost.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Once native is loaded we can consult the command-line (set via about:flags) and also finch
 * state to see if we should enable WebAPKs.
 */
public static void cacheEnabledStateForNextLaunch() {
    ChromePreferenceManager preferenceManager =
            ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext());

    boolean wasCommandLineEnabled = preferenceManager.getCachedWebApkCommandLineEnabled();
    boolean isCommandLineEnabled = isCommandLineFlagSet();
    if (isCommandLineEnabled != wasCommandLineEnabled) {
        // {@link launchWebApkRequirementsDialogIfNeeded()} is skipped the first time Chrome is
        // launched so do caching here instead.
        preferenceManager.setCachedWebApkCommandLineEnabled(isCommandLineEnabled);
    }

    boolean wasEnabled = isEnabledInPrefs();
    boolean isEnabled = computeEnabled();
    if (isEnabled != wasEnabled) {
        Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnabled);
        preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled);
    }
}
 
Example 6
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    Context context = ContextUtils.getApplicationContext();

    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet(context)) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(context);
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example 7
Source File: ChromeWebApkHost.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Once native is loaded we can consult the command-line (set via about:flags) and also finch
 * state to see if we should enable WebAPKs.
 */
public static void cacheEnabledStateForNextLaunch() {
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance();

    boolean wasEnabled = isEnabledInPrefs();
    boolean isEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.IMPROVED_A2HS);
    if (isEnabled != wasEnabled) {
        Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnabled);
        preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled);
    }
}
 
Example 8
Source File: NewTabPageRecyclerView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onCardBound(CardViewHolder cardViewHolder) {
    if (cardViewHolder.getAdapterPosition() == getNewTabPageAdapter().getFirstCardPosition()) {
        updatePeekingCard(cardViewHolder);
    } else {
        cardViewHolder.setNotPeeking();
    }

    // Animate the peeking card.
    // We only run if the feature is enabled and once per NTP.
    if (!shouldAnimateFirstCard()) return;
    mFirstCardAnimationRun = true;

    // We only want an animation to run if we are not scrolled.
    if (computeVerticalScrollOffset() != 0) return;

    // We only show the animation a certain number of times to a user.
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance();
    int animCount = manager.getNewTabPageFirstCardAnimationRunCount();
    if (animCount > CardsVariationParameters.getFirstCardAnimationMaxRuns()) return;
    manager.setNewTabPageFirstCardAnimationRunCount(animCount + 1);

    // We do not show the animation if the user has previously seen it then scrolled.
    if (manager.getCardsImpressionAfterAnimation()) return;

    // The peeking card bounces up twice from its position.
    ObjectAnimator animator =
            ObjectAnimator.ofFloat(cardViewHolder.itemView, View.TRANSLATION_Y, 0f,
                    -mPeekingCardBounceDistance, 0f, -mPeekingCardBounceDistance, 0f);
    animator.setStartDelay(PEEKING_CARD_ANIMATION_START_DELAY_MS);
    animator.setDuration(PEEKING_CARD_ANIMATION_TIME_MS);
    animator.setInterpolator(PEEKING_CARD_INTERPOLATOR);
    animator.start();
}
 
Example 9
Source File: CtrSuppression.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an object that tracks impressions and clicks per user to produce CTR and
 * impression metrics.
 */
CtrSuppression() {
    mPreferenceManager = ChromePreferenceManager.getInstance();

    // This needs to be done last in this constructor because the native code may call
    // into this object.
    mNativePointer = nativeInit();
}
 
Example 10
Source File: FeatureUtilities.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet()) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance();
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example 11
Source File: ContextualSearchPolicy.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * ContextualSearchPolicy constructor.
 */
public ContextualSearchPolicy(ContextualSearchSelectionController selectionController,
        ContextualSearchNetworkCommunicator networkCommunicator) {
    mPreferenceManager = ChromePreferenceManager.getInstance();

    mSelectionController = selectionController;
    mNetworkCommunicator = networkCommunicator;
}
 
Example 12
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not chrome should attach the toolbar to the bottom of the screen.
 */
public static boolean isChromeHomeEnabled() {
    if (sChromeHomeEnabled == null) {
        ChromePreferenceManager manager =
                ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext());
        sChromeHomeEnabled = manager.isChromeHomeEnabled();
    }

    return sChromeHomeEnabled;
}
 
Example 13
Source File: CtrSuppression.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an object that tracks impressions and clicks per user to produce CTR and
 * impression metrics.
 * @param context An Android Context.
 */
CtrSuppression(Context context) {
    mPreferenceManager = ChromePreferenceManager.getInstance(context);

    // This needs to be done last in this constructor because the native code may call
    // into this object.
    mNativePointer = nativeInit();
}
 
Example 14
Source File: ContextualSearchPolicy.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @param context The Android Context.
 */
public ContextualSearchPolicy(Context context,
                              ContextualSearchSelectionController selectionController,
                              ContextualSearchNetworkCommunicator networkCommunicator) {
    mPreferenceManager = ChromePreferenceManager.getInstance(context);

    mSelectionController = selectionController;
    mNetworkCommunicator = networkCommunicator;
}
 
Example 15
Source File: ContextualSearchPolicy.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @param context The Android Context.
 */
public ContextualSearchPolicy(Context context,
                              ContextualSearchSelectionController selectionController,
                              ContextualSearchNetworkCommunicator networkCommunicator) {
    mPreferenceManager = ChromePreferenceManager.getInstance(context);

    mSelectionController = selectionController;
    mNetworkCommunicator = networkCommunicator;
}
 
Example 16
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void finishNativeInitialization() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.finishNativeInitialization");

        refreshSignIn();

        initializeUI();

        // The dataset has already been created, we need to initialize our state.
        mTabModelSelectorImpl.notifyChanged();

        ApiCompatibilityUtils.setWindowIndeterminateProgress(getWindow());

        // Check for incognito tabs to handle the case where Chrome was swiped away in the
        // background.
        if (TabWindowManager.getInstance().canDestroyIncognitoProfile()) {
            IncognitoNotificationManager.dismissIncognitoNotification();
        }

        // LocaleManager can only function after the native library is loaded.
        mLocaleManager = LocaleManager.getInstance();
        boolean searchEnginePromoShown =
                mLocaleManager.showSearchEnginePromoIfNeeded(this, null);

        ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance();
        // Promos can only be shown when we start with ACTION_MAIN intent and
        // after FRE is complete. Native initialization can finish before the FRE flow is
        // complete, and this will only show promos on the second opportunity. This is
        // because the FRE is shown on the first opportunity, and we don't want to show such
        // content back to back.
        if (!searchEnginePromoShown && !mIntentWithEffect
                && FirstRunStatus.getFirstRunFlowComplete()
                && preferenceManager.getPromosSkippedOnFirstStart()) {
            // Data reduction promo should be temporarily suppressed if the sign in promo is
            // shown to avoid nagging users too much.
            if (!SigninPromoUtil.launchSigninPromoIfNeeded(this)) {
                DataReductionPromoScreen.launchDataReductionPromo(this);
            }
        } else {
            preferenceManager.setPromosSkippedOnFirstStart(true);
        }

        super.finishNativeInitialization();
    } finally {
        TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization");
    }
}
 
Example 17
Source File: ContextualSearchSelectionController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Handles an unhandled tap gesture.
 */
void handleShowUnhandledTapUIIfNeeded(int x, int y) {
    mWasTapGestureDetected = false;
    // TODO(donnd): shouldn't we check == TAP here instead of LONG_PRESS?
    // TODO(donnd): refactor to avoid needing a new handler API method as suggested by Pedro.
    if (mSelectionType != SelectionType.LONG_PRESS) {
        mWasTapGestureDetected = true;
        long tapTimeNanoseconds = System.nanoTime();
        // TODO(donnd): add a policy method to get adjusted tap count.
        ChromePreferenceManager prefs = ChromePreferenceManager.getInstance(mActivity);
        int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount()
                - prefs.getContextualSearchTapQuickAnswerCount();
        // Explicitly destroy the old heuristics so native code can dispose data.
        if (mTapHeuristics != null) mTapHeuristics.destroy();
        mTapHeuristics =
                new TapSuppressionHeuristics(this, mLastTapState, x, y, adjustedTapsSinceOpen);
        // TODO(donnd): Move to be called when the panel closes to work with states that change.
        mTapHeuristics.logConditionState();
        // Tell the manager what it needs in order to log metrics on whether the tap would have
        // been suppressed if each of the heuristics were satisfied.
        mHandler.handleMetricsForWouldSuppressTap(mTapHeuristics);
        mX = x;
        mY = y;
        boolean shouldSuppressTap = mTapHeuristics.shouldSuppressTap();
        if (shouldSuppressTap) {
            mHandler.handleSuppressedTap();
        } else {
            // TODO(donnd): Find a better way to determine that a navigation will be triggered
            // by the tap, or merge with other time-consuming actions like gathering surrounding
            // text or detecting page mutations.
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mHandler.handleValidTap();
                }
            }, TAP_NAVIGATION_DETECTION_DELAY);
        }
        // Remember the tap state for subsequent tap evaluation.
        mLastTapState =
                new ContextualSearchTapState(x, y, tapTimeNanoseconds, shouldSuppressTap);
    } else {
        // Long press; reset last tap state.
        mLastTapState = null;
        mHandler.handleInvalidTap();
    }
}
 
Example 18
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void finishNativeInitialization() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.finishNativeInitialization");

        launchFirstRunExperience();

        refreshSignIn();

        ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(this);
        // Promos can only be shown when we start with ACTION_MAIN intent and
        // after FRE is complete.
        if (!mIntentWithEffect && FirstRunStatus.getFirstRunFlowComplete()) {
            // Only show promos on the second oppurtunity. This is because we show FRE on the
            // first oppurtunity, and we don't want to show such content back to back.
            if (preferenceManager.getPromosSkippedOnFirstStart()) {
                // Data reduction promo should be temporarily suppressed if the sign in promo is
                // shown to avoid nagging users too much.
                if (!SigninPromoUtil.launchSigninPromoIfNeeded(this)) {
                    DataReductionPromoScreen.launchDataReductionPromo(this);
                }
            } else {
                preferenceManager.setPromosSkippedOnFirstStart(true);
            }

            // Notify users experimenting with WebAPKs if they need to do extra steps to enable
            // WebAPKs.
            ChromeWebApkHost.launchWebApkRequirementsDialogIfNeeded(this);
        }

        initializeUI();

        // The dataset has already been created, we need to initialize our state.
        mTabModelSelectorImpl.notifyChanged();

        getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS,
                Window.PROGRESS_VISIBILITY_OFF);

        // Check for incognito tabs to handle the case where Chrome was swiped away in the
        // background.
        int incognitoCount = TabWindowManager.getInstance().getIncognitoTabCount();
        if (incognitoCount == 0) IncognitoNotificationManager.dismissIncognitoNotification();

        // LocaleManager can only function after the native library is loaded.
        mLocaleManager = LocaleManager.getInstance();
        mLocaleManager.showSearchEnginePromoIfNeeded(this);

        super.finishNativeInitialization();
    } finally {
        TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization");
    }
}
 
Example 19
Source File: ContextualSearchSelectionController.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Handles an unhandled tap gesture.
 */
void handleShowUnhandledTapUIIfNeeded(int x, int y) {
    mWasTapGestureDetected = false;
    // TODO(donnd): shouldn't we check == TAP here instead of LONG_PRESS?
    // TODO(donnd): refactor to avoid needing a new handler API method as suggested by Pedro.
    if (mSelectionType != SelectionType.LONG_PRESS) {
        mWasTapGestureDetected = true;
        long tapTimeNanoseconds = System.nanoTime();
        // TODO(donnd): add a policy method to get adjusted tap count.
        ChromePreferenceManager prefs = ChromePreferenceManager.getInstance(mActivity);
        int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount()
                - prefs.getContextualSearchTapQuickAnswerCount();
        TapSuppressionHeuristics tapHeuristics =
                new TapSuppressionHeuristics(this, mLastTapState, x, y, adjustedTapsSinceOpen);
        // TODO(donnd): Move to be called when the panel closes to work with states that change.
        tapHeuristics.logConditionState();
        // Tell the manager what it needs in order to log metrics on whether the tap would have
        // been suppressed if each of the heuristics were satisfied.
        mHandler.handleMetricsForWouldSuppressTap(tapHeuristics);
        mX = x;
        mY = y;
        boolean shouldSuppressTap = tapHeuristics.shouldSuppressTap();
        if (shouldSuppressTap) {
            mHandler.handleSuppressedTap();
        } else {
            // TODO(donnd): Find a better way to determine that a navigation will be triggered
            // by the tap, or merge with other time-consuming actions like gathering surrounding
            // text or detecting page mutations.
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mHandler.handleValidTap();
                }
            }, TAP_NAVIGATION_DETECTION_DELAY);
        }
        // Remember the tap state for subsequent tap evaluation.
        mLastTapState =
                new ContextualSearchTapState(x, y, tapTimeNanoseconds, shouldSuppressTap);
    } else {
        // Long press; reset last tap state.
        mLastTapState = null;
        mHandler.handleInvalidTap();
    }
}
 
Example 20
Source File: ChromeTabbedActivity.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void finishNativeInitialization() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.finishNativeInitialization");

        launchFirstRunExperience();

        ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(this);
        // Promos can only be shown when we start with ACTION_MAIN intent and
        // after FRE is complete.
        if (!mIntentWithEffect && FirstRunStatus.getFirstRunFlowComplete(this)) {
            // Only show promos on the second oppurtunity. This is because we show FRE on the
            // first oppurtunity, and we don't want to show such content back to back.
            if (preferenceManager.getPromosSkippedOnFirstStart()) {
                // Data reduction promo should be temporarily suppressed if the sign in promo is
                // shown to avoid nagging users too much.
                if (!SigninPromoUtil.launchSigninPromoIfNeeded(this)) {
                    DataReductionPromoScreen.launchDataReductionPromo(this);
                }
            } else {
                preferenceManager.setPromosSkippedOnFirstStart(true);
            }
        }

        refreshSignIn();

        initializeUI();

        // The dataset has already been created, we need to initialize our state.
        mTabModelSelectorImpl.notifyChanged();

        getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS,
                Window.PROGRESS_VISIBILITY_OFF);

        // Check for incognito tabs to handle the case where Chrome was swiped away in the
        // background.
        int incognitoCount = TabWindowManager.getInstance().getIncognitoTabCount();
        if (incognitoCount == 0) IncognitoNotificationManager.dismissIncognitoNotification();

        super.finishNativeInitialization();
    } finally {
        TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization");
    }
}