package example.com.velezguiatour;

import android.app.Activity;
import android.content.Intent;
import android.gesture.Gesture;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.ArrayList;


public class Gallery extends Activity 
{
	private int page = 0;
	ImageView image = null;
    String Files = null; 
    String Title = null;
    int Position = 0;
    
    private GestureLibrary libreria;
    
    @Override public void onCreate(Bundle savedInstanceState)
    {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.image);
        
        Intent intent= getIntent();    
        Position = intent.getIntExtra("position", 0);
        Files = intent.getStringExtra("files"); 
        Title = intent.getStringExtra("title");
     
        page = 0;
        image = (ImageView) findViewById(R.id.test_image);
        page++;
        image.setImageResource(this.getResources().getIdentifier(Files+"_"+page, "drawable", this.getPackageName()));
        
	}
    
    public void onGesturePerformed(GestureOverlayView ov, Gesture gesture)
    {
    	ArrayList<Prediction> predictions = libreria.recognize(gesture);
    	if (predictions.size() > 0)
    	{
    		String comando = predictions.get(0).name;
    		if (comando.equals("next"))
    		{
    			NextPage(ov);
    		}
    		else if (comando.equals("back"))
    		{
    			InitPage(ov);
    		}
    	}
    }
    
    public void NextPage(View view)
    {
    	if (this.getResources().getIdentifier(Files+"_"+page, "drawable", this.getPackageName()) > 0)
    	{
    		image.setImageResource(this.getResources().getIdentifier(Files+"_"+page, "drawable", this.getPackageName()));
    		page++;
    	}
    	else
    	{ 		
			Toast.makeText(this, getResources().getString(R.string.lastpage), Toast.LENGTH_LONG).show();
    	}
    }
    
    public void InitPage(View view)
    {
    	page = 0;
    	page++;
    	image.setImageResource(this.getResources().getIdentifier(Files+"_"+page, "drawable", this.getPackageName()));
    }
    
}
