package findyourfate.com.rahuketupeyarchi;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context; 
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
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.webkit.WebView;  
import android.widget.Button; 

public class viewrahupeyarchiyear extends Fragment {  
	int fsize=0;
	View rootView; 
	 Context context;
	 String  ketuyear=null;  
	 	 WebView content;  

	 	protected SQLiteDatabase DB;
		 protected Cursor cursor;   
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
			  rootView = inflater.inflate(R.layout.signyear, container, false);
			  content=(WebView)rootView.findViewById(R.id.content2);
			  content.getSettings().setSupportZoom(true); 

	            content.getSettings().setBuiltInZoomControls(true); 
	            content.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);  
			  context = getActivity();

			 Bundle bundle=getArguments(); 
		 	  
			 ketuyear=bundle.getString("rahuyear");
		Button back = (Button) rootView.findViewById(R.id.back);
		 	   back.setOnClickListener(new View.OnClickListener() {
			 		@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
			 			Intent int_home1 = new Intent(getActivity(),rahuyear.class); 
			   		 	int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			    		startActivity(int_home1);
			 			 
					}
	  	  });	 
		 	 
		 	DisplayMetrics metrics = new DisplayMetrics(); 
	        Activity activity = (Activity) context;
	        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
	        content.getSettings().setSupportZoom(true); 
            content.getSettings().setBuiltInZoomControls(true);
            String userAgent = new WebView(context).getSettings().getUserAgentString();
	        if (userAgent.contains("Mobile")) {
	       
        if (metrics.densityDpi <= DisplayMetrics.DENSITY_LOW) {
        	//Toast.makeText(this, "low screen",Toast.LENGTH_LONG).show();
        	fsize=1;
        	 
        } else if (metrics.densityDpi <= DisplayMetrics.DENSITY_HIGH) {
        	// Toast.makeText(this, "high screen",Toast.LENGTH_LONG).show();
        	fsize=3;
        	 
        }
        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_MEDIUM) {
        	// Toast.makeText(this, "medium screen",Toast.LENGTH_LONG).show();
        	fsize=2;
        	 
        }
        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XHIGH) {
        	 //Toast.makeText(this, "xLarge screen",Toast.LENGTH_LONG).show();
        	fsize=4;
        	 
        }
        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXHIGH) {
        	// Toast.makeText(this, "xxLarge screen",Toast.LENGTH_LONG).show();
        	fsize=5;
        	 
        }
        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXXHIGH) {
        	 
        	fsize=6;
        	 
        }
        else {
        	 
        	fsize=3;
        	 
        }
	        }
	        else
	        {
	        	fsize=4;
	        }
	        
    
		        DB = (new DatabaseHandler(context)).getWritableDatabase();   
		  	 
			   	 String tit=null;
		  	   
		  	  
		  		  //cursor = mDataBase.rawQuery("SELECT * FROM saniper WHERE year(entry)='"+saniyear+"' ", null);
		  		cursor = DB.rawQuery("SELECT * FROM rahu WHERE entry like '%"+ketuyear+"%' ", null);
		  		tit="for Year "+ketuyear;  
		  	 
		  		 String result ="<p align=\"center\" style=\"font-family:Times New Roman, Times, serif; font-style:italic; color:#ffffff;text-shadow:  10px 10px 29px #a3b9e1;\"><font size=\"5\"><b>Rahu-Ketu Peyarchi "+tit+"</b></font></p>";
		  		result+= "<p align='left' style='font-family:Geneva, Arial, Helvetica, sans-serif; color:#fafadc;margin-left:5px;margin-right:5px'><font  size=\""+fsize+"\" >The dates when Rahu-Ketu Peyarchi  takes place in the year "+ketuyear+" are listed below.</font></p>";
					  
		 		if (cursor.moveToFirst())
		 	 
		      {
		 			 	
		 			 result+= "<table align='center' width='100%' border='0'   cellpadding='0' cellspacing='0' style='font-family:Geneva, Arial, Helvetica, sans-serif; color:#fcfcfc;height:auto; border:2px solid #a3b9e1;border-radius: 25px;' ><tr align='center' height='20'><td style='line-height:25px;border-right:1px solid #a3b9e1  ;border-bottom:2px solid #a3b9e1 ;' align='center'><font color=\"#fafadc\" size=\"3\" ><b>&nbsp;Node&nbsp;</b></font></td><td style='line-height:25px;border-right:1px solid #a3b9e1  ;border-bottom:2px solid #a3b9e1 ;' align='center'><font color=\"#fafadc\" size=\"3\" ><b>Rashi</b></font></td><td align='center' style='border-right:1px solid #a3b9e1 ;border-bottom:2px solid #a3b9e1 ;'><font color=\"#fafadc\" size=\"3\" ><b>Date of Entry</b></font></td><td align='center' style='border-bottom:2px solid #a3b9e1 ;'><font color=\"#fafadc\" size=\"3\" ><b>Date of Exit</b></font></td></tr>";
						  do { 
						   String node=cursor.getString(1); 
						   String rasi=cursor.getString(2);
						   String entrydt=cursor.getString(3);
						   String exitdt=cursor.getString(4); 
						   result+= "<tr><td align='center' style='line-height:20px;border-right:1px solid #a3b9e1  ;border-bottom:1px solid #a3b9e1 ;'><font  size=\""+fsize+"\" >"+node+"</font></td><td align='center' style='line-height:20px;border-right:1px solid #a3b9e1  ;border-bottom:1px solid #a3b9e1 ;'><font  size=\""+fsize+"\" >"+rasi+"</font></td><td align='center' style='line-height:20px;border-right:1px solid #a3b9e1 ;border-bottom:1px solid #a3b9e1  ;'><font  size=\""+fsize+"\" >"+entrydt+"</font></td><td align='center' style='line-height:20px;border-bottom:1px solid #a3b9e1 ;'><font  size=\""+fsize+"\" >"+exitdt+"</font></td></tr>";
								  	  }		  	   
						while (cursor.moveToNext()); 
						  cursor.close(); 
						   			 
				       }
			   else
				  {
				   result+="<center><font color=\"#fafadc\" size=\""+fsize+"\" ><b>No Records Found.........................!<br>Please Rephrase Your Search Criteria.</b></font></center>";
				 cursor.close();
				  }
		 		content.setBackgroundColor(0); 
			   content.loadDataWithBaseURL("file:///android_res/drawable/","<html><style type=\"text/css\">@font-face {font-family: MyFont;src: url('file:///android_asset/fonts/SEGOEPR.TTF')}body {font-family: MyFont; text-align: justify;}</style></head><body>"+result+"</table></body></html>", "text/html", "utf-8",null);
		 	 
		 	 
		return rootView;
		}	
	 
	public boolean onKeyDown(int keycode, KeyEvent event ) {
	   	 if(keycode == KeyEvent.KEYCODE_SETTINGS){
	       	 
	   		 	Intent int_home1 = new Intent(getActivity(),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(getActivity(),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(getActivity(),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(getActivity(),home.class); 
		   		 	int_home1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    		startActivity(int_home1);
				    return true;
			   	 	}
	   	     return this.onKeyDown(keycode,event);  
	   	    }

	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	    inflater.inflate(R.menu.main, menu);
	    menu.findItem(R.id.icon_rasi).setVisible(true);  
	    super.onCreateOptionsMenu(menu,inflater);
	}

@SuppressLint("NewApi")
	@Override
   public boolean onOptionsItemSelected(MenuItem item) {
	  if (item.getItemId() ==android.R.id.home) {
 		  Intent int_home = new Intent(getActivity(), 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(getActivity(), 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(getActivity());
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(getActivity());
 			  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(getActivity());
		         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;
	           
	    
   }
    
	
}










