com.ncs.msg.ui.widget; android.content.Context; android.content.res.TypedArray; android.graphics.Canvas; android.graphics.Movie; android.util.AttributeSet; android.view.View; com.ncs.msg.R; java.io.ByteArrayOutputStream; java.io.InputStream; GifView View { Movie ; ; = ; ; ; ; ; GifView(Context context) { (context); init(context, ); } GifView(Context context, AttributeSet set) { (context, set); init(context, set); } init(Context context, AttributeSet set) { TypedArray a = context.obtainStyledAttributes(set, R.styleable.); = a.getResourceId(R.styleable., -); = a.getBoolean(R.styleable., ); = a.getInteger( R.styleable., ); a.recycle(); setFocusable(); java.io.InputStream is; is = context.getResources().openRawResource(); () { = Movie.(is); } { [] array = (is); = Movie.(array, , array.); } } onDraw(Canvas canvas) { (!= ) { (!) { updateAnimationTime(); drawMovieFrame(canvas); invalidate(); } { drawMovieFrame(canvas); } } } updateAnimationTime() { now = android.os.SystemClock.(); (== ) { = now; } dur = .duration(); (dur == ) { dur = ; } = () ((now - ) % dur); } drawMovieFrame(Canvas canvas) { .setTime(); canvas.save(Canvas.); .draw(canvas, , ); canvas.restore(); } setPaused(paused) { .= paused; (!paused) { = android.os.SystemClock.() - ; } invalidate(); } isPaused() { .; } onMeasure(widthMeasureSpec, heightMeasureSpec) { widthMode = MeasureSpec.(widthMeasureSpec); widthSize = MeasureSpec.(widthMeasureSpec); heightMode = MeasureSpec.(heightMeasureSpec); heightSize = MeasureSpec.(heightMeasureSpec); width; height; (widthMode == MeasureSpec.) { width = widthSize; } { desired = () (getPaddingLeft() + .width() + getPaddingRight()); width = Math.(desired, widthSize); } (heightMode == MeasureSpec.) { height = heightSize; } { desired = () (getPaddingTop() + .height() + getPaddingBottom()); height = Math.(desired, heightSize); } setMeasuredDimension(width, height); } [] streamToBytes(InputStream is) { ByteArrayOutputStream os = ByteArrayOutputStream(); [] buffer = []; len; { ((len = is.read(buffer)) >= ) { os.write(buffer, , len); } } (java.io.IOException e) { } os.toByteArray(); } } <declare-styleable name="gifCommon"> <attr name="gif_src" format="reference" /> <attr name="decode_stream" format="boolean" /> <attr name="default_animation_time" format="integer" /> </declare-styleable> <com.example.powerimageviewtest.GifView android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#ffffff" gif:decode_stream="true" gif:default_animation_time="1000" gif:gif_src="@drawable/corporate_login" />