package sunsigns2014.findyourfate.com;

import android.app.Activity;


import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
import sunsigns2014.findyourfate.com.dutch2019.MyAdapter;
public class home extends Activity {
	
	  String[] Languages = { "Choose Language flag", "2019 in English", "2019 in French", "2019 in Spanish", "2019 in Hindi","2019 in Dutch", "2019 in Arabic", "2019 in Malay", 
			  "2019 in German","2019 in Chinese","2019 in Japanese","2019 in Russian","2019 in Portuguese"};
 			 
	Integer[] images = { 0, R.drawable.us, R.drawable.france,R.drawable.spanish, R.drawable.india, R.drawable.dutch, R.drawable.arabia, R.drawable.malay, R.drawable.germany, R.drawable.china, R.drawable.japanse, R.drawable.russia, R.drawable.port};


 	@Override
		protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		    setContentView(R.layout.home);
		    TextView textview=(TextView) findViewById(R.id.text);
		    textview.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view)
                {
                    Uri adress= Uri.parse("https://www.findyourfate.com");  
                    Intent browser= new Intent(Intent.ACTION_VIEW, adress);  
                    startActivity(browser);  
                }
         });
		    
		    Runnable swapImage = new Runnable() {
			    @Override
			    public void run() {
			    	Intent intent = new Intent(home.this,main2019.class);
			    	startActivity(intent);
			    }
	 	    };
		   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,main2019.class);
			    	startActivity(intent);
					return true;
				}
			});
			    
		   
			}
	@Override
    public void onBackPressed() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Are you sure you want to exit from Sun signs app?")
               .setCancelable(false)
               .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();
   }
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.custommenu, menu);
	    RelativeLayout layout = (RelativeLayout) menu.findItem(R.id.layout_item).getActionView();
	    View v = getLayoutInflater().inflate(R.layout.ab_bottom_layout, null);
	    
	    final Spinner sp = (Spinner) v.findViewById(R.id.bottomspinner);	 
 	    
	     sp.setAdapter(new MyAdapter(home.this, R.layout.spinnernew,
	    		Languages));
	   		 	  
	 	       final AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
	 	        sp.setOnItemSelectedListener(new OnItemSelectedListener() {
	 	    	   public void onClick(View v) {
	 	    	    // TODO Auto-generated method stub
	 	    	   } 
	 	    	   @Override
	 	    	    public void onItemSelected(AdapterView<?> arg0, View view,
	 	    	            int position, long row_id) {
	 	    		   
	 	    	         switch(position){
	 	    	       
	 	    	                case 1:
	 	    	               
	 	    	            	Intent inn=new Intent(home.this,main2019.class);
	 			            	inn.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	 			            	startActivity(inn);
	 			            	break;
	 	    	                case 2:
	 	    	            	Intent in2=new Intent(home.this,french2019.class);
	 			            	in2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	 			            	startActivity(in2);
	 			            	break;
	 	    	               case 3:
		 	    	            	Intent in3=new Intent(home.this,spain2019.class);
		 			            	in3.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 			            	startActivity(in3);
		 			            	break;
	 	    	              case 4:
		 	    	            	Intent in4=new Intent(home.this,hindi2019.class);
		 			            	in4.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 			            	startActivity(in4);
		 			            	break;
	 	    	             case 5:
		 	    	            	Intent in5=new Intent(home.this,dutch2019.class);
		 			            	in5.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 			            	startActivity(in5);
		 			            	break;
	 	    	            case 6:
	 	    	            	Intent in6=new Intent(home.this,arabic2019.class);
	 			            	in6.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	 			            	startActivity(in6);
	 			            	break;
	 	    	           case 7:
	 	    	            	Intent in7=new Intent(home.this,malay2019.class);
	 			            	in7.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	 			            	startActivity(in7);
	 			            	break;
	 	    	          case 8:
	 	    	            	Intent in8=new Intent(home.this,german2019.class);
	 			            	in8.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	 			            	startActivity(in8);
	 			            	break;
	 	    	         case 9:
	 	    	            	Intent in9=new Intent(home.this,chinese2019.class);
	 			            	in9.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	 			            	startActivity(in9);
	 			            	break;
	 	    	        case 10:
 	    	            	Intent in10=new Intent(home.this,japanese2019.class);
 			            	in10.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 			            	startActivity(in10);
 			            	break;
 			            	
	 	    	       case 11:
 	    	            	Intent in11=new Intent(home.this,russian2019.class);
 			            	in11.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 			            	startActivity(in11);
 			            	break;
 			            	
	 	    	      case 12:
 	    	            	Intent in12=new Intent(home.this,portuguese2019.class);
 			            	in12.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 			            	startActivity(in12);
 			            	break;
	 			         }
	  	    	    }
  	    	    @Override
	 	    	    public void onNothingSelected(AdapterView<?> arg0) {
	 	    	        // TODO Auto-generated method stub
	 	    	    }
 	    	   });
	    
	    
	    layout.addView(v); 

	    return super.onCreateOptionsMenu(menu);
	}
	public boolean onOptionsItemSelected(MenuItem item) {
		 
        if (item.getItemId()==android.R.id.home)
        {
    	Intent int_abt = new Intent(this,main2019.class);
        int_abt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(int_abt);
        }
      	  
		 else if (item.getItemId() == R.id.exit)
		  {
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			 builder.setMessage("Are you sure  want to exit from Sun Signs app?")
			      .setCancelable(false)
			      .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();
		  }
		 
		   else
		  {
			  
		  }
	            return true;
	    }
	public class MyAdapter extends ArrayAdapter {
		 
		public MyAdapter(Context context, int textViewResourceId,
		String[] objects) {
		super(context, textViewResourceId, objects);
		}
		 
		public View getCustomView(int position, View convertView,
		ViewGroup parent) {
		 
		// Inflating the layout for the custom Spinner
		LayoutInflater inflater = getLayoutInflater();
		View layout = inflater.inflate(R.layout.spinnernew, parent, false);
		 
	  	TextView tvLanguage = (TextView) layout
		.findViewById(R.id.spintext);
		 
	 	tvLanguage.setText(Languages[position]);
		 
	 	ImageView img = (ImageView) layout.findViewById(R.id.sspin);
		 
	 	img.setImageResource(images[position]);
		 
	 	if (position == 0) {
	 	img.setVisibility(View.GONE);
	 //	tvLanguage.setTextColor(Color.BLACK);
 	  	}
		 
		return layout;
		}
		 
		// It gets a View that displays in the drop down popup the data at the specified position
		@Override
		public View getDropDownView(int position, View convertView,
		ViewGroup parent) {
		return getCustomView(position, convertView, parent);
		}
		 
		// It gets a View that displays the data at the specified position
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
		}
		}
}

