Java Code Examples for android.animation.AnimatorInflater#loadStateListAnimator()

The following examples show how to use android.animation.AnimatorInflater#loadStateListAnimator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MountState.java    From litho with Apache License 2.0 6 votes vote down vote up
private static void setViewStateListAnimator(View view, ViewNodeInfo viewNodeInfo) {
  StateListAnimator stateListAnimator = viewNodeInfo.getStateListAnimator();
  final int stateListAnimatorRes = viewNodeInfo.getStateListAnimatorRes();
  if (stateListAnimator == null && stateListAnimatorRes == 0) {
    return;
  }
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    throw new IllegalStateException(
        "MountState has a ViewNodeInfo with stateListAnimator, "
            + "however the current Android version doesn't support stateListAnimator on Views");
  }
  if (stateListAnimator == null) {
    stateListAnimator =
        AnimatorInflater.loadStateListAnimator(view.getContext(), stateListAnimatorRes);
  }
  view.setStateListAnimator(stateListAnimator);
}
 
Example 2
Source File: DragAndDropItemCallback.java    From SimpleRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
  if (actionState != ItemTouchHelper.ACTION_STATE_DRAG) {
    super.onSelectedChanged(viewHolder, actionState);
    return;
  }

  if (dragAndDropCallback != null) {
    dragAndDropCallback.onCellDragStarted(simpleRecyclerView, viewHolder.itemView, draggingItem, draggingItemPosition);
  }

  if (options.isDefaultEffectEnabled()) {
    viewHolder.itemView.setSelected(true);
    viewHolder.itemView.setAlpha(0.95f);
    if (Build.VERSION.SDK_INT >= 21 && animator == null) {
      animator = AnimatorInflater.loadStateListAnimator(viewHolder.itemView.getContext(), R.animator.raise);
      viewHolder.itemView.setStateListAnimator(animator);
    }
  }

  super.onSelectedChanged(viewHolder, actionState);
}
 
Example 3
Source File: WallpapersAdapter.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: ViewUtilsLollipop.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
static void setStateListAnimatorFromAttrs(
    @NonNull View view, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
  final Context context = view.getContext();
  final TypedArray a =
      ThemeEnforcement.obtainStyledAttributes(
          context, 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();
  }
}
 
Example 5
Source File: FunnyButton.java    From Fun with Apache License 2.0 5 votes vote down vote up
public FunnyButton(Context context) {
    super(context);
    setPreventCornerOverlap(false);
    setUseCompatPadding(true);
    setClickable(true);
    if (Build.VERSION.SDK_INT >= 21){
        stateListAnimator = AnimatorInflater
                .loadStateListAnimator(context, R.anim.card_ripple_touch);
        setStateListAnimator(stateListAnimator);
    }
    setForeground(ContextCompat.getDrawable(context, R.drawable.card_ripple));
    textView = new TextView(context);
}
 
Example 6
Source File: FunnyButton.java    From Fun with Apache License 2.0 5 votes vote down vote up
public FunnyButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    setPreventCornerOverlap(false);
    setUseCompatPadding(true);
    setClickable(true);
    if (Build.VERSION.SDK_INT >= 21){
        stateListAnimator = AnimatorInflater
                .loadStateListAnimator(context, R.anim.card_ripple_touch);
        setStateListAnimator(stateListAnimator);
    }
    setForeground(ContextCompat.getDrawable(context, R.drawable.card_ripple));
    textView = new TextView(context);
    initButton(context, attrs);
}
 
Example 7
Source File: CategoriesAdapter.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: WallpaperDetailsCategoryAdapter.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: ViewUtilsLollipop.java    From GpCollapsingToolbar with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 10
Source File: RaiflatUtils.java    From RaiflatButton with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 11
Source File: WallpapersAdapter.java    From candybar with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 12
Source File: StateAnimationActivity.java    From Android-Animation-Set with Apache License 2.0 4 votes vote down vote up
private void setStateListAnimator() {
    StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(this, R.animator.anim_view_state_change_2);
    findViewById(R.id.view_puppet2).setStateListAnimator(stateListAnimator);
}
 
Example 13
Source File: CollectionFragment.java    From wallpaperboard with Apache License 2.0 4 votes vote down vote up
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();
    });
}
 
Example 14
Source File: LatestAdapter.java    From wallpaperboard with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 15
Source File: WallpapersAdapter.java    From candybar-library with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 16
Source File: StateAnimationActivity.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
private void setStateListAnimator() {
    StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(this, R.animator.anim_view_state_change_2);
    findViewById(R.id.view_puppet2).setStateListAnimator(stateListAnimator);
}