Java Code Examples for android.support.v7.widget.CardView

The following examples show how to use android.support.v7.widget.CardView. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: SwipeableCard   Author: michelelacorte   File: SwipeableCard.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Animation Card for down animation, please do not modify this.
 * @param card card view instance
 * @param toolbar toolbar instance
 */
@Override
public void animationCardDown(@NotNull final CardView card, @NotNull final Toolbar toolbar, final long duration){
    new CountDownTimer(1, 1) {
        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            card.animate()
                    .translationY(height - ((int)(toolbar.getHeight() * 1.7)))
                    .setDuration(duration).start();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                fab.animate()
                        .translationY((height - ((int) (toolbar.getHeight() * 1.7))) + card.getHeight() - (fab.getHeight() - fab.getHeight()/4))
                        .setDuration(duration).start();
            }else{
                fab.animate()
                        .translationY((height - ((int) (toolbar.getHeight() * 1.7))) + card.getHeight() - (fab.getHeight() - fab.getHeight()/3))
                        .setDuration(duration).start();
            }
        }
    }.start();
}
 
Example #2
Source Project: ViewPagerCards   Author: rubensousa   File: CardPagerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(container.getContext())
            .inflate(R.layout.adapter, container, false);
    container.addView(view);
    bind(mData.get(position), view);
    CardView cardView = (CardView) view.findViewById(R.id.cardView);

    if (mBaseElevation == 0) {
        mBaseElevation = cardView.getCardElevation();
    }

    cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
    mViews.set(position, cardView);
    return view;
}
 
Example #3
Source Project: MaterialDesignSupport   Author: shawwinbin   File: PlaygroundNavigationCardRow.java    License: MIT License 6 votes vote down vote up
private ViewHolder createViewHolder(View contentView, int position) {
    ViewHolder viewHolder = new ViewHolder();
    if (contentView == null) {
        return viewHolder;
    }

    viewHolder.cardView = (CardView) contentView.findViewById(R.id.card_view);
    // viewHolder.cardView.setViewName("card:view:" + position);
    viewHolder.titleText = (TextView) contentView.findViewById(R.id.navigation_title_text);
    // viewHolder.titleText.setViewName("nav:title:" + position);
    viewHolder.infoText = (TextView) contentView.findViewById(R.id.navigation_info_text);
    // viewHolder.infoText.setViewName("nav:info:" + position);

    contentView.setTag(viewHolder);

    return viewHolder;
}
 
Example #4
Source Project: go-bees   Author: davidmigloz   File: RecordingsAdapter.java    License: GNU General Public License v3.0 6 votes vote down vote up
RecordingViewHolder(View itemView) {
    super(itemView);

    // Get views
    viewHolder = itemView;
    card = (CardView) itemView.findViewById(R.id.card);
    recordingDate = (TextView) itemView.findViewById(R.id.recording_date);
    chart = (LineChart) itemView.findViewById(R.id.chart);
    moreIcon = (ImageView) itemView.findViewById(R.id.more_icon);

    // Set listeners
    viewHolder.setOnClickListener(this);
    viewHolder.setOnCreateContextMenuListener(this);
    moreIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Open Menu
            listener.onOpenMenuClick(viewHolder);
        }
    });

    background = card.getBackground();
    formatter = new SimpleDateFormat(
            context.getString(R.string.hive_recordings_date_format), Locale.getDefault());
}
 
Example #5
Source Project: go-bees   Author: davidmigloz   File: HivesAdapter.java    License: GNU General Public License v3.0 6 votes vote down vote up
HivesViewHolder(View itemView) {
    super(itemView);

    // Get views
    viewHolder = itemView;
    card = (CardView) itemView.findViewById(R.id.card);
    hiveName = (TextView) itemView.findViewById(R.id.hive_name);
    lastRevision = (TextView) itemView.findViewById(R.id.last_revision);
    moreIcon = (ImageView) itemView.findViewById(R.id.more_icon);

    // Set listeners
    viewHolder.setOnClickListener(this);
    viewHolder.setOnCreateContextMenuListener(this);
    moreIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Open Menu
            listener.onOpenMenuClick(viewHolder);
        }
    });

    background = card.getBackground();
}
 
Example #6
Source Project: timecat   Author: triline3   File: TimeCatActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initContentView(boolean fullScreen) {
    alpha = SPHelper.getInt(Constants.TIMECAT_ALPHA, 100);
    lastPickedColor = SPHelper.getInt(Constants.TIMECAT_DIY_BG_COLOR, Color.parseColor("#03A9F4"));
    int value = (int) ((alpha / 100.0f) * 255);

    RegexUtil.refreshSymbolSelection();
    if (fullScreen) {
        setTheme(R.style.PreSettingTheme);
        setContentView(R.layout.activity_time_cat);
        getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.timecat_activity_window_full));
        getWindow().getDecorView().setBackgroundColor(Color.argb(value, Color.red(lastPickedColor), Color.green(lastPickedColor), Color.blue(lastPickedColor)));
        showAppList4OneStep();
    } else {
        CardView cardView = new CardView(this);
        cardView.setRadius(ViewUtil.dp2px(10));
        cardView.setCardBackgroundColor(Color.argb(value, Color.red(lastPickedColor), Color.green(lastPickedColor), Color.blue(lastPickedColor)));
        View view = LayoutInflater.from(this).inflate(R.layout.activity_time_cat, null, false);
        cardView.addView(view);

        getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.trans));
        setContentView(cardView);
    }
}
 
Example #7
Source Project: timecat   Author: triline3   File: HistoryActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CardView cardView = new CardView(this);
    cardView.setRadius(ViewUtil.dp2px(10));
    View view = LayoutInflater.from(this).inflate(R.layout.activity_history, null, false);
    cardView.addView(view);
    getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.trans));
    setContentView(cardView);

    //<功能归类分区方法,必须调用>-----------------------------------------------------------------
    initView();
    initData();
    initEvent();
    //</功能归类分区方法,必须调用>----------------------------------------------------------------
}
 
Example #8
Source Project: Password-Storage   Author: Pritom14   File: LoginRegistrationActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_login_registration);
    login = (Button) findViewById(R.id.btn_login);
    register = (Button) findViewById(R.id.btn_register);
    cardView=(CardView)findViewById(R.id.layout2);
    splashActivity=new SplashActivity();

    login.setOnClickListener(this);
    register.setOnClickListener(this);
    b=splashActivity.containsPass("password");

    if(b==true)
    {
        register.setVisibility(View.INVISIBLE);
        cardView.setVisibility(View.INVISIBLE);
    }
}
 
Example #9
Source Project: EasyPortfolio   Author: webianks   File: PortfolioActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void init() {

        if (getSupportActionBar() != null)
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);

        githubContainer = (FrameLayout) findViewById(R.id.githubContainer);
        playStoreContainer = (FrameLayout) findViewById(R.id.playStoreContainer);
        linkedInContainer = (FrameLayout) findViewById(R.id.linkedInContainer);
        socialContainer = (CardView) findViewById(R.id.socialContainer);

        githubContainer.setOnClickListener(this);
        playStoreContainer.setOnClickListener(this);
        linkedInContainer.setOnClickListener(this);

    }
 
Example #10
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: VideoAdapter.java    License: Apache License 2.0 6 votes vote down vote up
public VideoViewHolder(View contentView) {
    super(contentView);

    img = (ImageView) contentView.findViewById(R.id.img);
    tv_title = (TextView) contentView.findViewById(R.id.tv_title);
    tv_like = (TextView) contentView.findViewById(R.id.tv_like);
    tv_unlike = (TextView) contentView.findViewById(R.id.tv_unlike);

    tv_comment_count = (TextView) contentView.findViewById(R.id.tv_comment_count);
    tv_un_support_des = (TextView) contentView.findViewById(R.id.tv_unsupport_des);
    tv_support_des = (TextView) contentView.findViewById(R.id.tv_support_des);

    img_share = (ImageView) contentView.findViewById(R.id.img_share);
    ll_comment = (LinearLayout) contentView.findViewById(R.id.ll_comment);
    card = (CardView) contentView.findViewById(R.id.card);
}
 
Example #11
Source Project: fab-speed-dial   Author: yavski   File: FabSpeedDial.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    fab.setSelected(false);
    removeFabMenuItems();

    if (menuListener != null) {
        if (v == this || v == touchGuard) {
            menuListener.onMenuClosed();
        } else if (v instanceof FloatingActionButton) {
            menuListener.onMenuItemSelected(fabMenuItemMap.get(v));
        } else if (v instanceof CardView) {
            menuListener.onMenuItemSelected(cardViewMenuItemMap.get(v));
        }
    } else {
        Log.d(TAG, "You haven't provided a MenuListener.");
    }
}
 
Example #12
Source Project: ViewPagerCards   Author: open-android   File: CardPagerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(container.getContext())
            .inflate(R.layout.adapter, container, false);
    container.addView(view);
    bind(mData.get(position), view);
    CardView cardView = (CardView) view.findViewById(R.id.cardView);

    if (mBaseElevation == 0) {
        mBaseElevation = cardView.getCardElevation();
    }

    cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
    mViews.set(position, cardView);
    return view;
}
 
Example #13
Source Project: skype-android-app-sdk-samples   Author: OfficeDev   File: ParticipantItemPresenter.java    License: MIT License 6 votes vote down vote up
public ParticipantItemPresenter(CardView view, Conversation conversation) {
    super(view);
    this.cardView = view;
    this.conversation = conversation;
    this.propertyChangeListener = new ParticipantItemPropertyChangeListener();
    this.participant = null;

    this.participantDisplayNameTextView = (TextView)this.cardView.findViewById(
            R.id.participantDisplayId);

    this.participantOnHoldTextView = (TextView)this.cardView.findViewById(
            R.id.participantHoldId);

    this.participantMuteButton = (Button)this.cardView.findViewById(R.id.participantMuteId);
    this.participantMuteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onParticipantMuteButtonClicked(v);
        }
    });


    this.conversation.getSelfParticipant().addOnPropertyChangedCallback(
            this.propertyChangeListener);
    this.setLocalParticipantLeader();
}
 
Example #14
Source Project: PainlessMusicPlayer   Author: Doctoror   File: QueueActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void onEnterTransitionFinished() {
    if (fab.getScaleX() != 1f) {
        fab.animate().scaleX(1f).scaleY(1f).setDuration(mShortAnimTime).start();
    }
    if (albumArtDim.getAlpha() != 1f) {
        albumArtDim.animate().alpha(1f).setDuration(mShortAnimTime).start();
    }

    final CardView cardView = findViewById(R.id.cardView);
    if (cardView != null && cardView.getVisibility() != View.VISIBLE) {
        if (TransitionUtils.supportsActivityTransitions() && hasCoverTransition) {
            cardView.setTranslationY(SlideFromBottomHelper.getStartTranslation(cardView));
            cardView.setVisibility(View.VISIBLE);
            SlideFromBottomHelper.createAnimator(cardView).setDuration(mMediumAnimTime).start();
        } else {
            cardView.setVisibility(View.VISIBLE);
        }
    }
}
 
Example #15
Source Project: Dictionary   Author: Yuanhongliang   File: PlanActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View v, ViewGroup parent) {
    ViewHolder vh = null;

    if (v == null) {
        v = View.inflate(PlanActivity.this, R.layout.item_plan, null);
        vh = new ViewHolder();
        vh.cv = (CardView) v.findViewById(R.id.item_plan_cv);
        vh.name = (TextView) v.findViewById(R.id.item_plan_name);
        vh.des = (TextView) v.findViewById(R.id.item_plan_des);
        v.setTag(vh);
    } else {
        vh = (ViewHolder) v.getTag();
    }

    int ranColor = 0xff000000 | random.nextInt(0x00ffffff);
    vh.cv.setCardBackgroundColor(ranColor);
    vh.name.setText(plans.get(position));
    vh.des.setText("共" + counts.get(position).getTotal() + "个,已完成" + counts.get(position).getDone() + "个");
    return v;
}
 
Example #16
Source Project: Aurora   Author: Zweihui   File: MineFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view =inflater.inflate(R.layout.fragment_mine, container, false);
    mLlFace = (CardView) view.findViewById(R.id.ll_face);
    mCivFace = (CircleImageView) view.findViewById(R.id.civ_face);
    mTvName = (TextView) view.findViewById(R.id.tv_name);
    mLlCache = (LinearLayout) view.findViewById(R.id.ll_cache);
    mLlAttention = (LinearLayout) view.findViewById(R.id.ll_attention);
    mLlFeedBack = (LinearLayout) view.findViewById(R.id.ll_feedback);
    mLlRecord = (LinearLayout) view.findViewById(R.id.ll_record);
    return view;
}
 
Example #17
Source Project: ForPDA   Author: RadiationX   File: MessagePanelBehavior.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final CardView child,
                                   final View directTargetChild, final View target, final int nestedScrollAxes) {
    if (!canScrolling)
        child.setTranslationY(0);
    return canScrolling;
}
 
Example #18
Source Project: easyweather   Author: byhieg   File: LaboratoryFragment.java    License: MIT License 5 votes vote down vote up
public void initView() {
    cardView = (CardView) view.findViewById(R.id.item1);
    textView = (TextView) view.findViewById(R.id.lab_textview);
    textView.setText(R.string.nightMode1);
    aSwitch = (Switch) cardView.findViewById(R.id.cb);
    SharedPreferences sharedPreferences = getActivity().getSharedPreferences(MyApplication.shareFilename2, getActivity().MODE_PRIVATE);
    boolean checked = sharedPreferences.getBoolean("ischecked", false);
    aSwitch.setChecked(checked);
    switchStatus(aSwitch, MyApplication.shareFilename2);


}
 
Example #19
Source Project: AutoLabelUI   Author: DavidPizarro   File: MyRecyclerAdapter.java    License: Apache License 2.0 5 votes vote down vote up
PersonViewHolder(View itemView) {
    super(itemView);
    itemView.setOnClickListener(this);
    cv = (CardView) itemView.findViewById(R.id.cv);
    personName = (TextView) itemView.findViewById(R.id.person_name);
    personAge = (TextView) itemView.findViewById(R.id.person_age);
    personPhoto = (ImageView) itemView.findViewById(R.id.person_photo);
    cbSelected = (CheckBox) itemView.findViewById(R.id.cbSelected);
}
 
Example #20
Source Project: PersistentSearchView   Author: crysehillmes   File: PersistentSearchView.java    License: Apache License 2.0 5 votes vote down vote up
static float calculateVerticalPadding(CardView cardView) {
    float maxShadowSize = cardView.getMaxCardElevation();
    float cornerRadius = cardView.getRadius();
    boolean addPaddingForCorners = cardView.getPreventCornerOverlap();

    if (addPaddingForCorners) {
        return (float) (maxShadowSize * 1.5f + (1 - COS_45) * cornerRadius);
    } else {
        return maxShadowSize * 1.5f;
    }
}
 
Example #21
Source Project: iGap-Android   Author: RooyeKhat-Media   File: AdapterBottomSheet.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public ViewHolder(View view) {
    super(view);

    cr = (CardView) view.findViewById(R.id.card_view);
    imgSrc = (ImageView) view.findViewById(R.id.img_gallery);
    checkBoxSelect = (AnimateCheckBox) view.findViewById(R.id.cig_checkBox_select_user);
    prgBottomSheet = (ProgressBar) view.findViewById(R.id.prgBottomSheet);
}
 
Example #22
Source Project: QuickLyric   Author: QuickLyric   File: LocalAdapter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public View getRealChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    ChildViewHolder holder;
    if (convertView == null || !(convertView.getTag() instanceof ChildViewHolder)) {
        convertView = inflater.inflate(R.layout.local_child_item, parent, false);
        holder = new ChildViewHolder();
        holder.title = convertView.findViewById(R.id.child_title);
        holder.divider = convertView.findViewById(R.id.child_divider);
        holder.card = (CardView) holder.title.getParent();
        convertView.setTag(holder);
    } else
        holder = (ChildViewHolder) convertView.getTag();
    holder.lyrics = getChild(groupPosition, childPosition);
    if (holder.lyrics != null) {
        holder.title.setText(holder.lyrics.getTitle());
        holder.card.setBackgroundColor(markedRows.contains(new int[]{groupPosition, childPosition}) ? childSelectedStateColor : childDefaultStateColor);
        holder.title.setTextColor(markedRows.contains(new int[]{groupPosition, childPosition}) ? childDefaultStateColor : childSelectedStateColor);
        convertView.setOnTouchListener(mTouchListener);
        holder.groupPosition = groupPosition;
        holder.divider.setVisibility(isLastChild ? View.GONE : View.VISIBLE);
        convertView.setAlpha(1f);
        convertView.setVisibility(View.VISIBLE);
    } else
        convertView.setVisibility(View.GONE);
    convertView.setTranslationX(0f);
    return convertView;
}
 
Example #23
Source Project: MLManager   Author: javiersantos   File: AppAdapter.java    License: GNU General Public License v3.0 5 votes vote down vote up
public AppViewHolder(View v) {
    super(v);
    vName = (TextView) v.findViewById(R.id.txtName);
    vApk = (TextView) v.findViewById(R.id.txtApk);
    vIcon = (ImageView) v.findViewById(R.id.imgIcon);
    vExtract = (ButtonFlat) v.findViewById(R.id.btnExtract);
    vShare = (ButtonFlat) v.findViewById(R.id.btnShare);
    vCard = (CardView) v.findViewById(R.id.app_card);

}
 
Example #24
Source Project: LRecyclerView   Author: jdsjlzx   File: EndlessStaggeredGridLayoutActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBindItemHolder(SuperViewHolder holder, int position) {
    CardView cardView =  holder.getView(R.id.card_view);
    TextView textView = holder.getView(R.id.info_text);

    ItemModel itemModel = mDataList.get(position);

    textView.setText(itemModel.title);

    //修改高度,模拟交错效果
    cardView.getLayoutParams().height = itemModel.height;
}
 
Example #25
Source Project: YTS   Author: MuhamedFathy   File: GlideUtil.java    License: MIT License 5 votes vote down vote up
public static void loadPoster(Context context, CardView card, ImageView imageView, String url) {
  Glide.with(context)
      .load(url)
      .listener(getPalette(Type.POSTER, null, null, card, url))
      .transition(DrawableTransitionOptions.withCrossFade())
      .apply(RequestOptions.centerCropTransform())
      .into(imageView);
}
 
Example #26
Source Project: SwipeableCard   Author: michelelacorte   File: SwipeableCardAdapter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Animation Card for up animation, please do not modify this.
 * @param card card view instance
 * @param toolbar toolbar instance
 */
@Override
public void animationCardUp(@NotNull final CardView card,  final Toolbar toolbar, final long duration){
    new CountDownTimer(1, 1) {
        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            card.animate()
                    .translationY(height - (card.getHeight() + toolbar.getHeight()))
                    .setDuration(duration).start();
        }
    }.start();
}
 
Example #27
Source Project: Nibo   Author: aliumujib   File: NiboPlacesAutoCompleteSearchView.java    License: MIT License 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int count = getChildCount();
    int searchViewWidth = r - l;
    int searchViewHeight = b - t;
    int searchCardLeft;
    int searchCardTop;
    int searchCardRight;
    int searchCardBottom;
    int searchCardWidth;
    int searchCardHeight;
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (i == 0 && child instanceof CardView) {
            CardView searchCard = (CardView) child;
            int horizontalPadding = (int) Math.ceil(calculateHorizontalPadding(searchCard));
            int verticalPadding = (int) Math.ceil(calculateVerticalPadding(searchCard));
            searchCardLeft = mCardHorizontalPadding - horizontalPadding;
            searchCardTop = mCardVerticalPadding - verticalPadding;
            searchCardWidth = searchViewWidth - searchCardLeft * 2;
            searchCardHeight = child.getMeasuredHeight();
            searchCardRight = searchCardLeft + searchCardWidth;
            searchCardBottom = searchCardTop + searchCardHeight;
            child.layout(searchCardLeft, searchCardTop, searchCardRight, searchCardBottom);
        }
    }
}
 
Example #28
Source Project: PopCorn   Author: hitanshu-dhawan   File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public VideoViewHolder(View itemView) {
    super(itemView);
    videoCard = (CardView) itemView.findViewById(R.id.card_view_video);
    videoImageView = (ImageView) itemView.findViewById(R.id.image_view_video);
    videoTextView = (TextView) itemView.findViewById(R.id.text_view_video_name);

    videoCard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent youtubeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.YOUTUBE_WATCH_BASE_URL + mVideos.get(getAdapterPosition()).getKey()));
            mContext.startActivity(youtubeIntent);
        }
    });
}
 
Example #29
Source Project: nongbeer-mvp-android-demo   Author: TheKhaeng   File: MapActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void bindView(){
    btnBack = (ImageView) findViewById( R.id.btn_back );
    btnOrder = (Button) findViewById( R.id.btn_order );
    cardLoading = (CardView) findViewById( R.id.card_loading );
    mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById( R.id.map );
}
 
Example #30
Source Project: PersistentSearchView   Author: crysehillmes   File: PersistentSearchView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int totalHeight = 0;
    int searchCardWidth;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (i == 0 && child instanceof CardView) {
                CardView searchCard = (CardView) child;
                int horizontalPadding = (int) Math.ceil(calculateHorizontalPadding(searchCard));
                int verticalPadding = (int) Math.ceil(calculateVerticalPadding(searchCard));
                // searchCardWidth = widthSize - 2 * mCardVisiblePadding + horizontalPadding * 2;
                int searchCardLeft = mCardHorizontalPadding - horizontalPadding;
                // searchCardTop = mCardVisiblePadding - verticalPadding;
                searchCardWidth = widthSize - searchCardLeft * 2;
                int cardWidthSpec = MeasureSpec.makeMeasureSpec(searchCardWidth, MeasureSpec.EXACTLY);
                // int cardHeightSpec = MeasureSpec.makeMeasureSpec(searchCardHeight, MeasureSpec.EXACTLY);
                measureChild(child, cardWidthSpec, heightMeasureSpec);
                int childMeasuredHeight = child.getMeasuredHeight();
                int childMeasuredWidth = child.getMeasuredWidth();
                int childHeight = childMeasuredHeight - verticalPadding * 2;
                totalHeight = totalHeight + childHeight + mCardVerticalPadding * 2;
            }
        }
    }
    if(totalHeight < mCustomToolbarHeight)
        totalHeight = mCustomToolbarHeight;
    setMeasuredDimension(widthSize, totalHeight);
}