package com.example.super_duckhunt;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class After extends Activity implements OnRatingBarChangeListener, OnClickListener {
main ob;

float[]i;
Button e,comp,save;
 int numstars;
    TextView tv2,tv3;
    RatingBar rb;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.after);
		ob=new main();
	
		tv2=(TextView)findViewById(R.id.textView2);
		tv3=(TextView)findViewById(R.id.textView3);
		rb=(RatingBar)findViewById(R.id.ratingBar1);
		e=(Button)findViewById(R.id.button1);
		e.setOnClickListener(this);
		comp=(Button)findViewById(R.id.button2);
		comp.setOnClickListener(this);
		save=(Button)findViewById(R.id.button3);
		save.setOnClickListener(this);
		rb.setOnClickListener(this);
		tv2.setText(ob.points+"");
		        if(ob.points<=10){
		        	tv3.setText("Better luck next time");
		        }else if(ob.points>10 && ob.points<15){
		        	tv3.setText("Good performance");
		        }else{
		        	tv3.setText("Excellent performance");
		        }
		     
	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.equals(e)){
			Intent homeIntent = new Intent(Intent.ACTION_MAIN);
		    homeIntent.addCategory( Intent.CATEGORY_HOME );
		    homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
		    startActivity(homeIntent); 
		}
		
		else if(v.equals(comp)){boolean work=true;
		
		

			try{
			String point=(ob.points)+"";
			Bundle got=getIntent().getExtras();
			String s=got.getString("hg");
			
			
			
			Data o=new Data(After.this);
			o.open();
			o.createEntry(s,point,String.valueOf(rb.getRating()));
			o.close();}catch(Exception e){
				Dialog d=new Dialog(this);
				d.setTitle("error"+e.toString());
				d.show();
				work=false;
			}finally{
				if(work){
					Dialog d=new Dialog(this);
					d.setTitle("score updated");
					d.show();
				}
			}
		}else if(v.equals(save)){
			Intent i=new Intent("android.intent.action.SQLVIEW");
			startActivity(i);
		}
		
	}
	public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) {
		// TODO Auto-generated method stub
		
	}
 
}
