Example usage for android.widget CheckBox.OnCheckedChangeListener CheckBox.OnCheckedChangeListener

List of usage examples for android.widget CheckBox.OnCheckedChangeListener CheckBox.OnCheckedChangeListener

Introduction

In this page you can find the example usage for android.widget CheckBox.OnCheckedChangeListener CheckBox.OnCheckedChangeListener.

Prototype

CheckBox.OnCheckedChangeListener

Source Link

Usage

From source file:ca.xef6.firecamp.ProfilePictureSampleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View fragmentView = inflater.inflate(R.layout.fragment_profile_picture_sample, parent, false);

    randomGenerator = new Random((new Date()).getTime());

    profilePic = (ProfilePictureView) fragmentView.findViewById(R.id.profilepic);
    smallerButton = (Button) fragmentView.findViewById(R.id.smallerButton);
    largerButton = (Button) fragmentView.findViewById(R.id.largerButton);
    sizeLabel = (TextView) fragmentView.findViewById(R.id.sizeLabel);
    presetSizeView = fragmentView.findViewById(R.id.presetSizeView);
    customSizeView = (SeekBar) fragmentView.findViewById(R.id.customSizeView);
    cropToggle = (CheckBox) fragmentView.findViewById(R.id.squareCropToggle);

    LinearLayout container = (LinearLayout) fragmentView.findViewById(R.id.userbuttoncontainer);
    int numChildren = container.getChildCount();
    for (int i = 0; i < numChildren; i++) {
        View childView = container.getChildAt(i);
        Object tag = childView.getTag();
        if (childView instanceof Button) {
            setupUserButton((Button) childView);
            if (i == 0) {
                // Initialize the image to the first user
                firstUserId = tag.toString();
            }/*from  w ww  .  j a v  a 2  s  . co m*/
        }
    }

    cropToggle.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            profilePic.setCropped(checked);
        }
    });

    final Button sizeToggle = (Button) fragmentView.findViewById(R.id.sizeToggle);
    sizeToggle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (pictureSizeType != ProfilePictureView.CUSTOM) {
                sizeToggle.setText("preset size button text");
                switchToCustomSize();
            } else {
                sizeToggle.setText("custom size button text");
                switchToPresetSize(ProfilePictureView.LARGE);
            }
        }
    });

    smallerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (profilePic.getPresetSize()) {
            case ProfilePictureView.LARGE:
                switchToPresetSize(ProfilePictureView.NORMAL);
                break;
            case ProfilePictureView.NORMAL:
                switchToPresetSize(ProfilePictureView.SMALL);
                break;
            }
        }
    });

    largerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (profilePic.getPresetSize()) {
            case ProfilePictureView.NORMAL:
                switchToPresetSize(ProfilePictureView.LARGE);
                break;
            case ProfilePictureView.SMALL:
                switchToPresetSize(ProfilePictureView.NORMAL);
                break;
            }
        }
    });

    // We will fetch a new image for each change in the SeekBar. So keeping the count low
    // to prevent too much network chatter. SeekBar reports 0-max, so we will get max+1
    // notifications of change.
    customSizeView.setMax(MAX_CUSTOM_SIZES);
    customSizeView.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            updateProfilePicForCustomSizeIncrement(i);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // NO-OP
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // NO-OP
        }
    });

    restoreState(savedInstanceState);

    return fragmentView;
}

From source file:com.facebook.samples.profilepicture.ProfilePictureSampleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View fragmentView = inflater.inflate(R.layout.fragment_profile_picture_sample, parent, false);

    randomGenerator = new Random((new Date()).getTime());

    profilePic = (ProfilePictureView) fragmentView.findViewById(R.id.profilepic);
    smallerButton = (Button) fragmentView.findViewById(R.id.smallerButton);
    largerButton = (Button) fragmentView.findViewById(R.id.largerButton);
    sizeLabel = (TextView) fragmentView.findViewById(R.id.sizeLabel);
    presetSizeView = fragmentView.findViewById(R.id.presetSizeView);
    customSizeView = (SeekBar) fragmentView.findViewById(R.id.customSizeView);
    cropToggle = (CheckBox) fragmentView.findViewById(R.id.squareCropToggle);

    LinearLayout container = (LinearLayout) fragmentView.findViewById(R.id.userbuttoncontainer);
    int numChildren = container.getChildCount();
    for (int i = 0; i < numChildren; i++) {
        View childView = container.getChildAt(i);
        Object tag = childView.getTag();
        if (childView instanceof Button) {
            setupUserButton((Button) childView);
            if (i == 0) {
                // Initialize the image to the first user
                firstUserId = tag.toString();
            }//from   ww  w  .j  a v a2 s.c o  m
        }
    }

    cropToggle.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean checked) {
            profilePic.setCropped(checked);
        }
    });

    final Button sizeToggle = (Button) fragmentView.findViewById(R.id.sizeToggle);
    sizeToggle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (pictureSizeType != ProfilePictureView.CUSTOM) {
                sizeToggle.setText(R.string.preset_size_button_text);
                switchToCustomSize();
            } else {
                sizeToggle.setText(R.string.custom_size_button_text);
                switchToPresetSize(ProfilePictureView.LARGE);
            }
        }
    });

    smallerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (profilePic.getPresetSize()) {
            case ProfilePictureView.LARGE:
                switchToPresetSize(ProfilePictureView.NORMAL);
                break;
            case ProfilePictureView.NORMAL:
                switchToPresetSize(ProfilePictureView.SMALL);
                break;
            }
        }
    });

    largerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (profilePic.getPresetSize()) {
            case ProfilePictureView.NORMAL:
                switchToPresetSize(ProfilePictureView.LARGE);
                break;
            case ProfilePictureView.SMALL:
                switchToPresetSize(ProfilePictureView.NORMAL);
                break;
            }
        }
    });

    // We will fetch a new image for each change in the SeekBar. So keeping the count low
    // to prevent too much network chatter. SeekBar reports 0-max, so we will get max+1
    // notifications of change.
    customSizeView.setMax(MAX_CUSTOM_SIZES);
    customSizeView.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            updateProfilePicForCustomSizeIncrement(i);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // NO-OP
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // NO-OP
        }
    });

    restoreState(savedInstanceState);

    return fragmentView;
}