Java Code Examples for android.graphics.drawable.AnimationDrawable#getNumberOfFrames()

The following examples show how to use android.graphics.drawable.AnimationDrawable#getNumberOfFrames() . 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: ProgressBar.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 2
Source File: IcsProgressBar.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 3
Source File: SkinCompatProgressBarHelper.java    From AndroidSkinAnimator with MIT License 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 4
Source File: SkinCompatProgressBarHelper.java    From Android-skin-support with MIT License 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 5
Source File: SkinCompatProgressBarHelper.java    From Android-skin-support with MIT License 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 6
Source File: SkinCompatProgressBarHelper.java    From Android-skin-support with MIT License 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 7
Source File: IcsProgressBar.java    From android-apps with MIT License 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 8
Source File: IcsProgressBar.java    From zen4android with MIT License 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 9
Source File: IcsProgressBar.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 10
Source File: IcsProgressBar.java    From Libraries-for-Android-Developers with MIT License 6 votes vote down vote up
/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader.
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}
 
Example 11
Source File: PointViewAnimObject.java    From DragPointView with Apache License 2.0 5 votes vote down vote up
private void start(AnimationDrawable object, final OnPointDragListener removeListener) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        int duration = 0;
        for (int i = 0; i < object.getNumberOfFrames(); i++) {
            duration += object.getDuration(i);
        }
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    view.setBackground(background);
                }
                end(removeListener);
            }
        }, duration + 5);
        view.setText("");
        int drawableL = (view.getWidth() + view.getHeight()) / 2;
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.height = lp.width = drawableL;
        view.setLayoutParams(lp);
        view.setBackground(object);
        if (object.isRunning())
            object.stop();
        object.start();
    } else {
        end(removeListener);
    }
}
 
Example 12
Source File: NotifyingAnimationDrawable.java    From MultiStateAnimation with Apache License 2.0 5 votes vote down vote up
/**
 * @param drawable The frames data from animation will be copied into this instance. The animation object will be unchanged.
 */
public NotifyingAnimationDrawable(AnimationDrawable drawable) {
    for (int i = 0; i < drawable.getNumberOfFrames(); i++) {
        addFrame(drawable.getFrame(i), drawable.getDuration(i));
    }
    setOneShot(drawable.isOneShot());
}
 
Example 13
Source File: NumberProgressBar.java    From Android_Skin_2.0 with Apache License 2.0 5 votes vote down vote up
private Drawable tileifyAnimationDrawable(AnimationDrawable wrapped) {
	NumberAnimationDrawable drawable = new NumberAnimationDrawable();
	drawable.setOneShot(wrapped.isOneShot());
	final int N = wrapped.getNumberOfFrames();
	for (int i = 0; i < N; i++) {
		Drawable frame = wrapped.getFrame(i);
		int duration = wrapped.getDuration(i);
		drawable.addFrame(frame, duration);
	}
	return drawable;
}
 
Example 14
Source File: PointerIcon.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void loadResource(Context context, Resources resources, @XmlRes int resourceId) {
    final XmlResourceParser parser = resources.getXml(resourceId);
    final int bitmapRes;
    final float hotSpotX;
    final float hotSpotY;
    try {
        XmlUtils.beginDocument(parser, "pointer-icon");

        final TypedArray a = resources.obtainAttributes(
                parser, com.android.internal.R.styleable.PointerIcon);
        bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0);
        hotSpotX = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0);
        hotSpotY = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0);
        a.recycle();
    } catch (Exception ex) {
        throw new IllegalArgumentException("Exception parsing pointer icon resource.", ex);
    } finally {
        parser.close();
    }

    if (bitmapRes == 0) {
        throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute.");
    }

    Drawable drawable;
    if (context == null) {
        drawable = resources.getDrawable(bitmapRes);
    } else {
        drawable = context.getDrawable(bitmapRes);
    }
    if (drawable instanceof AnimationDrawable) {
        // Extract animation frame bitmaps.
        final AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
        final int frames = animationDrawable.getNumberOfFrames();
        drawable = animationDrawable.getFrame(0);
        if (frames == 1) {
            Log.w(TAG, "Animation icon with single frame -- simply treating the first "
                    + "frame as a normal bitmap icon.");
        } else {
            // Assumes they have the exact duration.
            mDurationPerFrame = animationDrawable.getDuration(0);
            mBitmapFrames = new Bitmap[frames - 1];
            final int width = drawable.getIntrinsicWidth();
            final int height = drawable.getIntrinsicHeight();
            for (int i = 1; i < frames; ++i) {
                Drawable drawableFrame = animationDrawable.getFrame(i);
                if (!(drawableFrame instanceof BitmapDrawable)) {
                    throw new IllegalArgumentException("Frame of an animated pointer icon "
                            + "must refer to a bitmap drawable.");
                }
                if (drawableFrame.getIntrinsicWidth() != width ||
                    drawableFrame.getIntrinsicHeight() != height) {
                    throw new IllegalArgumentException("The bitmap size of " + i + "-th frame "
                            + "is different. All frames should have the exact same size and "
                            + "share the same hotspot.");
                }
                BitmapDrawable bitmapDrawableFrame = (BitmapDrawable) drawableFrame;
                mBitmapFrames[i - 1] = getBitmapFromDrawable(bitmapDrawableFrame);
            }
        }
    }
    if (!(drawable instanceof BitmapDrawable)) {
        throw new IllegalArgumentException("<pointer-icon> bitmap attribute must "
                + "refer to a bitmap drawable.");
    }

    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    final Bitmap bitmap = getBitmapFromDrawable(bitmapDrawable);
    validateHotSpot(bitmap, hotSpotX, hotSpotY);
    // Set the properties now that we have successfully loaded the icon.
    mBitmap = bitmap;
    mHotSpotX = hotSpotX;
    mHotSpotY = hotSpotY;
}
 
Example 15
Source File: HumanBodyActivity.java    From HumanBody with Apache License 2.0 4 votes vote down vote up
/**
 * 将圆点add入,播放动画
 * @author leibing
 * @createTime 2016/10/07
 * @lastModify 2016/10/07
 * @param clickPos 点击部位
 * @return
 */
public void addIVandPlay(int clickPos){
    setCanTouch(false);
    // 设置点X、Y坐标
    ivPoint.setX(touchScreenPos[0] - 15);
    ivPoint.setY(touchScreenPos[1] - getStatusBarHeight() - toTopDistance);
    // 将点添加到父类容器
    if(ivPoint.getParent() == null){
        treatSelfBodyFly.addView(ivPoint);
    }
    // 人体部位提示框
    // 1:头部;2:颈部;3:胸部;4:腹部;5:男性勾股;6:女性盆骨;7:上肢;8:下肢;
    // 9:下肢(本应足部,但数据没分出来);10:背部;11:腰部;12:臀部;
    // 13:上肢(本应手指,但数据没分出来)
    switch (clickPos){
        case 1:
            posName = "头部";
            break;
        case 2:
            posName = "颈部";
            break;
        case 3:
            posName = "胸部";
            break;
        case 4:
            posName = "腹部";
            break;
        case 5:
            posName = "男性勾股";
            break;
        case 6:
            posName = "女性盆骨";
            break;
        case 7:
        case 13:
            posName = "上肢";
            break;
        case 8:
        case 9:
            posName = "下肢";
            break;
        case 10:
            posName = "背部";
            break;
        case 11:
            posName = "腰部";
            break;
        case 12:
            posName = "臀部";
            break;
        default:
            break;
    }
    treatSelfBodyFly.post(new Runnable() {
        @Override
        public void run() {
            mHumanBodyPopupWindow = new HumanBodyPopupWindow(HumanBodyActivity.this, posName);
            mHumanBodyPopupWindow.showAsDropDown(ivPoint,-80,-150);
            mHumanBodyPopupWindow.delayDismissDialog(mHumanBodyPopupWindow, 0);
        }
    });

    // 执行点动画
    pointAnim = (AnimationDrawable) ivPoint.getBackground();
    pointAnim.start();
    int duration = 0;
    for (int i = 0; i < pointAnim.getNumberOfFrames(); i++) {
        duration += pointAnim.getDuration(i);
    }
    // 将点击的部位发送到新启动的activity
    Message msg = Message.obtain();
    msg.what = MSG_TO_NEXT_ACTIVITY;
    Bundle bundle = new Bundle();
    bundle.putInt(CLICK_POS, clickPos);
    // 当前性别
    String curSex = (curSexFace == MAN_FRONT || curSexFace == MAN_BACK)?"男":"女";
    // 将性别值传给Handler
    bundle.putString(SEX, curSex);
    msg.setData(bundle);
    mHandler.sendMessageDelayed(msg, duration);
}
 
Example 16
Source File: HumanBodyActivity.java    From HumanBody with Apache License 2.0 4 votes vote down vote up
/**
 * 将圆点add入,播放动画
 * @author leibing
 * @createTime 2016/10/07
 * @lastModify 2016/10/07
 * @param clickPos 点击部位
 * @return
 */
public void addIVandPlay(int clickPos){
    setCanTouch(false);
    // 设置点X、Y坐标
    ivPoint.setX(touchScreenPos[0] - 15);
    ivPoint.setY(touchScreenPos[1] - getStatusBarHeight() - toTopDistance);
    // 将点添加到父类容器
    if(ivPoint.getParent() == null){
        treatSelfBodyFly.addView(ivPoint);
    }
    // 人体部位提示框
    // 1:头部;2:颈部;3:胸部;4:腹部;5:男性勾股;6:女性盆骨;7:上肢;8:下肢;
    // 9:下肢(本应足部,但数据没分出来);10:背部;11:腰部;12:臀部;
    // 13:上肢(本应手指,但数据没分出来)
    switch (clickPos){
        case 1:
            posName = "头部";
            break;
        case 2:
            posName = "颈部";
            break;
        case 3:
            posName = "胸部";
            break;
        case 4:
            posName = "腹部";
            break;
        case 5:
            posName = "男性勾股";
            break;
        case 6:
            posName = "女性盆骨";
            break;
        case 7:
        case 13:
            posName = "上肢";
            break;
        case 8:
        case 9:
            posName = "下肢";
            break;
        case 10:
            posName = "背部";
            break;
        case 11:
            posName = "腰部";
            break;
        case 12:
            posName = "臀部";
            break;
        default:
            break;
    }
    treatSelfBodyFly.post(new Runnable() {
        @Override
        public void run() {
            mHumanBodyPopupWindow = new HumanBodyPopupWindow(HumanBodyActivity.this, posName);
            mHumanBodyPopupWindow.showAsDropDown(ivPoint,-80,-150);
            mHumanBodyPopupWindow.delayDismissDialog(mHumanBodyPopupWindow, 0);
        }
    });

    // 执行点动画
    pointAnim = (AnimationDrawable) ivPoint.getBackground();
    pointAnim.start();
    int duration = 0;
    for (int i = 0; i < pointAnim.getNumberOfFrames(); i++) {
        duration += pointAnim.getDuration(i);
    }
    // 将点击的部位发送到新启动的activity
    Message msg = Message.obtain();
    msg.what = MSG_TO_NEXT_ACTIVITY;
    Bundle bundle = new Bundle();
    bundle.putInt(CLICK_POS, clickPos);
    // 当前性别
    String curSex = (curSexFace == MAN_FRONT || curSexFace == MAN_BACK)?"男":"女";
    // 将性别值传给Handler
    bundle.putString(SEX, curSex);
    msg.setData(bundle);
    mHandler.sendMessageDelayed(msg, duration);
}