package sunsigns2014.findyourfate.com;


 

import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
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.daily.MyAdapter;

public class daily1 extends FragmentActivity implements
	 ActionBar.TabListener {
	
 	private ViewPager viewPager;
	private TabsPagerAdapter mAdapter;
	private ActionBar actionBar;
	private String[] tabs = { "Today", "Next Day" };
	String Sign;

	String lang;
	
	   String[] Languages = { "Choose Language flag", "English", "French", "Spanish", "Hindi","Dutch", "Arabic", "Malay", 
				  "German","Chinese","Japanese","Russian","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.daily);
		
	 	lang=getIntent().getStringExtra("language");

    	 
 		viewPager = (ViewPager) findViewById(R.id.pager);
		actionBar = getActionBar();
		mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
 	 	viewPager.setAdapter(mAdapter);
		actionBar.setHomeButtonEnabled(false);
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);		
		
		Sign=getIntent().getStringExtra("key");

		// Adding Tabs
		for (String tab_name : tabs) {
			actionBar.addTab(actionBar.newTab().setText(tab_name)
					.setTabListener(this));
		}
  		viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				// on changing the page
				// make respected tab selected
				actionBar.setSelectedNavigationItem(position);
			}
		@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		});
		}
	public class TabsPagerAdapter extends FragmentPagerAdapter {
 	public TabsPagerAdapter(FragmentManager fm) {
			super(fm);
		}
 	@Override
		public Fragment getItem(int index) {

			switch (index) {
			case 0:
				// Top Rated fragment activity
				Fragment newFragment = new todayhoroscope(); 
				Bundle args = new Bundle();  
				args.putString("signs",Sign);
				args.putString("language", lang);
			 	newFragment.setArguments(args);
       	 	  return newFragment;
			 
			case 1:
		 	Fragment secondFragment = new nextdayhoroscope(); 
				Bundle arg = new Bundle();  
				arg.putString("signs",Sign);
				arg.putString("language", lang);
				secondFragment.setArguments(arg);
       	 	  return secondFragment;
				 
			}
 		return null;
		}
 	@Override
		public int getCount() {
			// get item count - equal to number of tabs
			return 2;
		}

	}
	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		// on tab selected
		// show respected fragment view
		viewPager.setCurrentItem(tab.getPosition());
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
	}
	@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(daily1.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) {
		 	    		   
		 	    	      String lang1;
						 switch(position){
		 	    	       
		 	    	                case 1:
		 	    	               
		 	    	                	Intent int_eng = new Intent(daily1.this,daily.class);
		 	    	       	    	lang1="English";
		 	    	       	    	int_eng.putExtra("language", lang1);
		 	    	       	    	int_eng.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    	       	    	startActivity(int_eng);
		 	    	       	    	
		 	    	       	    	break;
		 	    	                case 2:
		 	    	                	Intent int_fran=new Intent(daily1.this,daily.class);
		 	    	       	    	lang1="French";
		 	    	       	    	int_fran.putExtra("language", lang1);
		 	    	       	      	int_fran.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    	       	    	startActivity(int_fran);
		 			            	break;
		 	    	            case 3:
		 	    	            	Intent int_span=new Intent(daily1.this,daily.class);
		 	    	   	    	lang1="Spanish";
		 	    	   	    	int_span.putExtra("language", lang1);
		 	    	   	      	int_span.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    	   	    	startActivity(int_span);
			 			            	break;
		 	    	            case 4:
		 	    	            	Intent int_hind=new Intent(daily1.this,daily.class);
		 	    	   	    	lang1="Hindi";
		 	    	   	        int_hind.putExtra("language", lang1);
		 	    	     	   int_hind.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    	   	    	startActivity(int_hind);
			 			            	break;
		 	    	            case 5:
		 	    	            	Intent int_duts=new Intent(daily1.this,daily.class);
		 	    	   	    	lang1="Dutch";
		 	    	   	    int_duts.putExtra("language", lang1);
		 	    	     	int_duts.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    	   	    	startActivity(int_duts);
			 			            	break;
		 	    	            case 6:
		 	    	            	Intent int_aras=new Intent(daily1.this,daily.class);
		 	    	   	     	lang1="Arabic";
		 	    	   	    int_aras.putExtra("language", lang1);
		 	    	      	int_aras.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    	   	    	startActivity(int_aras);
		 			            	break;
		 	    	           case 7:
		 	    	        	  Intent ini_malay=new Intent(daily1.this,daily.class);
		 	    				  lang1="Malay";
		 	    				 ini_malay.putExtra("language", lang1);
		 	    				ini_malay.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    				  startActivity(ini_malay);
		 			            	break;
		 	    	          case 8:
		 	    	        	 Intent int_gerns=new Intent(daily1.this,daily.class);
		 	    		    	lang1="German";
		 	    		    	int_gerns.putExtra("language", lang1);
		 	    		    	int_gerns.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    		    	startActivity(int_gerns);
		 			            	break;
		 	    	         case 9:
		 	    	        	Intent int_chi=new Intent(daily1.this,daily.class);
		 	    		    	lang1="Chinese";
		 	    		    	int_chi.putExtra("language", lang1);
		 	    		      	int_chi.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    		    	startActivity(int_chi);
		 			            	break;
		 	    	        case 10:
		 	    	        	Intent int_japs=new Intent(daily1.this,daily.class);
		 	    		    	lang1="Japanese";
		 	    		    	int_japs.putExtra("language", lang1);
		 	    		    	int_japs.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    		    	startActivity(int_japs);
	 			            	break;
	 			            	
		 	    	       case 11:
		 	    	    	  Intent int_rus=new Intent(daily1.this,daily.class);
		 	    		    	lang1="Russian";
		 	    		    	int_rus.putExtra("language", lang1);
		 	    		    	int_rus.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	    		    	startActivity(int_rus);
		 	    		    	break;
	 			            	
		 	    	      case 12:
		 	    	    	 Intent ini_portu=new Intent(daily1.this,daily.class);
		 	  			  lang1="Portuguese";
		 	  			  ini_portu.putExtra("language", lang1);
		 	  			  ini_portu.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		 	  			  startActivity(ini_portu);
	 			            	break;
		 			         }
		  	    	    }
	  	    	    @Override
		 	    	    public void onNothingSelected(AdapterView<?> arg0) {
		 	    	        // TODO Auto-generated method stub
		 	    	    }
	 	    	   });
		    
		    
		    layout.addView(v); 

		    return super.onCreateOptionsMenu(menu);
 	}
	 String langu;
	public boolean onOptionsItemSelected(MenuItem item) {
		
	     if (item.getItemId() == R.id.exit)
	   		  {
	   			 AlertDialog.Builder builder = new AlertDialog.Builder(this);
	   			    builder.setMessage("Are you sure  want to exit?")
	   			           .setCancelable(false)
	   			           .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
	   			               public void onClick(DialogInterface dialog, int id) {
	   			            	daily1.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);
		}
		}
}





