package cancer.findyourfate.com;
 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

public class home  extends AppCompatActivity {
	String regId; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	    setContentView(R.layout.home);
	    regId = getIntent().getStringExtra("REGID");  
	        Runnable swapImage = new Runnable() {
		    @Override
		    public void run() {
		    	Intent intent = new Intent(home.this,MainActivity.class);
		     	intent.putExtra("REGID", regId);
		    	startActivity(intent);
		    }
		    };
		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=\"21px\"><b>Cancer</b></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  img = (ImageView) findViewById(R.id.imageView1);
	   img.postDelayed(swapImage, 1000); 
	   img.setOnTouchListener(new View.OnTouchListener() {
		
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			// TODO Auto-generated method stub
			Intent intent = new Intent(home.this,MainActivity.class);
		 	intent.putExtra("REGID", regId);
	    	startActivity(intent);
			return true;
		}
	});
}
			@Override
			public void onBackPressed() {
                super.onBackPressed();
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle("Exit!");
			builder.setMessage("Are you sure you want to exit from Cancer app?")
			       .setCancelable(false)
			       .setIcon(R.drawable.alert)
			       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			        	home.this.finish();
			        	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();
	}

}
