use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.
the class LocationBarPhone method finishUrlFocusChange.
/**
* Handles any actions to be performed after all other actions triggered by the URL focus
* change. This will be called after any animations are performed to transition from one
* focus state to the other.
* @param hasFocus Whether the URL field has gained focus.
*/
public void finishUrlFocusChange(boolean hasFocus) {
final WindowDelegate windowDelegate = getWindowDelegate();
if (!hasFocus) {
// Remove the selection from the url text. The ending selection position
// will determine the scroll position when the url field is restored. If
// we do not clear this, it will scroll to the end of the text when you
// enter/exit the tab stack.
// We set the selection to 0 instead of removing the selection to avoid a crash that
// happens if you clear the selection instead.
//
// Triggering the bug happens by:
// 1.) Selecting some portion of the URL (where the two selection handles
// appear)
// 2.) Trigger a text change in the URL bar (i.e. by triggering a new URL load
// by a command line intent)
// 3.) Simultaneously moving one of the selection handles left and right. This will
// occasionally throw an AssertionError on the bounds of the selection.
Selection.setSelection(mUrlBar.getText(), 0);
// The animation rendering may not yet be 100% complete and hiding the keyboard makes
// the animation quite choppy.
postDelayed(new Runnable() {
@Override
public void run() {
UiUtils.hideKeyboard(mUrlBar);
}
}, KEYBOARD_HIDE_DELAY_MS);
// of time in hopes the keyboard will be completely hidden before making this change).
if (mKeyboardResizeModeTask == null && windowDelegate.getWindowSoftInputMode() != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
mKeyboardResizeModeTask = new Runnable() {
@Override
public void run() {
windowDelegate.setWindowSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
mKeyboardResizeModeTask = null;
}
};
postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS);
}
mUrlActionsContainer.setVisibility(GONE);
} else {
if (mKeyboardResizeModeTask != null) {
removeCallbacks(mKeyboardResizeModeTask);
mKeyboardResizeModeTask = null;
}
if (windowDelegate.getWindowSoftInputMode() != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) {
windowDelegate.setWindowSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
UiUtils.showKeyboard(mUrlBar);
// updated to reflect the new position.
if (getSuggestionList() != null && getSuggestionList().isShown()) {
getSuggestionList().invalidateSuggestionViews();
}
}
setUrlFocusChangeInProgress(false);
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (hasFocus && ntp != null && ntp.isLocationBarShownInNTP()) {
fadeInOmniboxResultsContainerBackground();
}
}
use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.
the class LocationBarTablet method setUrlFocusChangePercent.
/**
* Updates percentage of current the URL focus change animation.
* @param percent 1.0 is 100% focused, 0 is completely unfocused.
*/
private void setUrlFocusChangePercent(float percent) {
mUrlFocusChangePercent = percent;
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (ntp != null)
ntp.setUrlFocusChangeAnimationPercent(percent);
}
use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.
the class ToolbarPhone method updateUrlExpansionAnimation.
/**
* Updates the parameters relating to expanding the location bar, as the result of either a
* focus change or scrolling the New Tab Page.
*/
private void updateUrlExpansionAnimation() {
if (mTabSwitcherState != STATIC_TAB) {
mToolbarButtonsContainer.setVisibility(VISIBLE);
return;
}
FrameLayout.LayoutParams locationBarLayoutParams = getFrameLayoutParams(mLocationBar);
int currentLeftMargin = locationBarLayoutParams.leftMargin;
int currentWidth = locationBarLayoutParams.width;
float locationBarBaseTranslationX = mUnfocusedLocationBarLayoutLeft - currentLeftMargin;
boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
if (isLocationBarRtl) {
locationBarBaseTranslationX += mUnfocusedLocationBarLayoutWidth - currentWidth;
}
locationBarBaseTranslationX *= 1f - mUrlExpansionPercent;
mLocationBarBackgroundNtpOffset.setEmpty();
mLocationBarNtpOffsetLeft = 0;
mLocationBarNtpOffsetRight = 0;
Tab currentTab = getToolbarDataProvider().getTab();
if (currentTab != null) {
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
// compensation that only applies during focus animations.
if (ntp != null && mUrlFocusChangeInProgress) {
ntp.setUrlFocusChangeAnimationPercent(mUrlFocusChangePercent);
}
if (isLocationBarShownInNTP()) {
updateNtpTransitionAnimation();
} else {
// Reset these values in case we transitioned to a different page during the
// transition.
resetNtpAnimationValues();
}
}
boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
float locationBarTranslationX;
// |mLocationBarBackgroundPadding|, because it might be different in incognito mode.
if (isRtl) {
locationBarTranslationX = locationBarBaseTranslationX + mLocationBarNtpOffsetRight - mLocationBar.getPaddingRight();
} else {
locationBarTranslationX = locationBarBaseTranslationX + mLocationBarNtpOffsetLeft + mLocationBar.getPaddingLeft();
}
mLocationBar.setTranslationX(locationBarTranslationX);
// Negate the location bar translation to keep the URL action container in the same
// place during the focus expansion.
float urlActionsTranslationX = 0;
if (!isLocationBarRtl || isRtl) {
urlActionsTranslationX = -locationBarBaseTranslationX;
}
if (isRtl) {
urlActionsTranslationX += mLocationBarNtpOffsetLeft - mLocationBarNtpOffsetRight;
} else {
urlActionsTranslationX += mLocationBarNtpOffsetRight - mLocationBarNtpOffsetLeft;
}
mUrlActionContainer.setTranslationX(urlActionsTranslationX);
mLocationBar.setUrlFocusChangePercent(mUrlExpansionPercent);
// Ensure the buttons are invisible after focusing the omnibox to prevent them from
// accepting click events.
int toolbarButtonVisibility = mUrlExpansionPercent == 1f ? INVISIBLE : VISIBLE;
mToolbarButtonsContainer.setVisibility(toolbarButtonVisibility);
if (mHomeButton.getVisibility() != GONE) {
mHomeButton.setVisibility(toolbarButtonVisibility);
}
// Force an invalidation of the location bar to properly handle the clipping of the URL
// bar text as a result of the url action container translations.
mLocationBar.invalidate();
invalidate();
}
use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.
the class LocationBarLayout method updateOmniboxResultsContainerBackground.
/**
* Set the background of the omnibox results container.
* @param visible Whether the background should be made visible.
*/
private void updateOmniboxResultsContainerBackground(boolean visible) {
if (getToolbarDataProvider() == null)
return;
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
boolean locationBarShownInNTP = ntp != null && ntp.isLocationBarShownInNTP();
if (visible) {
if (locationBarShownInNTP) {
mOmniboxResultsContainer.getBackground().setAlpha(0);
} else {
fadeInOmniboxResultsContainerBackground();
}
} else {
if (locationBarShownInNTP) {
updateOmniboxResultsContainerVisibility(false);
} else {
fadeOutOmniboxResultsContainerBackground();
}
}
}
use of org.chromium.chrome.browser.ntp.NewTabPage in project AndroidChromium by JackyAndroid.
the class ToolbarManager method shouldShowCusrsorInLocationBar.
private boolean shouldShowCusrsorInLocationBar() {
Tab tab = mToolbarModel.getTab();
if (tab == null)
return false;
NativePage nativePage = tab.getNativePage();
if (!(nativePage instanceof NewTabPage) && !(nativePage instanceof IncognitoNewTabPage)) {
return false;
}
Context context = mToolbar.getContext();
return DeviceFormFactor.isTablet(context) && context.getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;
}
Aggregations