package findyourfate.com.rahuketupeyarchi; 
 
import findyourfate.com.rahuketupeyarchi.ArrayWheelAdapter;

import findyourfate.com.rahuketupeyarchi.OnWheelChangedListener;
import findyourfate.com.rahuketupeyarchi.OnWheelScrollListener;
import findyourfate.com.rahuketupeyarchi.WheelView;
 


import android.annotation.SuppressLint;  
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; 
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.os.StrictMode; 
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu; 
import android.view.MenuItem;
import android.view.View; 
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup; 
import android.widget.Spinner; 
import android.widget.TextView;


public class zodiacsign extends Activity{
	 final Context context = this;
	int fsize,ssize; 
    public static final String MyPREFERENCES = "MyPrefs" ;
    public static final String name = "fontsize";  
    public static SharedPreferences sharedpreferences;
	private static Typeface mTypeface;
	String zodiacsign=null;
	 
	 String[]  wheelMenu1;
 
	 private boolean wheelScrolled = false;
	 private final static String TAG = "WheelDemo";
	 
	@SuppressLint("NewApi")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() .penaltyLog().build()); 
		  
		super.onCreate(savedInstanceState);
		 setContentView(R.layout.zodicsign);
		
		 
		 final AlertDialog.Builder alt_bld = new AlertDialog.Builder(this); 	
	 	// final Spinner s1 = (Spinner) findViewById(R.id.sign);
	 	// final Button go  = (Button) findViewById(R.id.go);
	 	 
	 	 
	 	 wheelMenu1 = new String[]{
	 			 "Mesha", "Vrishabha", "Mithuna", "Karkata", "Simha","Kanya","Thula","Vrischika","Dhanushya","Makara","Kumbha","Meena"};
	 		  
	 	 initWheel(R.id.country, wheelMenu1);
	 	 
	 
	        
	        TextView tabtitle = (TextView) findViewById(R.id.tabtitle);
		     
		       DisplayMetrics metrics = new DisplayMetrics(); 
	 	        Activity activity = (Activity) context;
	 	        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
	 	         
	 	       
	 	        
	 	     
	 	   
	 	        
	 	       String userAgent = new WebView(zodiacsign.this).getSettings().getUserAgentString();
		        if (userAgent.contains("Mobile")) {
		       
	        if (metrics.densityDpi <= DisplayMetrics.DENSITY_LOW) {
	        	//Toast.makeText(this, "low screen",Toast.LENGTH_LONG).show();
	        	ssize=11;
	        	 
	        } else if (metrics.densityDpi <= DisplayMetrics.DENSITY_HIGH) {
	        	// Toast.makeText(this, "high screen",Toast.LENGTH_LONG).show();
	        	ssize=15;
	        	 
	        }
	        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_MEDIUM) {
	        	// Toast.makeText(this, "medium screen",Toast.LENGTH_LONG).show();
	        	ssize=13;
	        	 
	        }
	        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XHIGH) {
	        	 //Toast.makeText(this, "xLarge screen",Toast.LENGTH_LONG).show();
	        	ssize=17;
	        	 
	        }
	        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXHIGH) {
	        	// Toast.makeText(this, "xxLarge screen",Toast.LENGTH_LONG).show();
	        	ssize=20;
	        	 
	        }
	        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXXHIGH) {
	        	 
	        	ssize=23;
	        	 
	        }
	        else {
	        	 
	        	ssize=15;
	        	 
	        }
		        }
		        else
		        {
		        	ssize=20;
		        }
		        String fontkey=getfontName(); 
		       
		        if (fontkey != null) 
		        {
		       	  if(fontkey.equals("Small"))
		       	  {
		       		  fsize=11;
		       	  }
		       	  else if(fontkey.equals("Medium"))
		       	  {
		       		  fsize=16;
		       	  }
		       	  else if(fontkey.equals("Large"))
		       	  {
		       		  fsize=18;
		       	  }
		       	if(fontkey.equals("Larger"))
		       	  {
		       		  fsize=20;
		       	  }
		    	if(fontkey.equals("X-Large"))
		       	  {
		       		  fsize=23;
		       	  }
		        }
		        else
		        {
		   	   fsize=ssize;  
		        }
	        
	 	        
	 	          
	 		         mTypeface = Typeface.createFromAsset(zodiacsign.this.getAssets(), "arial.ttf"); 
	 		         tabtitle.setTextSize(fsize); 
	 				tabtitle.setTypeface(mTypeface,Typeface.BOLD_ITALIC);
	 				
	 				//go.setTextSize(fsize);
	 				//go.setTypeface(mTypeface,Typeface.BOLD_ITALIC);
		 final	TextView  sign = new TextView(this);
		 sign.setGravity(Gravity.CENTER); 
		 
		 
     
	/* final  ArrayAdapter<CharSequence> dataAdapter1 = ArrayAdapter.createFromResource(this,R.array.sign_array, android.R.layout.simple_spinner_item);
	 dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_item);
	 s1.setAdapter(dataAdapter1); 
      
     go.setOnClickListener(new OnClickListener()
	 { 
	 public void onClick(View v)
	 {
		// zodiacsign=s1.getSelectedItem().toString();
		 if (zodiacsign.equals("-- Choose Your Sign --"))
		 {
		 alt_bld.setTitle("Alert Message");
		 alt_bld.setMessage("Please Select Your Zodiac Sign ?")
		 .setCancelable(false)
					 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
					 public void onClick(DialogInterface dialog, int id) {
					// s1.requestFocus(); 
					 }
					 });
		 AlertDialog alert = alt_bld.create();
		 alert.setTitle("Alert Message");
		 alert.setIcon(R.drawable.alert);
		 alert.show();
		 } 
		 else
		 {
				if (mInterstitialAd.isLoaded()) {
	 				 mInterstitialAd.show();
	 				mInterstitialAd.setAdListener(new AdListener() {
			            public void onAdClosed() {
			            	 Intent int_ep = new Intent(zodiacsign.this,findsign.class); 
			     				int_ep.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			     				int_ep.putExtra("sign", zodiacsign); 
			     				startActivity(int_ep); 
			               }
			              }); 
	 				 
	 		           }
				 else
				 {
	                	 Intent int_ep = new Intent(zodiacsign.this,findsign.class); 
	     				int_ep.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	     				int_ep.putExtra("sign", zodiacsign); 
	     				startActivity(int_ep);   
		   	    		 
				 } 
	                
			    
		 }  
			 
		 
		 
		   		 
	 } 
	 
	 }); */ 
	}	
	protected String getfontName()
	{
		 
		 String restoredText=null;
		 sharedpreferences=getSharedPreferences(MyPREFERENCES,Context.MODE_PRIVATE);
	      if (sharedpreferences.contains(name))
	      {
	    	  restoredText = sharedpreferences.getString("fontsize", name); 
	       
	    	 
	      
	      }


	return restoredText;
	}
	
    
    OnWheelScrollListener scrolledListener = new OnWheelScrollListener()  {
 		@Override    
 		public void onScrollingStarted(WheelView wheel) {
 			wheelScrolled = true;
 		}
 		@Override
 		public void onScrollingFinished(WheelView wheel) {
 			wheelScrolled = false;
 			updateStatus();
 		}
 	};

 	// Wheel changed listener
 	private final OnWheelChangedListener changedListener = new OnWheelChangedListener() {
 		@Override    
 		public void onChanged(WheelView wheel, int oldValue, int newValue) {
 			Log.d(TAG, "onChanged, wheelScrolled = " + wheelScrolled);    
 			if (!wheelScrolled) {
 				updateStatus();
 			}
 		}
 	};

 	/**
 	 * Updates entered PIN status
 	 */
 	private void updateStatus() {
 		//text1.setText(wheelMenu1[getWheel(R.id.p1).getCurrentItem()]);
 		 

 		final String sid=wheelMenu1[getWheel(R.id.country).getCurrentItem()];
 		
 		/*Log.d(TAG, "sid = " + sid);    
 		if (mInterstitialAd.isLoaded()) {
				 mInterstitialAd.show();
				mInterstitialAd.setAdListener(new AdListener() {
		            public void onAdClosed() {
		            	 Intent int_ep = new Intent(zodiacsign.this,findsign.class); 
		     				int_ep.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		     				int_ep.putExtra("sign", sid); 
		     				startActivity(int_ep); 
		               }
		              }); 
				 
		           }
			 else
			 {
             	 Intent int_ep = new Intent(zodiacsign.this,findsign.class); 
  				int_ep.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  				int_ep.putExtra("sign", sid); 
  				startActivity(int_ep);   
	   	    		 
			 } */
 	}
 	  
		/**
 	 	 * Initializes wheel
 	 	 *
 	 	 * @param id
 	 	 *          the wheel widget Id
 	 	 */
 	 	private void initWheel(int id, String[] wheelMenu1) {
 	 		WheelView wheel = (WheelView) findViewById(id);
 	 		wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, wheelMenu1));
 	 		wheel.setVisibleItems(2);
 	 		wheel.setCurrentItem(0);
 	 		wheel.addChangingListener(changedListener);
 	 		wheel.addScrollingListener(scrolledListener);
 	 	}
 	 	
 	 	private WheelView getWheel(int id) {
 	 		return (WheelView) findViewById(id);
 	 	}
 	 
 		 
	@Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
		getMenuInflater().inflate(R.menu.main, menu);
        return true; 
    } 
	  
	/*  @Override
     public void onBackPressed() {
         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 int_home1 = new Intent(zodiacsign.this, MercuryRetrogradeActivity.class);
            int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(int_home1);
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                         dialog.cancel();
                    }
                });
         AlertDialog alert = builder.create();
         alert.setIcon(R.drawable.alert);
         alert.show();

     }
     */
	  
	@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(zodiacsign.this);
	  		progressDoalog.setProgressDrawable(zodiacsign.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(zodiacsign.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;
	           
	    
    }
     
 	@Override
	public void onBackPressed() {
 		zodiacsign.this.finish();
 	}
}

	 
	 
	