1/* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.example.androidx.viewpager2.cards; 18 19import android.view.LayoutInflater; 20import android.view.View; 21import android.view.ViewGroup; 22import android.widget.TextView; 23 24import com.example.androidx.viewpager2.R; 25 26/** Inflates and populates a {@link View} representing a {@link Card} */ 27public class CardView { 28 private final View mView; 29 private final TextView mTextSuite; 30 private final TextView mTextCorner1; 31 private final TextView mTextCorner2; 32 33 public CardView(LayoutInflater layoutInflater, ViewGroup container) { 34 mView = layoutInflater.inflate(R.layout.item_card_layout, container, false); 35 mTextSuite = mView.findViewById(R.id.label_center); 36 mTextCorner1 = mView.findViewById(R.id.label_top); 37 mTextCorner2 = mView.findViewById(R.id.label_bottom); 38 } 39 40 /** 41 * Updates the view to represent the passed in card 42 */ 43 public void bind(Card card) { 44 mTextSuite.setText(Character.toString(card.getSuit())); 45 46 String cornerLabel = card.getCornerLabel(); 47 mTextCorner1.setText(cornerLabel); 48 mTextCorner2.setText(cornerLabel); 49 mTextCorner2.setRotation(180); 50 } 51 52 public View getView() { 53 return mView; 54 } 55} 56