From e439d208c20f3f007032c81cf69c756d56abcb50 Mon Sep 17 00:00:00 2001 From: Alex Vasilkov Date: Tue, 24 Nov 2020 22:03:57 +0700 Subject: [PATCH] Removed deprecated public API. Cleaned up deprecation warnings. --- build.gradle | 6 + .../gestures/GestureController.java | 12 -- .../com/alexvasilkov/gestures/Settings.java | 16 -- .../gestures/StateController.java | 109 ---------- .../animation/ViewPositionAnimator.java | 36 +--- .../gestures/commons/FinderView.java | 189 ------------------ .../transition/GestureTransitions.java | 1 - .../transition/SimpleViewsTracker.java | 24 --- .../gestures/transition/ViewsTracker.java | 39 ---- .../transition/ViewsTransitionAnimator.java | 7 +- .../transition/ViewsTransitionBuilder.java | 92 --------- .../gestures/utils/ClipHelper.java | 18 +- .../gestures/utils/CropUtils.java | 26 +-- .../gestures/views/GestureImageView.java | 25 --- .../gestures/sample/demo/DemoActivity.java | 10 +- .../sample/demo/utils/DecorUtils.java | 5 + 16 files changed, 42 insertions(+), 573 deletions(-) delete mode 100644 library/src/main/java/com/alexvasilkov/gestures/commons/FinderView.java delete mode 100644 library/src/main/java/com/alexvasilkov/gestures/transition/SimpleViewsTracker.java delete mode 100644 library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTracker.java delete mode 100644 library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionBuilder.java diff --git a/build.gradle b/build.gradle index 064a5e0b..e57404d6 100644 --- a/build.gradle +++ b/build.gradle @@ -44,4 +44,10 @@ allprojects { } } } + + gradle.projectsEvaluated { + tasks.withType(JavaCompile) { + options.compilerArgs << "-Xlint:deprecation" + } + } } diff --git a/library/src/main/java/com/alexvasilkov/gestures/GestureController.java b/library/src/main/java/com/alexvasilkov/gestures/GestureController.java index 79624f11..b769532c 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/GestureController.java +++ b/library/src/main/java/com/alexvasilkov/gestures/GestureController.java @@ -180,18 +180,6 @@ public void removeOnStateChangeListener(@NonNull OnStateChangeListener listener) stateListeners.remove(listener); } - /** - * @param enabled Whether long press should be enabled or not - * @deprecated In order to enable long clicks you should either set - * {@link View#setOnLongClickListener(View.OnLongClickListener)} or use - * {@link View#setLongClickable(boolean)}. - */ - @SuppressWarnings({ "unused", "WeakerAccess" }) // Public API - @Deprecated - public void setLongPressEnabled(boolean enabled) { - targetView.setLongClickable(true); - } - /** * Returns settings that can be updated. *

diff --git a/library/src/main/java/com/alexvasilkov/gestures/Settings.java b/library/src/main/java/com/alexvasilkov/gestures/Settings.java index 12333203..1adf11fc 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/Settings.java +++ b/library/src/main/java/com/alexvasilkov/gestures/Settings.java @@ -601,22 +601,6 @@ public Settings enableBounds() { return this; } - /** - * @param restrict Whether image bounds should be restricted or not - * @return Current settings object for calls chaining - * @deprecated Use {@link #disableBounds()} and {@link #enableBounds()} methods instead. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - @NonNull - public Settings setRestrictBounds(boolean restrict) { - boundsDisableCount += restrict ? -1 : 1; - if (boundsDisableCount < 0) { // In case someone explicitly used this method during setup - boundsDisableCount = 0; - } - return this; - } - /** * Duration of animations. * diff --git a/library/src/main/java/com/alexvasilkov/gestures/StateController.java b/library/src/main/java/com/alexvasilkov/gestures/StateController.java index 383b1b69..586696e3 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/StateController.java +++ b/library/src/main/java/com/alexvasilkov/gestures/StateController.java @@ -11,7 +11,6 @@ import com.alexvasilkov.gestures.internal.MovementBounds; import com.alexvasilkov.gestures.internal.ZoomBounds; import com.alexvasilkov.gestures.utils.GravityUtils; -import com.alexvasilkov.gestures.utils.MathUtils; /** * Helper class that holds reference to {@link Settings} object and controls some aspects of view @@ -324,112 +323,4 @@ public void getMovementArea(@NonNull State state, @NonNull RectF out) { movBounds.set(state).getExternalBounds(out); } - - /* - * Deprecated methods. - */ - - /** - * @return Min zoom level - * @deprecated Use {@link #getMinZoom(State)} instead. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public float getEffectiveMinZoom() { - return zoomBounds.getMinZoom(); - } - - /** - * @return Max zoom level - * @deprecated Use {@link #getMaxZoom(State)} instead. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public float getEffectiveMaxZoom() { - return zoomBounds.getMaxZoom(); - } - - /** - * @param out Output movement area rectangle - * @param state Current state - * @deprecated User {@link #getMovementArea(State, RectF)} instead. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public void getEffectiveMovementArea(RectF out, State state) { - getMovementArea(state, out); - } - - /** - * @param value Value to be restricted - * @param minValue Min value - * @param maxValue Max value - * @return Restricted value - * @deprecated Use {@link MathUtils#restrict(float, float, float)}. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public static float restrict(float value, float minValue, float maxValue) { - return Math.max(minValue, Math.min(value, maxValue)); - } - - /** - * @param out Interpolated state (output) - * @param start Start state - * @param end End state - * @param factor Factor - * @deprecated Use {@link MathUtils#interpolate(State, State, State, float)}. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public static void interpolate(State out, State start, State end, float factor) { - MathUtils.interpolate(out, start, end, factor); - } - - /** - * @param out Interpolated state (output) - * @param start Start state - * @param startPivotX Pivot point's X coordinate in start state coordinates - * @param startPivotY Pivot point's Y coordinate in start state coordinates - * @param end End state - * @param endPivotX Pivot point's X coordinate in end state coordinates - * @param endPivotY Pivot point's Y coordinate in end state coordinates - * @param factor Factor - * @deprecated Use - * {@link MathUtils#interpolate(State, State, float, float, State, float, float, float)}. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public static void interpolate(State out, State start, float startPivotX, float startPivotY, - State end, float endPivotX, float endPivotY, float factor) { - MathUtils.interpolate(out, start, startPivotX, startPivotY, - end, endPivotX, endPivotY, factor); - } - - /** - * @param start Start value - * @param end End value - * @param factor Factor - * @return Interpolated value - * @deprecated Use {@link MathUtils#interpolate(float, float, float)}. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public static float interpolate(float start, float end, float factor) { - return MathUtils.interpolate(start, end, factor); - } - - /** - * @param out Interpolated rectangle (output) - * @param start Start rectangle - * @param end End rectangle - * @param factor Factor - * @deprecated Use {@link MathUtils#interpolate(RectF, RectF, RectF, float)}, - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public static void interpolate(RectF out, RectF start, RectF end, float factor) { - MathUtils.interpolate(out, start, end, factor); - } - } diff --git a/library/src/main/java/com/alexvasilkov/gestures/animation/ViewPositionAnimator.java b/library/src/main/java/com/alexvasilkov/gestures/animation/ViewPositionAnimator.java index 2c5de556..9de5c3f6 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/animation/ViewPositionAnimator.java +++ b/library/src/main/java/com/alexvasilkov/gestures/animation/ViewPositionAnimator.java @@ -385,27 +385,6 @@ private void ensurePositionUpdateListenersRemoved() { listenersToRemove.clear(); } - /** - * @return Animation duration - * @deprecated Use {@link Settings#getAnimationsDuration()} instead. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public long getDuration() { - return toController.getSettings().getAnimationsDuration(); - } - - /** - * @param duration Animation duration - * @deprecated Use {@link Settings#setAnimationsDuration(long)} instead. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public void setDuration(long duration) { - toController.getSettings().setAnimationsDuration(duration); - } - - /** * @return Target (to) position as set by {@link #setToState(State, float)}. * Maybe useful to determine real animation position during exit gesture. @@ -430,16 +409,6 @@ public float getPosition() { return position; } - /** - * @return Current position - * @deprecated Use {@link #getPosition()} method instead. - */ - @SuppressWarnings("unused") // Public API - @Deprecated - public float getPositionState() { - return position; - } - /** * @return Whether animator is in leaving state. Means that animation direction is * from final (to) position back to initial (from) position. @@ -785,10 +754,13 @@ private float compareAndSetClipBound(float origBound, int viewPos, int visiblePo } + @SuppressWarnings("deprecation") private static void getDisplaySize(Context context, Rect rect) { WindowManager wm = getActivity(context).getWindowManager(); DisplayMetrics metrics = new DisplayMetrics(); - if (Build.VERSION.SDK_INT >= 17) { + if (Build.VERSION.SDK_INT >= 30) { + context.getDisplay().getRealMetrics(metrics); + } else if (Build.VERSION.SDK_INT >= 17) { wm.getDefaultDisplay().getRealMetrics(metrics); } else { wm.getDefaultDisplay().getMetrics(metrics); diff --git a/library/src/main/java/com/alexvasilkov/gestures/commons/FinderView.java b/library/src/main/java/com/alexvasilkov/gestures/commons/FinderView.java deleted file mode 100644 index 6aab20a2..00000000 --- a/library/src/main/java/com/alexvasilkov/gestures/commons/FinderView.java +++ /dev/null @@ -1,189 +0,0 @@ -package com.alexvasilkov.gestures.commons; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffXfermode; -import android.graphics.Rect; -import android.graphics.RectF; -import android.os.Build; -import android.util.AttributeSet; -import android.util.TypedValue; -import android.view.View; - -import androidx.annotation.ColorInt; - -import com.alexvasilkov.gestures.Settings; -import com.alexvasilkov.gestures.internal.UnitsUtils; -import com.alexvasilkov.gestures.utils.GravityUtils; -import com.alexvasilkov.gestures.views.GestureImageView; - -/** - * View to draw movement area above {@link GestureImageView}, useful when implementing cropping. - *

- * To use this view you should set corresponding {@link Settings} with - * {@link #setSettings(Settings)} method. Then whenever movement area is changed - * (see {@link Settings#setMovementArea(int, int)}) you will need to call {@link #update()} - * method to apply changes. - *

- * You may also use rounded corners with {@link #setRounded(boolean)} method, changes between - * rounded and non-rounded mode can optionally be animated. - * - * @deprecated Use {@link CropAreaView} instead. - */ -@Deprecated -@SuppressWarnings("unused") // Kept for backward compatibility -public class FinderView extends View { - - public static final int DEFAULT_BACK_COLOR = Color.argb(128, 0, 0, 0); - public static final int DEFAULT_BORDER_COLOR = Color.WHITE; - public static final float DEFAULT_BORDER_WIDTH = 2f; - - // Temporary objects - private static final Rect tmpRect = new Rect(); - - private final RectF rect = new RectF(); - private float rounding = 0f; - - private final RectF strokeRect = new RectF(); - - private final Paint paintStroke = new Paint(); - private final Paint paintClear = new Paint(); - - private int backColor; - private Settings settings; - - public FinderView(Context context) { - this(context, null); - } - - public FinderView(Context context, AttributeSet attrs) { - super(context, attrs); - - paintClear.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); - paintClear.setAntiAlias(true); - - paintStroke.setStyle(Paint.Style.STROKE); - paintStroke.setAntiAlias(true); - - // Default values - setBackColor(DEFAULT_BACK_COLOR); - setBorderColor(DEFAULT_BORDER_COLOR); - setBorderWidth(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_BORDER_WIDTH); - } - - /** - * Sets background color. Default value is {@link #DEFAULT_BACK_COLOR}. - * - * @param color Background color - */ - public void setBackColor(@ColorInt int color) { - backColor = color; - } - - /** - * Sets borders color. Default value is {@link #DEFAULT_BORDER_COLOR}. - * - * @param color Finder area borders color - */ - public void setBorderColor(@ColorInt int color) { - paintStroke.setColor(color); - } - - /** - * Sets borders width in pixels. Default value is {@link #DEFAULT_BORDER_WIDTH} dp. - * - * @param width Finder area borders width in pixels - */ - public void setBorderWidth(float width) { - paintStroke.setStrokeWidth(width); - } - - /** - * Sets borders width in particular units. Default value is {@link #DEFAULT_BORDER_WIDTH} dp. - * - * @param unit One of {@link TypedValue}.COMPLEX_UNIT_* constants - * @param width Finder area borders width in given unit - */ - public void setBorderWidth(int unit, float width) { - setBorderWidth(UnitsUtils.toPixels(getContext(), unit, width)); - } - - /** - * Sets settings to get movement area from. - * - * @param settings Settings of the corresponding {@link GestureImageView} - */ - public void setSettings(Settings settings) { - this.settings = settings; - update(); - } - - /** - * Whether to round bounds' corners. - * - * @param rounded Whether finder area should be rounded or not - */ - public void setRounded(boolean rounded) { - rounding = rounded ? 1f : 0f; - update(); - } - - /** - * Applies area size, area position and corners rounding. - * - * @param animate This paratemter is ignored - */ - public void update(boolean animate) { - update(); - } - - /** - * Updates finder area size and position. Should be called whenever - * corresponding settings are changed, see {@link #setSettings(Settings)} - */ - public void update() { - if (settings != null && getWidth() > 0 && getHeight() > 0) { - // Updating finder area rectangle - GravityUtils.getMovementAreaPosition(settings, tmpRect); - rect.set(tmpRect); - rect.offset(getPaddingLeft(), getPaddingTop()); - - // We want to stroke outside of finder rectangle, while by default stroke is centered - strokeRect.set(rect); - float halfStroke = 0.5f * paintStroke.getStrokeWidth(); - strokeRect.inset(-halfStroke, -halfStroke); - - invalidate(); - } - } - - @Override - protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { - update(); - } - - @SuppressLint("CanvasSize") - @SuppressWarnings("deprecation") - @Override - protected void onDraw(Canvas canvas) { - float rx = rounding * 0.5f * rect.width(); - float ry = rounding * 0.5f * rect.height(); - - // Punching hole in background color requires offscreen drawing - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null); - } else { - canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null, 0); - } - canvas.drawColor(backColor); - canvas.drawRoundRect(rect, rx, ry, paintClear); - canvas.restore(); - - canvas.drawRoundRect(strokeRect, rx, ry, paintStroke); - } - -} diff --git a/library/src/main/java/com/alexvasilkov/gestures/transition/GestureTransitions.java b/library/src/main/java/com/alexvasilkov/gestures/transition/GestureTransitions.java index 31c0e610..3e7d4c2a 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/transition/GestureTransitions.java +++ b/library/src/main/java/com/alexvasilkov/gestures/transition/GestureTransitions.java @@ -22,7 +22,6 @@ public class GestureTransitions { // ViewsTransitionAnimator' public constructor is temporary deprecated - @SuppressWarnings("deprecation") private final ViewsTransitionAnimator animator = new ViewsTransitionAnimator<>(); private GestureTransitions() {} diff --git a/library/src/main/java/com/alexvasilkov/gestures/transition/SimpleViewsTracker.java b/library/src/main/java/com/alexvasilkov/gestures/transition/SimpleViewsTracker.java deleted file mode 100644 index d7ef6671..00000000 --- a/library/src/main/java/com/alexvasilkov/gestures/transition/SimpleViewsTracker.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alexvasilkov.gestures.transition; - -import androidx.annotation.NonNull; - -import com.alexvasilkov.gestures.transition.tracker.SimpleTracker; - -/** - * @deprecated Use {@link GestureTransitions} class with {@link SimpleTracker} instead. - */ -@SuppressWarnings({ "unused", "deprecation" }) // Class is left for compatibility -@Deprecated -public abstract class SimpleViewsTracker implements ViewsTracker { - - @Override - public int getPositionForId(@NonNull Integer id) { - return id; - } - - @Override - public Integer getIdForPosition(int position) { - return position; - } - -} diff --git a/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTracker.java b/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTracker.java deleted file mode 100644 index 1a572a51..00000000 --- a/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTracker.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.alexvasilkov.gestures.transition; - -import android.view.View; - -import androidx.annotation.NonNull; - -import com.alexvasilkov.gestures.transition.tracker.FromTracker; -import com.alexvasilkov.gestures.transition.tracker.IntoTracker; - -/** - * @deprecated Use {@link GestureTransitions} class with {@link FromTracker} and - * {@link IntoTracker} instead. - */ -@SuppressWarnings({ "WeakerAccess", "unused" }) // Class is left for compatibility -@Deprecated -public interface ViewsTracker { - - int NO_POSITION = -1; - - /** - * @param id Item ID - * @return Position for item with given id, or {@link #NO_POSITION} if item was not found. - */ - int getPositionForId(@NonNull ID id); - - /** - * @param position List position - * @return Item's id at given position, or {@code null} if position is invalid. - */ - ID getIdForPosition(int position); - - /** - * @param position List position - * @return View at given position, or {@code null} if there is no known view for given position - * or position is invalid. - */ - View getViewForPosition(int position); - -} diff --git a/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionAnimator.java b/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionAnimator.java index 7d145876..4fdce0b1 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionAnimator.java +++ b/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionAnimator.java @@ -39,12 +39,7 @@ public class ViewsTransitionAnimator extends ViewsCoordinator { private boolean exitRequested; private boolean exitWithAnimation; - /** - * @deprecated Use {@link GestureTransitions} instead. - */ - @SuppressWarnings({ "WeakerAccess", "DeprecatedIsStillUsed" }) // Public temporary API - @Deprecated - public ViewsTransitionAnimator() { + ViewsTransitionAnimator() { addPositionUpdateListener(new PositionUpdateListener() { @Override public void onPositionUpdate(float position, boolean isLeaving) { diff --git a/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionBuilder.java b/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionBuilder.java deleted file mode 100644 index 2ef2e160..00000000 --- a/library/src/main/java/com/alexvasilkov/gestures/transition/ViewsTransitionBuilder.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.alexvasilkov.gestures.transition; - -import android.view.View; -import android.widget.ListView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import androidx.viewpager.widget.ViewPager; - -import com.alexvasilkov.gestures.transition.internal.FromListViewListener; -import com.alexvasilkov.gestures.transition.internal.FromRecyclerViewListener; -import com.alexvasilkov.gestures.transition.internal.IntoViewPagerListener; -import com.alexvasilkov.gestures.transition.tracker.FromTracker; -import com.alexvasilkov.gestures.transition.tracker.IntoTracker; - -/** - * @deprecated Use {@link GestureTransitions} instead. - */ -@SuppressWarnings({ "deprecation", "unused", "WeakerAccess" }) // Class is left for compatibility -@Deprecated -public class ViewsTransitionBuilder { - - private final ViewsTransitionAnimator animator = new ViewsTransitionAnimator<>(); - - public ViewsTransitionBuilder fromRecyclerView( - @NonNull RecyclerView recyclerView, - @NonNull ViewsTracker tracker) { - - animator.setFromListener( - new FromRecyclerViewListener<>(recyclerView, toFromTracker(tracker), true)); - - return this; - } - - public ViewsTransitionBuilder fromListView( - @NonNull ListView listView, - @NonNull ViewsTracker tracker) { - - animator.setFromListener( - new FromListViewListener<>(listView, toFromTracker(tracker), true)); - - return this; - } - - public ViewsTransitionBuilder intoViewPager( - @NonNull ViewPager viewPager, - @NonNull ViewsTracker tracker) { - - animator.setToListener(new IntoViewPagerListener<>(viewPager, toIntoTracker(tracker))); - - return this; - } - - public ViewsTransitionAnimator build() { - return animator; - } - - - private static FromTracker toFromTracker(final ViewsTracker tracker) { - return new FromTracker() { - @Override - public int getPositionById(@NonNull ID id) { - return tracker.getPositionForId(id); - } - - @Override - public View getViewById(@NonNull ID id) { - return tracker.getViewForPosition(tracker.getPositionForId(id)); - } - }; - } - - private static IntoTracker toIntoTracker(final ViewsTracker tracker) { - return new IntoTracker() { - @Override - public ID getIdByPosition(int position) { - return tracker.getIdForPosition(position); - } - - @Override - public int getPositionById(@NonNull ID id) { - return tracker.getPositionForId(id); - } - - @Override - public View getViewById(@NonNull ID id) { - return tracker.getViewForPosition(tracker.getPositionForId(id)); - } - }; - } - -} diff --git a/library/src/main/java/com/alexvasilkov/gestures/utils/ClipHelper.java b/library/src/main/java/com/alexvasilkov/gestures/utils/ClipHelper.java index aee6f9ae..5fc67e89 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/utils/ClipHelper.java +++ b/library/src/main/java/com/alexvasilkov/gestures/utils/ClipHelper.java @@ -3,6 +3,7 @@ import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.RectF; +import android.os.Build; import android.view.View; import androidx.annotation.NonNull; @@ -45,6 +46,7 @@ public ClipHelper(@NonNull View view) { /** * {@inheritDoc} */ + @SuppressWarnings("deprecation") @Override public void clipView(@Nullable RectF rect, float rotation) { if (rect == null) { @@ -72,12 +74,16 @@ public void clipView(@Nullable RectF rect, float rotation) { tmpMatrix.mapRect(clipBounds); } - // Invalidating only updated part (min area holding both new and old clip bounds) - int left = (int) Math.min(clipBounds.left, clipBoundsOld.left); - int top = (int) Math.min(clipBounds.top, clipBoundsOld.top); - int right = (int) Math.max(clipBounds.right, clipBoundsOld.right) + 1; - int bottom = (int) Math.max(clipBounds.bottom, clipBoundsOld.bottom) + 1; - view.invalidate(left, top, right, bottom); + if (Build.VERSION.SDK_INT >= 21) { + view.invalidate(); + } else { + // Invalidating only updated part (min area holding both new and old clip bounds) + int left = (int) Math.min(clipBounds.left, clipBoundsOld.left); + int top = (int) Math.min(clipBounds.top, clipBoundsOld.top); + int right = (int) Math.max(clipBounds.right, clipBoundsOld.right) + 1; + int bottom = (int) Math.max(clipBounds.bottom, clipBoundsOld.bottom) + 1; + view.invalidate(left, top, right, bottom); + } } } diff --git a/library/src/main/java/com/alexvasilkov/gestures/utils/CropUtils.java b/library/src/main/java/com/alexvasilkov/gestures/utils/CropUtils.java index 8916d9c4..59937e78 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/utils/CropUtils.java +++ b/library/src/main/java/com/alexvasilkov/gestures/utils/CropUtils.java @@ -23,32 +23,18 @@ private CropUtils() {} * @param controller Image controller * @return Cropped image part */ - @SuppressWarnings("deprecation") // We'll clean it up once deprecated method is removed @Nullable public static Bitmap crop(Drawable drawable, GestureController controller) { - controller.stopAllAnimations(); - controller.updateState(); // Applying state restrictions - return crop(drawable, controller.getState(), controller.getSettings()); - } - - /** - * Crops image drawable into bitmap according to current image position. - * - * @param drawable Image drawable - * @param state Image state - * @param settings Image settings - * @return Cropped image part - * @deprecated Use {@link #crop(Drawable, GestureController)} instead - */ - @SuppressWarnings("DeprecatedIsStillUsed") - @Deprecated - @Nullable - public static Bitmap crop(Drawable drawable, State state, Settings settings) { if (drawable == null) { return null; } - float zoom = state.getZoom(); + controller.stopAllAnimations(); + controller.updateState(); // Applying state restrictions + + final Settings settings = controller.getSettings(); + final State state = controller.getState(); + final float zoom = state.getZoom(); // Computing crop size for base zoom level (zoom == 1) int width = Math.round(settings.getMovementAreaW() / zoom); diff --git a/library/src/main/java/com/alexvasilkov/gestures/views/GestureImageView.java b/library/src/main/java/com/alexvasilkov/gestures/views/GestureImageView.java index 4b650113..1dcad1b4 100644 --- a/library/src/main/java/com/alexvasilkov/gestures/views/GestureImageView.java +++ b/library/src/main/java/com/alexvasilkov/gestures/views/GestureImageView.java @@ -128,21 +128,6 @@ public void clipBounds(@Nullable RectF rect) { clipBoundsHelper.clipView(rect, 0f); } - /** - * Crops bitmap as it is seen inside movement area: {@link Settings#setMovementArea(int, int)}. - * Result will be delivered to provided snapshot listener. - * - * @param listener Snapshot listener - * @deprecated Use {@link #crop()} method instead. - */ - @SuppressWarnings({ "deprecation", "unused" }) // Public API - @Deprecated - public void getSnapshot(@NonNull OnSnapshotLoadedListener listener) { - if (getDrawable() != null) { - listener.onSnapshotLoaded(crop()); - } - } - /** * Crops bitmap as it is seen inside movement area: {@link Settings#setMovementArea(int, int)}. *

@@ -228,14 +213,4 @@ private static Drawable getDrawable(Context context, @DrawableRes int id) { } } - - /** - * @deprecated Use {@link #crop()} method instead. - */ - @SuppressWarnings("WeakerAccess") // Public API - @Deprecated - public interface OnSnapshotLoadedListener { - void onSnapshotLoaded(@Nullable Bitmap bitmap); - } - } diff --git a/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/DemoActivity.java b/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/DemoActivity.java index 6564b51a..1d46c3fc 100644 --- a/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/DemoActivity.java +++ b/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/DemoActivity.java @@ -216,8 +216,12 @@ public void onPageSelected(int position) { showSystemUi(!isSystemUiShown()); } }); - getWindow().getDecorView().setOnSystemUiVisibilityChangeListener( - visibility -> views.pagerToolbar.animate().alpha(isSystemUiShown() ? 1f : 0f)); + + DecorUtils.onInsetsChanged(views.pagerToolbar, () -> { + float alpha = isSystemUiShown() ? 1f : 0f; + views.pagerToolbar.animate().alpha(alpha); + views.pagerTitle.animate().alpha(alpha); + }); } /** @@ -286,6 +290,7 @@ private void applyFullPagerState(float position, boolean isLeaving) { /** * Checks if system UI (status bar and navigation bar) is shown or we are in fullscreen mode. */ + @SuppressWarnings("deprecation") // New insets controller API is not back-ported yet private boolean isSystemUiShown() { return (getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0; @@ -294,6 +299,7 @@ private boolean isSystemUiShown() { /** * Shows or hides system UI (status bar and navigation bar). */ + @SuppressWarnings("deprecation") // New insets controller API is not back-ported yet private void showSystemUi(boolean show) { int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN diff --git a/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/utils/DecorUtils.java b/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/utils/DecorUtils.java index f303bf8d..089521a7 100644 --- a/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/utils/DecorUtils.java +++ b/sample/src/main/java/com/alexvasilkov/gestures/sample/demo/utils/DecorUtils.java @@ -82,6 +82,11 @@ public static void size(View view, int direction) { }); } + public static void onInsetsChanged(View view, Runnable action) { + addListener(view, insets -> action.run()); + } + + private static Rect getExtraInsets(View view, Insets insets, int direction, int tagId) { Rect oldInsets = (Rect) view.getTag(tagId); oldInsets = oldInsets == null ? new Rect() : oldInsets;