This source file includes following definitions.
- onInterceptTouchEvent
- onTouchEvent
- getBoundaryHeight
- hasChildView
- detachCurrentView
- addChildView
- prepareTransition
- startTransition
- finishTransition
- getViewToShowHeight
- getViewToHideHeight
- getTransitionHeightDifference
- getAnimationsForTransition
- getClippingRect
package org.chromium.chrome.browser.infobar;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import java.util.ArrayList;
public class ContentWrapperView extends FrameLayout {
private static final int CONTENT_INDEX = 0;
private final int mGravity;
private final boolean mInfoBarsFromTop;
private final InfoBar mInfoBar;
private View mViewToHide;
private View mViewToShow;
public ContentWrapperView(Context context, InfoBar infoBar, int backgroundType, View panel,
boolean infoBarsFromTop) {
super(context);
mInfoBar = infoBar;
mGravity = infoBarsFromTop ? Gravity.BOTTOM : Gravity.TOP;
mInfoBarsFromTop = infoBarsFromTop;
int separatorBackground = R.color.infobar_info_background_separator;
int layoutBackground = R.drawable.infobar_info_background;
if (backgroundType == InfoBar.BACKGROUND_TYPE_WARNING) {
layoutBackground = R.drawable.infobar_warning_background;
separatorBackground = R.color.infobar_warning_background_separator;
}
Resources resources = context.getResources();
LayoutParams wrapParams = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
setLayoutParams(wrapParams);
ApiCompatibilityUtils.setBackgroundForView(this, resources.getDrawable(layoutBackground));
View separator = new View(context);
separator.setBackgroundColor(resources.getColor(separatorBackground));
addView(separator, new LayoutParams(LayoutParams.MATCH_PARENT, getBoundaryHeight(context),
mGravity));
addChildView(panel);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return !mInfoBar.areControlsEnabled();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
private int getBoundaryHeight(Context context) {
float density = context.getResources().getDisplayMetrics().density;
return density < 2.0f ? 1 : 2;
}
public boolean hasChildView() {
return getChildCount() > 1;
}
public View detachCurrentView() {
assert getChildCount() > 1;
View view = getChildAt(CONTENT_INDEX);
removeView(view);
return view;
}
private void addChildView(View viewToAdd) {
addView(viewToAdd, CONTENT_INDEX, new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, mGravity));
}
public void prepareTransition(View viewToShow) {
assert mViewToHide == null && mViewToShow == null;
assert getChildCount() <= 2;
if (hasChildView()) {
mViewToHide = getChildAt(CONTENT_INDEX);
}
mViewToShow = viewToShow;
assert mViewToHide != null || mViewToShow != null;
assert mViewToHide != mViewToShow;
}
public void startTransition() {
if (mViewToShow != null) {
ViewParent parent = mViewToShow.getParent();
assert parent != null && parent instanceof ViewGroup;
((ViewGroup) parent).removeView(mViewToShow);
addChildView(mViewToShow);
if (mViewToHide != null) mViewToShow.setAlpha(0.0f);
if (mInfoBarsFromTop && getViewToShowHeight() > getViewToHideHeight()) {
getLayoutParams().height = getViewToShowHeight();
int translation = getTransitionHeightDifference();
for (int i = 0; i < getChildCount(); ++i) {
View v = getChildAt(i);
v.setTop(v.getTop() + translation);
v.setBottom(v.getBottom() + translation);
}
}
}
}
public void finishTransition() {
if (mViewToHide != null) {
removeView(mViewToHide);
}
getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
requestLayout();
mViewToHide = null;
mViewToShow = null;
mInfoBar.setControlsEnabled(true);
}
private int getViewToShowHeight() {
return mViewToShow == null ? 0 : mViewToShow.getHeight();
}
private int getViewToHideHeight() {
return mViewToHide == null ? 0 : mViewToHide.getHeight();
}
public int getTransitionHeightDifference() {
return getViewToShowHeight() - getViewToHideHeight();
}
public void getAnimationsForTransition(ArrayList<Animator> animators) {
if (mViewToHide != null && mViewToShow != null) {
ObjectAnimator hideAnimator;
hideAnimator = ObjectAnimator.ofFloat(mViewToHide, "alpha", 1.0f, 0.0f);
animators.add(hideAnimator);
ObjectAnimator showAnimator;
showAnimator = ObjectAnimator.ofFloat(mViewToShow, "alpha", 0.0f, 1.0f);
animators.add(showAnimator);
}
}
public Rect getClippingRect() {
int maxHeight = Math.max(getViewToHideHeight(), getViewToShowHeight());
return new Rect(getLeft(), getTop(), getRight(), getTop() + maxHeight);
}
}