Created
January 23, 2018 09:02
-
-
Save sjarifHD/74b163864e944c97f750475aee527a48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package id.efishery.tmanlite.ui.listfeeder; | |
| import android.animation.ValueAnimator; | |
| import android.content.Context; | |
| import android.support.v7.widget.CardView; | |
| import android.support.v7.widget.RecyclerView; | |
| import android.util.DisplayMetrics; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.view.ViewTreeObserver; | |
| import android.view.WindowManager; | |
| import android.widget.LinearLayout; | |
| import android.widget.TextView; | |
| import butterknife.BindView; | |
| import butterknife.ButterKnife; | |
| import id.efishery.tmanlite.R; | |
| /** | |
| * Created by sjarifhd on 19/01/18. | |
| * Innovation, eFishery | |
| */ | |
| public class FeederViewHolder extends RecyclerView.ViewHolder { | |
| private int minHeight; | |
| @BindView(R.id.tvSSID) | |
| TextView tvSSID; | |
| @BindView(R.id.tvBarcode) | |
| TextView tvBarcode; | |
| @BindView(R.id.tvVersion) | |
| TextView tvVersion; | |
| @BindView(R.id.cardContainer) | |
| CardView cardView; | |
| // @BindView(R.id.containerDetail) | |
| // LinearLayout containerDetail; | |
| public FeederViewHolder(View itemView, Context context) { | |
| super(itemView); | |
| ButterKnife.bind(this, itemView); | |
| // | |
| // WindowManager windowmanager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); | |
| // DisplayMetrics dimension = new DisplayMetrics(); | |
| // windowmanager.getDefaultDisplay().getMetrics(dimension); | |
| // final int height = dimension.heightPixels; | |
| // | |
| // cardView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { | |
| // @Override | |
| // public boolean onPreDraw() { | |
| // cardView.getViewTreeObserver().removeOnPreDrawListener(this); | |
| // minHeight = cardView.getHeight(); | |
| // ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams(); | |
| // layoutParams.height = minHeight; | |
| // cardView.setLayoutParams(layoutParams); | |
| // | |
| // return true; | |
| // } | |
| // }); | |
| // | |
| // cardView.setOnClickListener(v -> toggleCardViewHeight(height)); | |
| } | |
| private void toggleCardViewHeight(int height) { | |
| if (cardView.getHeight() == minHeight) { | |
| expandView(height); //'height' is the height of screen which we have measured already. | |
| } else { | |
| collapseView(); | |
| } | |
| } | |
| private void collapseView() { | |
| ValueAnimator anim = ValueAnimator.ofInt(cardView.getMeasuredHeightAndState(), | |
| minHeight); | |
| anim.addUpdateListener(valueAnimator -> { | |
| int val = (Integer) valueAnimator.getAnimatedValue(); | |
| ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams(); | |
| layoutParams.height = val; | |
| cardView.setLayoutParams(layoutParams); | |
| }); | |
| anim.start(); | |
| containerDetail.setVisibility(View.GONE); | |
| } | |
| private void expandView(int height) { | |
| ValueAnimator anim = ValueAnimator.ofInt(cardView.getMeasuredHeightAndState(), | |
| height); | |
| anim.addUpdateListener(valueAnimator -> { | |
| int val = (Integer) valueAnimator.getAnimatedValue(); | |
| ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams(); | |
| layoutParams.height = val; | |
| cardView.setLayoutParams(layoutParams); | |
| }); | |
| anim.start(); | |
| containerDetail.setVisibility(View.VISIBLE); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment