Skip to content

Commit

Permalink
Merge pull request #160 from yuyakaido/issue/159
Browse files Browse the repository at this point in the history
The rotation is disabled when the card is clickable
  • Loading branch information
yuyakaido authored Dec 9, 2018
2 parents d70f486 + 99d8efa commit ae65df4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import com.yuyakaido.android.cardstackview.internal.CardStackSnapHelper;

public class CardStackView extends RecyclerView implements View.OnTouchListener {
public class CardStackView extends RecyclerView {

private final AdapterDataObserver observer = new AdapterDataObserver() {
private CardStackLayoutManager getCardStackLayoutManager() {
Expand Down Expand Up @@ -104,12 +103,12 @@ protected void onDetachedFromWindow() {
}

@Override
public boolean onTouch(View v, MotionEvent event) {
public boolean onInterceptTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
CardStackLayoutManager manager = (CardStackLayoutManager) getLayoutManager();
manager.updateProportion(event.getX(), event.getY());
}
return false;
return super.onInterceptTouchEvent(event);
}

public void swipe() {
Expand All @@ -128,7 +127,6 @@ public void rewind() {

private void initialize() {
new CardStackSnapHelper().attachToRecyclerView(this);
setOnTouchListener(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

Expand All @@ -31,12 +32,19 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Spot spot = spots.get(position);
final Spot spot = spots.get(position);
holder.name.setText(spot.name);
holder.city.setText(spot.city);
Glide.with(holder.image)
.load(spot.url)
.into(holder.image);

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), spot.name, Toast.LENGTH_SHORT).show();
}
});
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/res/layout/item_spot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:foreground="?attr/selectableItemBackground"
app:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp"
card_view:cardBackgroundColor="@android:color/white">
Expand Down

0 comments on commit ae65df4

Please sign in to comment.