Search in sources :

Example 1 with AspectRatioTextView

use of com.yalantis.ucrop.view.widget.AspectRatioTextView in project uCrop by Yalantis.

the class UCropFragment method setupAspectRatioWidget.

private void setupAspectRatioWidget(@NonNull Bundle bundle, View view) {
    int aspectRationSelectedByDefault = bundle.getInt(UCrop.Options.EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, 0);
    ArrayList<AspectRatio> aspectRatioList = bundle.getParcelableArrayList(UCrop.Options.EXTRA_ASPECT_RATIO_OPTIONS);
    if (aspectRatioList == null || aspectRatioList.isEmpty()) {
        aspectRationSelectedByDefault = 2;
        aspectRatioList = new ArrayList<>();
        aspectRatioList.add(new AspectRatio(null, 1, 1));
        aspectRatioList.add(new AspectRatio(null, 3, 4));
        aspectRatioList.add(new AspectRatio(getString(R.string.ucrop_label_original).toUpperCase(), CropImageView.SOURCE_IMAGE_ASPECT_RATIO, CropImageView.SOURCE_IMAGE_ASPECT_RATIO));
        aspectRatioList.add(new AspectRatio(null, 3, 2));
        aspectRatioList.add(new AspectRatio(null, 16, 9));
    }
    LinearLayout wrapperAspectRatioList = view.findViewById(R.id.layout_aspect_ratio);
    FrameLayout wrapperAspectRatio;
    AspectRatioTextView aspectRatioTextView;
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
    lp.weight = 1;
    for (AspectRatio aspectRatio : aspectRatioList) {
        wrapperAspectRatio = (FrameLayout) getLayoutInflater().inflate(R.layout.ucrop_aspect_ratio, null);
        wrapperAspectRatio.setLayoutParams(lp);
        aspectRatioTextView = ((AspectRatioTextView) wrapperAspectRatio.getChildAt(0));
        aspectRatioTextView.setActiveColor(mActiveControlsWidgetColor);
        aspectRatioTextView.setAspectRatio(aspectRatio);
        wrapperAspectRatioList.addView(wrapperAspectRatio);
        mCropAspectRatioViews.add(wrapperAspectRatio);
    }
    mCropAspectRatioViews.get(aspectRationSelectedByDefault).setSelected(true);
    for (ViewGroup cropAspectRatioView : mCropAspectRatioViews) {
        cropAspectRatioView.setOnClickListener(new View.OnClickListener() {

            @Override
            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);
                    }
                }
            }
        });
    }
}
Also used : ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) CropImageView(com.yalantis.ucrop.view.CropImageView) HorizontalProgressWheelView(com.yalantis.ucrop.view.widget.HorizontalProgressWheelView) View(android.view.View) AspectRatioTextView(com.yalantis.ucrop.view.widget.AspectRatioTextView) TransformImageView(com.yalantis.ucrop.view.TransformImageView) OverlayView(com.yalantis.ucrop.view.OverlayView) UCropView(com.yalantis.ucrop.view.UCropView) TextView(android.widget.TextView) GestureCropImageView(com.yalantis.ucrop.view.GestureCropImageView) AspectRatio(com.yalantis.ucrop.model.AspectRatio) FrameLayout(android.widget.FrameLayout) AspectRatioTextView(com.yalantis.ucrop.view.widget.AspectRatioTextView) LinearLayout(android.widget.LinearLayout)

Example 2 with AspectRatioTextView

use of com.yalantis.ucrop.view.widget.AspectRatioTextView in project uCrop by Yalantis.

the class UCropActivity method setupAspectRatioWidget.

private void setupAspectRatioWidget(@NonNull Intent intent) {
    int aspectRationSelectedByDefault = intent.getIntExtra(UCrop.Options.EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, 0);
    ArrayList<AspectRatio> aspectRatioList = intent.getParcelableArrayListExtra(UCrop.Options.EXTRA_ASPECT_RATIO_OPTIONS);
    if (aspectRatioList == null || aspectRatioList.isEmpty()) {
        aspectRationSelectedByDefault = 2;
        aspectRatioList = new ArrayList<>();
        aspectRatioList.add(new AspectRatio(null, 1, 1));
        aspectRatioList.add(new AspectRatio(null, 3, 4));
        aspectRatioList.add(new AspectRatio(getString(R.string.ucrop_label_original).toUpperCase(), CropImageView.SOURCE_IMAGE_ASPECT_RATIO, CropImageView.SOURCE_IMAGE_ASPECT_RATIO));
        aspectRatioList.add(new AspectRatio(null, 3, 2));
        aspectRatioList.add(new AspectRatio(null, 16, 9));
    }
    LinearLayout wrapperAspectRatioList = findViewById(R.id.layout_aspect_ratio);
    FrameLayout wrapperAspectRatio;
    AspectRatioTextView aspectRatioTextView;
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
    lp.weight = 1;
    for (AspectRatio aspectRatio : aspectRatioList) {
        wrapperAspectRatio = (FrameLayout) getLayoutInflater().inflate(R.layout.ucrop_aspect_ratio, null);
        wrapperAspectRatio.setLayoutParams(lp);
        aspectRatioTextView = ((AspectRatioTextView) wrapperAspectRatio.getChildAt(0));
        aspectRatioTextView.setActiveColor(mActiveControlsWidgetColor);
        aspectRatioTextView.setAspectRatio(aspectRatio);
        wrapperAspectRatioList.addView(wrapperAspectRatio);
        mCropAspectRatioViews.add(wrapperAspectRatio);
    }
    mCropAspectRatioViews.get(aspectRationSelectedByDefault).setSelected(true);
    for (ViewGroup cropAspectRatioView : mCropAspectRatioViews) {
        cropAspectRatioView.setOnClickListener(new View.OnClickListener() {

            @Override
            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);
                    }
                }
            }
        });
    }
}
Also used : ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) CropImageView(com.yalantis.ucrop.view.CropImageView) HorizontalProgressWheelView(com.yalantis.ucrop.view.widget.HorizontalProgressWheelView) View(android.view.View) AspectRatioTextView(com.yalantis.ucrop.view.widget.AspectRatioTextView) OverlayView(com.yalantis.ucrop.view.OverlayView) TextView(android.widget.TextView) TransformImageView(com.yalantis.ucrop.view.TransformImageView) UCropView(com.yalantis.ucrop.view.UCropView) GestureCropImageView(com.yalantis.ucrop.view.GestureCropImageView) AspectRatio(com.yalantis.ucrop.model.AspectRatio) FrameLayout(android.widget.FrameLayout) AspectRatioTextView(com.yalantis.ucrop.view.widget.AspectRatioTextView) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 FrameLayout (android.widget.FrameLayout)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 AspectRatio (com.yalantis.ucrop.model.AspectRatio)2 CropImageView (com.yalantis.ucrop.view.CropImageView)2 GestureCropImageView (com.yalantis.ucrop.view.GestureCropImageView)2 OverlayView (com.yalantis.ucrop.view.OverlayView)2 TransformImageView (com.yalantis.ucrop.view.TransformImageView)2 UCropView (com.yalantis.ucrop.view.UCropView)2 AspectRatioTextView (com.yalantis.ucrop.view.widget.AspectRatioTextView)2 HorizontalProgressWheelView (com.yalantis.ucrop.view.widget.HorizontalProgressWheelView)2