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);
}
}
}
});
}
}
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);
}
}
}
});
}
}
Aggregations