package mh.adib.shiveh;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class Menu extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.menu);
		
		if (getIntent().getBooleanExtra("EXIT", false)) 
		{
		        finish();
		}
		
		ImageView home=(ImageView)findViewById(R.id.imageView2);
		home.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
				startActivity(new Intent(Menu.this, mh.adib.shiveh.Menu.class));
				overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
			}
		});
		
		RelativeLayout fehrest=(RelativeLayout)findViewById(R.id.fehrest);
		fehrest.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
				startActivity(new Intent(Menu.this, MainActivity.class));
				overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
			}
		});
		
		RelativeLayout search=(RelativeLayout)findViewById(R.id.search);
		search.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
				startActivity(new Intent(Menu.this, Search.class));
				overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
			}
		});
		
		RelativeLayout exit=(RelativeLayout)findViewById(R.id.exit);
		exit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				ShowAlertDialog();
			}
		});
	}
	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub

		ShowAlertDialog();
	}
	public void ShowAlertDialog() {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(Menu.this);
        alertDialog.setTitle("خروج");
        alertDialog.setMessage("خارج می‌شوید؟");
        alertDialog.setIcon(R.drawable.ic_launcher);
        // Setting Positive "Yes" Button
        alertDialog.setPositiveButton("بله",
                        new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        
                    	Intent intent = new Intent(Menu.this, Menu.class);
                    	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    	intent.putExtra("EXIT", true);
                    	startActivity(intent);
                    }
                });
        // Setting Negative "NO" Button
        alertDialog.setNegativeButton("خیر",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // Write your code here to invoke NO event
                        dialog.cancel();
                       
                    }
                });
        // Showing Alert Message
        alertDialog.show();
    }

}
