Skip to content

Commit

Permalink
Merge pull request #1 from steelkiwi/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
flasher297 authored Oct 24, 2017
2 parents 539fae8 + 06f6cfb commit 13ca3d9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The library is a highly configurable widget for image cropping.
## Gradle
Add this into your dependencies block.
```
compile 'com.steelkiwi:cropiwa:1.0.1'
compile 'com.steelkiwi:cropiwa:1.0.3'
```
## Sample
Please see the [sample app](sample/src/main/java/com/steelkiwi/cropiwa/sample) for library usage examples.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ext {
groupId = 'com.steelkiwi'
uploadName = 'cropiwa'
description = 'Configurable Custom Crop widget for Android'
publishVersion = '1.0.1'
publishVersion = '1.0.3'
licences = ['Apache-2.0']
}

7 changes: 1 addition & 6 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">

</application>
<application />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class CropIwaOverlayView extends View implements ConfigChangeListener, OnImagePo
private Paint overlayPaint;
private OnNewBoundsListener newBoundsListener;
private CropIwaShape cropShape;

private float cropScale;

private RectF imageBounds;

protected RectF cropRect;
Expand All @@ -40,7 +43,7 @@ protected void initWith(CropIwaOverlayConfig c) {
config.addConfigChangeListener(this);

imageBounds = new RectF();

cropScale = config.getCropScale();
cropShape = c.getCropShape();

cropRect = new RectF();
Expand Down Expand Up @@ -123,6 +126,7 @@ public void setNewBoundsListener(OnNewBoundsListener newBoundsListener) {
public void onConfigChanged() {
overlayPaint.setColor(config.getOverlayColor());
cropShape = config.getCropShape();
cropScale = config.getCropScale();
cropShape.onConfigChanged();
setCropRectAccordingToAspectRatio();
notifyNewBounds();
Expand Down Expand Up @@ -156,10 +160,10 @@ private void setCropRectAccordingToAspectRatio() {
|| (aspectRatio.isSquare() && viewWidth < viewHeight);

if (calculateFromWidth) {
halfWidth = viewWidth * 0.8f * 0.5f;
halfWidth = viewWidth * cropScale * 0.5f;
halfHeight = halfWidth / aspectRatio.getRatio();
} else {
halfHeight = viewHeight * 0.8f * 0.5f;
halfHeight = viewHeight * cropScale * 0.5f;
halfWidth = halfHeight * aspectRatio.getRatio();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.util.AttributeSet;

Expand All @@ -21,6 +22,7 @@
*/
public class CropIwaOverlayConfig {

private static final float DEFAULT_CROP_SCALE = 0.8f;

public static CropIwaOverlayConfig createDefault(Context context) {
ResUtil r = new ResUtil(context);
Expand All @@ -31,6 +33,7 @@ public static CropIwaOverlayConfig createDefault(Context context) {
.setOverlayColor(r.color(R.color.cropiwa_default_overlay_color))
.setBorderStrokeWidth(r.dimen(R.dimen.cropiwa_default_border_stroke_width))
.setCornerStrokeWidth(r.dimen(R.dimen.cropiwa_default_corner_stroke_width))
.setCropScale(DEFAULT_CROP_SCALE)
.setGridStrokeWidth(r.dimen(R.dimen.cropiwa_default_grid_stroke_width))
.setMinWidth(r.dimen(R.dimen.cropiwa_default_min_width))
.setMinHeight(r.dimen(R.dimen.cropiwa_default_min_height))
Expand Down Expand Up @@ -58,6 +61,9 @@ public static CropIwaOverlayConfig createFromAttributes(Context context, Attribu
c.setAspectRatio(new AspectRatio(
ta.getInteger(R.styleable.CropIwaView_ci_aspect_ratio_w, 1),
ta.getInteger(R.styleable.CropIwaView_ci_aspect_ratio_h, 1)));
c.setCropScale(ta.getFloat(
R.styleable.CropIwaView_ci_crop_scale,
c.getCropScale()));
c.setBorderColor(ta.getColor(
R.styleable.CropIwaView_ci_border_color,
c.getBorderColor()));
Expand Down Expand Up @@ -109,6 +115,8 @@ public static CropIwaOverlayConfig createFromAttributes(Context context, Attribu

private AspectRatio aspectRatio;

private float cropScale;

private boolean isDynamicCrop;
private boolean shouldDrawGrid;
private CropIwaShape cropShape;
Expand Down Expand Up @@ -169,6 +177,10 @@ public boolean isDynamicCrop() {
return isDynamicCrop;
}

public float getCropScale() {
return cropScale;
}

public AspectRatio getAspectRatio() {
return aspectRatio;
}
Expand Down Expand Up @@ -208,6 +220,11 @@ public CropIwaOverlayConfig setGridStrokeWidth(int gridStrokeWidth) {
return this;
}

public CropIwaOverlayConfig setCropScale(@FloatRange(from = 0.01, to = 1f) float cropScale) {
this.cropScale = cropScale;
return this;
}

public CropIwaOverlayConfig setMinHeight(int minHeight) {
this.minHeight = minHeight;
return this;
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<attr name="ci_scale_enabled" format="boolean" />
<attr name="ci_translation_enabled" format="boolean" />
<attr name="ci_max_scale" format="float" />
<attr name="ci_crop_scale" format="float" />
<attr name="ci_initial_position" format="enum">
<enum name="centerInside" value="0" />
<enum name="centerCrop" value="1" />
Expand Down

0 comments on commit 13ca3d9

Please sign in to comment.