package com.example.template003;

import android.os.Bundle;

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity 
{
	Button button;
	EditText textReport;
    DAOtextReport daOtextReport;
  
    
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_main);
	
			daOtextReport = new DAOtextReport(this);
			
			textReport = (EditText) findViewById(R.id.report_edit_text);
			button = (Button) findViewById(R.id.MyButton);
			
			// Capture button clicks
			/*button.setOnClickListener(new OnClickListener() 
			{
				public void onClick(View arg0) {
	
					// Start NewActivity.class
					Intent myIntent = new Intent(MainActivity.this,	NewActivity.class);
					startActivity(myIntent);
				}
			});
			*/
			
			//remplir_db();
	}
	
	public void textReportOnClicked(View view) 
	{
			Toast.makeText(getApplicationContext(), "Added to DB", Toast.LENGTH_SHORT).show();

			Random_generator msr = new Random_generator();
		
			String report = msr.generateRandomString();
			//String report = textReport.getText().toString();
			
        	long result = daOtextReport.addReport(new TextReport("junjunguo.com", report, 63.4187362, 10.4387621));

        	if (result >= 0)
        	{
        		Toast.makeText(getApplicationContext(), "succsefully add report to row " + result, Toast.LENGTH_SHORT).show();
        		textReport.getText().clear();
        	} 
        	else 
        	{
        		Toast.makeText(getApplicationContext(), "not succeed ! please try again !", Toast.LENGTH_SHORT).show();
        	}
        	
    }
	
	
	
	public void remplir_db()
	{
		long result = daOtextReport.addReport(new TextReport("junjunguo.com", "report", 63.4187362, 10.4387621));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
			getMenuInflater().inflate(R.menu.activity_main, menu);
			return true;
	}
	
	@Override
    public boolean onOptionsItemSelected(MenuItem item) 
	{
       
        switch (item.getItemId())
        {
        case R.id.menu_remind:
  			Toast.makeText(getApplicationContext(),"Remind",Toast.LENGTH_SHORT).show();
  			Intent Intent04 = new Intent(MainActivity.this, NewActivity.class);
  			startActivity(Intent04);
	        return true;
        
  		case R.id.menu_repeat:
  			Toast.makeText(getApplicationContext(),"Repeat",Toast.LENGTH_SHORT).show();
  			Intent Intent05 = new Intent(MainActivity.this, Control_Service.class);
  			startActivity(Intent05);
	        return true;
	        
  		case R.id.menu_about:
  			Toast.makeText(getApplicationContext(),"CAbout",Toast.LENGTH_SHORT).show();
	        return true;

  		case R.id.menu_quit:
  			Toast.makeText(getApplicationContext(),"Salut on ferme la boutique...",Toast.LENGTH_SHORT).show();
  			finish();
	        return true;    
          
  		default:
          return super.onOptionsItemSelected(item);
        
        }
    }
	
	
	
}