use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project Launcher3 by chislon.
the class LauncherTransitionable method showAppsCustomizeHelper.
private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded, final AppsCustomizePagedView.ContentType contentType) {
if (mStateAnimation != null) {
mStateAnimation.setDuration(0);
mStateAnimation.cancel();
mStateAnimation = null;
}
final Resources res = getResources();
final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
final View fromView = mWorkspace;
final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
final int startDelay = res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
setPivotsForZoom(toView, scale);
// Shrink workspaces away if going to AppsCustomize from workspace
Animator workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
// Set the content type for the all apps space
mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
}
if (animated) {
toView.setScaleX(scale);
toView.setScaleY(scale);
final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
scaleAnim.scaleX(1f).scaleY(1f).setDuration(duration).setInterpolator(new Workspace.ZoomOutInterpolator());
toView.setVisibility(View.VISIBLE);
toView.setAlpha(0f);
final ObjectAnimator alphaAnim = LauncherAnimUtils.ofFloat(toView, "alpha", 0f, 1f).setDuration(fadeDuration);
alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (animation == null) {
throw new RuntimeException("animation is null");
}
float t = (Float) animation.getAnimatedValue();
dispatchOnLauncherTransitionStep(fromView, t);
dispatchOnLauncherTransitionStep(toView, t);
}
});
// toView should appear right at the end of the workspace shrink
// animation
mStateAnimation = LauncherAnimUtils.createAnimatorSet();
mStateAnimation.play(scaleAnim).after(startDelay);
mStateAnimation.play(alphaAnim).after(startDelay);
mStateAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
// Prepare the position
toView.setTranslationX(0.0f);
toView.setTranslationY(0.0f);
toView.setVisibility(View.VISIBLE);
toView.bringToFront();
}
@Override
public void onAnimationEnd(Animator animation) {
dispatchOnLauncherTransitionEnd(fromView, animated, false);
dispatchOnLauncherTransitionEnd(toView, animated, false);
// Hide the search bar
if (mSearchDropTargetBar != null) {
mSearchDropTargetBar.hideSearchBar(false);
}
}
});
if (workspaceAnim != null) {
mStateAnimation.play(workspaceAnim);
}
boolean delayAnim = false;
dispatchOnLauncherTransitionPrepare(fromView, animated, false);
dispatchOnLauncherTransitionPrepare(toView, animated, false);
// yet, delay the animation until we get a layout pass
if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || (mWorkspace.getMeasuredWidth() == 0) || (toView.getMeasuredWidth() == 0)) {
delayAnim = true;
}
final AnimatorSet stateAnimation = mStateAnimation;
final Runnable startAnimRunnable = new Runnable() {
public void run() {
// we waited for a layout/draw pass
if (mStateAnimation != stateAnimation)
return;
setPivotsForZoom(toView, scale);
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView);
}
};
if (delayAnim) {
final ViewTreeObserver observer = toView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
startAnimRunnable.run();
toView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
} else {
startAnimRunnable.run();
}
} else {
toView.setTranslationX(0.0f);
toView.setTranslationY(0.0f);
toView.setScaleX(1.0f);
toView.setScaleY(1.0f);
toView.setVisibility(View.VISIBLE);
toView.bringToFront();
if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
// Hide the search bar
if (mSearchDropTargetBar != null) {
mSearchDropTargetBar.hideSearchBar(false);
}
}
dispatchOnLauncherTransitionPrepare(fromView, animated, false);
dispatchOnLauncherTransitionStart(fromView, animated, false);
dispatchOnLauncherTransitionEnd(fromView, animated, false);
dispatchOnLauncherTransitionPrepare(toView, animated, false);
dispatchOnLauncherTransitionStart(toView, animated, false);
dispatchOnLauncherTransitionEnd(toView, animated, false);
}
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project UltimateAndroid by cymcsg.
the class TextRoundCornerProgressBar method setup.
@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
int color;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
autoTextChange = typedArray.getBoolean(R.styleable.RoundCornerProgress_rcp_autoTextChange, false);
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundRadius, radius);
textViewValue = (TextView) findViewById(R.id.round_corner_progress_text);
textSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressSize, textSize);
textViewValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
textViewValue.setTextColor(typedArray.getColor(R.styleable.RoundCornerProgress_rcp_textProgressColor, textColor));
text = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgress);
text = (text == null) ? "" : text;
textViewValue.setText(text);
textPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressPadding, textPadding);
textViewValue.setPadding(textPadding, 0, textPadding, 0);
textUnit = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgressUnit);
textUnit = (textUnit == null) ? "" : textUnit;
textWidth = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressWidth, textWidth);
layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
layoutBackground.setPadding(padding, padding, padding, padding);
if (!isBackgroundColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
setBackgroundColor(color);
}
ViewTreeObserver observer = layoutBackground.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int height = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
backgroundWidth = layoutBackground.getMeasuredWidth() - textWidth;
height = layoutBackground.getMeasuredHeight();
} else {
backgroundWidth = layoutBackground.getWidth() - textWidth;
height = layoutBackground.getHeight();
}
backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) layoutBackground.getLayoutParams();
params.width = backgroundWidth;
params.height = backgroundHeight;
layoutBackground.setLayoutParams(params);
setProgress(progress);
}
});
layoutProgress = (LinearLayout) findViewById(R.id.round_corner_progress_progress);
if (!isProgressColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_progressColor, progressColor);
setProgressColor(color);
}
if (!isMaxProgressSetBeforeDraw) {
max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
}
if (!isProgressSetBeforeDraw) {
progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
}
typedArray.recycle();
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project android-app by eoecn.
the class XListView method initWithContext.
private void initWithContext(Context context) {
mScroller = new Scroller(context, new DecelerateInterpolator());
// XListView need the scroll event, and it will dispatch the event to
// user's listener (as a proxy).
super.setOnScrollListener(this);
// init header view
mHeaderView = new XListViewHeader(context);
mHeaderViewContent = (RelativeLayout) mHeaderView.findViewById(R.id.xlistview_header_content);
mHeaderTimeView = (TextView) mHeaderView.findViewById(R.id.xlistview_header_time);
addHeaderView(mHeaderView);
// init footer view
mFooterView = new XListViewFooter(context);
// init header height
mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mHeaderViewHeight = mHeaderViewContent.getHeight();
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project Libraries-for-Android-Developers by eoecn.
the class XListView method initWithContext.
private void initWithContext(Context context) {
mScroller = new Scroller(context, new DecelerateInterpolator());
// XListView need the scroll event, and it will dispatch the event to
// user's listener (as a proxy).
super.setOnScrollListener(this);
// init header view
mHeaderView = new XListViewHeader(context);
mHeaderViewContent = (RelativeLayout) mHeaderView.findViewById(R.id.xlistview_header_content);
mHeaderTimeView = (TextView) mHeaderView.findViewById(R.id.xlistview_header_time);
addHeaderView(mHeaderView);
// init footer view
mFooterView = new XListViewFooter(context);
// init header height
mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@Override
public void onGlobalLayout() {
mHeaderViewHeight = mHeaderViewContent.getHeight();
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
use of android.view.ViewTreeObserver.OnGlobalLayoutListener in project android_frameworks_base by ParanoidAndroid.
the class RecentsHorizontalScrollView method update.
private void update() {
for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
View v = mLinearLayout.getChildAt(i);
addToRecycledViews(v);
mAdapter.recycleView(v);
}
LayoutTransition transitioner = getLayoutTransition();
setLayoutTransition(null);
mLinearLayout.removeAllViews();
Iterator<View> recycledViews = mRecycledViews.iterator();
for (int i = 0; i < mAdapter.getCount(); i++) {
View old = null;
if (recycledViews.hasNext()) {
old = recycledViews.next();
recycledViews.remove();
old.setVisibility(VISIBLE);
}
final View view = mAdapter.getView(i, old, mLinearLayout);
if (mPerformanceHelper != null) {
mPerformanceHelper.addViewCallback(view);
}
OnTouchListener noOpListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
};
view.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mCallback.dismiss();
}
});
// We don't want a click sound when we dimiss recents
view.setSoundEffectsEnabled(false);
OnClickListener launchAppListener = new OnClickListener() {
public void onClick(View v) {
mCallback.handleOnClick(view);
}
};
RecentsPanelView.ViewHolder holder = (RecentsPanelView.ViewHolder) view.getTag();
final View thumbnailView = holder.thumbnailView;
OnLongClickListener longClickListener = new OnLongClickListener() {
public boolean onLongClick(View v) {
final View anchorView = view.findViewById(R.id.app_description);
mCallback.handleLongPress(view, anchorView, thumbnailView);
return true;
}
};
thumbnailView.setClickable(true);
thumbnailView.setOnClickListener(launchAppListener);
thumbnailView.setOnLongClickListener(longClickListener);
// We don't want to dismiss recents if a user clicks on the app title
// (we also don't want to launch the app either, though, because the
// app title is a small target and doesn't have great click feedback)
final View appTitle = view.findViewById(R.id.app_label);
appTitle.setContentDescription(" ");
appTitle.setOnTouchListener(noOpListener);
mLinearLayout.addView(view);
}
setLayoutTransition(transitioner);
// Scroll to end after initial layout.
final OnGlobalLayoutListener updateScroll = new OnGlobalLayoutListener() {
public void onGlobalLayout() {
mLastScrollPosition = scrollPositionOfMostRecent();
scrollTo(mLastScrollPosition, 0);
final ViewTreeObserver observer = getViewTreeObserver();
if (observer.isAlive()) {
observer.removeOnGlobalLayoutListener(this);
}
}
};
getViewTreeObserver().addOnGlobalLayoutListener(updateScroll);
}
Aggregations