Giter Site home page Giter Site logo

myungsinkim / gifdrawable-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nemosupremo/gifdrawable-android

0.0 2.0 0.0 7.35 MB

Java class for rendering and animating gif files on Android that extends Bitmap Drawable that makes use of the Android NDK.

License: MIT License

Makefile 0.41% C 90.78% Java 8.81%

gifdrawable-android's Introduction

GifDrawable

April 13, 2013

Overview

GifDrawable is a BitmapDrawable class extended to provide animated gif capabilities to Android, specifically an ImageView. Natively the only way AFAIK to get animated gif in Android is to either user a WebView, or the poorly documented Movie class. A WebView is overkill, and the Movie class isn't very flexible.

The GifDrawable uses the JNI so that GIF frames can be drawn in sub 10ms. A attempted a pure Java implementation and it was not very fast.

Libraries

The GIFLIB http://sourceforge.net/projects/giflib/ library is included.

You will need the latest version of the Android NDK to build http://developer.android.com/tools/sdk/ndk/index.html.

Building

  1. Copy the files in /jni to your project.
  2. Copy the com.droidtools.android.graphics.GifDrawable to your project.
  3. cd into the jni directory and run ndk-build

Once done, you should be set up to use the class with your project.

Loading GIFs

Gifs can be loaded by 2 ways.

  1. Loading the gif from the file system using com.droidtools.android.graphics.GifDrawable.gifFromFile(getResources(), "path/to/file.gif")
  2. Loading the gif from the "asset" directory from inside your APK. To do this make sure you place the gif file in the "assets" directory (NOT /res/drawable) and use com.droidtools.android.graphics.GifDrawable.gifFromAsset(getResources(), "path/to/asset.gif")

If you need to load a Gif from a URL, then download the gif to the local filesystem, then load it into GifDrawable.

Animating GIFs

The frames of a GifDrawable can be changed with the com.droidtools.android.graphics.GifDrawable.setLevel(int level) function (http://developer.android.com/reference/android/graphics/drawable/Drawable.html#setLevel(int)). Each 'tick' is 1/100th of a second. (So if a Gif has a delay of 10ms, setLevel(0) and setLevel(1) will be 2 different frames.)

The easiest way to animate a GIF is to simply pass .setLevel((int)(System.currentTimeMillis()/10 % 10000)) to GifDrawable in some sort of onDraw loop or Handler message.

Example

See the com.droidtools.example.MainActivity for an example of using the project.

Supported Devices

Since the <android/asset_manager.h> is only supported in API Level 9, gifFromAsset only supports API Level 9 (Gingerbread). However if you remove those calls, then API Level 5 (Eclair) will be supported.

Bugs

  1. Large gifs can crash
  2. Some dispose methods are unsupported.
  3. com.droidtools.android.graphics.GifDrawable.setLevel() always returns true even if the gif did not need the change frames.

License

Copyright (c) 2013 [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gifdrawable-android's People

Contributors

nemosupremo avatar ph0b avatar

Watchers

James Cloos avatar kelvinkims avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.