Search in sources :

Example 1 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat 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)

Example 2 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project fresco by facebook.

the class DraweeHierarchyFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    final Uri uriSuccess = sampleUris().createSampleUri(ImageUriProvider.ImageSize.XL, ImageUriProvider.Orientation.ANY, ImageUriProvider.UriModification.CACHE_BREAKER);
    final Uri uriFailure = sampleUris().getNonExistingUri();
    final SimpleDraweeView draweeView = view.findViewById(R.id.drawee);
    final SwitchCompat retrySwitch = view.findViewById(R.id.retry_enabled);
    // noinspection deprecation
    final Drawable failureDrawable = getResources().getDrawable(R.drawable.ic_error_black_96dp);
    DrawableCompat.setTint(failureDrawable, Color.RED);
    final ProgressBarDrawable progressBarDrawable = new ProgressBarDrawable();
    progressBarDrawable.setColor(getResources().getColor(R.color.accent));
    progressBarDrawable.setBackgroundColor(getResources().getColor(R.color.primary));
    progressBarDrawable.setRadius(getResources().getDimensionPixelSize(R.dimen.drawee_hierarchy_progress_radius));
    draweeView.getHierarchy().setProgressBarImage(progressBarDrawable);
    draweeView.getHierarchy().setFailureImage(failureDrawable, ScaleType.CENTER_INSIDE);
    view.findViewById(R.id.load_success).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setUri(draweeView, uriSuccess, retrySwitch.isChecked());
        }
    });
    view.findViewById(R.id.load_fail).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setUri(draweeView, uriFailure, retrySwitch.isChecked());
        }
    });
    view.findViewById(R.id.clear).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            draweeView.setController(null);
            Fresco.getImagePipeline().evictFromCache(uriSuccess);
        }
    });
    final SwitchCompat roundCorners = view.findViewById(R.id.switch_rounded);
    roundCorners.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            RoundingParams roundingParams = new RoundingParams().setCornersRadius(isChecked ? buttonView.getResources().getDimensionPixelSize(R.dimen.drawee_hierarchy_corner_radius) : 0);
            draweeView.getHierarchy().setRoundingParams(roundingParams);
        }
    });
    final SwitchCompat useNinePatch = view.findViewById(R.id.switch_ninepatch);
    useNinePatch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            draweeView.getHierarchy().setPlaceholderImage(isChecked ? R.drawable.ninepatch : R.drawable.logo, isChecked ? ScaleType.FIT_XY : ScaleType.CENTER_INSIDE);
        }
    });
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Drawable(android.graphics.drawable.Drawable) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Uri(android.net.Uri) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) CompoundButton(android.widget.CompoundButton) RoundingParams(com.facebook.drawee.generic.RoundingParams) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 3 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project fresco by facebook.

the class ImageFormatSvgFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mSimpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view);
    mSimpleDraweeView.setImageURI(sampleUris().createSvgUri());
    final SwitchCompat switchBackground = (SwitchCompat) 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);
        }
    });
    SwitchCompat switchCompat = (SwitchCompat) view.findViewById(R.id.decoder_switch);
    switchCompat.setChecked(CustomImageFormatConfigurator.isSvgEnabled(getContext()));
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            CustomImageFormatConfigurator.setSvgEnabled(getContext(), isChecked);
            getShowRestartMessageDialog().show(getChildFragmentManager(), null);
        }
    });
}
Also used : CheckerBoardDrawable(com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable) CompoundButton(android.widget.CompoundButton) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 4 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project K6nele by Kaljurand.

the class RewritesActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.rewrites, menu);
    // TODO: review (seems like a detour)
    MenuItem menuItem = menu.findItem(R.id.menuRewritesToggle);
    menuItem.setActionView(R.layout.ab_switch);
    SwitchCompat abSwitch = menuItem.getActionView().findViewById(R.id.abSwitch);
    abSwitch.setChecked(mRewrites.isSelected());
    abSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
        mRewrites.setSelected(isChecked);
        if (isChecked) {
            toast(String.format(getString(R.string.toastActivated), mRewrites.getId()));
        } else {
            toast(String.format(getString(R.string.toastDeactivated), mRewrites.getId()));
        }
    });
    /*
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        MenuItem searchMenuItem = menu.findItem(R.id.search);
        SearchView searchView = (SearchView) searchMenuItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setSubmitButtonEnabled(false);
        searchView.setOnQueryTextListener(mFragment);
        */
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 5 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project sexytopo by richsmith.

the class DeviceActivity method toggleConnection.

public void toggleConnection(View view) {
    SwitchCompat connectionSwitch = (SwitchCompat) view;
    if (connectionSwitch.isChecked()) {
        Log.device(getString(R.string.device_log_connection_requested));
        isConnectionStartingOrStarted = true;
        startConnection();
    } else {
        Log.device(getString(R.string.device_log_connection_stop_requested));
        isConnectionStartingOrStarted = false;
        stopConnection();
    }
}
Also used : SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Aggregations

SwitchCompat (androidx.appcompat.widget.SwitchCompat)43 TextView (android.widget.TextView)23 View (android.view.View)20 CompoundButton (android.widget.CompoundButton)17 RelativeLayout (android.widget.RelativeLayout)8 LayoutInflater (android.view.LayoutInflater)7 AlertDialog (androidx.appcompat.app.AlertDialog)6 PopupMenu (androidx.appcompat.widget.PopupMenu)6 Toolbar (androidx.appcompat.widget.Toolbar)5 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)5 ArrayList (java.util.ArrayList)5 Activity (android.app.Activity)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 Uri (android.net.Uri)4 ViewGroup (android.view.ViewGroup)4 ContextCompat (androidx.core.content.ContextCompat)4 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)4 Dialog (android.app.Dialog)3 Drawable (android.graphics.drawable.Drawable)3