package com.camera.simplemjpeg;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ZoomControls;


public class vision_miniature extends Activity 
{
		TextView textView;
		Button btn;
		ZoomControls zoom;
		ImageView image;
		
		@Override
		public void onCreate(Bundle savedInstanceState) 
		{
			super.onCreate(savedInstanceState);
			setContentView(R.layout.vision_miniature);
			textView = (TextView) findViewById(R.id.text);
			
			Intent intent = getIntent();
			String item = intent.getStringExtra("selected-item");
			textView.setPadding(10, 0, 0, 0);
			textView.setText(item);
			
      		 image = (ImageView) findViewById(R.id.imageView);
      		
      		zoom = (ZoomControls) findViewById(R.id.zoomControls1);
        		
        	FileInputStream in;
        	BufferedInputStream buf;
		    try {
		       	    in = new FileInputStream("/sdcard/"+item);
		            buf = new BufferedInputStream(in);
		            Bitmap bMap = BitmapFactory.decodeStream(buf);
		            image.setImageBitmap(bMap);
		    } 
		        
		    catch (Exception e) 
		    {
		       	Log.e("Error reading file", e.toString());
		    }
		    
		    Button nextActivity = (Button) findViewById(R.id.btn_retour);
		    nextActivity.setOnClickListener(new View.OnClickListener() 
		    {
			     public void onClick(View view) 
			     {
				      finish();
			     }
		    });
		    
		    
		    
		    
		    zoom.setOnZoomInClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					
					float x = image.getScaleX();
					float y = image.getScaleY();
					
					image.setScaleX((float) (x+1));
					image.setScaleY((float) (y+1));
				}
			});
		    
		    zoom.setOnZoomOutClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					
		 
					float x = image.getScaleX();
					float y = image.getScaleY();
					
					image.setScaleX((float) (x-1));
					image.setScaleY((float) (y-1));
				}
			});
		    
		/*    
		    image.setOnTouchListener(new OnTouchListener() 
	        {

	            @Override
	            public boolean onTouch(View arg0, MotionEvent arg1) 
	            {
	                    img.setImageURI(uri[pos]);
	                    pos++;
	                    return false;
	            }
	        });
		    */
		}
    
 
}
