GIFView is a library for showing GIFs in applications

Related tags

UI/UX GIFView
Overview

GIFView

GIFView is a library for showing GIFs in applications.

Setup

In your project's build.gradle file:

allprojects {
    repositories {
        ...
        maven { 
            url "https://jitpack.io"
        }
        ...
    }
}

In your Application's or Module's build.gradle file:

dependencies {
    ...
    compile 'com.github.Gavras:GIFView:v1.2'
    ...
}

XML Attributes:

starting_on_init: A boolean that represents if the view starts the gif when its initialization finishes or not. Default is true.

on_click_start_or_pause: If sets to true, every click toggles the state of the gif. If the gif is showing stops the gif, and if the gif is not showing starts it. If sets to false clicking the gif does nothing. Default is false.

delay_in_millis: A positive integer that represents how many milliseconds should pass between every calculation of the next frame to be set. Default is 33.

gif_src: A string that represents the gif's source.

  • If you want to get the gif from a url concatenate the string "url:" with the full url.

  • if you want to get the gif from the assets directory concatenate the string "asset:" with the full path of the gif within the assets directory. You can exclude the .gif extension.

for example if you have a gif in the path "assets/ex_dir/ex_gif.gif" the string should be: "asset:ex_dir/ex_gif"

Code Example

From XML:

<com.whygraphics.gifview.gif.GIFView xmlns:gif_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_activity_gif_vie"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:scaleType="center"
        gif_view:gif_src="url:http://pop.h-cdn.co/assets/16/33/480x264/gallery-1471381857-gif-season-2.gif" />

In the activity:

GIFView mGifView = (GIFView) findViewById(R.id.main_activity_gif_vie);
        
mGifView.setOnSettingGifListener(new GIFView.OnSettingGifListener() {
            @Override
            public void onSuccess(GIFView view, Exception e) {
                Toast.makeText(MainActivity.this, "onSuccess()", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailure(GIFView view, Exception e) {

            }
});

Setting the gif programmatically:

mGifView.setGifResource("asset:gif1");

File Caching

GIFView is caching all GIF files it downloads when being provided with an URL to an image. If an InputStream is used, no caching is performed.

The caching works as follows:

The GIFView initializes the GIFCache class with the URL provided by the caller. The GIFCache class now checks for the existence of the sub-directory "GIFView" within the app's own cache-directory. If that is not found, it will be created and the GIF-image will be downloaded into it. If it does exist, the existence of the GIF-image is checked, and if found, the cached-version will be provided. If the image is not found, it will be downloaded and then the cached file will be used.

In order to clear the cached files programmatically, GIFCache offers the possibility to retrieve the folder as a java.io.File object by calling the static method getCacheSubDir():

File GIFCache.getCacheSubDir(Context context);
Comments
  • Caching when downloading via URL

    Caching when downloading via URL

    When GIFView is requested to download the GIF images via URL, caching that image falls into the responsibility of the View. It doesn't, when the caller provides an InputStream, but if the caller only provides an URL, the GIFView should do the caching. Therefore, I have created this PR, with a class called GIFCache that hooks into the loading process when loading from an URL, and downloads the GIF image into the app's cache area, and opens an InputStream from there, passing that on, as before was done with the URL-inputstream.

    opened by dimensionv 8
  • use library in RecyclerView

    use library in RecyclerView

    i want to use library in recyclerview but it has one problem : lib downloads gif every time on view create and need disk & memory cache. can you update library and add this feature?

    opened by imehrzadm 7
  • The Gif has not been initialized yet

    The Gif has not been initialized yet

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.al_rehman.dawatiapp/com.al_rehman.dawatiapp.activities.Tasbeeh}: java.lang.IllegalStateException: the gif has not been initialized yet

    After View initialized GifView Implementation,

    gifView1.setGifResource("asset:tashbeeh_counter"); gifView1.start();

    After Click on Button.

    private void runHandler() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                gifView1.stop();
                if (m != null) {
                    if (m.isPlaying()) {
                        m.stop();
                        m.release();
                        m = new MediaPlayer();
                    }
                }
            }
        }, 1200); // wait for 2 seconds
        calculation();
        gifView1.start();
        if (isAudioAllow)
            playBeep();
    }
    

    PlayBeep Method is just only for using playing Beep for 1 second only.

    Caused by: java.lang.IllegalStateException: the gif has not been initialized yet

    @Gavras can you please help me to resolve that issue asap.

    Thanks you.

    opened by masheransari 0
  • Play animation once only

    Play animation once only

    I am using your library and I can display animated gifs in Android. I would like to be able to play the animation only once from the begin to end. Is this possible? Kind Regards DanG

    opened by dgogoasa 3
  • Transparent gif displays frames at background.

    Transparent gif displays frames at background.

    I have been using your gif code snippet. Problem is its displaying the older frames at background. Is this a known issue or do we have any solution for this. See attachment image.

    Thanks

    Original Gif: giphy

    After loading via your code: Screenshot_20190313-180746

    opened by DeepakPandiri 3
  • Only first image is displayed

    Only first image is displayed

    Hello, I successfully used this view in my app but when I am setting GIF by using InputStream only first image is displayed.

    Please any suggestion...

    My code is....

        final GIFView mGifView = (GIFView) findViewById(R.id.main_activity_gif_vie);
    
        InputStream is=null;
        try {
            is=new FileInputStream("/sdcard/test.gif");
    
            mGifView.setGifResource(is);
    
    
    
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    
    
        mGifView.setOnSettingGifListener(new GIFView.OnSettingGifListener() {
            @Override
            public void onSuccess(GIFView view, Exception e) {
                Toast.makeText(Main2Activity.this, "onSuccess()", Toast.LENGTH_SHORT).show();
                mGifView.start(); // I have tested with and without this statement
            }
    
            @Override
            public void onFailure(GIFView view, Exception e) {
            }
        });
    
    opened by ghanshyambagul 1
Releases(v1.2)
Owner
Tzlil Gavra
https://www.linkedin.com/in/tzlil-gavra-973663127/
Tzlil Gavra
GreenDroid is a development library for the Android platform. It makes UI developments easier and consistent through your applications.

#GreenDroid Foreword : This project, initially initiated by me, Cyril Mottier, is not maintained anymore and can be considered as deprecated. As a con

Cyril Mottier 2.6k Jan 4, 2023
A color picker and a color preference for use in Android applications.

HSV-Alpha Color Picker for Android This library implements a color picker and a color preference for use in Android applications. Features I couldn't

Martin Stone 279 Nov 26, 2022
A customizable debug screen to view and edit flags that can be used for development in Jetpack Compose applications

Tweaks A customizable debug screen to view and edit flags that can be used for development in Jetpack Compose applications To include the library add

Guillermo Merino Jiménez 4 Jan 14, 2022
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Enrique López Mañas 3.6k Dec 29, 2022
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
Android library providing bread crumbs to the support library fragments.

Hansel And Gretel Android library providing bread crumbs for compatibility fragments. Usage For a working implementation of this project see the sampl

Jake Wharton 163 Nov 25, 2022
A Tinder-like Android library to create the swipe cards effect. You can swipe left or right to like or dislike the content.

Swipecards Travis master: A Tinder-like cards effect as of August 2014. You can swipe left or right to like or dislike the content. The library create

Dionysis Lorentzos 2.3k Dec 9, 2022
A Material design Android pincode library. Supports Fingerprint.

LolliPin A Lollipop material design styled android pincode library (API 14+) To include in your project, add this to your build.gradle file: //Loll

Omada Health 1.6k Nov 25, 2022
Android Library to implement simple touch/tap/swipe gestures

SimpleFingerGestures An android library to implement simple 1 or 2 finger gestures easily Example Library The library is inside the libSFG folder Samp

Arnav Gupta 315 Dec 21, 2022
Useful library to use custom fonts in your android app

EasyFonts A simple and useful android library to use custom fonts in android apps without adding fonts into asset/resource folder.Also by using this l

Vijay Vankhede 419 Sep 9, 2022
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

Jake Klinker 1.3k Nov 25, 2022
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

Umano: News Read To You 9.4k Dec 31, 2022
An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.

ShortcutBadger: The ShortcutBadger makes your Android App show the count of unread messages as a badge on your App shortcut! Supported launchers: Sony

Leo Lin 7.2k Dec 30, 2022
Android Library to build a UI Card

Card Library Travis master: Travis dev: Card Library provides an easy way to display a UI Card using the Official Google CardView in your Android app.

Gabriele Mariotti 4.7k Dec 29, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
A horizontal view scroller library for Android

View Flow for Android ViewFlow is an Android UI widget providing a horizontally scrollable ViewGroup with items populated from an Adapter. Scroll down

Patrik Åkerfeldt 1.8k Dec 29, 2022
[] Android library that provides a file explorer to let users select files on external storage.

aFileChooser - Android File Chooser aFileChooser is an Android Library Project that simplifies the process of presenting a file chooser on Android 2.1

Paul Burke 1.8k Jan 5, 2023
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Android library for multiple snapping of RecyclerView

MultiSnapRecyclerView Gradle dependencies { implementation 'com.github.takusemba:multisnaprecyclerview:x.x.x' } Features This is an Android Libra

TakuSemba 2.5k Jan 4, 2023