Search in sources :

Example 1 with LottieComposition

use of com.airbnb.lottie.LottieComposition in project lottie-android by airbnb.

the class AnimationFragment method loadUrl.

private void loadUrl(String url) {
    Request request;
    try {
        request = new Request.Builder().url(url).build();
    } catch (IllegalArgumentException e) {
        onLoadError();
        return;
    }
    if (client == null) {
        client = new OkHttpClient();
    }
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            onLoadError();
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (!response.isSuccessful()) {
                onLoadError();
            }
            try {
                JSONObject json = new JSONObject(response.body().string());
                LottieComposition.Factory.fromJson(getResources(), json, new OnCompositionLoadedListener() {

                    @Override
                    public void onCompositionLoaded(LottieComposition composition) {
                        setComposition(composition, "Network Animation");
                    }
                });
            } catch (JSONException e) {
                onLoadError();
            }
        }
    });
}
Also used : Call(okhttp3.Call) OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) JSONException(org.json.JSONException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) LottieComposition(com.airbnb.lottie.LottieComposition)

Example 2 with LottieComposition

use of com.airbnb.lottie.LottieComposition in project lottie-android by airbnb.

the class AnimationFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;
    }
    switch(requestCode) {
        case RC_ASSET:
            final String assetName = data.getStringExtra(EXTRA_ANIMATION_NAME);
            animationView.setImageAssetsFolder(assetFolders.get(assetName));
            LottieComposition.Factory.fromAssetFileName(getContext(), assetName, new OnCompositionLoadedListener() {

                @Override
                public void onCompositionLoaded(LottieComposition composition) {
                    setComposition(composition, assetName);
                }
            });
            break;
        case RC_FILE:
            onFileLoaded(data.getData());
            break;
        case RC_URL:
            break;
    }
}
Also used : OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) LottieComposition(com.airbnb.lottie.LottieComposition)

Example 3 with LottieComposition

use of com.airbnb.lottie.LottieComposition in project lottie-android by airbnb.

the class AnimationFragment method onFileLoaded.

private void onFileLoaded(final Uri uri) {
    InputStream fis;
    try {
        switch(uri.getScheme()) {
            case "file":
                fis = new FileInputStream(uri.getPath());
                break;
            case "content":
                fis = getContext().getContentResolver().openInputStream(uri);
                break;
            default:
                onLoadError();
                return;
        }
    } catch (FileNotFoundException e) {
        onLoadError();
        return;
    }
    LottieComposition.Factory.fromInputStream(getContext(), fis, new OnCompositionLoadedListener() {

        @Override
        public void onCompositionLoaded(LottieComposition composition) {
            setComposition(composition, uri.getPath());
        }
    });
}
Also used : OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) LottieComposition(com.airbnb.lottie.LottieComposition)

Example 4 with LottieComposition

use of com.airbnb.lottie.LottieComposition in project lottie-android by airbnb.

the class LottieFontViewGroup method init.

private void init() {
    setFocusableInTouchMode(true);
    LottieComposition.Factory.fromAssetFileName(getContext(), "Mobilo/BlinkingCursor.json", new OnCompositionLoadedListener() {

        @Override
        public void onCompositionLoaded(LottieComposition composition) {
            cursorView = new LottieAnimationView(getContext());
            cursorView.setLayoutParams(new LottieFontViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            cursorView.setComposition(composition);
            cursorView.loop(true);
            cursorView.playAnimation();
            addView(cursorView);
        }
    });
}
Also used : OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) LottieAnimationView(com.airbnb.lottie.LottieAnimationView) LottieComposition(com.airbnb.lottie.LottieComposition)

Example 5 with LottieComposition

use of com.airbnb.lottie.LottieComposition in project lottie-android by airbnb.

the class LottieFontViewGroup method onKeyUp.

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_SPACE) {
        addSpace();
        return true;
    }
    if (keyCode == KeyEvent.KEYCODE_DEL) {
        removeLastView();
        return true;
    }
    if (!isValidKey(event)) {
        return super.onKeyUp(keyCode, event);
    }
    String letter = "" + Character.toUpperCase((char) event.getUnicodeChar());
    // switch (letter) {
    //     case ",":
    //         letter = "Comma";
    //         break;
    //     case "'":
    //         letter = "Apostrophe";
    //         break;
    //     case ";":
    //     case ":":
    //         letter = "Colon";
    //         break;
    // }
    final String fileName = "Mobilo/" + letter + ".json";
    if (compositionMap.containsKey(fileName)) {
        addComposition(compositionMap.get(fileName));
    } else {
        LottieComposition.Factory.fromAssetFileName(getContext(), fileName, new OnCompositionLoadedListener() {

            @Override
            public void onCompositionLoaded(LottieComposition composition) {
                compositionMap.put(fileName, composition);
                addComposition(composition);
            }
        });
    }
    return true;
}
Also used : OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) LottieComposition(com.airbnb.lottie.LottieComposition)

Aggregations

LottieComposition (com.airbnb.lottie.LottieComposition)5 OnCompositionLoadedListener (com.airbnb.lottie.OnCompositionLoadedListener)5 LottieAnimationView (com.airbnb.lottie.LottieAnimationView)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Call (okhttp3.Call)1 Callback (okhttp3.Callback)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1