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

The following examples show how to use org.chromium.chrome.browser.preferences.ChromePreferenceManager#getContextualSearchTapQuickAnswerCount() . 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: ContextualSearchSelectionController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Handles Tap suppression by making a callback to either the handler's #handleSuppressedTap()
 * or #handleNonSuppressedTap() after a possible delay.
 * This should be called when the context is fully built (by gathering surrounding text
 * if needed, etc) but before showing any UX.
 */
void handleShouldSuppressTap() {
    int x = (int) mX;
    int y = (int) mY;

    // TODO(donnd): add a policy method to get adjusted tap count.
    ChromePreferenceManager prefs = ChromePreferenceManager.getInstance();
    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);

    boolean shouldSuppressTap = tapHeuristics.shouldSuppressTap();
    if (mTapTimeNanoseconds != 0) {
        // Remember the tap state for subsequent tap evaluation.
        mLastTapState =
                new ContextualSearchTapState(x, y, mTapTimeNanoseconds, shouldSuppressTap);
    } else {
        mLastTapState = null;
    }

    if (shouldSuppressTap) {
        mHandler.handleSuppressedTap();
    } else {
        mHandler.handleNonSuppressedTap();
    }
}
 
Example 2
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 3
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();
    }
}