package findyourfate.com.rahuketupeyarchi; 
 
 

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog; 
import android.content.DialogInterface;
import android.content.Intent; 
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent; 
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; 
import android.widget.AdapterView;
import android.widget.Spinner; 
 

public class moonsign extends  FragmentActivity implements  AdapterView.OnItemSelectedListener{
	 String[] countryNames={"-- Select--","Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius","Pisces"};
	    int flags[] = {R.drawable.selecticon, R.drawable.ariesicon, R.drawable.taurusicon, R.drawable.geminiicon, R.drawable.cancericon, R.drawable.leoicon, R.drawable.virgoicon, R.drawable.libraicon
	    		, R.drawable.scorpioicon, R.drawable.sagicon, R.drawable.capricorn, R.drawable.aquaricon, R.drawable.piscesicon};

View rootView; 

ProgressDialog progressBar;
private int progressBarStatus = 0;
private long fileSize = 0;
private Handler progressBarHandler = new Handler();
String zodiacsign=null;

 
private AlertDialog.Builder alt_bld;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.moon);
			 alt_bld = new AlertDialog.Builder(moonsign.this); 
			 Spinner spin = (Spinner) findViewById(R.id.simpleSpinner);
		        spin.setOnItemSelectedListener(this);

		        CustomAdapter customAdapter=new CustomAdapter(getApplicationContext(),flags,countryNames);
		        spin.setAdapter(customAdapter);
		    }
			/* ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(moonsign.this, R.array.sign_array,  R.layout.spinnersign);
			    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);  
			    moonspinner.setAdapter(new NothingSelectedSpinnerAdapter(adapter,
			            R.layout.spinnersign,
			            // R.layout.contact_spinner_nothing_selected_dropdown, // Optional
			            moonsign.this));*/

 
				
				 
				
	/*		 
			 go.setOnClickListener(new View.OnClickListener()
			 { 
				 @Override
					public void onClick(View v) {
					 if(!(moonspinner.getSelectedItem() == null))
		                {	 
		    		  	 zodiacsign =moonspinner.getSelectedItem().toString();
		    		  //	String  SpinerValue3 = moonspinner.getItemAtPosition(0).toString();

						 //zodiacsign =moonspinner.getItemAtPosition(position).
		    		  Toast.makeText(moonsign.this, "value"+zodiacsign, Toast.LENGTH_LONG).show();
						 progressBar = new ProgressDialog(v.getContext());
				    	 progressBar.setProgressDrawable(moonsign.this.getResources().getDrawable(R.drawable.progress));  
		 					progressBar.setCancelable(true);
		 					progressBar.setMessage("Please Wait....");
		 					progressBar.setTitle("Loading...");
		 					progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		 					progressBar.setProgress(0);
		 					progressBar.setMax(20);
		 					progressBar.show();
		 					progressBarStatus = 0;
		 					fileSize = 0;
		 					new Thread(new Runnable() {
		 						 public void run() {
		  							while (progressBarStatus < 20) {
		  							   progressBarStatus = doSomeTasks();
		  						 	  try {
		  								Thread.sleep(1200);
		  							  } catch (InterruptedException e) {
		  								e.printStackTrace();
		  							  }
		  						 	  progressBarHandler.post(new Runnable() {
		  								public void run() {
		  								  progressBar.setProgress(progressBarStatus);
		  								}
		  							  });
		  							}
				            if (progressBarStatus >= 20) {
				    			 
 							 	try {
 									Thread.sleep(1200);
 								} catch (InterruptedException e) {
 									e.printStackTrace();
 								}

 							 	
 							 	   Fragment newFragment = new viewrahupeyarchi();   
		         					Bundle args = new Bundle();  
		         					args.putString("sign",zodiacsign);
		         				 	newFragment.setArguments(args);
		         				 	 
		         				 	 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		         					 transaction.setCustomAnimations(R.anim.bottom_in,R.anim.top_out);
		         	 				 transaction.replace(R.id.frame1, newFragment);  
		         	 				 transaction.addToBackStack(null);
		         					 transaction.commit();  
		         					progressBar.dismiss();
 						 	}
 						  }
				            
				        }).start(); 
		    		 
				     }
				     
				     else
				     {
				    	 alt_bld.setTitle("Alert Message");
			    		 alt_bld.setMessage("Please Select Your Moon Sign ")
			    		 .setCancelable(false)
			    					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
			    					 public void onClick(DialogInterface dialog, int id) {
			    						 moonspinner.requestFocus(); 
			    					 }
			    					 });
			    		 AlertDialog alert = alt_bld.create();
			    		 alert.setTitle("Alert Message");
			    		 alert.setIcon(R.drawable.alert);
			    		 alert.show();
				    	 
				     }
		        	 
		 		  
				 }
 
				 public int doSomeTasks() {
					 
						while (fileSize <= 1000000) {
				 
							fileSize++;
				 
							if (fileSize == 100000) {
								return 10;
							}
							
						}
				 
						return 100;
				 	}
			});
		      
	 
	
			 
}	*/
	 @Override
	    public void onItemSelected(AdapterView<?> arg0, View arg1, int position,long id) {
	       // Toast.makeText(getApplicationContext(), countryNames[position], Toast.LENGTH_LONG).show();
		 
		 zodiacsign=countryNames[position];
		 if((zodiacsign.equals("-- Select--")))
         {	
         
         }
		 else
		 {
			 //Toast.makeText(getApplicationContext(), countryNames[position], Toast.LENGTH_LONG).show();
		/*	 progressBar = new ProgressDialog(arg1.getContext());
	    	 progressBar.setProgressDrawable(moonsign.this.getResources().getDrawable(R.drawable.progress));  
					progressBar.setCancelable(true);
					progressBar.setMessage("Please Wait....");
					progressBar.setTitle("Loading...");
					progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
					progressBar.setProgress(0);
					progressBar.setMax(20);
					progressBar.show();
					progressBarStatus = 0;
					fileSize = 0;
					new Thread(new Runnable() {
						 public void run() {
							while (progressBarStatus < 20) {
							   progressBarStatus = doSomeTasks();
						 	  try {
								Thread.sleep(1200);
							  } catch (InterruptedException e) {
								e.printStackTrace();
							  }
						 	  progressBarHandler.post(new Runnable() {
								public void run() {
								  progressBar.setProgress(progressBarStatus);
								}
							  });
							}
	            if (progressBarStatus >= 20) {
	    			 
					 	try {
							Thread.sleep(1200);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
*/
					 	
					 	Fragment newFragment = new viewrahupeyarchi();   
     					Bundle args = new Bundle();  
     					args.putString("sign",zodiacsign);
     				 	newFragment.setArguments(args);
     				 	 
     				 	 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
     					 transaction.setCustomAnimations(R.anim.bottom_in,R.anim.top_out);
     	 				 transaction.replace(R.id.frame1, newFragment);  
     	 				 transaction.addToBackStack(null);
     					 transaction.commit();  
     					//progressBar.dismiss();
				 	}
				  }
	            
	        //}).start(); 
		 
		// }
	     
	 //}

	 public int doSomeTasks() {
		 
			while (fileSize <= 1000000) {
	 
				fileSize++;
	 
				if (fileSize == 100000) {
					return 10;
				}
				
			}
	 
			return 100;
	 	}
 
 
	     

	    @Override
	    public void onNothingSelected(AdapterView<?> arg0) {
	        // TODO Auto-generated method stub
	    }
 	 

	
	
	public boolean onKeyDown(int keycode, KeyEvent event ) {
	   	 if(keycode == KeyEvent.KEYCODE_SETTINGS){
	       	 
	   		 	Intent int_home1 = new Intent(moonsign.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(moonsign.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(moonsign.this,home.class); 
		   		 	int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    		startActivity(int_home1);
			   	  return true;
			   	 }
			   	 if(keycode == KeyEvent.KEYCODE_BACK){
			   		Intent int_home1 = new Intent(moonsign.this,home.class); 
		   		 	int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    		startActivity(int_home1);
				    return true;
			   	 	}
	   	     return this.onKeyDown(keycode,event);  
	   	    }
	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
 	
		 MenuInflater inflater = getMenuInflater();
		    inflater.inflate(R.menu.main, menu);
		    menu.findItem(R.id.icon_rasi).setVisible(true);  
		 // animation = (AnimationView) menu.findItem(R.id.character);
		    return super.onCreateOptionsMenu(menu); 
		    
		    
    }

 @SuppressLint("NewApi")
	@Override
   public boolean onOptionsItemSelected(MenuItem item) {
	  if (item.getItemId() ==android.R.id.home) {
 		  Intent int_home = new Intent(this, home.class);
	           int_home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	             startActivity(int_home); 
 	  }
	  else if (item.getItemId() ==R.id.icon_rasi) {
 		  Intent int_home = new Intent(this, home.class);
	           int_home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	             startActivity(int_home); 
 	  }
	/*  else if (item.getItemId() ==R.id.rahu) {
 		  Intent int_home = new Intent(this, rahucontent.class);
	           int_home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	             startActivity(int_home); 
 	  }
	  else if (item.getItemId() ==R.id.rahupalan) {
	  		final ProgressDialog progressDoalog = new ProgressDialog(rahucontent.this);
	  		progressDoalog.setProgressDrawable(rahucontent.this.getResources().getDrawable(R.drawable.progress));  
	     progressDoalog.setMessage("Please Wait....");
	    progressDoalog.setTitle("Loading...");
	    progressDoalog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	    progressDoalog.setCancelable(true); 
	    progressDoalog.show();
	    new Thread() {
	        public void run() {
	            try {
	            	 Intent int_home = new Intent(rahucontent.this, palangal2017.class);
	  	           int_home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	  	             startActivity(int_home); 
	   	    		 
		  			 
	            } catch (Exception e) {
	            }
	            progressDoalog.dismiss();
	        }
	    }.start();
	  }*/
     		else if (item.getItemId() ==R.id.guru) {
	    
	    
AlertDialog.Builder alt_compat = new AlertDialog.Builder(this);
String desc="App to find out when Guru Peyarchi or Jupiter transit takes place.";	


	/*LinearLayout layout = new LinearLayout(this); 
	TextView tvMessage = new TextView(this);  
	tvMessage.setBackgroundColor(Color.parseColor("#e9b44f")); 
	tvMessage.setText(desc); 
 tvMessage.setPadding(5, 5, 5, 5);
	tvMessage.setTextSize(17); 
	layout.setOrientation(LinearLayout.VERTICAL);
	layout.addView(tvMessage); 
	alt_compat.setView(layout);  */

				alt_compat.setTitle("Guru Peyarchi");
				alt_compat.setMessage(desc); 
				alt_compat.setCancelable(false) 
						 
						                .setPositiveButton("Later", new DialogInterface.OnClickListener() {
						                    public void onClick(DialogInterface dialog, int id) {
						                    	 
						                    	 dialog.cancel();
						                    }
						                })
						                .setNegativeButton("Never/Already", new DialogInterface.OnClickListener() {
						                    public void onClick(DialogInterface dialog, int id) {
						                    	dialog.cancel();
						                    	      	  						                    }
						                })
						                
						                .setNeutralButton("Open", new DialogInterface.OnClickListener() {
						    public void onClick(DialogInterface dialog, int id) {
						    	
						    	
						     
						    	 Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=findyourfate.com.gurupeyarchi"));
						    	 startActivity(browserIntent);
						    
						   
}
						    });
						
						      
						         AlertDialog alert = alt_compat.create();   
						         alert.show();

 	    	}
    		else if (item.getItemId() ==R.id.sani) {
   	  	    
   	  	    
 			  AlertDialog.Builder alt_compat = new AlertDialog.Builder(this);
 			  String desc="App to find out when Sani Peyarchi or Saturn transit takes place.";	
 			  
 			  
 				/*LinearLayout layout = new LinearLayout(this); 
 				TextView tvMessage = new TextView(this);  
 				tvMessage.setBackgroundColor(Color.parseColor("#e9b44f")); 
 				tvMessage.setText(desc); 
 			    tvMessage.setPadding(5, 5, 5, 5);
 				tvMessage.setTextSize(17); 
 				layout.setOrientation(LinearLayout.VERTICAL);
 				layout.addView(tvMessage); 
 				alt_compat.setView(layout);  */
 			  
 			  				alt_compat.setTitle("Sani Peyarchi");
 			  				alt_compat.setMessage(desc); 
 							alt_compat.setCancelable(false) 
 			  						 
 			  						                .setPositiveButton("Later", new DialogInterface.OnClickListener() {
 			  						                    public void onClick(DialogInterface dialog, int id) {
 			  						                    	 
 			  						                    	 dialog.cancel();
 			  						                    }
 			  						                })
 			  						                .setNegativeButton("Never/Already", new DialogInterface.OnClickListener() {
 			  						                    public void onClick(DialogInterface dialog, int id) {
 			  						                    	dialog.cancel();
 			  						                    	      	  						                    }
 			  						                })
 			  						                
 			  						                .setNeutralButton("Open", new DialogInterface.OnClickListener() {
 			  						    public void onClick(DialogInterface dialog, int id) {
 			  						    	
 			  						    	
 			  						     
 			  						    	 Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=findyourfate.com.sanipeyarchi"));
 			  						    	 startActivity(browserIntent);
 			  						    
 			  						   
 			  }
 			  						    });
 			  						
 			  						      
 			  						         AlertDialog alert = alt_compat.create();   
 			  						         alert.show();

 			    	    	}
 	    	else if (item.getItemId() ==R.id.icon_exit) {
	     	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 alert1 = builder.create();
		         alert1.setTitle("Close App.");
		         alert1.setIcon(R.drawable.alert);
		         alert1.show();
 	    	}
 	    	
 	    	else if (item.getItemId() ==R.id.share) {
 	    		
	    	Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
	    	emailIntent.setType("text/plain");
   		emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Rahu-Ketu Peyarchi by findyourfate.com");
   		emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hi,I would like to suggest, this Rahu-Ketu Peyarchi App to you. Click this link to download app http://goo.gl/ypifK6"+"\n\n"+" Regards");
     startActivity(Intent.createChooser(emailIntent,"Share using")); 
 	    	}
 	    	 else {
 	     	} 
 	    	return true;
	           
	    
   }
    
	
}



