Example usage for android.graphics.drawable AnimationDrawable start

List of usage examples for android.graphics.drawable AnimationDrawable start

Introduction

In this page you can find the example usage for android.graphics.drawable AnimationDrawable start.

Prototype

@Override
public void start() 

Source Link

Document

Starts the animation from the first frame, looping if necessary.

Usage

From source file:Main.java

public static void startFrameAnimation(ImageView targetImageView, int animationDrawableId) {
    if (targetImageView == null || animationDrawableId <= 0) {
        return;/*from  www  . j  a v  a  2 s .  c  o  m*/
    }
    targetImageView.setImageResource(animationDrawableId);
    AnimationDrawable animationDrawable = (AnimationDrawable) targetImageView.getDrawable();
    animationDrawable.start();
}

From source file:Main.java

public static AnimationDrawable startAnimDrawable(ImageView img) {
    AnimationDrawable animDrawble = (AnimationDrawable) img.getBackground();
    animDrawble.setOneShot(false);/*from  w ww . j  a  v a2  s  .  c  o  m*/
    animDrawble.start();
    return animDrawble;
}

From source file:Main.java

/**
 * Start given animation on provided view.
 *//*from w  w  w  .  j a  v  a2 s . com*/
public static void startAnimation(View view, int animationId) {
    view.setBackgroundResource(animationId);
    AnimationDrawable animationDrawable = (AnimationDrawable) view.getBackground();
    if (animationDrawable != null) {
        animationDrawable.start();
    }
}

From source file:Main.java

/**
 * Starts an AnimationDrawable animation at the specified point in the future.
 * @param handler The Handler for the Activity in which the animation will run.
 * @param drawable The AnimationDrawable that will have its animation started.
 * @param millisFromNow The number of milliseconds to wait before starting this animation. 
 *//*  w  w  w  .j a va 2  s . c o m*/
public static void startAnimationInFuture(final Handler handler, final AnimationDrawable drawable,
        long millisFromNow) {
    handler.postAtTime(new Runnable() {
        @Override
        public void run() {
            drawable.start();
        }
    }, SystemClock.uptimeMillis() + millisFromNow);
}

From source file:cat.terrones.devops.radiofx.ui.MediaItemViewHolder.java

public static Drawable getDrawableByState(Context context, int state) {
    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(context);
    }/*  w w  w  . ja v a 2 s .c o m*/

    switch (state) {
    case STATE_PLAYABLE:
        Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play_arrow_black_36dp);
        DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
        return pauseDrawable;
    case STATE_PLAYING:
        AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context,
                R.drawable.ic_equalizer_white_36dp);
        DrawableCompat.setTintList(animation, sColorStatePlaying);
        animation.start();
        return animation;
    case STATE_PAUSED:
        Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.ic_equalizer1_white_36dp);
        DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
        return playDrawable;
    default:
        return null;
    }
}

From source file:com.classiqo.nativeandroid_32bitz.ui.MediaItemViewHolder.java

public static Drawable getDrawableByState(Context context, int state) {
    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(context);
    }//from w  w  w  .  ja  va  2s .co  m

    switch (state) {
    case STATE_PLAYABLE:
        Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play_arrow_black_36dp);
        DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);

        return pauseDrawable;
    case STATE_PLAYING:
        AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context,
                R.drawable.ic_equalizer_white_36dp);
        DrawableCompat.setTintList(animation, sColorStatePlaying);
        animation.start();

        return animation;
    case STATE_PAUSED:
        Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.ic_equalizer1_white_36dp);
        DrawableCompat.setTintList(playDrawable, sColorStatePlaying);

        return playDrawable;
    default:
        return null;
    }
}

From source file:com.murati.oszk.audiobook.ui.MediaItemViewHolder.java

public static Drawable getDrawableByState(Context context, int state) {
    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(context);
    }/* ww  w.  ja  v a2s .c o  m*/

    switch (state) {
    case STATE_PLAYABLE:
        Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play_arrow_black_36dp);
        DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
        return pauseDrawable;
    case STATE_PLAYING:
        AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context,
                R.drawable.ic_equalizer_white_36dp);
        DrawableCompat.setTintList(animation, sColorStatePlaying);
        animation.start();
        return animation;
    case STATE_PAUSED:
        Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.ic_equalizer1_white_36dp);
        DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
        return playDrawable;
    case STATE_NONE:
    default:
        return null;
    }
}

From source file:com.phearom.um.ui.MediaItemViewHolder.java

public static View setupView(Context context, View convertView, ViewGroup parent,
        MediaDescriptionCompat description, int state) {

    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(context);
    }/*from  w w  w  .  j a va  2s.c o m*/

    MediaItemViewHolder holder;

    Integer cachedState = STATE_INVALID;

    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.media_list_item, parent, false);
        holder = new MediaItemViewHolder();
        holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
        holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
        holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (MediaItemViewHolder) convertView.getTag();
        cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache);
    }

    holder.mTitleView.setText(description.getTitle());
    holder.mDescriptionView.setText(description.getSubtitle());

    // If the state of convertView is different, we need to adapt the view to the
    // new state.
    if (cachedState == null || cachedState != state) {
        switch (state) {
        case STATE_PLAYABLE:
            Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play_arrow_black_36dp);
            DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
            holder.mImageView.setImageDrawable(pauseDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        case STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context,
                    R.drawable.ic_equalizer_white_36dp);
            DrawableCompat.setTintList(animation, sColorStatePlaying);
            holder.mImageView.setImageDrawable(animation);
            holder.mImageView.setVisibility(View.VISIBLE);
            animation.start();
            break;
        case STATE_PAUSED:
            Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.ic_equalizer1_white_36dp);
            DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
            holder.mImageView.setImageDrawable(playDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        default:
            holder.mImageView.setVisibility(View.GONE);
        }
        convertView.setTag(R.id.tag_mediaitem_state_cache, state);
    }

    return convertView;
}

From source file:com.bayapps.android.robophish.ui.MediaItemViewHolder.java

static View setupView(Activity activity, View convertView, ViewGroup parent, MediaDescriptionCompat description,
        int state) {

    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(activity);
    }// ww w  . j a va2 s  .  co  m

    MediaItemViewHolder holder;

    Integer cachedState = STATE_INVALID;

    if (convertView == null) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.media_list_item, parent, false);
        holder = new MediaItemViewHolder();
        holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
        holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
        holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (MediaItemViewHolder) convertView.getTag();
        cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache);
    }

    holder.mTitleView.setText(description.getTitle());
    holder.mDescriptionView.setText(description.getSubtitle());

    // If the state of convertView is different, we need to adapt the view to the
    // new state.
    if (cachedState == null || cachedState != state) {
        switch (state) {
        case STATE_PLAYABLE:
            Drawable pauseDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_play_arrow_black_36dp);
            DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
            holder.mImageView.setImageDrawable(pauseDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        case STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(activity,
                    R.drawable.ic_equalizer_white_36dp);
            DrawableCompat.setTintList(animation, sColorStatePlaying);
            holder.mImageView.setImageDrawable(animation);
            holder.mImageView.setVisibility(View.VISIBLE);
            animation.start();
            break;
        case STATE_PAUSED:
            Drawable playDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_equalizer1_white_36dp);
            DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
            holder.mImageView.setImageDrawable(playDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        default:
            holder.mImageView.setVisibility(View.GONE);
        }
        convertView.setTag(R.id.tag_mediaitem_state_cache, state);
    }

    return convertView;
}

From source file:dk.glutter.android.knr.ui.MediaItemViewHolder.java

static View setupView(Activity activity, View convertView, ViewGroup parent, MediaDescriptionCompat description,
        int state) {

    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(activity);
    }//from   w  w w . ja  v  a 2s.c  o  m

    MediaItemViewHolder holder;

    Integer cachedState = STATE_INVALID;

    if (convertView == null) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.media_list_item, parent, false);
        holder = new MediaItemViewHolder();
        holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
        holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
        holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (MediaItemViewHolder) convertView.getTag();
        cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache);
    }

    //TODO: HGL - song list title and  is being set here
    holder.mTitleView.setText(description.getTitle());
    holder.mDescriptionView.setText(description.getSubtitle());

    // If the state of convertView is different, we need to adapt the view to the
    // new state.
    if (cachedState == null || cachedState != state) {
        switch (state) {
        case STATE_PLAYABLE:
            Drawable pauseDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_play_arrow_black_36dp);
            DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
            holder.mImageView.setImageDrawable(pauseDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        case STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(activity,
                    R.drawable.ic_equalizer_white_36dp);
            DrawableCompat.setTintList(animation, sColorStatePlaying);
            holder.mImageView.setImageDrawable(animation);
            holder.mImageView.setVisibility(View.VISIBLE);
            animation.start();
            break;
        case STATE_PAUSED:
            Drawable playDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_equalizer1_white_36dp);
            DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
            holder.mImageView.setImageDrawable(playDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        default:
            holder.mImageView.setVisibility(View.GONE);
        }
        convertView.setTag(R.id.tag_mediaitem_state_cache, state);
    }

    return convertView;
}