Skip to content

Commit

Permalink
* Image is loaded in background thread. Better error-handling for im…
Browse files Browse the repository at this point in the history
…age decoding.

 * Improved EXIF data support (rotation and mirror).
 * Small UI updates.
 * Couple new things to configure

 * Sample updated with possibility to choose custom aspect ratio.
  • Loading branch information
shliama committed Feb 27, 2016
1 parent 72b7335 commit 3ffa94c
Show file tree
Hide file tree
Showing 18 changed files with 407 additions and 168 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

1. Include the library as local library project.

``` compile 'com.yalantis:ucrop:1.2.+' ```
``` compile 'com.yalantis:ucrop:1.3.+' ```

2. Add UCropActivity into your AndroidManifest.xml

Expand Down Expand Up @@ -73,6 +73,15 @@ Currently you can change:
# Changelog
### Version: 1.3
* Image is loaded in background thread. Better error-handling for image decoding.
* Improved EXIF data support (rotation and mirror).
* Small UI updates.
* Couple new things to configure
* Sample updated with possibility to choose custom aspect ratio.
### Version: 1.2
* Updated core logic so an image corrects its position smoothly and obviously.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta5'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME=1.2.4
VERSION_CODE=10
VERSION_NAME=1.3.0
VERSION_CODE=11
GROUP=com.yalantis

POM_DESCRIPTION=Android Library for cropping images
Expand Down
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.yalantis.ucrop.sample"
minSdkVersion 15
targetSdkVersion 23
versionCode 4
versionName "1.0.3"
versionCode 5
versionName "1.0.4"
}
buildTypes {
release {
Expand All @@ -28,7 +28,7 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.2.0'

compile project (':ucrop')
}
44 changes: 35 additions & 9 deletions sample/src/main/java/com/yalantis/ucrop/sample/SampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
Expand All @@ -31,13 +33,11 @@ public class SampleActivity extends BaseActivity {
private static final String TAG = "SampleActivity";

private static final int REQUEST_SELECT_PICTURE = 0x01;

private static final int SAMPLE_IMAGE_MAX_SIZE_WIDTH = 200;
private static final int SAMPLE_IMAGE_MAX_SIZE_HEIGHT = 300;
private static final String SAMPLE_CROPPED_IMAGE_NAME = "SampleCropImage.jpeg";

private RadioGroup mRadioGroupAspectRatio, mRadioGroupCompressionSettings;
private EditText mEditTextMaxWidth, mEditTextMaxHeight;
private EditText mEditTextRatioX, mEditTextRatioY;
private CheckBox mCheckBoxMaxSize;
private SeekBar mSeekBarQuality;
private TextView mTextViewQuality;
Expand Down Expand Up @@ -100,17 +100,19 @@ public void onClick(View v) {
mRadioGroupAspectRatio = ((RadioGroup) findViewById(R.id.radio_group_aspect_ratio));
mRadioGroupCompressionSettings = ((RadioGroup) findViewById(R.id.radio_group_compression_settings));
mCheckBoxMaxSize = ((CheckBox) findViewById(R.id.checkbox_max_size));
mEditTextRatioX = ((EditText) findViewById(R.id.edit_text_ratio_x));
mEditTextRatioY = ((EditText) findViewById(R.id.edit_text_ratio_y));
mEditTextMaxWidth = ((EditText) findViewById(R.id.edit_text_max_width));
mEditTextMaxHeight = ((EditText) findViewById(R.id.edit_text_max_height));
mSeekBarQuality = ((SeekBar) findViewById(R.id.seekbar_quality));
mTextViewQuality = ((TextView) findViewById(R.id.text_view_quality));

mRadioGroupAspectRatio.check(R.id.radio_dynamic);
mEditTextRatioX.addTextChangedListener(mAspectRatioTextWatcher);
mEditTextRatioY.addTextChangedListener(mAspectRatioTextWatcher);
mRadioGroupCompressionSettings.check(R.id.radio_jpeg);
mSeekBarQuality.setProgress(UCropActivity.DEFAULT_COMPRESS_QUALITY);
mTextViewQuality.setText(String.format(getString(R.string.format_quality_d), mSeekBarQuality.getProgress()));
mEditTextMaxWidth.setText(String.valueOf(SAMPLE_IMAGE_MAX_SIZE_WIDTH));
mEditTextMaxHeight.setText(String.valueOf(SAMPLE_IMAGE_MAX_SIZE_HEIGHT));
mSeekBarQuality.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Expand All @@ -129,6 +131,23 @@ public void onStopTrackingTouch(SeekBar seekBar) {
});
}

private TextWatcher mAspectRatioTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
mRadioGroupAspectRatio.clearCheck();
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {

}
};

private void pickFromGallery() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN // Permission was added in API Level 16
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
Expand Down Expand Up @@ -168,13 +187,20 @@ private UCrop basisConfig(@NonNull UCrop uCrop) {
case R.id.radio_square:
uCrop = uCrop.withAspectRatio(1, 1);
break;
case R.id.radio_16_9:
uCrop = uCrop.withAspectRatio(16, 9);
break;
case R.id.radio_dynamic:
default:
// do nothing
break;
default:
try {
float ratioX = Float.valueOf(mEditTextRatioX.getText().toString().trim());
float ratioY = Float.valueOf(mEditTextRatioY.getText().toString().trim());
if (ratioX > 0 && ratioY > 0) {
uCrop = uCrop.withAspectRatio(ratioX, ratioY);
}
} catch (NumberFormatException e) {
Log.e(TAG, "Number please", e);
}
break;
}

if (mCheckBoxMaxSize.isChecked()) {
Expand Down
40 changes: 32 additions & 8 deletions sample/src/main/res/layout/activity_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
android:layout_height="wrap_content"
android:text="@string/button_pick_amp_crop"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textAppearance="?android:textAppearanceMedium"
android:textStyle="bold"/>

Expand Down Expand Up @@ -84,13 +85,36 @@
android:text="@string/label_square"
android:textAppearance="?android:textAppearanceMedium"/>

<RadioButton
android:id="@+id/radio_16_9"
android:layout_width="match_parent"
<LinearLayout
android:layout_width="140dp"
android:layout_height="wrap_content"
android:text="16x9"
android:textAppearance="?android:textAppearanceMedium"
tools:ignore="HardcodedText"/>
android:orientation="horizontal">

<EditText
android:id="@+id/edit_text_ratio_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="x"
android:inputType="numberDecimal"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="to"
tools:ignore="HardcodedText"/>

<EditText
android:id="@+id/edit_text_ratio_y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:hint="y"
android:inputType="numberDecimal"/>

</LinearLayout>

</RadioGroup>

Expand Down Expand Up @@ -126,7 +150,7 @@
android:layout_weight="1"
android:gravity="center"
android:hint="@string/label_width"
android:inputType="numberDecimal"/>
android:inputType="number"/>

<TextView
android:layout_width="wrap_content"
Expand All @@ -141,7 +165,7 @@
android:layout_weight="1"
android:gravity="center"
android:hint="@string/label_height"
android:inputType="numberDecimal"/>
android:inputType="number"/>

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorButtonNormal">@color/colorAccent</item>
</style>

</resources>
8 changes: 5 additions & 3 deletions ucrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 10
versionName "1.2.4"
versionCode 11
versionName "1.3.0"

vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
Expand All @@ -29,5 +31,5 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.2.0'
}
30 changes: 29 additions & 1 deletion ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class UCrop {

public static final String EXTRA_INPUT_URI = EXTRA_PREFIX + ".InputUri";
public static final String EXTRA_OUTPUT_URI = EXTRA_PREFIX + ".OutputUri";
public static final String EXTRA_OUTPUT_CROP_ASPECT_RATIO = EXTRA_PREFIX + ".CropAspectRatio";
public static final String EXTRA_ERROR = EXTRA_PREFIX + ".Error";

public static final String EXTRA_ASPECT_RATIO_SET = EXTRA_PREFIX + ".AspectRatioSet";
Expand Down Expand Up @@ -66,7 +67,7 @@ private UCrop(@NonNull Uri source, @NonNull Uri destination) {
* @param x aspect ratio X
* @param y aspect ratio Y
*/
public UCrop withAspectRatio(@IntRange(from = 1) int x, @IntRange(from = 1) int y) {
public UCrop withAspectRatio(float x, float y) {
mCropIntent.putExtra(EXTRA_ASPECT_RATIO_SET, true);
mCropIntent.putExtra(EXTRA_ASPECT_RATIO_X, x);
mCropIntent.putExtra(EXTRA_ASPECT_RATIO_Y, y);
Expand Down Expand Up @@ -180,6 +181,16 @@ public static Uri getOutput(@NonNull Intent intent) {
return intent.getParcelableExtra(EXTRA_OUTPUT_URI);
}

/**
* Retrieve cropped image aspect ratio from the result Intent
*
* @param intent crop result intent
* @return aspect ratio as a floating point value (x:y) - so it will be 1 for 1:1 or 4/3 for 4:3
*/
public static float getOutputCropAspectRatio(@NonNull Intent intent) {
return intent.getParcelableExtra(EXTRA_OUTPUT_CROP_ASPECT_RATIO);
}

/**
* Method retrieves error from the result intent.
*
Expand Down Expand Up @@ -225,6 +236,9 @@ public static class Options {
public static final String EXTRA_UCROP_COLOR_WIDGET_ACTIVE = EXTRA_PREFIX + ".UcropColorWidgetActive";

public static final String EXTRA_UCROP_TITLE_COLOR_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarTitleColor";
public static final String EXTRA_UCROP_TITLE_TEXT_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarTitleText";

public static final String EXTRA_UCROP_LOGO_COLOR = EXTRA_PREFIX + ".UcropLogoColor";


private final Bundle mOptionBundle;
Expand Down Expand Up @@ -386,6 +400,20 @@ public void setToolbarTitleTextColor(@ColorInt int color) {
mOptionBundle.putInt(EXTRA_UCROP_TITLE_COLOR_TOOLBAR, color);
}

/**
* @param text - desired text for Toolbar title
*/
public void setToolbarTitle(@Nullable String text) {
mOptionBundle.putString(EXTRA_UCROP_TITLE_TEXT_TOOLBAR, text);
}

/**
* @param color - desired resolved color of logo fill (default is darker grey)
*/
public void setLogoColor(@ColorInt int color) {
mOptionBundle.putInt(EXTRA_UCROP_LOGO_COLOR, color);
}

}

}
Loading

0 comments on commit 3ffa94c

Please sign in to comment.