Java 类android.animation.StateListAnimator 实例源码
项目:Hitalk
文件:FloatingActionButton.java
@SuppressLint("NewApi")
private void init(Context context, AttributeSet attributeSet) {
mVisible = true;
mColorNormal = getColor(R.color.material_blue_500);
mColorPressed = darkenColor(mColorNormal);
mColorRipple = lightenColor(mColorNormal);
mColorDisabled = getColor(android.R.color.darker_gray);
mType = TYPE_NORMAL;
mShadow = true;
mScrollThreshold = getResources().getDimensionPixelOffset(R.dimen.fab_scroll_threshold);
mShadowSize = getDimension(R.dimen.fab_shadow_size);
if (hasLollipopApi()) {
StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(context,
R.animator.fab_press_elevation);
setStateListAnimator(stateListAnimator);
}
if (attributeSet != null) {
initAttributes(context, attributeSet);
}
updateBackground();
}
项目:cwac-crossport
文件:ViewUtilsLollipop.java
/**
* 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);
}
项目:wallpaperboard
文件:WallpapersAdapter.java
ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
setCardViewToFlat(card);
if (!Preferences.get(mContext).isShadowEnabled()) {
card.setCardElevation(0f);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = AnimatorInflater
.loadStateListAnimator(mContext, R.animator.card_lift_long);
card.setStateListAnimator(stateListAnimator);
}
card.setOnClickListener(this);
card.setOnLongClickListener(this);
favorite.setOnClickListener(this);
}
项目:GpCollapsingToolbar
文件:ViewUtilsLollipop.java
/**
* Creates and sets a {@link StateListAnimator} with a custom elevation value
*/
@SuppressLint("PrivateResource")
static void setDefaultAppBarLayoutStateListAnimator(final View view, final float targetElevation) {
final StateListAnimator sla = new StateListAnimator();
// Enabled, collapsible and collapsed == elevated
sla.addState(new int[]{android.R.attr.enabled, R.attr.state_collapsible, R.attr.state_collapsed},
ObjectAnimator.ofFloat(view, "elevation", targetElevation));
// Enabled and collapsible, but not collapsed != elevated
sla.addState(new int[]{android.R.attr.enabled, R.attr.state_collapsible, -R.attr.state_collapsed},
ObjectAnimator.ofFloat(view, "elevation", 0f));
// Enabled but not collapsible == elevated
sla.addState(new int[]{android.R.attr.enabled, -R.attr.state_collapsible},
ObjectAnimator.ofFloat(view, "elevation", targetElevation));
// Default, none elevated state
sla.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0));
view.setStateListAnimator(sla);
}
项目:permissionsModule
文件:FloatingActionButtonLollipop.java
@Override
void onTranslationZChanged(float translationZ) {
StateListAnimator stateListAnimator = new StateListAnimator();
// Animate translationZ to our value when pressed or focused
stateListAnimator.addState(PRESSED_ENABLED_STATE_SET,
setupAnimator(ObjectAnimator.ofFloat(mView, "translationZ", translationZ)));
stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET,
setupAnimator(ObjectAnimator.ofFloat(mView, "translationZ", translationZ)));
// Animate translationZ to 0 otherwise
stateListAnimator.addState(EMPTY_STATE_SET,
setupAnimator(ObjectAnimator.ofFloat(mView, "translationZ", 0f)));
mView.setStateListAnimator(stateListAnimator);
if (mShadowViewDelegate.isCompatPaddingEnabled()) {
updatePadding();
}
}
项目:material-components-android
文件:ViewUtilsLollipop.java
/** 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);
}
项目:AyoSunny
文件:FloatingActionButton.java
@SuppressLint("NewApi")
private void init(Context context, AttributeSet attributeSet) {
mVisible = true;
mColorNormal = getColor(R.color.material_blue_500);
mColorPressed = darkenColor(mColorNormal);
mColorRipple = lightenColor(mColorNormal);
mColorDisabled = getColor(android.R.color.darker_gray);
mType = TYPE_NORMAL;
mShadow = true;
mScrollThreshold = getResources().getDimensionPixelOffset(R.dimen.fab_scroll_threshold);
mShadowSize = getDimension(R.dimen.fab_shadow_size);
if (hasLollipopApi()) {
StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(context,
R.anim.fab_press_elevation);
setStateListAnimator(stateListAnimator);
}
if (attributeSet != null) {
initAttributes(context, attributeSet);
}
updateBackground();
}
项目:Doctor
文件:FloatingActionButton.java
@SuppressLint("NewApi")
private void init(Context context, AttributeSet attributeSet) {
mVisible = true;
mColorNormal = getColor(R.color.material_blue_500);
mColorPressed = darkenColor(mColorNormal);
mColorRipple = lightenColor(mColorNormal);
mColorDisabled = getColor(android.R.color.darker_gray);
mType = TYPE_NORMAL;
mShadow = true;
mScrollThreshold = getResources().getDimensionPixelOffset(R.dimen.fab_scroll_threshold);
mShadowSize = getDimension(R.dimen.fab_shadow_size);
if (hasLollipopApi()) {
StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(context,
R.anim.fab_press_elevation);
setStateListAnimator(stateListAnimator);
}
if (attributeSet != null) {
initAttributes(context, attributeSet);
}
updateBackground();
}
项目:BookMySkills
文件:FloatingActionButton.java
@SuppressLint("NewApi")
private void init(Context context, AttributeSet attributeSet) {
mVisible = true;
mColorNormal = getColor(R.color.material_blue_500);
mColorPressed = darkenColor(mColorNormal);
mColorRipple = lightenColor(mColorNormal);
mColorDisabled = getColor(android.R.color.darker_gray);
mType = TYPE_NORMAL;
mShadow = true;
mScrollThreshold = getResources().getDimensionPixelOffset(
R.dimen.fab_scroll_threshold);
mShadowSize = getDimension(R.dimen.fab_shadow_size);
if (hasLollipopApi()) {
StateListAnimator stateListAnimator = AnimatorInflater
.loadStateListAnimator(context, R.anim.fab_press_elevation);
setStateListAnimator(stateListAnimator);
}
if (attributeSet != null) {
initAttributes(context, attributeSet);
}
updateBackground();
}
项目:iosched
文件:ViewUtilsLollipop.java
/** 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);
}
项目:Mire
文件:ButtonIcon.java
private void initView(Context context)
{
inflater.inflate(R.layout.ms__button, this, true);
Resources res = getResources();
StateListAnimator sla = AnimatorInflater.loadStateListAnimator(context, R.animator.button_elevation);
setBackground(res.getDrawable(R.drawable.button_background));
setStateListAnimator(sla);
setOrientation(LinearLayout.HORIZONTAL);
setGravity(Gravity.CENTER);
setOnClickListener(null);
content = findViewById(R.id.ms__content);
buttonIcon = (ImageView)content.findViewById(R.id.ms__button_icon);
buttonIcon.setImageResource(mResource);
buttonIcon.setImageDrawable(mDrawable);
buttonText = (TextView)content.findViewById(R.id.ms__button_text);
buttonText.setText(mText);
buttonText.setTextColor(mTextColor);
buttonText.setTextSize(mTextSize);
if (mState)
{
buttonText.setTypeface(mTypface);
}
else
{ }
}
项目:cwac-crossport
文件:ViewUtilsLollipop.java
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();
}
}
项目:boohee_v5.6
文件:FloatingActionButtonLollipop.java
void onTranslationZChanged(float translationZ) {
StateListAnimator stateListAnimator = new StateListAnimator();
stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, setupAnimator(ObjectAnimator.ofFloat(this.mView, "translationZ", new float[]{translationZ})));
stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, setupAnimator(ObjectAnimator.ofFloat(this.mView, "translationZ", new float[]{translationZ})));
stateListAnimator.addState(EMPTY_STATE_SET, setupAnimator(ObjectAnimator.ofFloat(this.mView, "translationZ", new float[]{0.0f})));
this.mView.setStateListAnimator(stateListAnimator);
if (this.mShadowViewDelegate.isCompatPaddingEnabled()) {
updatePadding();
}
}
项目:wallpaperboard
文件:CategoriesAdapter.java
ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
if (mContext.getResources().getInteger(R.integer.categories_column_count) == 1) {
if (card.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
GridLayoutManager.LayoutParams params =
(GridLayoutManager.LayoutParams) card.getLayoutParams();
params.leftMargin = 0;
params.rightMargin = 0;
params.topMargin = 0;
params.bottomMargin = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(0);
}
}
} else {
setCardViewToFlat(card);
}
if (!Preferences.get(mContext).isShadowEnabled()) {
card.setCardElevation(0f);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = AnimatorInflater
.loadStateListAnimator(mContext, R.animator.card_lift_long);
card.setStateListAnimator(stateListAnimator);
}
card.setOnClickListener(this);
}
项目:wallpaperboard
文件:WallpaperDetailsCategoryAdapter.java
ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = AnimatorInflater
.loadStateListAnimator(mContext, R.animator.card_lift_long);
card.setStateListAnimator(stateListAnimator);
}
card.setOnClickListener(this);
}
项目:GpCollapsingToolbar
文件:ViewUtilsLollipop.java
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();
}
}
项目:RaiflatButton
文件:RaiflatUtils.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void setupRaiflat(View view) {
StateListAnimator stateListAnimator
= AnimatorInflater.loadStateListAnimator(view.getContext(),
R.drawable.raiflatbutton_statelistanimator);
view.setStateListAnimator(stateListAnimator);
}
项目:material-components-android
文件:ViewUtilsLollipop.java
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();
}
}
项目:iosched
文件:ViewUtilsLollipop.java
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();
}
}
项目:wallpaperboard
文件:CollectionFragment.java
private void initSearchBar() {
Drawable drawable = ConfigurationHelper.getNavigationIcon(getActivity(),
WallpaperBoardApplication.getConfig().getNavigationIcon());
int color = ColorHelper.getAttributeColor(getActivity(), R.attr.search_bar_icon);
if (drawable != null) {
mNavigation.setImageDrawable(DrawableHelper.getTintedDrawable(drawable, color));
}
mNavigation.setOnClickListener(view -> {
if (getActivity() instanceof WallpaperBoardActivity) {
((WallpaperBoardActivity) getActivity()).openDrawer();
}
});
ImageView searchIcon = getActivity().findViewById(R.id.search);
if (searchIcon != null) {
searchIcon.setImageDrawable(DrawableHelper.getTintedDrawable(
getActivity(), R.drawable.ic_toolbar_search, color));
}
TextView searchBarTitle = getActivity().findViewById(R.id.search_bar_title);
if (searchBarTitle != null) {
if (WallpaperBoardApplication.getConfig().getAppLogoColor() != -1) {
searchBarTitle.setTextColor(WallpaperBoardApplication.getConfig().getAppLogoColor());
} else {
searchBarTitle.setTextColor(ColorHelper.setColorAlpha(color, 0.7f));
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mSearchBar.getLayoutParams() instanceof CoordinatorLayout.LayoutParams) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mSearchBar.getLayoutParams();
params.setMargins(params.leftMargin,
params.topMargin + WindowHelper.getStatusBarHeight(getActivity()),
params.leftMargin,
params.bottomMargin);
}
StateListAnimator stateListAnimator = AnimatorInflater
.loadStateListAnimator(getActivity(), R.animator.card_lift);
mSearchBar.setStateListAnimator(stateListAnimator);
}
mSearchBar.setOnClickListener(view -> {
Intent intent = new Intent(getActivity(), WallpaperBoardBrowserActivity.class);
intent.putExtra(Extras.EXTRA_FRAGMENT_ID, Extras.ID_WALLPAPER_SEARCH);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
});
mMenuSort.setImageDrawable(DrawableHelper.getTintedDrawable(
getActivity(), R.drawable.ic_toolbar_sort, color));
mMenuSort.setOnClickListener(view -> {
Popup.Builder(getActivity())
.to(mMenuSort)
.list(PopupItem.getSortItems(getActivity(), true))
.callback((popup, position) -> {
Preferences.get(getActivity())
.setSortBy(popup.getItems().get(position).getType());
refreshWallpapers();
popup.dismiss();
})
.show();
});
}
项目:wallpaperboard
文件:LatestAdapter.java
ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
if (mContext.getResources().getInteger(R.integer.latest_wallpapers_column_count) == 1) {
if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
StaggeredGridLayoutManager.LayoutParams params =
(StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams();
params.leftMargin = 0;
params.rightMargin = 0;
params.topMargin = 0;
params.bottomMargin = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(0);
}
}
} else {
setCardViewToFlat(card);
}
if (!Preferences.get(mContext).isShadowEnabled()) {
card.setCardElevation(0f);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = AnimatorInflater
.loadStateListAnimator(mContext, R.animator.card_lift_long);
card.setStateListAnimator(stateListAnimator);
}
if (mContext.getResources().getBoolean(R.bool.enable_wallpaper_download)) {
download.setImageDrawable(DrawableHelper.getTintedDrawable(
mContext, R.drawable.ic_toolbar_download, Color.WHITE));
download.setOnClickListener(this);
}
apply.setImageDrawable(DrawableHelper.getTintedDrawable(
mContext, R.drawable.ic_toolbar_apply_options, Color.WHITE));
card.setOnClickListener(this);
favorite.setOnClickListener(this);
apply.setOnClickListener(this);
}
项目:candybar-library
文件:WallpapersAdapter.java
ViewHolder(View itemView) {
super(itemView);
String viewStyle = mContext.getResources().getString(
R.string.wallpaper_grid_preview_style);
Point ratio = ViewHelper.getWallpaperViewRatio(viewStyle);
image = itemView.findViewById(R.id.image);
image.setRatio(ratio.x, ratio.y);
card = itemView.findViewById(R.id.card);
if (CandyBarApplication.getConfiguration().getWallpapersGrid() == CandyBarApplication.GridStyle.FLAT) {
if (card.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
card.setRadius(0f);
card.setUseCompatPadding(false);
int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) card.getLayoutParams();
params.setMargins(0, 0, margin, margin);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.setMarginEnd(margin);
}
}
}
if (!Preferences.get(mContext).isCardShadowEnabled()) {
card.setCardElevation(0);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
StateListAnimator stateListAnimator = AnimatorInflater
.loadStateListAnimator(mContext, R.animator.card_lift);
card.setStateListAnimator(stateListAnimator);
}
if (mIsShowName) {
name = itemView.findViewById(R.id.name);
author = itemView.findViewById(R.id.author);
}
card.setOnClickListener(this);
card.setOnLongClickListener(this);
}
项目:RaiflatButton
文件:RaiflatDelegate.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupStateListAnimator() {
mFlatStateListAnimator = new StateListAnimator();
ObjectAnimator pressed = ObjectAnimator.ofFloat(this, "elevation", 0)
.setDuration(mView.getContext().getResources()
.getInteger(android.R.integer.config_shortAnimTime));
ObjectAnimator notPressed = ObjectAnimator.ofFloat(this, "elevation", mView.getElevation()
+ mView.getTranslationZ()).setDuration(mView.getContext().getResources()
.getInteger(android.R.integer.config_shortAnimTime));
notPressed.setStartDelay(100);
mFlatStateListAnimator.addState(new int[]{android.R.attr.state_pressed,
android.R.attr.state_enabled}, pressed);
mFlatStateListAnimator.addState(new int[]{android.R.attr.state_enabled}, notPressed);
mFlatStateListAnimator.addState(new int[]{},
ObjectAnimator.ofFloat(this, "elevation", 0).setDuration(0));
mView.setStateListAnimator(mFlatStateListAnimator);
}
项目:material-components-android
文件:FloatingActionButtonImplLollipop.java
@Override
void onElevationsChanged(
final float elevation,
final float hoveredFocusedTranslationZ,
final float pressedTranslationZ) {
if (Build.VERSION.SDK_INT == VERSION_CODES.LOLLIPOP) {
// Animations produce NPE in version 21. Bluntly set the values instead in
// #onDrawableStateChanged (matching the logic in the animations below).
view.refreshDrawableState();
} else {
final StateListAnimator stateListAnimator = new StateListAnimator();
// Animate elevation and translationZ to our values when pressed, focused, and hovered
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));
// Animate translationZ to 0 if not pressed, focused, or hovered
AnimatorSet set = new AnimatorSet();
List<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(view, "elevation", elevation).setDuration(0));
if (Build.VERSION.SDK_INT >= 22 && Build.VERSION.SDK_INT <= 24) {
// This is a no-op animation which exists here only for introducing the duration
// because setting the delay (on the next animation) via "setDelay" or "after"
// can trigger a NPE between android versions 22 and 24 (due to a framework
// bug). The issue has been fixed in version 25.
animators.add(
ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, view.getTranslationZ())
.setDuration(ELEVATION_ANIM_DELAY));
}
animators.add(
ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, 0f)
.setDuration(ELEVATION_ANIM_DURATION));
set.playSequentially(animators.toArray(new Animator[0]));
set.setInterpolator(ELEVATION_ANIM_INTERPOLATOR);
stateListAnimator.addState(ENABLED_STATE_SET, set);
// Animate everything to 0 when disabled
stateListAnimator.addState(EMPTY_STATE_SET, createElevationAnimator(0f, 0f));
view.setStateListAnimator(stateListAnimator);
}
if (shadowViewDelegate.isCompatPaddingEnabled()) {
updatePadding();
}
}
项目:PowerSwitch_Android
文件:ConfirmationActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = this.getIntent();
int animationType = intent.getIntExtra("animation_type", 1);
String message = intent.getStringExtra("message");
this.mActionPage = new ActionPage(this);
long displayDurationMs;
if (animationType == 3) {
this.setContentView(layout.error_layout);
TextView animatedDrawable = (TextView) this.findViewById(id.message);
animatedDrawable.setText(message);
displayDurationMs = 1666L;
} else {
this.mActionPage.setColor(0);
this.mActionPage.setStateListAnimator(new StateListAnimator());
this.mActionPage.setImageScaleMode(ActionPage.SCALE_MODE_CENTER);
this.setContentView(this.mActionPage);
if (message != null) {
this.mActionPage.setText(message);
}
Drawable animatedDrawable1;
switch (animationType) {
case 1:
animatedDrawable1 = this.getResources().getDrawable(drawable.generic_confirmation_animation);
displayDurationMs = 1666L;
break;
case 2:
animatedDrawable1 = this.getResources().getDrawable(drawable.open_on_phone_animation);
displayDurationMs = 1666L;
break;
default:
throw new IllegalArgumentException("Unknown type of animation: " + animationType);
}
this.mActionPage.setImageDrawable(animatedDrawable1);
final ActionLabel label = this.mActionPage.getLabel();
long fadeDuration = label.animate().getDuration();
((Animatable) animatedDrawable1).start();
label.setAlpha(0.0F);
label.animate().alpha(1.0F).setStartDelay(50L).withEndAction(new Runnable() {
public void run() {
ConfirmationActivity.this.finish();
ConfirmationActivity.this.overridePendingTransition(0, android.R.anim.fade_out);
}
});
}
this.mActionPage.setKeepScreenOn(true);
}
项目:ProjectX
文件:AMViewCompat.java
@Override
public void setStateListAnimator(View view, StateListAnimator stateListAnimator) {
// do nothing
}
项目:ProjectX
文件:AMViewCompat.java
@Override
public void setStateListAnimator(View view, StateListAnimator stateListAnimator) {
view.setStateListAnimator(stateListAnimator);
}
项目:iosched
文件:FloatingActionButtonLollipop.java
@Override
void onElevationsChanged(final float elevation, final float pressedTranslationZ) {
if (Build.VERSION.SDK_INT == 21) {
// Animations produce NPE in version 21. Bluntly set the values instead (matching the
// 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),
// This is a no-op animation which exists here only for introducing the duration
// because setting the delay (on the next animation) via "setDelay" or "after"
// can trigger a NPE between android versions 22 and 24 (due to a framework
// 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();
}
}
项目:ProjectX
文件:AMViewCompat.java
/**
* Attaches the provided StateListAnimator to this View.
* <p>
* Any previously attached StateListAnimator will be detached.
*
* @param stateListAnimator The StateListAnimator to update the view
* @see android.animation.StateListAnimator
*/
public static void setStateListAnimator(View view, StateListAnimator stateListAnimator) {
IMPL.setStateListAnimator(view, stateListAnimator);
}
项目:ProjectX
文件:AMViewCompat.java
void setStateListAnimator(View view, StateListAnimator stateListAnimator);