package findyourfate.com.rahuketupeyarchi;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;


public class home extends Activity {

	ImageView image;


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		String userAgent = new WebView(home.this).getSettings()
				.getUserAgentString();

		if (userAgent.contains("Mobile")) {
			setContentView(R.layout.home);
		} else {
			setContentView(R.layout.home_tab);
		}

	

		Button rasi = (Button) findViewById(R.id.rashi);

		// Listening to button event
		rasi.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// Starting a new Intent
				Intent nextScreen = new Intent(getApplicationContext(),
						rahucontent.class);
				startActivity(nextScreen);
			}
		});

		Button link = (Button) findViewById(R.id.link);
		// Listening to button event
		link.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				Intent myWebLink = new Intent(
						android.content.Intent.ACTION_VIEW);
				myWebLink.setData(Uri.parse("http://www.findyourfate.com/"));
				startActivity(myWebLink);

			}
		});

		Button moonsigns = (Button) findViewById(R.id.moon);
		moonsigns.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				// Starting a new Intent
				Intent nextScreen = new Intent(getApplicationContext(),
						moonsign.class);
				startActivity(nextScreen);
			}
		});

		Button years = (Button) findViewById(R.id.year);
		years.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				Intent nextScreen = new Intent(getApplicationContext(),
						rahuyear.class);
				startActivity(nextScreen);

			}
		});

		TextView rasitext = (TextView) findViewById(R.id.rashi1);
		rasitext.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				// Starting a new Intent
				Intent nextScreen = new Intent(getApplicationContext(),
						rahucontent.class);
				startActivity(nextScreen);

			}
		});

		TextView moontext = (TextView) findViewById(R.id.moon1);
		moontext.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// Starting a new Intent
				Intent nextScreen = new Intent(getApplicationContext(),
						moonsign.class);
				startActivity(nextScreen);

			}
		});

		TextView yeartext = (TextView) findViewById(R.id.year1);
		yeartext.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// Starting a new Intent
				Intent nextScreen = new Intent(getApplicationContext(),
						rahuyear.class);
				startActivity(nextScreen);

			}
		});

		Button palangal1 = (Button) findViewById(R.id.palangal);
		palangal1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent nextScreen = new Intent(getApplicationContext(),
						palangal2017.class);
				startActivity(nextScreen);
			}
		});

		TextView palangaltext = (TextView) findViewById(R.id.palangal1);
		palangaltext.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent nextScreen = new Intent(getApplicationContext(),
						palangal2017.class);
				startActivity(nextScreen);
			}
		});
		
		Button rahu1 = (Button) findViewById(R.id.rahu);
		rahu1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent nextScreen = new Intent(getApplicationContext(),
						rahu2019.class);
				startActivity(nextScreen);
			}
		});

		TextView rahutext = (TextView) findViewById(R.id.rahu1);
		rahutext.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent nextScreen = new Intent(getApplicationContext(),
						rahu2019.class);
				startActivity(nextScreen);
			}
		});


	}

	
	@Override
	public void onBackPressed() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("Are you sure you want to leave this App.")
				.setCancelable(false)
				.setPositiveButton("Yes",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								Intent intent = new Intent(Intent.ACTION_MAIN);
								intent.addCategory(Intent.CATEGORY_HOME);
								intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
								startActivity(intent);
							}
						})
				.setNegativeButton("No", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					}
				});
		AlertDialog alert = builder.create();
		alert.show();

	}

	/*public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);

	}
*/
	

  @SuppressLint("NewApi")
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	  /* if (item.getItemId() ==android.R.id.home) {
  		  Intent int_home = new Intent(this, home.class);
	           int_home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	             startActivity(int_home); 
  	  }
  	 
  	 
  	 
	  else if (item.getItemId() ==R.id.rahu) {
		final ProgressDialog progressDoalog = new ProgressDialog(home.this);
		progressDoalog.setProgressDrawable(home.this.getResources().getDrawable(R.drawable.progress));  
   progressDoalog.setMessage("Please Wait....");
  progressDoalog.setTitle("Loading...");
  progressDoalog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  progressDoalog.setCancelable(true); 
  progressDoalog.show();
  new Thread() {
      public void run() {
          try {
          	 Intent int_home = new Intent(home.this, rahucontent.class);
	           int_home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	             startActivity(int_home); 
 	    		 
	  			 
          } catch (Exception e) {
          }
          progressDoalog.dismiss();
      }
  }.start();
		  
  		  
  	  }
	else if (item.getItemId() ==R.id.rahupalan) {
		final ProgressDialog progressDoalog = new ProgressDialog(home.this);
		progressDoalog.setProgressDrawable(home.this.getResources().getDrawable(R.drawable.progress));  
   progressDoalog.setMessage("Please Wait....");
  progressDoalog.setTitle("Loading...");
  progressDoalog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  progressDoalog.setCancelable(true); 
  progressDoalog.show();
  new Thread() {
      public void run() {
          try {
          	 Intent int_home = new Intent(home.this,palangal2017.class);
	           int_home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	             startActivity(int_home); 
 	    		 
	  			 
          } catch (Exception e) {
          }
          progressDoalog.dismiss();
      }
  }.start();
}*/
      		 if (item.getItemId() ==R.id.guru) {
	    
	    
AlertDialog.Builder alt_compat = new AlertDialog.Builder(this);
String desc="App to find out when Guru Peyarchi or Jupiter transit takes place.";	


	/*LinearLayout layout = new LinearLayout(this); 
	TextView tvMessage = new TextView(this);  
	tvMessage.setBackgroundColor(Color.parseColor("#e9b44f")); 
	tvMessage.setText(desc); 
  tvMessage.setPadding(5, 5, 5, 5);
	tvMessage.setTextSize(17); 
	layout.setOrientation(LinearLayout.VERTICAL);
	layout.addView(tvMessage); 
	alt_compat.setView(layout);  */

				alt_compat.setTitle("Guru Peyarchi");
				alt_compat.setMessage(desc); 
				alt_compat.setCancelable(false) 
						 
						                .setPositiveButton("Later", new DialogInterface.OnClickListener() {
						                    public void onClick(DialogInterface dialog, int id) {
						                    	 
						                    	 dialog.cancel();
						                    }
						                })
						                .setNegativeButton("Never/Already", new DialogInterface.OnClickListener() {
						                    public void onClick(DialogInterface dialog, int id) {
						                    	dialog.cancel();
						                    	      	  						                    }
						                })
						                
						                .setNeutralButton("Open", new DialogInterface.OnClickListener() {
						    public void onClick(DialogInterface dialog, int id) {
						    	
						    	
						     
						    	 Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=findyourfate.com.gurupeyarchi"));
						    	 startActivity(browserIntent);
						    
						   
}
						    });
						
						      
						         AlertDialog alert = alt_compat.create();   
						         alert.show();

  	    	}
  	
      		else if (item.getItemId() ==R.id.sani) {
      	  	    
      	  	    
      			  AlertDialog.Builder alt_compat = new AlertDialog.Builder(this);
      			 String desc="App to find out when Sani Peyarchi or Saturn transit takes place.";	
      			  //LayoutInflater inflater = this.getLayoutInflater();
      			  
      			 // alt_compat.setView(inflater.inflate(R.layout.customdialog, null))
      				/*LinearLayout layout = new LinearLayout(this); 
      				TextView tvMessage = new TextView(this);  
      				tvMessage.setBackgroundColor(Color.parseColor("#e9b44f")); 
      				tvMessage.setText(desc); 
      			    tvMessage.setPadding(5, 5, 5, 5);
      				tvMessage.setTextSize(17); 
      				layout.setOrientation(LinearLayout.VERTICAL);
      				layout.addView(tvMessage); 
      				alt_compat.setView(layout);  */
      			  
      			  				 alt_compat.setTitle("Sani Peyarchi");
      			  			 alt_compat.setMessage(desc); 
      			  			 alt_compat.setCancelable(false)  
      			  						 
      			  						                .setPositiveButton("Later", new DialogInterface.OnClickListener() {
      			  						                    public void onClick(DialogInterface dialog, int id) {
      			  						                    	 
      			  						                    	 dialog.cancel();
      			  						                    }
      			  						                })
      			  						                .setNegativeButton("Never/Already", new DialogInterface.OnClickListener() {
      			  						                    public void onClick(DialogInterface dialog, int id) {
      			  						                    	dialog.cancel();
      			  						                    	      	  						                    }
      			  						                })
      			  						                
      			  						                .setNeutralButton("Open", new DialogInterface.OnClickListener() {
      			  						    public void onClick(DialogInterface dialog, int id) {
      			  						    	
      			  						    	
      			  						     
      			  						    	 Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=findyourfate.com.sanipeyarchi"));
      			  						    	 startActivity(browserIntent);
      			  						    
      			  						   
      			  }
      			  						    });
      			  						
      			  						      
      			  						         AlertDialog alert = alt_compat.create();   
      			  						         alert.show();

      			    	    	}
  	    	else if (item.getItemId() ==R.id.icon_exit) {
	     	AlertDialog.Builder builder = new AlertDialog.Builder(this);
		         builder.setMessage("Are you sure you want to leave this App.")
		                .setCancelable(false)
		                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int id) {
		                    	Intent intent = new Intent(Intent.ACTION_MAIN);
			       		    	intent.addCategory(Intent.CATEGORY_HOME);
			       		    	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			       		    	startActivity(intent);
		                    }
		                })
		                .setNegativeButton("No", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int id) {
		                         dialog.cancel();
		                    }
		                });
		         AlertDialog alert1 = builder.create();
		         alert1.setTitle("Close App.");
		         alert1.setIcon(R.drawable.alert);
		         alert1.show();
  	    	}
  	    	
  	    	else if (item.getItemId() ==R.id.share) {
  	    		
	    	Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
	    	emailIntent.setType("text/plain");
    		emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Rahu-Ketu Peyarchi by findyourfate.com");
    		emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hi,I would like to suggest, this Rahu-Ketu Peyarchi App to you. Click this link to download app http://goo.gl/ypifK6"+"\n\n"+" Regards");
    		startActivity(Intent.createChooser(emailIntent,"Share using")); 
  	    	}
  	    	 else {
  	     	} 
  	    	return true;
	           
	    
    }
     
 	
}