Java tutorial
/* * Copyright (C) 2013 YojiokiSoft * * 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 3 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, see <http://www.gnu.org/licenses/>. */ package com.yojiokisoft.japanesecalc; import java.util.List; import android.content.Context; import android.content.res.Configuration; import android.support.v4.view.PagerAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import com.yojiokisoft.japanesecalc.dao.BackImageEntity; import com.yojiokisoft.japanesecalc.utils.MyResource; /** * ? */ public class SkinPagerAdapter extends PagerAdapter { private ImageView mBigImage; private List<BackImageEntity> mList; private LayoutInflater mInflter; private int mOrientation; /** * . * * @param context */ public SkinPagerAdapter(Context context, List<BackImageEntity> list) { mOrientation = context.getResources().getConfiguration().orientation; mInflter = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mList = list; } /** * @see PagerAdapter#instantiateItem(ViewGroup, int) */ @Override public Object instantiateItem(ViewGroup container, int position) { FrameLayout layout = (FrameLayout) this.mInflter.inflate(R.layout.page_skin, null); mBigImage = (ImageView) layout.findViewById(R.id.big_image); int padding = MyResource.dpi2Px(5); if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mBigImage.setPadding(0, 0, padding, 0); } else { mBigImage.setPadding(0, padding, 0, 0); } BackImageEntity item = mList.get(position); String resName = item.resourceName; int resId = MyResource.getResourceIdByName(resName); mBigImage.setImageResource(resId); mBigImage.setTag(resName); // ? container.addView(layout); return layout; } /** * @see PagerAdapter#destroyItem(ViewGroup, int, Object) */ @Override public void destroyItem(ViewGroup container, int position, Object object) { // ? View container.removeView((View) object); } /** * @see PagerAdapter#getCount() */ @Override public int getCount() { // ?? return mList.size(); } /** * @see PagerAdapter#isViewFromObject(View, Object) */ @Override public boolean isViewFromObject(View view, Object object) { // Object ? View ???? return view == (FrameLayout) object; } /** * ??. * * @param position * @return */ public BackImageEntity getSkin(int position) { return mList.get(position); } }