.class public Lcom/moji/lottie/LottieComposition$Factory;
.super Ljava/lang/Object;
.source "LottieComposition.java"


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/moji/lottie/LottieComposition;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x9
    name = "Factory"
.end annotation


# direct methods
.method private constructor <init>()V
    .locals 0

    .line 103
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static a(Landroid/content/Context;Ljava/io/InputStream;Lcom/moji/lottie/OnCompositionLoadedListener;)Lcom/moji/lottie/Cancellable;
    .locals 2

    .line 127
    new-instance v0, Lcom/moji/lottie/FileCompositionLoader;

    .line 128
    invoke-virtual {p0}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object p0

    invoke-direct {v0, p0, p2}, Lcom/moji/lottie/FileCompositionLoader;-><init>(Landroid/content/res/Resources;Lcom/moji/lottie/OnCompositionLoadedListener;)V

    .line 129
    sget-object p0, Landroid/os/AsyncTask;->THREAD_POOL_EXECUTOR:Ljava/util/concurrent/Executor;

    const/4 p2, 0x1

    new-array p2, p2, [Ljava/io/InputStream;

    const/4 v1, 0x0

    aput-object p1, p2, v1

    invoke-virtual {v0, p0, p2}, Lcom/moji/lottie/FileCompositionLoader;->executeOnExecutor(Ljava/util/concurrent/Executor;[Ljava/lang/Object;)Landroid/os/AsyncTask;

    return-object v0
.end method

.method public static a(Landroid/content/Context;Ljava/lang/String;Lcom/moji/lottie/OnCompositionLoadedListener;)Lcom/moji/lottie/Cancellable;
    .locals 2

    .line 113
    :try_start_0
    invoke-virtual {p0}, Landroid/content/Context;->getAssets()Landroid/content/res/AssetManager;

    move-result-object v0

    invoke-virtual {v0, p1}, Landroid/content/res/AssetManager;->open(Ljava/lang/String;)Ljava/io/InputStream;

    move-result-object v0
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    .line 117
    invoke-static {p0, v0, p2}, Lcom/moji/lottie/LottieComposition$Factory;->a(Landroid/content/Context;Ljava/io/InputStream;Lcom/moji/lottie/OnCompositionLoadedListener;)Lcom/moji/lottie/Cancellable;

    move-result-object p0

    return-object p0

    :catch_0
    move-exception p0

    .line 115
    new-instance p2, Ljava/lang/IllegalStateException;

    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    const-string v1, "Unable to find file "

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p1

    invoke-direct {p2, p1, p0}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw p2
.end method

.method public static a(Landroid/content/res/Resources;Lorg/json/JSONObject;Lcom/moji/lottie/OnCompositionLoadedListener;)Lcom/moji/lottie/Cancellable;
    .locals 2

    .line 149
    new-instance v0, Lcom/moji/lottie/JsonCompositionLoader;

    invoke-direct {v0, p0, p2}, Lcom/moji/lottie/JsonCompositionLoader;-><init>(Landroid/content/res/Resources;Lcom/moji/lottie/OnCompositionLoadedListener;)V

    .line 150
    sget-object p0, Landroid/os/AsyncTask;->THREAD_POOL_EXECUTOR:Ljava/util/concurrent/Executor;

    const/4 p2, 0x1

    new-array p2, p2, [Lorg/json/JSONObject;

    const/4 v1, 0x0

    aput-object p1, p2, v1

    invoke-virtual {v0, p0, p2}, Lcom/moji/lottie/JsonCompositionLoader;->executeOnExecutor(Ljava/util/concurrent/Executor;[Ljava/lang/Object;)Landroid/os/AsyncTask;

    return-object v0
.end method

.method static a(Landroid/content/res/Resources;Ljava/io/InputStream;)Lcom/moji/lottie/LottieComposition;
    .locals 3

    .line 158
    :try_start_0
    invoke-virtual {p1}, Ljava/io/InputStream;->available()I

    move-result v0

    .line 159
    new-array v0, v0, [B

    .line 161
    invoke-virtual {p1, v0}, Ljava/io/InputStream;->read([B)I

    .line 162
    new-instance v1, Ljava/lang/String;

    const-string v2, "UTF-8"

    invoke-direct {v1, v0, v2}, Ljava/lang/String;-><init>([BLjava/lang/String;)V

    .line 163
    new-instance v0, Lorg/json/JSONObject;

    invoke-direct {v0, v1}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V

    .line 164
    invoke-static {p0, v0}, Lcom/moji/lottie/LottieComposition$Factory;->a(Landroid/content/res/Resources;Lorg/json/JSONObject;)Lcom/moji/lottie/LottieComposition;

    move-result-object p0
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Lorg/json/JSONException; {:try_start_0 .. :try_end_0} :catch_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 170
    invoke-static {p1}, Lcom/moji/lottie/Utils;->a(Ljava/io/Closeable;)V

    return-object p0

    :catchall_0
    move-exception p0

    goto :goto_0

    :catch_0
    move-exception p0

    .line 168
    :try_start_1
    new-instance v0, Ljava/lang/IllegalStateException;

    const-string v1, "Unable to load JSON."

    invoke-direct {v0, v1, p0}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v0

    :catch_1
    move-exception p0

    .line 166
    new-instance v0, Ljava/lang/IllegalStateException;

    const-string v1, "Unable to find file."

    invoke-direct {v0, v1, p0}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v0
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    .line 170
    :goto_0
    invoke-static {p1}, Lcom/moji/lottie/Utils;->a(Ljava/io/Closeable;)V

    throw p0
.end method

.method static a(Landroid/content/res/Resources;Lorg/json/JSONObject;)Lcom/moji/lottie/LottieComposition;
    .locals 12

    .line 177
    invoke-virtual {p0}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;

    move-result-object p0

    iget v7, p0, Landroid/util/DisplayMetrics;->density:F

    const-string p0, "w"

    const/4 v0, -0x1

    .line 178
    invoke-virtual {p1, p0, v0}, Lorg/json/JSONObject;->optInt(Ljava/lang/String;I)I

    move-result p0

    const-string v1, "h"

    .line 179
    invoke-virtual {p1, v1, v0}, Lorg/json/JSONObject;->optInt(Ljava/lang/String;I)I

    move-result v1

    const/4 v2, 0x0

    if-eq p0, v0, :cond_0

    if-eq v1, v0, :cond_0

    int-to-float p0, p0

    mul-float p0, p0, v7

    float-to-int p0, p0

    int-to-float v0, v1

    mul-float v0, v0, v7

    float-to-int v0, v0

    .line 184
    new-instance v1, Landroid/graphics/Rect;

    invoke-direct {v1, v2, v2, p0, v0}, Landroid/graphics/Rect;-><init>(IIII)V

    goto :goto_0

    :cond_0
    const/4 p0, 0x0

    move-object v1, p0

    :goto_0
    const-string p0, "ip"

    const-wide/16 v3, 0x0

    .line 187
    invoke-virtual {p1, p0, v3, v4}, Lorg/json/JSONObject;->optLong(Ljava/lang/String;J)J

    move-result-wide v5

    const-string p0, "op"

    .line 188
    invoke-virtual {p1, p0, v3, v4}, Lorg/json/JSONObject;->optLong(Ljava/lang/String;J)J

    move-result-wide v8

    const-string p0, "fr"

    .line 189
    invoke-virtual {p1, p0, v2}, Lorg/json/JSONObject;->optInt(Ljava/lang/String;I)I

    move-result p0

    .line 190
    new-instance v10, Lcom/moji/lottie/LottieComposition;

    const/4 v11, 0x0

    move-object v0, v10

    move-wide v2, v5

    move-wide v4, v8

    move v6, p0

    move-object v8, v11

    invoke-direct/range {v0 .. v8}, Lcom/moji/lottie/LottieComposition;-><init>(Landroid/graphics/Rect;JJIFLcom/moji/lottie/LottieComposition$1;)V

    const-string p0, "assets"

    .line 192
    invoke-virtual {p1, p0}, Lorg/json/JSONObject;->optJSONArray(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object p0

    .line 193
    invoke-static {p0, v10}, Lcom/moji/lottie/LottieComposition$Factory;->b(Lorg/json/JSONArray;Lcom/moji/lottie/LottieComposition;)V

    .line 194
    invoke-static {p0, v10}, Lcom/moji/lottie/LottieComposition$Factory;->a(Lorg/json/JSONArray;Lcom/moji/lottie/LottieComposition;)V

    .line 195
    invoke-static {p1, v10}, Lcom/moji/lottie/LottieComposition$Factory;->a(Lorg/json/JSONObject;Lcom/moji/lottie/LottieComposition;)V

    return-object v10
.end method

.method private static a(Ljava/util/List;Landroid/support/v4/util/LongSparseArray;Lcom/moji/lottie/Layer;)V
    .locals 2
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List<",
            "Lcom/moji/lottie/Layer;",
            ">;",
            "Landroid/support/v4/util/LongSparseArray<",
            "Lcom/moji/lottie/Layer;",
            ">;",
            "Lcom/moji/lottie/Layer;",
            ")V"
        }
    .end annotation

    .line 249
    invoke-interface {p0, p2}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 250
    invoke-virtual {p2}, Lcom/moji/lottie/Layer;->c()J

    move-result-wide v0

    invoke-virtual {p1, v0, v1, p2}, Landroid/support/v4/util/LongSparseArray;->put(JLjava/lang/Object;)V

    return-void
.end method

.method private static a(Lorg/json/JSONArray;Lcom/moji/lottie/LottieComposition;)V
    .locals 11
    .param p0    # Lorg/json/JSONArray;
        .annotation build Landroid/support/annotation/Nullable;
        .end annotation
    .end param

    if-nez p0, :cond_0

    return-void

    .line 213
    :cond_0
    invoke-virtual {p0}, Lorg/json/JSONArray;->length()I

    move-result v0

    const/4 v1, 0x0

    const/4 v2, 0x0

    :goto_0
    if-ge v2, v0, :cond_3

    .line 215
    invoke-virtual {p0, v2}, Lorg/json/JSONArray;->optJSONObject(I)Lorg/json/JSONObject;

    move-result-object v3

    const-string v4, "layers"

    .line 216
    invoke-virtual {v3, v4}, Lorg/json/JSONObject;->optJSONArray(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object v4

    if-nez v4, :cond_1

    goto :goto_2

    .line 220
    :cond_1
    new-instance v5, Ljava/util/ArrayList;

    invoke-virtual {v4}, Lorg/json/JSONArray;->length()I

    move-result v6

    invoke-direct {v5, v6}, Ljava/util/ArrayList;-><init>(I)V

    .line 221
    new-instance v6, Landroid/support/v4/util/LongSparseArray;

    invoke-direct {v6}, Landroid/support/v4/util/LongSparseArray;-><init>()V

    const/4 v7, 0x0

    .line 222
    :goto_1
    invoke-virtual {v4}, Lorg/json/JSONArray;->length()I

    move-result v8

    if-ge v7, v8, :cond_2

    .line 223
    invoke-virtual {v4, v7}, Lorg/json/JSONArray;->optJSONObject(I)Lorg/json/JSONObject;

    move-result-object v8

    invoke-static {v8, p1}, Lcom/moji/lottie/Layer$Factory;->a(Lorg/json/JSONObject;Lcom/moji/lottie/LottieComposition;)Lcom/moji/lottie/Layer;

    move-result-object v8

    .line 224
    invoke-virtual {v8}, Lcom/moji/lottie/Layer;->c()J

    move-result-wide v9

    invoke-virtual {v6, v9, v10, v8}, Landroid/support/v4/util/LongSparseArray;->put(JLjava/lang/Object;)V

    .line 225
    invoke-interface {v5, v8}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    add-int/lit8 v7, v7, 0x1

    goto :goto_1

    :cond_2
    const-string v4, "id"

    .line 227
    invoke-virtual {v3, v4}, Lorg/json/JSONObject;->optString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v3

    .line 228
    invoke-static {p1}, Lcom/moji/lottie/LottieComposition;->c(Lcom/moji/lottie/LottieComposition;)Ljava/util/Map;

    move-result-object v4

    invoke-interface {v4, v3, v5}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    :goto_2
    add-int/lit8 v2, v2, 0x1

    goto :goto_0

    :cond_3
    return-void
.end method

.method private static a(Lorg/json/JSONObject;Lcom/moji/lottie/LottieComposition;)V
    .locals 5

    const-string v0, "layers"

    .line 200
    invoke-virtual {p0, v0}, Lorg/json/JSONObject;->optJSONArray(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object p0

    .line 201
    invoke-virtual {p0}, Lorg/json/JSONArray;->length()I

    move-result v0

    const/4 v1, 0x0

    :goto_0
    if-ge v1, v0, :cond_0

    .line 203
    invoke-virtual {p0, v1}, Lorg/json/JSONArray;->optJSONObject(I)Lorg/json/JSONObject;

    move-result-object v2

    invoke-static {v2, p1}, Lcom/moji/lottie/Layer$Factory;->a(Lorg/json/JSONObject;Lcom/moji/lottie/LottieComposition;)Lcom/moji/lottie/Layer;

    move-result-object v2

    .line 204
    invoke-static {p1}, Lcom/moji/lottie/LottieComposition;->a(Lcom/moji/lottie/LottieComposition;)Ljava/util/List;

    move-result-object v3

    invoke-static {p1}, Lcom/moji/lottie/LottieComposition;->b(Lcom/moji/lottie/LottieComposition;)Landroid/support/v4/util/LongSparseArray;

    move-result-object v4

    invoke-static {v3, v4, v2}, Lcom/moji/lottie/LottieComposition$Factory;->a(Ljava/util/List;Landroid/support/v4/util/LongSparseArray;Lcom/moji/lottie/Layer;)V

    add-int/lit8 v1, v1, 0x1

    goto :goto_0

    :cond_0
    return-void
.end method

.method private static b(Lorg/json/JSONArray;Lcom/moji/lottie/LottieComposition;)V
    .locals 5
    .param p0    # Lorg/json/JSONArray;
        .annotation build Landroid/support/annotation/Nullable;
        .end annotation
    .end param

    if-nez p0, :cond_0

    return-void

    .line 237
    :cond_0
    invoke-virtual {p0}, Lorg/json/JSONArray;->length()I

    move-result v0

    const/4 v1, 0x0

    :goto_0
    if-ge v1, v0, :cond_2

    .line 239
    invoke-virtual {p0, v1}, Lorg/json/JSONArray;->optJSONObject(I)Lorg/json/JSONObject;

    move-result-object v2

    const-string v3, "p"

    .line 240
    invoke-virtual {v2, v3}, Lorg/json/JSONObject;->has(Ljava/lang/String;)Z

    move-result v3

    if-nez v3, :cond_1

    goto :goto_1

    .line 243
    :cond_1
    invoke-static {v2}, Lcom/moji/lottie/LottieImageAsset$Factory;->a(Lorg/json/JSONObject;)Lcom/moji/lottie/LottieImageAsset;

    move-result-object v2

    .line 244
    invoke-static {p1}, Lcom/moji/lottie/LottieComposition;->d(Lcom/moji/lottie/LottieComposition;)Ljava/util/Map;

    move-result-object v3

    invoke-virtual {v2}, Lcom/moji/lottie/LottieImageAsset;->a()Ljava/lang/String;

    move-result-object v4

    invoke-interface {v3, v4, v2}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    :goto_1
    add-int/lit8 v1, v1, 0x1

    goto :goto_0

    :cond_2
    return-void
.end method
