Java Code Examples for android.view.View#setStateListAnimator()

The following examples show how to use android.view.View#setStateListAnimator() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: litho   File: MountState.java    License: 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
/**
 * 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);
}
 
Example 3
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 4
/** Creates and sets a {@link StateListAnimator} with a custom elevation value */
static void setDefaultAppBarLayoutStateListAnimator(
    @NonNull 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 liftable, but not lifted means not elevated
  sla.addState(
      new int[] {android.R.attr.enabled, R.attr.state_liftable, -R.attr.state_lifted},
      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);
}
 
Example 5
Source Project: litho   File: MountState.java    License: Apache License 2.0 5 votes vote down vote up
private static void unsetViewStateListAnimator(View view, ViewNodeInfo viewNodeInfo) {
  if (viewNodeInfo.getStateListAnimator() == null
      && viewNodeInfo.getStateListAnimatorRes() == 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");
  }
  view.setStateListAnimator(null);
}
 
Example 6
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 7
Source Project: RaiflatButton   File: RaiflatUtils.java    License: 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 8
Source Project: ProjectX   File: AMViewCompat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setStateListAnimator(View view, StateListAnimator stateListAnimator) {
    view.setStateListAnimator(stateListAnimator);
}
 
Example 9
Source Project: ProjectX   File: AMViewCompat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setStateListAnimator(View view, int id) {
    view.setStateListAnimator(AnimatorInflater.loadStateListAnimator(view.getContext(), id));
}