com.tonnguyen.livelotte.view.ResultViewPagerAdapter.java Source code

Java tutorial

Introduction

Here is the source code for com.tonnguyen.livelotte.view.ResultViewPagerAdapter.java

Source

/*
 * Copyright (C) 2011  Nguyen Hoang Ton, a.k.a Ton Nguyen - tonng86@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.tonnguyen.livelotte.view;

import java.util.Calendar;

import android.os.Parcelable;
import android.support.v4.view.CustomPagerAdapter;
import android.support.v4.view.CustomViewPager;
import android.util.Log;
import android.view.View;

import com.tonnguyen.livelotte.MyApplication;

/**
 * @author Ton Nguyen
 * An implementation of Pager Adapter, for displaying result view
 */
public class ResultViewPagerAdapter extends CustomPagerAdapter {
    private static final String TAG = "ResultViewPagerAdapter";
    private static final boolean DEBUG = false;

    private MyApplication context;

    public ResultViewPagerAdapter(MyApplication context) {
        this.context = context;
    }

    @Override
    public Object instantiateItem(View collection, int position) {
        if (DEBUG)
            Log.d(TAG, "Drawing screen " + position);

        ResultViewGroup view = new ResultViewGroup(context);
        Calendar dateToGetResult = MyApplication.getToday();
        dateToGetResult.add(Calendar.DATE, position);
        view.loadData(dateToGetResult);

        ((CustomViewPager) collection).addView(view, 0);

        return view;
    }

    @Override
    public void destroyItem(View collection, int position, Object view) {
        ((CustomViewPager) collection).removeView((ResultViewGroup) view);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void finishUpdate(View arg0) {
    }

    @Override
    public void restoreState(Parcelable arg0, ClassLoader arg1) {
    }

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public void startUpdate(View arg0) {
    }
}