Example usage for android.widget AdapterView setOnClickListener

List of usage examples for android.widget AdapterView setOnClickListener

Introduction

In this page you can find the example usage for android.widget AdapterView setOnClickListener.

Prototype

@Override
    public void setOnClickListener(OnClickListener l) 

Source Link

Usage

From source file:com.willowtreeapps.spurceexampleapp.fragments.ControlsFragment.java

@Nullable
@Override//from   www . j a v  a 2s  . c om
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.controls_fragment, container, false);

    parent = (GridLayout) ((SpruceActivity) getActivity()).parent;
    children = ((SpruceActivity) getActivity()).children;
    sortDropDown = ((SpruceActivity) getActivity()).sortDropDown;

    linearRadioGroup = (RadioGroup) rootView.findViewById(R.id.directional_radio_group);
    corneredRadioGroup = (RadioGroup) rootView.findViewById(R.id.cornered_radio_group);
    positionalRadioGroup = (RadioGroupGridLayout) rootView.findViewById(R.id.positional_radio_group);
    RadioGroup verticalWeightedRadioGroup = (RadioGroup) rootView
            .findViewById(R.id.vertical_weighted_radio_group);
    RadioGroup horizontalWeightedRadioGroup = (RadioGroup) rootView
            .findViewById(R.id.horizontal_weighted_radio_group);
    verticalWeightLayout = (LinearLayout) rootView.findViewById(R.id.vertical_weight);
    horizontalWeightLayout = (LinearLayout) rootView.findViewById(R.id.horizontal_weight);
    linearReversed = (CheckBox) rootView.findViewById(R.id.linear_reversed);
    seekBar = (SeekBar) rootView.findViewById(R.id.animation_seek);
    animationEndText = (TextView) rootView.findViewById(R.id.animation_end);
    seekBarTitle = (TextView) rootView.findViewById(R.id.seek_bar_title);
    codeSample = (EditText) rootView.findViewById(R.id.code_sample);

    animators = new Animator[] { DefaultAnimations.shrinkAnimator(parent, /*duration=*/800),
            DefaultAnimations.fadeInAnimator(parent, /*duration=*/800) };

    View.OnClickListener click = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            resetChildViewsAndStartSort();
        }
    };
    container.setOnClickListener(click);
    parent.setOnClickListener(click);

    sortDropDown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case CORNERED_SORT:
            case INLINE_SORT:
                linearRadioGroup.setVisibility(View.GONE);
                linearReversed.setVisibility(View.VISIBLE);
                positionalRadioGroup.setVisibility(View.GONE);
                verticalWeightLayout.setVisibility(View.GONE);
                horizontalWeightLayout.setVisibility(View.GONE);
                corneredRadioGroup.setVisibility(View.VISIBLE);
                break;
            case LINEAR_SORT:
                linearRadioGroup.setVisibility(View.VISIBLE);
                linearReversed.setVisibility(View.VISIBLE);
                positionalRadioGroup.setVisibility(View.GONE);
                verticalWeightLayout.setVisibility(View.GONE);
                horizontalWeightLayout.setVisibility(View.GONE);
                corneredRadioGroup.setVisibility(View.GONE);
                break;
            case CONTINUOUS_SORT:
            case RADIAL_SORT:
                positionalRadioGroup.setVisibility(View.VISIBLE);
                verticalWeightLayout.setVisibility(View.GONE);
                horizontalWeightLayout.setVisibility(View.GONE);
                linearReversed.setVisibility(View.VISIBLE);
                linearRadioGroup.setVisibility(View.GONE);
                corneredRadioGroup.setVisibility(View.GONE);
                break;
            case CONTINUOUS_WEIGHTED_SORT:
                positionalRadioGroup.setVisibility(View.VISIBLE);
                verticalWeightLayout.setVisibility(View.VISIBLE);
                horizontalWeightLayout.setVisibility(View.VISIBLE);
                linearReversed.setVisibility(View.VISIBLE);
                linearRadioGroup.setVisibility(View.GONE);
                corneredRadioGroup.setVisibility(View.GONE);
                break;
            default:
                linearReversed.setVisibility(View.GONE);
                positionalRadioGroup.setVisibility(View.GONE);
                verticalWeightLayout.setVisibility(View.GONE);
                horizontalWeightLayout.setVisibility(View.GONE);
                linearRadioGroup.setVisibility(View.GONE);
                corneredRadioGroup.setVisibility(View.GONE);
                break;
            }
            resetChildViewsAndStartSort();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    // set default vertical weight
    verticalWeight = ContinuousWeightedSort.MEDIUM_WEIGHT;
    verticalWeightedRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            switch (checkedId) {
            case R.id.vertical_light:
                verticalWeight = ContinuousWeightedSort.LIGHT_WEIGHT;
                break;
            case R.id.vertical_medium:
                verticalWeight = ContinuousWeightedSort.MEDIUM_WEIGHT;
                break;
            case R.id.vertical_heavy:
                verticalWeight = ContinuousWeightedSort.HEAVY_WEIGHT;
                break;
            }
            resetChildViewsAndStartSort();
        }
    });

    // set default horizontal weight
    horizontalWeight = ContinuousWeightedSort.MEDIUM_WEIGHT;
    horizontalWeightedRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            switch (checkedId) {
            case R.id.horizontal_light:
                horizontalWeight = ContinuousWeightedSort.LIGHT_WEIGHT;
                break;
            case R.id.horizontal_medium:
                horizontalWeight = ContinuousWeightedSort.MEDIUM_WEIGHT;
                break;
            case R.id.horizontal_heavy:
                horizontalWeight = ContinuousWeightedSort.HEAVY_WEIGHT;
                break;
            }
            resetChildViewsAndStartSort();
        }
    });

    // set default direction
    direction = LinearSort.Direction.BOTTOM_TO_TOP;
    linearRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            switch (checkedId) {
            case R.id.bottom_to_top:
                direction = LinearSort.Direction.BOTTOM_TO_TOP;
                break;
            case R.id.top_to_bottom:
                direction = LinearSort.Direction.TOP_TO_BOTTOM;
                break;
            case R.id.left_to_right:
                direction = LinearSort.Direction.LEFT_TO_RIGHT;
                break;
            case R.id.right_to_left:
                direction = LinearSort.Direction.RIGHT_TO_LEFT;
                break;
            }
            resetChildViewsAndStartSort();
        }
    });

    // set default corner
    corner = CorneredSort.Corner.TOP_LEFT;
    corneredRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            switch (checkedId) {
            case R.id.top_left:
                corner = CorneredSort.Corner.TOP_LEFT;
                break;
            case R.id.top_right:
                corner = CorneredSort.Corner.TOP_RIGHT;
                break;
            case R.id.bottom_left:
                corner = CorneredSort.Corner.BOTTOM_LEFT;
                break;
            case R.id.bottom_right:
                corner = CorneredSort.Corner.BOTTOM_RIGHT;
                break;
            }
            resetChildViewsAndStartSort();
        }
    });

    linearReversed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            resetChildViewsAndStartSort();
        }
    });

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            resetChildViewsAndStartSort();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    positionalRadioGroup.setGroupChildChangedListener(this);
    resetChildViewsAndStartSort();

    return rootView;
}