mobile/android/base/widget/AnimatedHeightLayout.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.widget;
michael@0 6
michael@0 7 import org.mozilla.gecko.animation.HeightChangeAnimation;
michael@0 8
michael@0 9 import android.content.Context;
michael@0 10 import android.util.AttributeSet;
michael@0 11 import android.view.animation.Animation;
michael@0 12 import android.view.animation.DecelerateInterpolator;
michael@0 13 import android.widget.RelativeLayout;
michael@0 14
michael@0 15 public class AnimatedHeightLayout extends RelativeLayout {
michael@0 16 private static final String LOGTAG = "GeckoAnimatedHeightLayout";
michael@0 17 private static final int ANIMATION_DURATION = 100;
michael@0 18 private boolean mAnimating = false;
michael@0 19
michael@0 20 public AnimatedHeightLayout(Context context) {
michael@0 21 super(context, null);
michael@0 22 }
michael@0 23
michael@0 24 public AnimatedHeightLayout(Context context, AttributeSet attrs) {
michael@0 25 super(context, attrs, 0);
michael@0 26 }
michael@0 27
michael@0 28 public AnimatedHeightLayout(Context context, AttributeSet attrs, int defStyle) {
michael@0 29 super(context, attrs, defStyle);
michael@0 30 }
michael@0 31
michael@0 32 @Override
michael@0 33 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
michael@0 34 int oldHeight = getMeasuredHeight();
michael@0 35 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
michael@0 36 int newHeight = getMeasuredHeight();
michael@0 37
michael@0 38 if (!mAnimating && oldHeight != 0 && oldHeight != newHeight) {
michael@0 39 mAnimating = true;
michael@0 40 setMeasuredDimension(getMeasuredWidth(), oldHeight);
michael@0 41
michael@0 42 // Animate the difference of suggestion row height
michael@0 43 Animation anim = new HeightChangeAnimation(this, oldHeight, newHeight);
michael@0 44 anim.setDuration(ANIMATION_DURATION);
michael@0 45 anim.setInterpolator(new DecelerateInterpolator());
michael@0 46 anim.setAnimationListener(new Animation.AnimationListener() {
michael@0 47 @Override
michael@0 48 public void onAnimationStart(Animation animation) {}
michael@0 49 @Override
michael@0 50 public void onAnimationRepeat(Animation animation) {}
michael@0 51 @Override
michael@0 52 public void onAnimationEnd(Animation animation) {
michael@0 53 post(new Runnable() {
michael@0 54 @Override
michael@0 55 public void run() {
michael@0 56 finishAnimation();
michael@0 57 }
michael@0 58 });
michael@0 59 }
michael@0 60 });
michael@0 61 startAnimation(anim);
michael@0 62 }
michael@0 63 }
michael@0 64
michael@0 65 @Override
michael@0 66 protected void onDetachedFromWindow() {
michael@0 67 super.onDetachedFromWindow();
michael@0 68 finishAnimation();
michael@0 69 }
michael@0 70
michael@0 71 private void finishAnimation() {
michael@0 72 if (mAnimating) {
michael@0 73 getLayoutParams().height = LayoutParams.WRAP_CONTENT;
michael@0 74 mAnimating = false;
michael@0 75 }
michael@0 76 }
michael@0 77 }

mercurial