use of android.view.animation.Transformation in project Lightning-Browser by anthonycr.
the class BrowserActivity method changeToolbarBackground.
/**
* Animates the color of the toolbar from one color to another. Optionally animates
* the color of the tab background, for use when the tabs are displayed on the top
* of the screen.
*
* @param favicon the Bitmap to extract the color from
* @param tabBackground the optional LinearLayout to color
*/
@Override
public void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable final Drawable tabBackground) {
final int defaultColor = ContextCompat.getColor(this, R.color.primary_color);
if (mCurrentUiColor == Color.BLACK) {
mCurrentUiColor = defaultColor;
}
Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// OR with opaque black to remove transparency glitches
int color = 0xff000000 | palette.getVibrantColor(defaultColor);
// Lighten up the dark color if it is
final int finalColor;
// too dark
if (!mShowTabsInDrawer || Utils.isColorTooDark(color)) {
finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f);
} else {
finalColor = color;
}
final Window window = getWindow();
if (!mShowTabsInDrawer) {
window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
}
final int startSearchColor = getSearchBarColor(mCurrentUiColor, defaultColor);
final int finalSearchColor = getSearchBarColor(finalColor, defaultColor);
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final int color = DrawableUtils.mixColor(interpolatedTime, mCurrentUiColor, finalColor);
if (mShowTabsInDrawer) {
mBackground.setColor(color);
Handlers.MAIN.post(new Runnable() {
@Override
public void run() {
window.setBackgroundDrawable(mBackground);
}
});
} else if (tabBackground != null) {
tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
mCurrentUiColor = color;
mToolbarLayout.setBackgroundColor(color);
mSearchBackground.getBackground().setColorFilter(DrawableUtils.mixColor(interpolatedTime, startSearchColor, finalSearchColor), PorterDuff.Mode.SRC_IN);
}
};
animation.setDuration(300);
mToolbarLayout.startAnimation(animation);
}
});
}
use of android.view.animation.Transformation in project teaTime by ancfdy.
the class SunRefreshView method setupAnimations.
private void setupAnimations() {
mAnimation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
setRotate(interpolatedTime);
}
};
mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setRepeatMode(Animation.RESTART);
mAnimation.setInterpolator(LINEAR_INTERPOLATOR);
mAnimation.setDuration(ANIMATION_DURATION);
}
use of android.view.animation.Transformation in project BookReader by JustWayward.
the class MaterialProgressDrawable method setupAnimators.
private void setupAnimators() {
final Ring ring = mRing;
final Animation animation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
if (mFinishing) {
applyFinishTranslation(interpolatedTime, ring);
} else {
// The minProgressArc is calculated from 0 to create an
// angle that matches the stroke width.
final float minProgressArc = getMinProgressArc(ring);
final float startingEndTrim = ring.getStartingEndTrim();
final float startingTrim = ring.getStartingStartTrim();
final float startingRotation = ring.getStartingRotation();
updateRingColor(interpolatedTime, ring);
// single ring animation
if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
// scale the interpolatedTime so that the full
// transformation from 0 - 1 takes place in the
// remaining time
final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc) * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
ring.setStartTrim(startTrim);
}
// animation completes
if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
// scale the interpolatedTime so that the full
// transformation from 0 - 1 takes place in the
// remaining time
final float minArc = MAX_PROGRESS_ARC - minProgressArc;
float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET) / (1.0f - START_TRIM_DURATION_OFFSET);
final float endTrim = startingEndTrim + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
ring.setEndTrim(endTrim);
}
final float rotation = startingRotation + (0.25f * interpolatedTime);
ring.setRotation(rotation);
float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime) + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
setRotation(groupRotation);
}
}
};
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.RESTART);
animation.setInterpolator(LINEAR_INTERPOLATOR);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mRotationCount = 0;
}
@Override
public void onAnimationEnd(Animation animation) {
// do nothing
}
@Override
public void onAnimationRepeat(Animation animation) {
ring.storeOriginals();
ring.goToNextColor();
ring.setStartTrim(ring.getEndTrim());
if (mFinishing) {
// finished closing the last ring from the swipe gesture; go
// into progress mode
mFinishing = false;
animation.setDuration(ANIMATION_DURATION);
ring.setShowArrow(false);
} else {
mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
}
}
});
mAnimation = animation;
}
use of android.view.animation.Transformation in project BookReader by JustWayward.
the class SwipeRefreshLayout method startScaleDownAnimation.
private void startScaleDownAnimation(AnimationListener listener) {
mScaleDownAnimation = new Animation() {
@Override
public void applyTransformation(float interpolatedTime, Transformation t) {
setAnimationProgress(1 - interpolatedTime);
}
};
mScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
mCircleView.setAnimationListener(listener);
mCircleView.clearAnimation();
mCircleView.startAnimation(mScaleDownAnimation);
}
use of android.view.animation.Transformation in project XposedInstaller by rovo89.
the class WelcomeActivity method navigate.
private void navigate(final int itemId) {
final View elevation = findViewById(R.id.elevation);
Fragment navFragment = null;
switch(itemId) {
case R.id.nav_item_framework:
mPrevSelectedId = itemId;
setTitle(R.string.app_name);
navFragment = new StatusInstallerFragment();
break;
case R.id.nav_item_modules:
mPrevSelectedId = itemId;
setTitle(R.string.nav_item_modules);
navFragment = new ModulesFragment();
break;
case R.id.nav_item_downloads:
mPrevSelectedId = itemId;
setTitle(R.string.nav_item_download);
navFragment = new DownloadFragment();
break;
case R.id.nav_item_logs:
mPrevSelectedId = itemId;
setTitle(R.string.nav_item_logs);
navFragment = new LogsFragment();
break;
case R.id.nav_item_settings:
startActivity(new Intent(this, SettingsActivity.class));
mNavigationView.getMenu().findItem(mPrevSelectedId).setChecked(true);
return;
case R.id.nav_item_support:
startActivity(new Intent(this, SupportActivity.class));
mNavigationView.getMenu().findItem(mPrevSelectedId).setChecked(true);
return;
case R.id.nav_item_about:
startActivity(new Intent(this, AboutActivity.class));
mNavigationView.getMenu().findItem(mPrevSelectedId).setChecked(true);
return;
}
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp(4));
if (navFragment != null) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out);
try {
transaction.replace(R.id.content_frame, navFragment).commit();
if (elevation != null) {
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
elevation.setLayoutParams(params);
}
};
a.setDuration(150);
elevation.startAnimation(a);
}
} catch (IllegalStateException ignored) {
}
}
}
Aggregations