use of android.animation.TimeAnimator in project android_frameworks_base by AOSPA.
the class MLand method reset.
public void reset() {
L("reset");
final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]);
sky.setDither(true);
setBackground(sky);
mFlipped = frand() > 0.5f;
setScaleX(mFlipped ? -1 : 1);
int i = getChildCount();
while (i-- > 0) {
final View v = getChildAt(i);
if (v instanceof GameView) {
removeViewAt(i);
}
}
mObstaclesInPlay.clear();
mCurrentPipeId = 0;
mWidth = getWidth();
mHeight = getHeight();
boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25;
if (showingSun) {
final Star sun = new Star(getContext());
sun.setBackgroundResource(R.drawable.sun);
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
sun.setTranslationX(frand(w, mWidth - w));
if (mTimeOfDay == DAY) {
sun.setTranslationY(frand(w, (mHeight * 0.66f)));
sun.getBackground().setTint(0);
} else {
sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
sun.getBackground().setTintMode(PorterDuff.Mode.SRC_ATOP);
sun.getBackground().setTint(0xC0FF8000);
}
addView(sun, new LayoutParams(w, w));
}
if (!showingSun) {
final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT;
final float ff = frand();
if ((dark && ff < 0.75f) || ff < 0.5f) {
final Star moon = new Star(getContext());
moon.setBackgroundResource(R.drawable.moon);
moon.getBackground().setAlpha(dark ? 255 : 128);
moon.setScaleX(frand() > 0.5 ? -1 : 1);
moon.setRotation(moon.getScaleX() * frand(5, 30));
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
moon.setTranslationX(frand(w, mWidth - w));
moon.setTranslationY(frand(w, mHeight - w));
addView(moon, new LayoutParams(w, w));
}
}
final int mh = mHeight / 6;
final boolean cloudless = frand() < 0.25;
final int N = 20;
for (i = 0; i < N; i++) {
final float r1 = frand();
final Scenery s;
if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) {
s = new Star(getContext());
} else if (r1 < 0.6 && !cloudless) {
s = new Cloud(getContext());
} else {
switch(mScene) {
case SCENE_ZRH:
s = new Mountain(getContext());
break;
case SCENE_TX:
s = new Cactus(getContext());
break;
case SCENE_CITY:
default:
s = new Building(getContext());
break;
}
s.z = (float) i / N;
// no more shadows for these things
//s.setTranslationZ(PARAMS.SCENERY_Z * (1+s.z));
// buildings move proportional to their distance
s.v = 0.85f * s.z;
if (mScene == SCENE_CITY) {
s.setBackgroundColor(Color.GRAY);
s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh);
}
final int c = (int) (255f * s.z);
final Drawable bg = s.getBackground();
if (bg != null)
bg.setColorFilter(Color.rgb(c, c, c), PorterDuff.Mode.MULTIPLY);
}
final LayoutParams lp = new LayoutParams(s.w, s.h);
if (s instanceof Building) {
lp.gravity = Gravity.BOTTOM;
} else {
lp.gravity = Gravity.TOP;
final float r = frand();
if (s instanceof Star) {
lp.topMargin = (int) (r * r * mHeight);
} else {
lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2;
}
}
addView(s, lp);
s.setTranslationX(frand(-lp.width, mWidth + lp.width));
}
for (Player p : mPlayers) {
// put it back!
addView(p);
p.reset();
}
realignPlayers();
if (mAnim != null) {
mAnim.cancel();
}
mAnim = new TimeAnimator();
mAnim.setTimeListener(new TimeAnimator.TimeListener() {
@Override
public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) {
step(t, dt);
}
});
}
use of android.animation.TimeAnimator in project android_frameworks_base by ParanoidAndroid.
the class PanelView method animationTick.
private void animationTick(long dtms) {
if (!mTimeAnimator.isStarted()) {
// XXX HAX to work around bug in TimeAnimator.end() not resetting its last time
mTimeAnimator = new TimeAnimator();
mTimeAnimator.setTimeListener(mAnimationCallback);
if (mPeekAnimator != null)
mPeekAnimator.cancel();
mTimeAnimator.start();
mRubberbanding = // is it enabled at all?
mRubberbandingEnabled && // are we past the end?
mExpandedHeight > getFullHeight() && // was this not possibly a "close" gesture?
mVel >= -mFlingGestureMinDistPx;
if (mRubberbanding) {
mClosing = true;
} else if (mVel == 0) {
// if the panel is less than halfway open, close it
mClosing = (mFinalTouchY / getFullHeight()) < 0.5f;
} else {
mClosing = mExpandedHeight > 0 && mVel < 0;
}
} else if (dtms > 0) {
// ms -> s
final float dt = dtms * 0.001f;
if (DEBUG)
LOG("tick: v=%.2fpx/s dt=%.4fs", mVel, dt);
if (DEBUG)
LOG("tick: before: h=%d", (int) mExpandedHeight);
final float fh = getFullHeight();
boolean braking = false;
if (BRAKES) {
if (mClosing) {
braking = mExpandedHeight <= mCollapseBrakingDistancePx;
mAccel = braking ? 10 * mCollapseAccelPx : -mCollapseAccelPx;
} else {
braking = mExpandedHeight >= (fh - mExpandBrakingDistancePx);
mAccel = braking ? 10 * -mExpandAccelPx : mExpandAccelPx;
}
} else {
mAccel = mClosing ? -mCollapseAccelPx : mExpandAccelPx;
}
mVel += mAccel * dt;
if (braking) {
if (mClosing && mVel > -mBrakingSpeedPx) {
mVel = -mBrakingSpeedPx;
} else if (!mClosing && mVel < mBrakingSpeedPx) {
mVel = mBrakingSpeedPx;
}
} else {
if (mClosing && mVel > -mFlingCollapseMinVelocityPx) {
mVel = -mFlingCollapseMinVelocityPx;
} else if (!mClosing && mVel > mFlingGestureMaxOutputVelocityPx) {
mVel = mFlingGestureMaxOutputVelocityPx;
}
}
float h = mExpandedHeight + mVel * dt;
if (mRubberbanding && h < fh) {
h = fh;
}
if (DEBUG)
LOG("tick: new h=%d closing=%s", (int) h, mClosing ? "true" : "false");
setExpandedHeightInternal(h);
mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
if (mVel == 0 || (mClosing && mExpandedHeight == 0) || ((mRubberbanding || !mClosing) && mExpandedHeight == fh)) {
post(mStopAnimator);
}
} else {
Slog.v(TAG, "animationTick called with dtms=" + dtms + "; nothing to do (h=" + mExpandedHeight + " v=" + mVel + ")");
}
}
use of android.animation.TimeAnimator in project platform_frameworks_base by android.
the class MLand method reset.
public void reset() {
L("reset");
final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]);
sky.setDither(true);
setBackground(sky);
mFlipped = frand() > 0.5f;
setScaleX(mFlipped ? -1 : 1);
int i = getChildCount();
while (i-- > 0) {
final View v = getChildAt(i);
if (v instanceof GameView) {
removeViewAt(i);
}
}
mObstaclesInPlay.clear();
mCurrentPipeId = 0;
mWidth = getWidth();
mHeight = getHeight();
boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25;
if (showingSun) {
final Star sun = new Star(getContext());
sun.setBackgroundResource(R.drawable.sun);
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
sun.setTranslationX(frand(w, mWidth - w));
if (mTimeOfDay == DAY) {
sun.setTranslationY(frand(w, (mHeight * 0.66f)));
sun.getBackground().setTint(0);
} else {
sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
sun.getBackground().setTintMode(PorterDuff.Mode.SRC_ATOP);
sun.getBackground().setTint(0xC0FF8000);
}
addView(sun, new LayoutParams(w, w));
}
if (!showingSun) {
final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT;
final float ff = frand();
if ((dark && ff < 0.75f) || ff < 0.5f) {
final Star moon = new Star(getContext());
moon.setBackgroundResource(R.drawable.moon);
moon.getBackground().setAlpha(dark ? 255 : 128);
moon.setScaleX(frand() > 0.5 ? -1 : 1);
moon.setRotation(moon.getScaleX() * frand(5, 30));
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
moon.setTranslationX(frand(w, mWidth - w));
moon.setTranslationY(frand(w, mHeight - w));
addView(moon, new LayoutParams(w, w));
}
}
final int mh = mHeight / 6;
final boolean cloudless = frand() < 0.25;
final int N = 20;
for (i = 0; i < N; i++) {
final float r1 = frand();
final Scenery s;
if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) {
s = new Star(getContext());
} else if (r1 < 0.6 && !cloudless) {
s = new Cloud(getContext());
} else {
switch(mScene) {
case SCENE_ZRH:
s = new Mountain(getContext());
break;
case SCENE_TX:
s = new Cactus(getContext());
break;
case SCENE_CITY:
default:
s = new Building(getContext());
break;
}
s.z = (float) i / N;
// no more shadows for these things
//s.setTranslationZ(PARAMS.SCENERY_Z * (1+s.z));
// buildings move proportional to their distance
s.v = 0.85f * s.z;
if (mScene == SCENE_CITY) {
s.setBackgroundColor(Color.GRAY);
s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh);
}
final int c = (int) (255f * s.z);
final Drawable bg = s.getBackground();
if (bg != null)
bg.setColorFilter(Color.rgb(c, c, c), PorterDuff.Mode.MULTIPLY);
}
final LayoutParams lp = new LayoutParams(s.w, s.h);
if (s instanceof Building) {
lp.gravity = Gravity.BOTTOM;
} else {
lp.gravity = Gravity.TOP;
final float r = frand();
if (s instanceof Star) {
lp.topMargin = (int) (r * r * mHeight);
} else {
lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2;
}
}
addView(s, lp);
s.setTranslationX(frand(-lp.width, mWidth + lp.width));
}
for (Player p : mPlayers) {
// put it back!
addView(p);
p.reset();
}
realignPlayers();
if (mAnim != null) {
mAnim.cancel();
}
mAnim = new TimeAnimator();
mAnim.setTimeListener(new TimeAnimator.TimeListener() {
@Override
public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) {
step(t, dt);
}
});
}
Aggregations