package com.example.image09;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Images.Media;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;


public class MainActivity extends Activity {

	 LinearLayout myGallery;
	 
	 ViewPager mViewPager;
	
	 
	
	 
	    @Override
	    public void onCreate(Bundle savedInstanceState) 
	    {
		        super.onCreate(savedInstanceState);
		        setContentView(R.layout.activity_main);
		        
		        
		        mViewPager = (ViewPager)findViewById(R.id.pager);
		        TestAdapter mAdapter = new TestAdapter(this);
		        mViewPager.setAdapter(mAdapter);
		        mAdapter.change(getList());
		        
	    }

	    private List<String> getList() {
	    	List<String> list = new ArrayList<String>();
	    	list.add("file:///sdcard/patoche/b0008.jpg");
	    	list.add("file:///sdcard/patoche/33-xl.jpg");
	    	return list;
	    
	    
	}
}    

class TestAdapter extends PagerAdapter {

	private List<String> mPaths;
	
	private Context mContext;
	
	public TestAdapter(Context cx) {
		mContext = cx.getApplicationContext();
	}
	
	public void change(List<String> paths) {
		mPaths = paths;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mPaths.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object obj) {
		// TODO Auto-generated method stub
		return view == (View) obj;
	}

	@Override
	public Object instantiateItem (ViewGroup container, int position) {
		ImageView iv = new ImageView(mContext);
		try {
			Bitmap bm = BitmapFactory.decodeFile(mPaths.get(position));
			iv.setImageBitmap(bm);
		} catch (OutOfMemoryError e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		((ViewPager)container).addView(iv, 0);
		return iv;
	}
	
	@Override
	public void destroyItem (ViewGroup container, int position, Object object) {
		container.removeView((View)object);
	}
}