am 7ebde83a: am 6161c5b4: Merge "Floating toolbar no longer obstructs the soft keyboard." into mnc-dev
* commit '7ebde83a479f6447e0862e814830374a8477665b': Floating toolbar no longer obstructs the soft keyboard.
This commit is contained in:
@@ -37,7 +37,6 @@ import android.view.View.MeasureSpec;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowInsets;
|
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.AnimationSet;
|
import android.view.animation.AnimationSet;
|
||||||
@@ -436,8 +435,6 @@ public final class FloatingToolbar {
|
|||||||
// The "show" animation will make this visible.
|
// The "show" animation will make this visible.
|
||||||
mContentContainer.setAlpha(0);
|
mContentContainer.setAlpha(0);
|
||||||
}
|
}
|
||||||
refreshViewPort();
|
|
||||||
updateOverflowHeight(contentRect.top - (mMarginVertical * 2) - mViewPort.top);
|
|
||||||
refreshCoordinatesAndOverflowDirection(contentRect);
|
refreshCoordinatesAndOverflowDirection(contentRect);
|
||||||
preparePopupContent();
|
preparePopupContent();
|
||||||
mPopupWindow.showAtLocation(mParent, Gravity.NO_GRAVITY, mCoords.x, mCoords.y);
|
mPopupWindow.showAtLocation(mParent, Gravity.NO_GRAVITY, mCoords.x, mCoords.y);
|
||||||
@@ -501,7 +498,6 @@ public final class FloatingToolbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelOverflowAnimations();
|
cancelOverflowAnimations();
|
||||||
refreshViewPort();
|
|
||||||
refreshCoordinatesAndOverflowDirection(contentRect);
|
refreshCoordinatesAndOverflowDirection(contentRect);
|
||||||
preparePopupContent();
|
preparePopupContent();
|
||||||
mPopupWindow.update(mCoords.x, mCoords.y, getWidth(), getHeight());
|
mPopupWindow.update(mCoords.x, mCoords.y, getWidth(), getHeight());
|
||||||
@@ -529,28 +525,65 @@ public final class FloatingToolbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refreshCoordinatesAndOverflowDirection(Rect contentRect) {
|
private void refreshCoordinatesAndOverflowDirection(Rect contentRect) {
|
||||||
// NOTE: Ensure that mViewPort has been refreshed before this.
|
refreshViewPort();
|
||||||
|
|
||||||
|
int availableHeightAboveContent =
|
||||||
|
contentRect.top - mViewPort.top - 2 * mMarginVertical;
|
||||||
|
int availableHeightBelowContent =
|
||||||
|
mViewPort.bottom - contentRect.bottom - 2 * mMarginVertical;
|
||||||
|
int availableHeightThroughContent =
|
||||||
|
mViewPort.bottom - contentRect.top + getToolbarHeightWithVerticalMargin();
|
||||||
|
|
||||||
int x = contentRect.centerX() - getWidth() / 2;
|
int x = contentRect.centerX() - getWidth() / 2;
|
||||||
int y;
|
|
||||||
if (contentRect.top - getHeight() > mViewPort.top) {
|
|
||||||
y = contentRect.top - getHeight();
|
|
||||||
mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_UP;
|
|
||||||
} else if (contentRect.top - getToolbarHeightWithVerticalMargin() > mViewPort.top) {
|
|
||||||
y = contentRect.top - getToolbarHeightWithVerticalMargin();
|
|
||||||
mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_DOWN;
|
|
||||||
} else {
|
|
||||||
y = contentRect.bottom;
|
|
||||||
mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_DOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update x so that the toolbar isn't rendered behind the nav bar in landscape.
|
// Update x so that the toolbar isn't rendered behind the nav bar in landscape.
|
||||||
x = Math.max(0, Math.min(x, mViewPort.right - getWidth()));
|
x = Math.max(0, Math.min(x, mViewPort.right - getWidth()));
|
||||||
|
|
||||||
mCoords.set(x, y);
|
int y;
|
||||||
if (mOverflowPanel != null) {
|
if (mOverflowPanel == null) { // There is no overflow.
|
||||||
|
if (availableHeightAboveContent > getToolbarHeightWithVerticalMargin()) {
|
||||||
|
// There is enough space at the top of the content.
|
||||||
|
y = contentRect.top - getToolbarHeightWithVerticalMargin();
|
||||||
|
} else if (availableHeightBelowContent > getToolbarHeightWithVerticalMargin()) {
|
||||||
|
// There is enough space at the bottom of the content.
|
||||||
|
y = contentRect.bottom;
|
||||||
|
} else {
|
||||||
|
// Not enough space. Prefer to position as high as possible.
|
||||||
|
y = Math.max(
|
||||||
|
mViewPort.top,
|
||||||
|
contentRect.top - getToolbarHeightWithVerticalMargin());
|
||||||
|
}
|
||||||
|
} else { // There is an overflow.
|
||||||
|
if (availableHeightAboveContent > mOverflowPanel.getMinimumHeight()) {
|
||||||
|
// There is enough space at the top of the content rect for the overflow.
|
||||||
|
// Position above and open upwards.
|
||||||
|
updateOverflowHeight(availableHeightAboveContent);
|
||||||
|
y = contentRect.top - getHeight();
|
||||||
|
mOverflowDirection = OVERFLOW_DIRECTION_UP;
|
||||||
|
} else if (availableHeightAboveContent > getToolbarHeightWithVerticalMargin()
|
||||||
|
&& availableHeightThroughContent > mOverflowPanel.getMinimumHeight()) {
|
||||||
|
// There is enough space at the top of the content rect for the main panel
|
||||||
|
// but not the overflow.
|
||||||
|
// Position above but open downwards.
|
||||||
|
updateOverflowHeight(availableHeightThroughContent);
|
||||||
|
y = contentRect.top - getToolbarHeightWithVerticalMargin();
|
||||||
|
mOverflowDirection = OVERFLOW_DIRECTION_DOWN;
|
||||||
|
} else if (availableHeightBelowContent > mOverflowPanel.getMinimumHeight()) {
|
||||||
|
// There is enough space at the bottom of the content rect for the overflow.
|
||||||
|
// Position below and open downwards.
|
||||||
|
updateOverflowHeight(availableHeightBelowContent);
|
||||||
|
y = contentRect.bottom;
|
||||||
|
mOverflowDirection = OVERFLOW_DIRECTION_DOWN;
|
||||||
|
} else {
|
||||||
|
// Not enough space.
|
||||||
|
// Position at the bottom of the view port and open upwards.
|
||||||
|
updateOverflowHeight(mViewPort.height());
|
||||||
|
y = mViewPort.bottom - getHeight();
|
||||||
|
mOverflowDirection = OVERFLOW_DIRECTION_UP;
|
||||||
|
}
|
||||||
mOverflowPanel.setOverflowDirection(mOverflowDirection);
|
mOverflowPanel.setOverflowDirection(mOverflowDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mCoords.set(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getToolbarHeightWithVerticalMargin() {
|
private int getToolbarHeightWithVerticalMargin() {
|
||||||
@@ -837,13 +870,7 @@ public final class FloatingToolbar {
|
|||||||
|
|
||||||
|
|
||||||
private void refreshViewPort() {
|
private void refreshViewPort() {
|
||||||
mParent.getGlobalVisibleRect(mViewPort);
|
mParent.getWindowVisibleDisplayFrame(mViewPort);
|
||||||
WindowInsets windowInsets = mParent.getRootWindowInsets();
|
|
||||||
mViewPort.set(
|
|
||||||
mViewPort.left + windowInsets.getStableInsetLeft(),
|
|
||||||
mViewPort.top + windowInsets.getStableInsetTop(),
|
|
||||||
mViewPort.right - windowInsets.getStableInsetRight(),
|
|
||||||
mViewPort.bottom - windowInsets.getStableInsetBottom());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getToolbarWidth(int suggestedWidth) {
|
private int getToolbarWidth(int suggestedWidth) {
|
||||||
@@ -1139,6 +1166,12 @@ public final class FloatingToolbar {
|
|||||||
setListViewHeight();
|
setListViewHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMinimumHeight() {
|
||||||
|
return mContentView.getContext().getResources().
|
||||||
|
getDimensionPixelSize(R.dimen.floating_toolbar_minimum_overflow_height)
|
||||||
|
+ getEstimatedToolbarHeight(mContentView.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the content view of the overflow.
|
* Returns the content view of the overflow.
|
||||||
*/
|
*/
|
||||||
@@ -1173,13 +1206,18 @@ public final class FloatingToolbar {
|
|||||||
getDimensionPixelSize(R.dimen.floating_toolbar_maximum_overflow_height);
|
getDimensionPixelSize(R.dimen.floating_toolbar_maximum_overflow_height);
|
||||||
int minHeight = mContentView.getContext().getResources().
|
int minHeight = mContentView.getContext().getResources().
|
||||||
getDimensionPixelSize(R.dimen.floating_toolbar_minimum_overflow_height);
|
getDimensionPixelSize(R.dimen.floating_toolbar_minimum_overflow_height);
|
||||||
int availableHeight = mSuggestedHeight - (mSuggestedHeight % itemHeight)
|
int suggestedListViewHeight = mSuggestedHeight - (mSuggestedHeight % itemHeight)
|
||||||
- itemHeight; // reserve space for the back button.
|
- itemHeight; // reserve space for the back button.
|
||||||
ViewGroup.LayoutParams params = mListView.getLayoutParams();
|
ViewGroup.LayoutParams params = mListView.getLayoutParams();
|
||||||
if (availableHeight >= minHeight) {
|
if (suggestedListViewHeight <= 0) {
|
||||||
params.height = Math.min(Math.min(availableHeight, maxHeight), height);
|
// Invalid height. Use the maximum height available.
|
||||||
} else {
|
|
||||||
params.height = Math.min(maxHeight, height);
|
params.height = Math.min(maxHeight, height);
|
||||||
|
} else if (suggestedListViewHeight < minHeight) {
|
||||||
|
// Height is smaller than minimum allowed. Use minimum height.
|
||||||
|
params.height = minHeight;
|
||||||
|
} else {
|
||||||
|
// Use the suggested height. Cap it at the maximum available height.
|
||||||
|
params.height = Math.min(Math.min(suggestedListViewHeight, maxHeight), height);
|
||||||
}
|
}
|
||||||
mListView.setLayoutParams(params);
|
mListView.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
@@ -1360,6 +1398,7 @@ public final class FloatingToolbar {
|
|||||||
PopupWindow popupWindow = new PopupWindow(popupContentHolder);
|
PopupWindow popupWindow = new PopupWindow(popupContentHolder);
|
||||||
popupWindow.setWindowLayoutType(
|
popupWindow.setWindowLayoutType(
|
||||||
WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL);
|
WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL);
|
||||||
|
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
|
||||||
popupWindow.setAnimationStyle(0);
|
popupWindow.setAnimationStyle(0);
|
||||||
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
content.setLayoutParams(new ViewGroup.LayoutParams(
|
content.setLayoutParams(new ViewGroup.LayoutParams(
|
||||||
|
|||||||
Reference in New Issue
Block a user