Commit c8706cad authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Photo Picker: Implement animations for zoom switching

Bug: 1029056, 656015
Change-Id: Ib206c718ba4984d67209c708b4baa75e5f77816d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1940186Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720203}
parent cf21480d
...@@ -9,6 +9,7 @@ import android.animation.ObjectAnimator; ...@@ -9,6 +9,7 @@ import android.animation.ObjectAnimator;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
...@@ -97,6 +98,10 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { ...@@ -97,6 +98,10 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> {
// Whether the image has been loaded already. // Whether the image has been loaded already.
private boolean mImageLoaded; private boolean mImageLoaded;
// The background color to use for the tile (either the special tile or for pictures, when not
// animating).
private int mBackgroundColor = Color.TRANSPARENT;
// The selected state of a given picture tile. // The selected state of a given picture tile.
private boolean mSelectedState; private boolean mSelectedState;
...@@ -188,6 +193,7 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { ...@@ -188,6 +193,7 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> {
@Override @Override
protected boolean toggleSelectionForItem(PickerBitmap item) { protected boolean toggleSelectionForItem(PickerBitmap item) {
if (isGalleryTile() || isCameraTile()) return false; if (isGalleryTile() || isCameraTile()) return false;
if (mCategoryView.isZoomSwitchingInEffect()) return false;
return super.toggleSelectionForItem(item); return super.toggleSelectionForItem(item);
} }
...@@ -458,7 +464,9 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> { ...@@ -458,7 +464,9 @@ public class PickerBitmapView extends SelectableItemView<PickerBitmap> {
setEnabled(!anySelection); setEnabled(!anySelection);
} }
setBackgroundColor(ApiCompatibilityUtils.getColor(resources, bgColorId)); mBackgroundColor = ApiCompatibilityUtils.getColor(resources, bgColorId);
setBackgroundColor(mCategoryView.isZoomSwitchingInEffect() && !special ? Color.TRANSPARENT
: mBackgroundColor);
// The visibility of the unselected toggle for multi-selection mode is a little more complex // The visibility of the unselected toggle for multi-selection mode is a little more complex
// because we don't want to show it when nothing is selected and also not on a blank canvas. // because we don't want to show it when nothing is selected and also not on a blank canvas.
......
...@@ -15,6 +15,9 @@ import android.net.Uri; ...@@ -15,6 +15,9 @@ import android.net.Uri;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.transition.ChangeBounds;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.LruCache; import android.util.LruCache;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -44,6 +47,7 @@ import org.chromium.ui.UiUtils; ...@@ -44,6 +47,7 @@ import org.chromium.ui.UiUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
/** /**
...@@ -410,6 +414,14 @@ public class PickerCategoryView extends RelativeLayout ...@@ -410,6 +414,14 @@ public class PickerCategoryView extends RelativeLayout
} }
private void flipZoomMode() { private void flipZoomMode() {
// Bitmap scaling is cumulative, so if an image is selected when we switch modes, it will
// become skewed when switching between full size and square modes because dimensions of the
// picture also change (from square to full width). We therefore un-select all items before
// starting the animation and then reselect them once animation has ended.
final HashSet<PickerBitmap> selectedItems =
new HashSet<>(mSelectionDelegate.getSelectedItems());
mSelectionDelegate.clearSelection();
mMagnifyingMode = !mMagnifyingMode; mMagnifyingMode = !mMagnifyingMode;
ImageView zoom = findViewById(R.id.zoom); ImageView zoom = findViewById(R.id.zoom);
...@@ -421,6 +433,33 @@ public class PickerCategoryView extends RelativeLayout ...@@ -421,6 +433,33 @@ public class PickerCategoryView extends RelativeLayout
calculateGridMetrics(); calculateGridMetrics();
mZoomSwitchingInEffect = true;
ChangeBounds transition = new ChangeBounds();
transition.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {}
@Override
public void onTransitionEnd(Transition transition) {
mZoomSwitchingInEffect = false;
// Redo selection when switching between modes to make it obvious what got selected.
mSelectionDelegate.setSelectedItems(selectedItems);
}
@Override
public void onTransitionCancel(Transition transition) {}
@Override
public void onTransitionPause(Transition transition) {}
@Override
public void onTransitionResume(Transition transition) {}
});
TransitionManager.beginDelayedTransition(mRecyclerView, transition);
mLayoutManager.setSpanCount(mColumns); mLayoutManager.setSpanCount(mColumns);
mPickerAdapter.notifyDataSetChanged(); mPickerAdapter.notifyDataSetChanged();
mRecyclerView.requestLayout(); mRecyclerView.requestLayout();
...@@ -444,6 +483,10 @@ public class PickerCategoryView extends RelativeLayout ...@@ -444,6 +483,10 @@ public class PickerCategoryView extends RelativeLayout
return mMagnifyingMode; return mMagnifyingMode;
} }
public boolean isZoomSwitchingInEffect() {
return mZoomSwitchingInEffect;
}
public SelectionDelegate<PickerBitmap> getSelectionDelegate() { public SelectionDelegate<PickerBitmap> getSelectionDelegate() {
return mSelectionDelegate; return mSelectionDelegate;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment