Example usage for android.view ViewGroup setSelected

List of usage examples for android.view ViewGroup setSelected

Introduction

In this page you can find the example usage for android.view ViewGroup setSelected.

Prototype

public void setSelected(boolean selected) 

Source Link

Document

Changes the selection state of this view.

Usage

From source file:com.ez.gallery.ucrop.UCropActivity.java

private void setupAspectRatioWidget() {

    // Set the colors before the default item is selected
    ((AspectRatioTextView) ((ViewGroup) findViewById(R.id.crop_aspect_ratio_1_1)).getChildAt(0))
            .setActiveColor(mActiveWidgetColor);
    ((AspectRatioTextView) ((ViewGroup) findViewById(R.id.crop_aspect_ratio_3_4)).getChildAt(0))
            .setActiveColor(mActiveWidgetColor);
    ((AspectRatioTextView) ((ViewGroup) findViewById(R.id.crop_aspect_ratio_original)).getChildAt(0))
            .setActiveColor(mActiveWidgetColor);
    ((AspectRatioTextView) ((ViewGroup) findViewById(R.id.crop_aspect_ratio_3_2)).getChildAt(0))
            .setActiveColor(mActiveWidgetColor);
    ((AspectRatioTextView) ((ViewGroup) findViewById(R.id.crop_aspect_ratio_16_9)).getChildAt(0))
            .setActiveColor(mActiveWidgetColor);

    mCropAspectRatioViews.add((ViewGroup) findViewById(R.id.crop_aspect_ratio_1_1));
    mCropAspectRatioViews.add((ViewGroup) findViewById(R.id.crop_aspect_ratio_3_4));
    mCropAspectRatioViews.add((ViewGroup) findViewById(R.id.crop_aspect_ratio_original));
    mCropAspectRatioViews.add((ViewGroup) findViewById(R.id.crop_aspect_ratio_3_2));
    mCropAspectRatioViews.add((ViewGroup) findViewById(R.id.crop_aspect_ratio_16_9));
    mCropAspectRatioViews.get(2).setSelected(true);

    for (ViewGroup cropAspectRatioView : mCropAspectRatioViews) {
        cropAspectRatioView.setOnClickListener(new View.OnClickListener() {
            @Override//from w w  w.ja va  2 s .c  o  m
            public void onClick(View v) {
                mGestureCropImageView.setTargetAspectRatio(
                        ((AspectRatioTextView) ((ViewGroup) v).getChildAt(0)).getAspectRatio(v.isSelected()));
                mGestureCropImageView.setImageToWrapCropBounds();
                if (!v.isSelected()) {
                    for (ViewGroup cropAspectRatioView : mCropAspectRatioViews) {
                        cropAspectRatioView.setSelected(cropAspectRatioView == v);
                    }
                }
            }
        });
    }
}