Search in sources :

Example 1 with GifDecoder

use of com.facebook.animated.giflite.GifDecoder in project fresco by facebook.

the class ImageFormatGifFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mSpinnerEntries = new Entry[] { new Entry(R.string.format_gif_label_small, sampleUris().createGifUri(ImageUriProvider.ImageSize.S)), new Entry(R.string.format_gif_label_medium, sampleUris().createGifUri(ImageUriProvider.ImageSize.M)), new Entry(R.string.format_gif_label_large, sampleUris().createGifUri(ImageUriProvider.ImageSize.L)) };
    mSimpleDraweeView = view.findViewById(R.id.drawee_view);
    final SwitchCompat switchBackground = view.findViewById(R.id.switch_background);
    switchBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mSimpleDraweeView.getHierarchy().setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null);
        }
    });
    final SwitchCompat switchAutoPlay = view.findViewById(R.id.switch_autoplay);
    switchAutoPlay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mAutoPlayEnabled = isChecked;
            refreshAnimation();
        }
    });
    mAutoPlayEnabled = switchAutoPlay.isEnabled();
    final SwitchCompat switchAspect = view.findViewById(R.id.switch_aspect_ratio);
    switchAspect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            ViewGroup.LayoutParams layoutParams = mSimpleDraweeView.getLayoutParams();
            layoutParams.height = layoutParams.width * (isChecked ? 2 : 1);
            mSimpleDraweeView.setLayoutParams(layoutParams);
        }
    });
    mSpinner = (Spinner) view.findViewById(R.id.spinner);
    mSpinner.setAdapter(new SimpleUriListAdapter());
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            refreshAnimation();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mSpinner.setSelection(0);
    final Spinner decoderSpinner = view.findViewById(R.id.spinner_select_decoder);
    decoderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch(position) {
                case 0:
                    mGifDecoder = null;
                    break;
                case 1:
                    mGifDecoder = new GifDecoder();
                    break;
                default:
                    throw new IllegalArgumentException("Unknown decoder selected");
            }
            refreshAnimation();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    decoderSpinner.setSelection(0);
}
Also used : Spinner(android.widget.Spinner) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) GifDecoder(com.facebook.animated.giflite.GifDecoder) CheckerBoardDrawable(com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Aggregations

View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 SwitchCompat (androidx.appcompat.widget.SwitchCompat)1 GifDecoder (com.facebook.animated.giflite.GifDecoder)1 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)1 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)1