All Projects → Tenor-Inc → tenor-android-core

Tenor-Inc / tenor-android-core

Licence: Apache-2.0 license
Tenor Android Core

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to tenor-android-core

AMProgressHUD
A gif progress HUD for iOS.
Stars: ✭ 18 (-25%)
Mutual labels:  gif, loading-gifs
ZLPhotoBrowser-objc
(ZLPhotoBrowser oc 版本)轻量级照片选择框架,支持预览/相册内拍照及录视频、拖拽/滑动选择,编辑裁剪图片/视频,支持多语言国际化等功能
Stars: ✭ 54 (+125%)
Mutual labels:  gif
GTA-One-Liners
A collection of gifs made out of almost every dialogue in GTA and other games.
Stars: ✭ 37 (+54.17%)
Mutual labels:  gif
glips
screen clip to gif on web
Stars: ✭ 18 (-25%)
Mutual labels:  gif
gifter
Gif image renderer running in terminal.
Stars: ✭ 44 (+83.33%)
Mutual labels:  gif
durdraw
Animated Unicode, ANSI and ASCII Art Editor for Linux/Unix/macOS
Stars: ✭ 55 (+129.17%)
Mutual labels:  gif
AppThinning
Make app thinner. Help you find large files and compress png, gif, jpg, svg files. 应用程序瘦身工具,帮助你找到大文件,压缩png、gif、jpg、svg等文件。
Stars: ✭ 22 (-8.33%)
Mutual labels:  gif
gcnet
GCNet (GIF Caption Network) | Neural Network Generated GIF Captions
Stars: ✭ 14 (-41.67%)
Mutual labels:  gif
imagor
Fast, Docker-ready image processing server in Go and libvips
Stars: ✭ 2,276 (+9383.33%)
Mutual labels:  gif
tube2gif
Search and Generate Gif from Youtube
Stars: ✭ 21 (-12.5%)
Mutual labels:  gif
KGySoft.Drawing
KGy SOFT Drawing is a library for advanced image, icon and graphics handling.
Stars: ✭ 27 (+12.5%)
Mutual labels:  gif
Password Generator
🔄 Simple password generator class library in C# 6.0, use for generate your own password! 📗
Stars: ✭ 21 (-12.5%)
Mutual labels:  gif
Waifu2x-GUI
An app that upscales anime-styled images, gifs, and videos with waifu2x.
Stars: ✭ 89 (+270.83%)
Mutual labels:  gif
dot-screencap
A screencapturing library
Stars: ✭ 31 (+29.17%)
Mutual labels:  gif
GifBackgroundView
Gif background view demo
Stars: ✭ 21 (-12.5%)
Mutual labels:  gif
codegif
Use Canvas API to make a gif animation
Stars: ✭ 32 (+33.33%)
Mutual labels:  gif
img2gcode
convert jpg, png,gif to gcode with nodejs and jimp
Stars: ✭ 31 (+29.17%)
Mutual labels:  gif
Countdown-Gif-Generator
Generates a gif of a countdown clock at the endpoint that can be used on websites and in emails
Stars: ✭ 21 (-12.5%)
Mutual labels:  gif
reactnative-gallery-web
🎬 visualize RN apps at a glance
Stars: ✭ 54 (+125%)
Mutual labels:  gif
AGMobileGiftInterface
simplified interaction with GIF animations
Stars: ✭ 40 (+66.67%)
Mutual labels:  gif

Tenor Android Core

Introduction

Tenor's API delivers the most relevant GIFs for users anywhere in the world, across more than 30 languages. The Tenor Android Core provides Android developers with the code necessary to integrate essential Tenor GIF functionality into android mobile apps.

The Tenor Android Core provides all the requisite tools for an easy way to search for GIFs and to display GIFs - either as a single GIF, or as a single or multi-column list of GIFs.

To add Tenor GIF search to your app, please follow the steps below.

Setup

The following instructions are based on Android Studio.

Option 1: Embed as a Module

To embed the tenor-android-core.aar file as a module, right-click the project and select New -> Module -> Import .JAR/.AAR, then select the tenor-android-core.arr.

Once the file has been imported, you will need to include the tenor-android-core module as a dependency of any module that will use the core. Add the following lines to the build.gradle files of these modules:

    dependencies {
        compile project(':tenor-android-core')
    }

Option 2: Embed as a Library File

Alternatively, you can copy the tenor-android-core.aar into the libs folder of your app module.

This approach requires some additional setup on the build.gradle file of your app module, by adding the following lines:

    repositories {
        flatDir{
            dirs 'libs'
        }
    }

    dependencies {
      compile(name: 'tenor-android-core', ext: 'aar') {
          transitive = true
      }
    }

Additional Required Dependencies

For either of the import options used, you will also need to add the following dependencies to every module where tenor-android-core has been added, in order to use the full functionality of the Tenor Android Core:

  compile 'com.squareup.retrofit2:converter-gson:2.3.0'
  compile 'com.github.bumptech.glide:glide:3.8.0'
  compile 'com.android.support:support-annotations:26.1.0'

Initialize Tenor Core

You will need an API_KEY from Tenor. To request an api key, click here.

On your app's subclass of the Application class, add the following lines of code to the onCreate() function:

@Override
public void onCreate() {
    super.onCreate();

    // Create a builder for ApiService
    ApiService.IBuilder<IApiClient> builder = new ApiService.Builder<>(this, IApiClient.class)

    // add your tenor API key here
    builder.apiKey("");

    // initialize the Tenor ApiClient
    ApiClient.init(this, builder);
}

Alternatively, if you don't have a subclass of Application, then you should add these lines into your launcher activity.

Retrieving GIFs from Tenor

The Tenor API offers robust ways to fetch the most relevant GIFs your application’s users are most likely to share. The following sections will describe the simplest ways to fetch a stream of GIFs: the trending and the search API end points.

Trending GIFs

The trending stream fetches whatever the most popular GIFs are at the time of the request, in the order of most popular. If you wish to display GIFs to a user before a specific search term has been selected or entered, Tenor recommends displaying trending GIFs. To access the trending API endpoint, add these lines of code to your application:

    Call<GifsResponse> call = ApiClient.getInstance(getContext()).getTrending(
                    ApiClient.getServiceIds(getContext()),limit, pos);

    call.enqueue(new WeakRefCallback<Activity, GifsResponse>(this) {
        @Override
        public void success(@NonNull Activity activity, @Nullable GifsResponse response) {
            // handle success case
        }

        @Override
        public void failure(@NonNull Activity activity, @Nullable BaseError error) {
            // handle failure case
        }
    });

ApiClient.getServiceIds(getContext()) contains the necessary info for API authentication and accurate content results. The only additional fields that need to be supplied are limit and pos:

  • limit (type integer) - Fetch up to a specified number of results (max: 50).
  • pos (type string) - Get results starting at position "value". Use empty string "" for the initial pos.

Searching GIFs by a Specific Search Term

Search is where Tenor's API particularly excels. Our understanding of what daily users search, share, upload, favorite, and collect allows us to continually return with precision the most relevant and shareable GIFs.

search uses the same fields as trending, but with an additional q field that takes a single or multiple words, to return the most precise GIFs possible.

    Call<GifsResponse> call = ApiClient.getInstance(getContext()).search(
                    ApiClient.getServiceIds(getContext()), q, limit, pos);

    call.enqueue(new WeakRefCallback<Activity, GifsResponse>(this) {
        @Override
        public void success(@NonNull Activity activity, @Nullable GifsResponse response) {
            // handle success case
        }

        @Override
        public void failure(@NonNull Activity activity, @Nullable BaseError error) {
            // handle failure case
        }
    });

To see a detailed look of the GIF response JSON object, click here.

Displaying GIFs

Once the search or trending response is received, the GIFs can now be loaded into an ImageView. There are two steps involved in displaying GIFs.

Getting the GIF Url

For a stream of multiple GIFs being displayed at once, as well as creating smaller bundles used for sharing, Tenor reccommends using MediaCollectionFormats.GIF_TINY. Whereas for full size GIFs, you may use MediaCollectionFormats.GIF.

    // using the response variable from the success callback
    Result gif_result_object = response.getResults().get(i); // `i` being the index of the result
    String gif_url = gif_result_object.getMedias().get(i).get(type).getUrl();

A full list of available url types may be found in the MediaCollectionFormats class.

Loading the GIF into an ImageView

Once you have the url of the GIF, you can load it into an ImageView. There are many content loading libraries available, but Tenor reccomend's Glide, as it offers full support for loading GIFs into an ImageView.

We start by constructing a GlideTaskParams, which takes full advantage of the Glide library:

    GlideTaskParams<ImageView> params = new GlideTaskParams<>(mImageView, gif_url);
    params.setListener(new WeakRefContentLoaderTaskListener<Context, ImageView>(getContext()) {
            @Override
            public void success(@NonNull Context context, @NonNull ImageView imageView, @Nullable Drawable drawable) {
                // handle the success case
            }

            @Override
            public void failure(@NonNull Context context, @NonNull ImageView imageView, @Nullable Drawable drawable) {
                // handle the success case
            }
        });

mImageView is the reference to the ImageView where the GIF will be displayed, and you can also add a callback for when the gif loading has completed. For the full list of available loading options, see the GlideTaskParams class.

Once the params variable is constructed, use the GifLoader class to load the GIF:

    GifLoader.loadGif(getContext(), params);

Following the instructions above will enable your app to search and display GIFs to your users. A working demo - which showcases search,trending, and GIF image loading, as well as other Tenor API features like tags and search suggestions - can be found here.

For full documentation of the Tenor API, with details on how to further refine and bolster your users' GIF experience, click here.

FAQs

  1. Why does my GIF not appear after I call loadGif?

    • Check what the height and width are set to in the ImageView, and its parent widgets. If the ImageView or its parent has WRAP_CONTENT for both the height and width, the GIF rendering may not succeed (and neither callback of the WeakRefLoadImageListener will fire). When this happens, the ImageView will be interpreted as having both a height and width of 0. Check that bounds have been given in either the xml or in the java code. Depending on your view structure, a MATCH_PARENT in either the height or width may be sufficient.
  2. I get a gradle error message Error:Failed to resolve: com.android.support:support-v4:26.0.1. What is causing this?

    • If your app is building to Android API 26 and up, the following lines are required in order for the Tenor Android Core to build. Add them to your application's root build.gradle file.
        allprojects {
            repositories {
                maven { url 'https://maven.google.com' }
            }
        }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].