android.graphics.drawable.AnimationDrawable#getNumberOfFrames()源码实例Demo

下面列出了android.graphics.drawable.AnimationDrawable#getNumberOfFrames() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: ProgressBar.java
/**
 * 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;
}
 
源代码2 项目: CSipSimple   文件: IcsProgressBar.java
/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
源代码7 项目: android-apps   文件: IcsProgressBar.java
/**
 * 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;
}
 
源代码8 项目: zen4android   文件: IcsProgressBar.java
/**
 * 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;
}
 
源代码9 项目: zhangshangwuda   文件: IcsProgressBar.java
/**
 * 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;
}
 
/**
 * 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;
}
 
源代码11 项目: DragPointView   文件: PointViewAnimObject.java
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);
    }
}
 
/**
 * @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());
}
 
源代码13 项目: Android_Skin_2.0   文件: NumberProgressBar.java
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;
}
 
源代码14 项目: android_9.0.0_r45   文件: PointerIcon.java
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;
}
 
源代码15 项目: HumanBody   文件: HumanBodyActivity.java
/**
 * 将圆点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);
}
 
源代码16 项目: HumanBody   文件: HumanBodyActivity.java
/**
 * 将圆点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);
}