Skip to content

Commit

Permalink
Merge pull request #644 from Yalantis/feature/non_native
Browse files Browse the repository at this point in the history
Feature/non native
  • Loading branch information
ukevgen authored Apr 29, 2020
2 parents df14c58 + 684dd33 commit 411a11f
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 90 deletions.
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=2.2.3-non-native
VERSION_CODE=24
VERSION_NAME=2.2.5-non-native
VERSION_CODE=25
GROUP=com.yalantis

POM_DESCRIPTION=Android Library for cropping images
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 29
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.yalantis.ucrop.sample"
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 29
versionCode 13
versionName "1.2.4"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ Tune everything (ノ◕ヮ◕)ノ*:・゚✧
// Color palette
options.setToolbarColor(ContextCompat.getColor(this, R.color.your_color_res));
options.setStatusBarColor(ContextCompat.getColor(this, R.color.your_color_res));
options.setActiveWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
options.setRootViewBackgroundColor(ContextCompat.getColor(this, R.color.your_color_res));
options.setActiveControlsWidgetColor(ContextCompat.getColor(this, R.color.your_color_res));
// Aspect ratio options
options.setAspectRatioOptions(1,
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<color name="colorPrimary">#FF6E40</color>
<color name="colorPrimaryDark">#CC5833</color>
<color name="colorAccent">#FF6E40</color>

<color name="your_color_res">#03A9F4</color>
</resources>
4 changes: 2 additions & 2 deletions ucrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 24
versionName "2.2.4-non-native"
versionCode 25
versionName "2.2.5-non-native"

vectorDrawables.useSupportLibrary = true
}
Expand Down
15 changes: 4 additions & 11 deletions ucrop/src/main/java/com/yalantis/ucrop/UCrop.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yalantis.ucrop;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -123,7 +124,7 @@ public UCrop withOptions(@NonNull Options options) {
*
* @param activity Activity to receive result
*/
public void start(@NonNull AppCompatActivity activity) {
public void start(@NonNull Activity activity) {
start(activity, REQUEST_CROP);
}

Expand All @@ -133,7 +134,7 @@ public void start(@NonNull AppCompatActivity activity) {
* @param activity Activity to receive result
* @param requestCode requestCode for result
*/
public void start(@NonNull AppCompatActivity activity, int requestCode) {
public void start(@NonNull Activity activity, int requestCode) {
activity.startActivityForResult(getIntent(activity), requestCode);
}

Expand Down Expand Up @@ -260,7 +261,6 @@ public static class Options {

public static final String EXTRA_TOOL_BAR_COLOR = EXTRA_PREFIX + ".ToolbarColor";
public static final String EXTRA_STATUS_BAR_COLOR = EXTRA_PREFIX + ".StatusBarColor";
public static final String EXTRA_UCROP_COLOR_WIDGET_ACTIVE = EXTRA_PREFIX + ".UcropColorWidgetActive";
public static final String EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE = EXTRA_PREFIX + ".UcropColorControlsWidgetActive";

public static final String EXTRA_UCROP_WIDGET_COLOR_TOOLBAR = EXTRA_PREFIX + ".UcropToolbarWidgetColor";
Expand Down Expand Up @@ -425,14 +425,7 @@ public void setStatusBarColor(@ColorInt int color) {
}

/**
* @param color - desired resolved color of the progress wheel middle line (default is violet)
*/
public void setActiveWidgetColor(@ColorInt int color) {
mOptionBundle.putInt(EXTRA_UCROP_COLOR_WIDGET_ACTIVE, color);
}

/**
* @param color - desired resolved color of the active and selected widget (default is white)
* @param color - desired resolved color of the active and selected widget and progress wheel middle line (default is white)
*/
public void setActiveControlsWidgetColor(@ColorInt int color) {
mOptionBundle.putInt(EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, color);
Expand Down
35 changes: 29 additions & 6 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.transition.AutoTransition;
Expand Down Expand Up @@ -87,7 +88,6 @@ public class UCropActivity extends AppCompatActivity {
// Enables dynamic coloring
private int mToolbarColor;
private int mStatusBarColor;
private int mActiveWidgetColor;
private int mActiveControlsWidgetColor;
private int mToolbarWidgetColor;
@ColorInt
Expand Down Expand Up @@ -116,6 +116,10 @@ public class UCropActivity extends AppCompatActivity {
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY;
private int[] mAllowedGestures = new int[]{SCALE, ROTATE, ALL};

static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -282,7 +286,6 @@ private void processOptions(@NonNull Intent intent) {
private void setupViews(@NonNull Intent intent) {
mStatusBarColor = intent.getIntExtra(UCrop.Options.EXTRA_STATUS_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_statusbar));
mToolbarColor = intent.getIntExtra(UCrop.Options.EXTRA_TOOL_BAR_COLOR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar));
mActiveWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
mActiveControlsWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, ContextCompat.getColor(this, R.color.ucrop_color_active_controls_color));

mToolbarWidgetColor = intent.getIntExtra(UCrop.Options.EXTRA_UCROP_WIDGET_COLOR_TOOLBAR, ContextCompat.getColor(this, R.color.ucrop_color_toolbar_widget));
Expand All @@ -302,7 +305,6 @@ private void setupViews(@NonNull Intent intent) {
ViewGroup viewGroup = findViewById(R.id.ucrop_photobox);
ViewGroup wrapper = viewGroup.findViewById(R.id.controls_wrapper);
wrapper.setVisibility(View.VISIBLE);
wrapper.setBackgroundColor(mRootViewBackgroundColor);
LayoutInflater.from(this).inflate(R.layout.ucrop_controls, wrapper, true);

mControlsTransition = new AutoTransition();
Expand Down Expand Up @@ -364,6 +366,11 @@ private void initiateRootViews() {
((ImageView) findViewById(R.id.image_view_logo)).setColorFilter(mLogoColor, PorterDuff.Mode.SRC_ATOP);

findViewById(R.id.ucrop_frame).setBackgroundColor(mRootViewBackgroundColor);
if (!mShowBottomControls) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) findViewById(R.id.ucrop_frame).getLayoutParams();
params.bottomMargin = 0;
findViewById(R.id.ucrop_frame).requestLayout();
}
}

private TransformImageView.TransformImageListener mImageListener = new TransformImageView.TransformImageListener() {
Expand Down Expand Up @@ -394,7 +401,7 @@ public void onLoadFailure(@NonNull Exception e) {
};

/**
* Use {@link #mActiveWidgetColor} for color filter
* Use {@link #mActiveControlsWidgetColor} for color filter
*/
private void setupStatesWrapper() {
ImageView stateScaleImageView = findViewById(R.id.image_view_state_scale);
Expand Down Expand Up @@ -496,7 +503,7 @@ public void onScrollStart() {
}
});

((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
((HorizontalProgressWheelView) findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);


findViewById(R.id.wrapper_reset_rotate).setOnClickListener(new View.OnClickListener() {
Expand All @@ -511,6 +518,8 @@ public void onClick(View v) {
rotateByAngle(90);
}
});

setAngleTextColor(mActiveControlsWidgetColor);
}

private void setupScaleWidget() {
Expand Down Expand Up @@ -538,7 +547,9 @@ public void onScrollStart() {
mGestureCropImageView.cancelAllAnimations();
}
});
((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
((HorizontalProgressWheelView) findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);

setScaleTextColor(mActiveControlsWidgetColor);
}

private void setAngleText(float angle) {
Expand All @@ -547,12 +558,24 @@ private void setAngleText(float angle) {
}
}

private void setAngleTextColor(int textColor) {
if (mTextViewRotateAngle != null) {
mTextViewRotateAngle.setTextColor(textColor);
}
}

private void setScaleText(float scale) {
if (mTextViewScalePercent != null) {
mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100)));
}
}

private void setScaleTextColor(int textColor) {
if (mTextViewScalePercent != null) {
mTextViewScalePercent.setTextColor(textColor);
}
}

private void resetRotation() {
mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle());
mGestureCropImageView.setImageToWrapCropBounds();
Expand Down
38 changes: 30 additions & 8 deletions ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.transition.AutoTransition;
Expand Down Expand Up @@ -72,7 +73,6 @@ public class UCropFragment extends Fragment {
private UCropFragmentCallback callback;

private int mActiveControlsWidgetColor;
private int mActiveWidgetColor;
@ColorInt
private int mRootViewBackgroundColor;
private int mLogoColor;
Expand All @@ -94,6 +94,10 @@ public class UCropFragment extends Fragment {
private int mCompressQuality = DEFAULT_COMPRESS_QUALITY;
private int[] mAllowedGestures = new int[]{SCALE, ROTATE, ALL};

static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

public static UCropFragment newInstance(Bundle uCrop) {
UCropFragment fragment = new UCropFragment();
fragment.setArguments(uCrop);
Expand Down Expand Up @@ -133,8 +137,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c


public void setupViews(View view, Bundle args) {
mActiveWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_background));
mActiveControlsWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_active));
mActiveControlsWidgetColor = args.getInt(UCrop.Options.EXTRA_UCROP_COLOR_CONTROLS_WIDGET_ACTIVE, ContextCompat.getColor(getContext(), R.color.ucrop_color_widget_active));
mLogoColor = args.getInt(UCrop.Options.EXTRA_UCROP_LOGO_COLOR, ContextCompat.getColor(getContext(), R.color.ucrop_color_default_logo));
mShowBottomControls = !args.getBoolean(UCrop.Options.EXTRA_HIDE_BOTTOM_CONTROLS, false);
mRootViewBackgroundColor = args.getInt(UCrop.Options.EXTRA_UCROP_ROOT_VIEW_BACKGROUND_COLOR, ContextCompat.getColor(getContext(), R.color.ucrop_color_crop_background));
Expand All @@ -146,7 +149,6 @@ public void setupViews(View view, Bundle args) {

ViewGroup wrapper = view.findViewById(R.id.controls_wrapper);
wrapper.setVisibility(View.VISIBLE);
wrapper.setBackgroundColor(mRootViewBackgroundColor);
LayoutInflater.from(getContext()).inflate(R.layout.ucrop_controls, wrapper, true);

mControlsTransition = new AutoTransition();
Expand All @@ -167,6 +169,10 @@ public void setupViews(View view, Bundle args) {
setupRotateWidget(view);
setupScaleWidget(view);
setupStatesWrapper(view);
} else {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.findViewById(R.id.ucrop_frame).getLayoutParams();
params.bottomMargin = 0;
view.findViewById(R.id.ucrop_frame).requestLayout();
}
}

Expand Down Expand Up @@ -296,7 +302,7 @@ public void onLoadFailure(@NonNull Exception e) {
};

/**
* Use {@link #mActiveWidgetColor} for color filter
* Use {@link #mActiveControlsWidgetColor} for color filter
*/
private void setupStatesWrapper(View view) {
ImageView stateScaleImageView = view.findViewById(R.id.image_view_state_scale);
Expand Down Expand Up @@ -334,7 +340,7 @@ private void setupAspectRatioWidget(@NonNull Bundle bundle, View view) {
wrapperAspectRatio = (FrameLayout) getLayoutInflater().inflate(R.layout.ucrop_aspect_ratio, null);
wrapperAspectRatio.setLayoutParams(lp);
aspectRatioTextView = ((AspectRatioTextView) wrapperAspectRatio.getChildAt(0));
aspectRatioTextView.setActiveColor(mActiveWidgetColor);
aspectRatioTextView.setActiveColor(mActiveControlsWidgetColor);
aspectRatioTextView.setAspectRatio(aspectRatio);

wrapperAspectRatioList.addView(wrapperAspectRatio);
Expand Down Expand Up @@ -380,7 +386,7 @@ public void onScrollStart() {
}
});

((HorizontalProgressWheelView) view.findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
((HorizontalProgressWheelView) view.findViewById(R.id.rotate_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);


view.findViewById(R.id.wrapper_reset_rotate).setOnClickListener(new View.OnClickListener() {
Expand All @@ -395,6 +401,8 @@ public void onClick(View v) {
rotateByAngle(90);
}
});

setAngleTextColor(mActiveControlsWidgetColor);
}

private void setupScaleWidget(View view) {
Expand Down Expand Up @@ -422,7 +430,9 @@ public void onScrollStart() {
mGestureCropImageView.cancelAllAnimations();
}
});
((HorizontalProgressWheelView) view.findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveWidgetColor);
((HorizontalProgressWheelView) view.findViewById(R.id.scale_scroll_wheel)).setMiddleLineColor(mActiveControlsWidgetColor);

setScaleTextColor(mActiveControlsWidgetColor);
}

private void setAngleText(float angle) {
Expand All @@ -431,12 +441,24 @@ private void setAngleText(float angle) {
}
}

private void setAngleTextColor(int textColor) {
if (mTextViewRotateAngle != null) {
mTextViewRotateAngle.setTextColor(textColor);
}
}

private void setScaleText(float scale) {
if (mTextViewScalePercent != null) {
mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100)));
}
}

private void setScaleTextColor(int textColor) {
if (mTextViewScalePercent != null) {
mTextViewScalePercent.setTextColor(textColor);
}
}

private void resetRotation() {
mGestureCropImageView.postRotate(-mGestureCropImageView.getCurrentAngle());
mGestureCropImageView.setImageToWrapCropBounds();
Expand Down
Loading

0 comments on commit 411a11f

Please sign in to comment.