package com.aincc.lib.ui.widget.flip; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * * <h3><b>FlipAdapter</b></h3></br> * * 플립 어댑터 * * @author aincc@barusoft.com * @version 1.0.0 * @since 1.0.0 */ public abstract class FlipAdapter { private static final int INVALID_INDEX = -1; /** * 컨텍스트 */ protected Context context; /** * 플립 리스트 데이터 */ protected List<? extends FlipItem> listdata; /** * 캐시 플립 뷰 */ private Map<Integer, View> cachedView = new HashMap<Integer, View>(); /** * 현재 페이지 */ protected AtomicInteger currentPosition = new AtomicInteger(INVALID_INDEX); /** * * @since 1.0.0 * @param context * @param listdata */ public FlipAdapter(Context context, List<? extends FlipItem> listdata) { this.context = context; this.listdata = listdata; } /** * @return the Listdata */ protected List<? extends FlipItem> getListdata() { return listdata; } /** * @param listdata */ protected void setListdata(List<? extends FlipItem> listdata) { this.listdata = listdata; } /** * @return current position */ protected int getCurrentPosition() { return currentPosition.get(); } /** * * @since 1.0.0 * @param position */ protected View readyPage(int position) { if (!cachedView.containsKey(position)) { View view = LayoutInflater.from(context).inflate(listdata.get(position).layout, null); cachedView.put(position, view); return view; } return cachedView.get(position); } /** * @return 플립 리스트 전체 개수 */ abstract protected int getCount(); /** * * @since 1.0.0 * @param position * @return 지정한 인덱스의 플립아이템 */ abstract protected Object getItem(int position); /** * 지정된 인덱스의 플립 아이템을 생성 <br> * 최대 3개의 아이템을 생성하여 관리한다. <br> * front / current / back 으로 아이템을 관리한다. * * @since 1.0.0 * @param position * @return 플립 뷰 */ abstract protected View readyPage(int position, View view, ViewGroup parent); /** * 지정된 인덱스의 플립 아이템을 삭제 <br> * 플리핑 시 필요없어진 인덱스의 플립뷰를 삭제한다.<br> * * @since 1.0.0 * @param position */ abstract protected void destroyPage(int position, View view, ViewGroup parent); }