package findyourfate.com.rahuketupeyarchi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.ActionBar;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;  
public class homeactivity extends AppCompatActivity {
    /** Called when the activity is first created. */
 	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.homemain);
	final Context context = this;
		ActionBar actionBar = getSupportActionBar();
		if (actionBar != null) {
			// Enable the home button and set display options
			actionBar.setDisplayHomeAsUpEnabled(true);
			actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);

			// Set the title of the ActionBar
			actionBar.setTitle( Html.fromHtml("<font color=\"#ffffff\" size=\"3\">"+"Rahu-Ketu Peyarchi"+"</font>"));


			// Enable the home button for backward compatibility
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
				actionBar.setHomeButtonEnabled(true);
			}

			// Show the ActionBar
			actionBar.show();
		}


	ImageView homeimage = (ImageView) findViewById(R.id.rahuscreen);
	Runnable swapimage=new Runnable(){

		@Override
		public void run() {
			Intent intent = new Intent(context,home.class);
            startActivity(intent);   
			
		}
		
	};
	homeimage.postDelayed(swapimage, 2000);
	homeimage.setOnClickListener(new OnClickListener() {
@Override
	public void onClick(View arg0) {
			Intent intent = new Intent(context,home.class);
            startActivity(intent);   
 			}
 
		});   
	}
 	@Override
    public boolean onKeyDown(int keycode, KeyEvent event ) {
   	 if(keycode == KeyEvent.KEYCODE_SETTINGS){
       	 
   		 Intent int_home1 = new Intent(this,home.class);  
    		int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    		startActivity(int_home1);
   	      return true;
   	     }
   	if(keycode == KeyEvent.KEYCODE_HOME){
	  	  
   	 Intent int_home1 = new Intent(this,home.class);  
  	int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(int_home1);
  	
    		return true;
     }
   	      if(keycode == KeyEvent.KEYCODE_MENU){
   	    	  
   	    	 Intent int_home1 = new Intent(this,home.class);  
   	   	int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
   	 startActivity(int_home1);
		     		return true;
   	    
   	     }
   	       
   	     return super.onKeyDown(keycode,event);  
   	    }
     	
 	 @Override
     public void onBackPressed() {


		 super.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.setTitle("Close App.");
		 alert.setIcon(R.drawable.alert);
		 alert.show();

	 }
     
}
	