Search in sources :

Example 6 with OnCompositionLoadedListener

use of com.airbnb.lottie.OnCompositionLoadedListener 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)

Example 7 with OnCompositionLoadedListener

use of com.airbnb.lottie.OnCompositionLoadedListener in project Rocket by mozilla-tw.

the class FirstrunPagerAdapter method getView.

private View getView(int position, ViewPager pager) {
    final View view = LayoutInflater.from(context).inflate(R.layout.firstrun_page, pager, false);
    final FirstrunPage page = pages[position];
    final TextView titleView = (TextView) view.findViewById(R.id.title);
    titleView.setText(page.title);
    final TextView textView = (TextView) view.findViewById(R.id.text);
    textView.setText(page.text);
    final ImageView imageView = (ImageView) view.findViewById(R.id.image);
    final LottieDrawable drawable = new LottieDrawable();
    LottieComposition.Factory.fromAssetFileName(context, page.imageResource, new OnCompositionLoadedListener() {

        @Override
        public void onCompositionLoaded(@Nullable LottieComposition composition) {
            drawable.setComposition(composition);
        }
    });
    imageView.setImageDrawable(drawable);
    final Button buttonView = (Button) view.findViewById(R.id.button);
    buttonView.setOnClickListener(listener);
    if (position == pages.length - 1) {
        buttonView.setText(R.string.firstrun_close_button);
        buttonView.setId(R.id.finish);
    } else {
        buttonView.setText(R.string.firstrun_next_button);
        buttonView.setId(R.id.next);
    }
    if (position == TURBO_MODE_PAGE_INDEX) {
        initForTurboModePage(context, view);
    }
    return view;
}
Also used : LottieDrawable(com.airbnb.lottie.LottieDrawable) OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) LottieComposition(com.airbnb.lottie.LottieComposition)

Example 8 with OnCompositionLoadedListener

use of com.airbnb.lottie.OnCompositionLoadedListener in project atlas by alibaba.

the class LottieFontViewGroup method init.

private void init() {
    final float density = getContext().getResources().getDisplayMetrics().density;
    textSize = (int) (density * 120);
    for (int x = 0; x < 5; x++) {
        cursorView = new LottieAnimationView(getContext());
        cursorView.setLayoutParams(new LayoutParams(textSize, textSize));
        addView(cursorView);
        views.add(cursorView);
    }
    this.postDelayed(new Runnable() {

        @Override
        public void run() {
            LottieComposition.Factory.fromAssetFileName(getContext(), "A.json", new OnCompositionLoadedListener() {

                @Override
                public void onCompositionLoaded(LottieComposition composition) {
                    views.get(0).setBackgroundDrawable(new ColorDrawable(0x112233));
                    views.get(0).setComposition(composition);
                    views.get(0).playAnimation();
                }
            });
        }
    }, 300);
    this.postDelayed(new Runnable() {

        @Override
        public void run() {
            LottieComposition.Factory.fromAssetFileName(getContext(), "T.json", new OnCompositionLoadedListener() {

                @Override
                public void onCompositionLoaded(LottieComposition composition) {
                    views.get(1).setComposition(composition);
                    views.get(1).playAnimation();
                }
            });
        }
    }, 300);
    this.postDelayed(new Runnable() {

        @Override
        public void run() {
            LottieComposition.Factory.fromAssetFileName(getContext(), "L.json", new OnCompositionLoadedListener() {

                @Override
                public void onCompositionLoaded(LottieComposition composition) {
                    views.get(2).setComposition(composition);
                    views.get(2).playAnimation();
                }
            });
        }
    }, 300);
    this.postDelayed(new Runnable() {

        @Override
        public void run() {
            LottieComposition.Factory.fromAssetFileName(getContext(), "A.json", new OnCompositionLoadedListener() {

                @Override
                public void onCompositionLoaded(LottieComposition composition) {
                    views.get(3).setComposition(composition);
                    views.get(3).playAnimation();
                }
            });
        }
    }, 300);
    this.postDelayed(new Runnable() {

        @Override
        public void run() {
            LottieComposition.Factory.fromAssetFileName(getContext(), "S.json", new OnCompositionLoadedListener() {

                @Override
                public void onCompositionLoaded(LottieComposition composition) {
                    views.get(4).setComposition(composition);
                    views.get(4).playAnimation();
                }
            });
        }
    }, 300);
}
Also used : OnCompositionLoadedListener(com.airbnb.lottie.OnCompositionLoadedListener) ColorDrawable(android.graphics.drawable.ColorDrawable) LottieAnimationView(com.airbnb.lottie.LottieAnimationView) LottieComposition(com.airbnb.lottie.LottieComposition)

Aggregations

LottieComposition (com.airbnb.lottie.LottieComposition)8 OnCompositionLoadedListener (com.airbnb.lottie.OnCompositionLoadedListener)8 LottieAnimationView (com.airbnb.lottie.LottieAnimationView)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 LottieDrawable (com.airbnb.lottie.LottieDrawable)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