Search in sources :

Example 1 with AspectRatioTextView

use of com.yalantis.ucrop.weiui.library.view.widget.AspectRatioTextView in project weiui by kuaifan.

the class PictureMultiCuttingActivity method setupAspectRatioWidget.

private void setupAspectRatioWidget(@NonNull Intent intent) {
    int aspectRationSelectedByDefault = intent.getIntExtra(UCropMulti.Options.EXTRA_ASPECT_RATIO_SELECTED_BY_DEFAULT, 0);
    ArrayList<AspectRatio> aspectRatioList = intent.getParcelableArrayListExtra(UCropMulti.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 = (LinearLayout) 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(mActiveWidgetColor);
        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) GestureCropImageView(com.yalantis.ucrop.weiui.library.view.GestureCropImageView) ImageView(android.widget.ImageView) TransformImageView(com.yalantis.ucrop.weiui.library.view.TransformImageView) OverlayView(com.yalantis.ucrop.weiui.library.view.OverlayView) HorizontalProgressWheelView(com.yalantis.ucrop.weiui.library.view.widget.HorizontalProgressWheelView) View(android.view.View) TextView(android.widget.TextView) UCropView(com.yalantis.ucrop.weiui.library.view.UCropView) CropImageView(com.yalantis.ucrop.weiui.library.view.CropImageView) RecyclerView(android.support.v7.widget.RecyclerView) AspectRatioTextView(com.yalantis.ucrop.weiui.library.view.widget.AspectRatioTextView) AspectRatio(com.yalantis.ucrop.weiui.library.model.AspectRatio) FrameLayout(android.widget.FrameLayout) AspectRatioTextView(com.yalantis.ucrop.weiui.library.view.widget.AspectRatioTextView) LinearLayout(android.widget.LinearLayout)

Example 2 with AspectRatioTextView

use of com.yalantis.ucrop.weiui.library.view.widget.AspectRatioTextView in project weiui by kuaifan.

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 = (LinearLayout) 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(mActiveWidgetColor);
        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) GestureCropImageView(com.yalantis.ucrop.weiui.library.view.GestureCropImageView) ImageView(android.widget.ImageView) TransformImageView(com.yalantis.ucrop.weiui.library.view.TransformImageView) OverlayView(com.yalantis.ucrop.weiui.library.view.OverlayView) HorizontalProgressWheelView(com.yalantis.ucrop.weiui.library.view.widget.HorizontalProgressWheelView) UCropView(com.yalantis.ucrop.weiui.library.view.UCropView) View(android.view.View) CropImageView(com.yalantis.ucrop.weiui.library.view.CropImageView) TextView(android.widget.TextView) AspectRatioTextView(com.yalantis.ucrop.weiui.library.view.widget.AspectRatioTextView) AspectRatio(com.yalantis.ucrop.weiui.library.model.AspectRatio) FrameLayout(android.widget.FrameLayout) AspectRatioTextView(com.yalantis.ucrop.weiui.library.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.weiui.library.model.AspectRatio)2 CropImageView (com.yalantis.ucrop.weiui.library.view.CropImageView)2 GestureCropImageView (com.yalantis.ucrop.weiui.library.view.GestureCropImageView)2 OverlayView (com.yalantis.ucrop.weiui.library.view.OverlayView)2 TransformImageView (com.yalantis.ucrop.weiui.library.view.TransformImageView)2 UCropView (com.yalantis.ucrop.weiui.library.view.UCropView)2 AspectRatioTextView (com.yalantis.ucrop.weiui.library.view.widget.AspectRatioTextView)2 HorizontalProgressWheelView (com.yalantis.ucrop.weiui.library.view.widget.HorizontalProgressWheelView)2 RecyclerView (android.support.v7.widget.RecyclerView)1