use of android.animation.StateListAnimator in project GreenHouse by utsanjan.
the class FloatingActionButtonImplLollipop method onElevationsChanged.
// com.google.android.material.floatingactionbutton.FloatingActionButtonImpl
@Override
void onElevationsChanged(float elevation, float hoveredFocusedTranslationZ, float pressedTranslationZ) {
if (Build.VERSION.SDK_INT == 21) {
this.view.refreshDrawableState();
} else {
StateListAnimator stateListAnimator = new StateListAnimator();
stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, createElevationAnimator(elevation, pressedTranslationZ));
stateListAnimator.addState(HOVERED_FOCUSED_ENABLED_STATE_SET, createElevationAnimator(elevation, hoveredFocusedTranslationZ));
stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, createElevationAnimator(elevation, hoveredFocusedTranslationZ));
stateListAnimator.addState(HOVERED_ENABLED_STATE_SET, createElevationAnimator(elevation, hoveredFocusedTranslationZ));
AnimatorSet set = new AnimatorSet();
List<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(this.view, "elevation", elevation).setDuration(0L));
if (Build.VERSION.SDK_INT >= 22 && Build.VERSION.SDK_INT <= 24) {
animators.add(ObjectAnimator.ofFloat(this.view, View.TRANSLATION_Z, this.view.getTranslationZ()).setDuration(100L));
}
animators.add(ObjectAnimator.ofFloat(this.view, View.TRANSLATION_Z, 0.0f).setDuration(100L));
set.playSequentially((Animator[]) animators.toArray(new Animator[0]));
set.setInterpolator(ELEVATION_ANIM_INTERPOLATOR);
stateListAnimator.addState(ENABLED_STATE_SET, set);
stateListAnimator.addState(EMPTY_STATE_SET, createElevationAnimator(0.0f, 0.0f));
this.view.setStateListAnimator(stateListAnimator);
}
if (shouldAddPadding()) {
updatePadding();
}
}
use of android.animation.StateListAnimator in project material-components-android by material-components.
the class FloatingActionButtonLollipop method onElevationsChanged.
@Override
void onElevationsChanged(final float elevation, final float pressedTranslationZ) {
final int sdk = Build.VERSION.SDK_INT;
if (sdk == 21) {
// logic in the animations below).
if (mView.isEnabled()) {
mView.setElevation(elevation);
if (mView.isFocused() || mView.isPressed()) {
mView.setTranslationZ(pressedTranslationZ);
} else {
mView.setTranslationZ(0);
}
} else {
mView.setElevation(0);
mView.setTranslationZ(0);
}
} else {
final StateListAnimator stateListAnimator = new StateListAnimator();
// Animate elevation and translationZ to our values when pressed
AnimatorSet set = new AnimatorSet();
set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
set.setInterpolator(ANIM_INTERPOLATOR);
stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set);
// Same deal for when we're focused
set = new AnimatorSet();
set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
set.setInterpolator(ANIM_INTERPOLATOR);
stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set);
// Animate translationZ to 0 if not pressed
set = new AnimatorSet();
set.playSequentially(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0), // bug). The issue has been fixed in version 25.
ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ()).setDuration(PRESSED_ANIM_DELAY), ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION));
set.setInterpolator(ANIM_INTERPOLATOR);
stateListAnimator.addState(ENABLED_STATE_SET, set);
// Animate everything to 0 when disabled
set = new AnimatorSet();
set.play(ObjectAnimator.ofFloat(mView, "elevation", 0f).setDuration(0)).with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(0));
set.setInterpolator(ANIM_INTERPOLATOR);
stateListAnimator.addState(EMPTY_STATE_SET, set);
mView.setStateListAnimator(stateListAnimator);
}
if (mShadowViewDelegate.isCompatPaddingEnabled()) {
updatePadding();
}
}
use of android.animation.StateListAnimator in project material-components-android by material-components.
the class ViewUtilsLollipop method setStateListAnimatorFromAttrs.
static void setStateListAnimatorFromAttrs(View view, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
final Context context = view.getContext();
final TypedArray a = context.obtainStyledAttributes(attrs, STATE_LIST_ANIM_ATTRS, defStyleAttr, defStyleRes);
try {
if (a.hasValue(0)) {
StateListAnimator sla = AnimatorInflater.loadStateListAnimator(context, a.getResourceId(0, 0));
view.setStateListAnimator(sla);
}
} finally {
a.recycle();
}
}
use of android.animation.StateListAnimator in project iosched by google.
the class ViewUtilsLollipop method setDefaultAppBarLayoutStateListAnimator.
/**
* Creates and sets a {@link StateListAnimator} with a custom elevation value
*/
static void setDefaultAppBarLayoutStateListAnimator(final View view, final float elevation) {
final int dur = view.getResources().getInteger(R.integer.app_bar_elevation_anim_duration);
final StateListAnimator sla = new StateListAnimator();
// Enabled and collapsible, but not collapsed means not elevated
sla.addState(new int[] { android.R.attr.enabled, R.attr.state_collapsible, -R.attr.state_collapsed }, ObjectAnimator.ofFloat(view, "elevation", 0f).setDuration(dur));
// Default enabled state
sla.addState(new int[] { android.R.attr.enabled }, ObjectAnimator.ofFloat(view, "elevation", elevation).setDuration(dur));
// Disabled state
sla.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0).setDuration(0));
view.setStateListAnimator(sla);
}
use of android.animation.StateListAnimator in project guanggoo-android by mzlogin.
the class MainActivity method initViews.
private void initViews() {
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// 设置抽屉菜单图标为图片原色
navigationView.setItemIconTintList(null);
mAvatarImageView = navigationView.getHeaderView(0).findViewById(R.id.avatar);
mUsernameTextView = navigationView.getHeaderView(0).findViewById(R.id.username);
mSearchImageView = navigationView.getHeaderView(0).findViewById(R.id.search);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.avatar:
case R.id.username:
openUserProfile();
break;
case R.id.search:
openPage(ConstantUtil.SEARCH_URL, null);
break;
default:
break;
}
}
};
mAvatarImageView.setOnClickListener(listener);
mUsernameTextView.setOnClickListener(listener);
mSearchImageView.setOnClickListener(listener);
openPage(ConstantUtil.HOME_URL, getString(R.string.app_name));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean canGoBack = (getSupportFragmentManager().getBackStackEntryCount() > 1);
if (canGoBack) {
onBackPressed();
} else {
drawer.openDrawer(GravityCompat.START);
}
}
});
getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
@Override
public void onBackStackChanged() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof BaseFragment) {
BaseFragment baseFragment = (BaseFragment) fragment;
setTitle(baseFragment.getTitle());
boolean canGoBack = (getSupportFragmentManager().getBackStackEntryCount() > 1);
if (canGoBack) {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} else {
toolbar.setNavigationIcon(R.drawable.ic_menu);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = new StateListAnimator();
float elevation = 0;
if (!baseFragment.getClass().isAnnotationPresent(StartsWithAppBar.class)) {
elevation = DimensUtil.getDensity(getWindowManager()) * 5;
}
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(mMainAppBar, "elevation", elevation));
mMainAppBar.setStateListAnimator(stateListAnimator);
}
}
}
});
}
Aggregations