package leo.findyourfate.com;

import java.net.HttpURLConnection;
import java.net.URL;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource; 
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.StrictMode;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; 
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

public class horoscope extends Fragment {
   private WheelMenu wheelMenu;
     String stext = null;
     WebView content; 
     String sign=null ;
 	 String fromdate=null;
 	 String todate =null;
 	 String weekmonth,weekyear;
  	 View rootView;
  	 TextView roticon;
  	TextView nextyearcontent,prevyrcontent;
  	 int fsize=0;
  	 
       @Override
       public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
    	   
    	   StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() .penaltyLog().build()); 
    	   rootView = inflater.inflate(R.layout.horoscope, container, false);
 	 
    	   String userAgent = new WebView(getActivity()).getSettings().getUserAgentString();
    	   if (userAgent.contains("Mobile")) {
    		   rootView = inflater.inflate(R.layout.horoscope, container, false);
    		   fsize=17;
    	   } 
    	   else {
    		   rootView = inflater.inflate(R.layout.horoscopetab, container, false);
   	  		fsize=20;
    	   }
    	   nextyearcontent=(TextView) rootView.findViewById(R.id.nextyear);
    	   prevyrcontent=(TextView)rootView.findViewById(R.id.prevyear);
    	   
    	   roticon=(TextView) rootView.findViewById(R.id.rotate);
    	   wheelMenu = (WheelMenu)rootView.findViewById(R.id.wheelMenu);
    	roticon.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
				builder.setTitle("Rotate the Wheel");
				builder.setIcon(R.drawable.alert);
				builder.setMessage("Hi Leo, Rotate the Wheel to Read your Horoscopes.")
				       .setCancelable(false)
				         .setPositiveButton("OK", new DialogInterface.OnClickListener() {
				           public void onClick(DialogInterface dialog, int id) {
				                //do things
			 	           }
				       });
				AlertDialog alert = builder.create();
				alert.show();
			}
		});
   	 	content = (WebView)rootView.findViewById(R.id.content);
    	content.setBackgroundColor(0);
    	  WebSettings webSettings = content.getSettings(); 
    	  webSettings.setDefaultFontSize(fsize);
	      webSettings.setSupportZoom(true);
	      webSettings.setBuiltInZoomControls(true);
        wheelMenu.setDivCount(12);
         wheelMenu.setWheelImage(R.drawable.wheel);
        final Calendar cal = Calendar.getInstance();
		int moth=cal.get(Calendar.MONTH) + 1 ;
	    int date=cal.get(Calendar.DAY_OF_MONTH) ;
	    final int yr=cal.get(Calendar.YEAR);
	    
	    final int nextyr=cal.get(Calendar.YEAR)+1;
	    
	    ConnectivityManager conMgr = (ConnectivityManager) getActivity().getSystemService (Context.CONNECTIVITY_SERVICE);
    	String error1;
    	    if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) {
    		   } else {
    		  error1= "<html><head> <style type=\"text/css\">@font-face {font-family: MyFont; src: url(\"file:///android_asset/fonts/SEGOEPR.TTF\")}body { font-family: MyFont;  text-align: justify;font-size:larger; color:#000000; font-weight:bold; line-height:32px; }</style></head><body><p align=\"center\" style=\"padding-top:100px; padding-bottom:100px;\"><font  color=\"#000000\"  size=\"+2\" ><b> Unable to Download Feed <br />Check Your Data/WIFI Connection </b></font></p></body></html>";
     		  content.loadDataWithBaseURL("file:///android_res/drawable/", error1, "text/html", "utf-8",null); 
     	   }
	 String mname1 = null;
	 String month_name1=null;
	 
	     if (moth==1)
	     {
	     	  mname1="jan";
	     	  month_name1="January";
	     }
	     else if(moth==2)
	     {
	     	mname1="feb";
	     	month_name1="February";
	     }
	     else if(moth==3)
	     {
	     	mname1="mar";
	     	month_name1="March";
	     }
	     else if(moth==4)
	     {
	     	mname1="apr";
	     	month_name1="April";
	     }
	     else if(moth==5)
	     {
	     	mname1="may";
	     	month_name1="May";
	     }
	     else if(moth==6)
	     {
	     	mname1="jun";
	     	month_name1="June";
	     }
	     else if(moth==7)
	     {
	     	mname1="jul";
	     	month_name1="July";
	     }
	     else if(moth==8)
	     {
	     	mname1="aug";
	     	month_name1="August";
	     }
	     else if(moth==9)
	     {
	     	mname1="sep";
	     	month_name1="September";
	     }
	     else if(moth==10)
	     {
	     	mname1="oct";
	     	month_name1="October";
	     }
	     else if(moth==11)
	     {
	     	mname1="nov";
	     	month_name1="November";
	     }
	     else if(moth==12)
	     {
	     	mname1="dec";
	     	month_name1="December";
	     } 
	     
	     URL url = null;
	     
	  		try {
			url = new URL("https://www.findyourfate.com/android-horoscope/daily/"+yr+"/"+mname1+"/"+yr+moth+date+".xml");
	 	    
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			 DocumentBuilder db = null;
			 db = dbf.newDocumentBuilder();
			 Document doc = null;
			 doc = db.parse(new InputSource(url.openStream()));
			 // TODO Auto-generated catch block
			 // TODO Auto-generated catch block
		 	  doc.getDocumentElement().normalize();
			  NodeList nodeList = doc.getElementsByTagName("item");
			  webSettings.setSupportZoom(true);
			  webSettings.setDefaultFontSize(fsize);
		      webSettings.setBuiltInZoomControls(true);
			  Node node = nodeList.item(4);
			  Element fstElmnt = (Element) node;
			  NodeList contentList = fstElmnt.getElementsByTagName("content");
			  Element contentElement = (Element) contentList.item(0);
			  contentList = contentElement.getChildNodes();
			 		String 	text = null;
		  				 sign = "Daily Horoscope Leo (Jul 23 - Aug 22)";
		  				String userAgent1 = new WebView(getActivity()).getSettings().getUserAgentString();
		  				if (userAgent1.contains("Mobile")) {
		  				text = "<html><head><style type=\"text/css\"> @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\">"+" Leo-Daily Horoscope <br>"+"<b><font size=\""+2+"\">"+month_name1+" "+date+" ,"+yr+"</font></b></h4>"+ "<table border='0'><tr><td><p align=\"justify\">" +"<font color=\"#000000\" size=\""+3+"\"   face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> </td></tr></table>"+ "</body></html>";
		  			 	} 
		  				else {
		  				text = "<html><head><style type=\"text/css\">@font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h2 align=\"center\">"+" Leo-Daily Horoscope <br>"+"<font size=\""+3+"\" >"+month_name1+" "+date+" ,"+yr+"</font></b></h2>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\"   face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+"</body></html>";
		  	 			}
		  				content.setBackgroundColor(0);
		  				content.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null);  
		 		}
		 	  catch (Exception e) {
		     	 System.out.println("XML Pasing Excpetion = " + e);
			   }
			
      
        wheelMenu.setWheelChangeListener(new WheelMenu.WheelChangeListener() {
            @Override
            public void onSelectionChange(int selectedPosition) {
            	int intMonth=selectedPosition + 1;
            	  final Calendar cal = Calendar.getInstance();
 				   int moth=cal.get(Calendar.MONTH) + 1 ;
 				   int date=cal.get(Calendar.DAY_OF_MONTH) ;
 				   final int yr=cal.get(Calendar.YEAR);
 			    
 				  ConnectivityManager conMgr = (ConnectivityManager) getActivity().getSystemService (Context.CONNECTIVITY_SERVICE);
 			    	String error1;
 			    	    if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) {
 			    		   } else {
 			    		  error1= "<html><head> <style type=\"text/css\">@font-face {font-family: MyFont; src: url(\"file:///android_asset/fonts/SEGOEPR.TTF\")}body { font-family: MyFont;  text-align: justify;font-size:larger; color:#000000; font-weight:bold; line-height:32px; }</style></head><body><p align=\"center\" style=\"padding-top:100px; padding-bottom:100px;\"><font  color=\"#000000\"  size=\"+2\" ><b> Unable to Download Feed <br />Check Your Data/WIFI Connection </b></font></p></body></html>";
 			     		  content.loadDataWithBaseURL("file:///android_res/drawable/", error1, "text/html", "utf-8",null); 
 			     	   }
 			     String mname1 = null;
 			     String month_name1=null;
 			     if (moth==1)
 			     {
 			     	  mname1="jan";
 			     	  month_name1="January";
 			     }
 			     else if(moth==2)
 			     {
 			     	mname1="feb";
 			     	month_name1="February";
 			     }
 			     else if(moth==3)
 			     {
 			     	mname1="mar";
 			     	month_name1="March";
 			     }
 			     else if(moth==4)
 			     {
 			     	mname1="apr";
 			     	month_name1="April";
 			     }
 			     else if(moth==5)
 			     {
 			     	mname1="may";
 			     	month_name1="May";
 			     }
 			     else if(moth==6)
 			     {
 			     	mname1="jun";
 			     	month_name1="June";
 			     }
 			     else if(moth==7)
 			     {
 			     	mname1="jul";
 			     	month_name1="July";
 			     }
 			     else if(moth==8)
 			     {
 			     	mname1="aug";
 			     	month_name1="August";
 			     }
 			     else if(moth==9)
 			     {
 			     	mname1="sep";
 			     	month_name1="September";
 			     }
 			     else if(moth==10)
 			     {
 			     	mname1="oct";
 			     	month_name1="October";
 			     }
 			     else if(moth==11)
 			     {
 			     	mname1="nov";
 			     	month_name1="November";
 			     }
 			     else if(moth==12)
 			     {
 			     	mname1="dec";
 			     	month_name1="December";
 			     } 
 			     URL url = null;
            	
            	 
  			  if ( (intMonth == 1) || (intMonth ==2) || (intMonth ==3))
  			 {
  				prevyrcontent.setVisibility(View.GONE);
				nextyearcontent.setVisibility(View.GONE);		 	
  				try {
  					url = new URL("https://www.findyourfate.com/android-horoscope/daily/"+yr+"/"+mname1+"/"+yr+moth+date+".xml");
  				 
  			     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  				   DocumentBuilder db = null;
  				 	db = dbf.newDocumentBuilder();
  				    Document doc = null;
  				 	doc = db.parse(new InputSource(url.openStream()));
  				 	// TODO Auto-generated catch block
  				 		// TODO Auto-generated catch block
  			 	    doc.getDocumentElement().normalize();
  				   NodeList nodeList = doc.getElementsByTagName("item");
  				  WebSettings webSettings = content.getSettings(); 
  			      webSettings.setSupportZoom(true);
  			    webSettings.setDefaultFontSize(fsize);
  			      webSettings.setBuiltInZoomControls(true);
  			      Node node = nodeList.item(4);
  				  Element fstElmnt = (Element) node;
  				  NodeList contentList = fstElmnt.getElementsByTagName("content");
  				  Element contentElement = (Element) contentList.item(0);
  				  contentList = contentElement.getChildNodes();
  				 String text = null;
  			  				sign = "Daily Horoscope Leo (Jul 23 - Aug 22)";
  			  				String userAgent1 = new WebView(getActivity()).getSettings().getUserAgentString();
  			  				if (userAgent1.contains("Mobile")) {
  			  				 text = "<html><head><style type=\"text/css\">  @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\">"+" Leo-Daily Horoscope <br> "+"<b><font size=\""+2+"\">"+month_name1+" "+date+" ,"+yr+"</font></b></h4>"+ "<table border='0'><tr><td><p align=\"justify\">" +"<font color=\"#000000\" size=\""+3+"\"   face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> </td></tr></table>"+ "</body></html>";
  			  			 	} 
  			  				else {
  			  				 text = "<html><head><style type=\"text/css\">  @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h2 align=\"center\">"+" Leo-Daily Horoscope <br>"+"<b><font size=\""+3+"\">"+month_name1+" "+date+" ,"+yr+"</font></b></h2>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\"   face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  			  	 			}
  			  		 	content.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null);  
  					}
  	 			catch (Exception e) {
  			     	 System.out.println("XML Pasing Excpetion = " + e);
  				   }
  			 	}
  			  
  			 else if ( (intMonth ==4) || (intMonth == 5)  || (intMonth ==6))
  			 {
  				prevyrcontent.setVisibility(View.GONE);
				nextyearcontent.setVisibility(View.GONE);
  				Calendar calendarFirstDay = Calendar.getInstance(); 
  	      	    Date now = new Date(); 
  	      	    calendarFirstDay.setTime(now); 
  	      	    calendarFirstDay.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  	      	    DateFormat weekFormat = new SimpleDateFormat("MM-dd-yyyy"); 
  	      	    fromdate=weekFormat.format(calendarFirstDay.getTime()); 
  	       	   DateFormat m = new SimpleDateFormat("MM");
  	      	   weekmonth=m.format(calendarFirstDay.getTime());
  	      	   DateFormat y = new SimpleDateFormat("yyyy");
  	      	   weekyear=y.format(calendarFirstDay.getTime());  
  	      	    Calendar cal2 = Calendar.getInstance();
  	              cal2.setTime(calendarFirstDay.getTime());
  	              cal2.add(Calendar.DATE, 6); 
  	              todate=weekFormat.format(cal2.getTime());  
  	              
  	              URL url1 = null;
  				try {
  					
  					url1 = new URL("https://www.findyourfate.com/android-horoscope/weekly/"+weekyear+"/"+weekmonth+"/"+fromdate+"to"+todate+".xml");
  				 
  	             DocumentBuilderFactory dbf1 = DocumentBuilderFactory.newInstance();
  	         	 DocumentBuilder db1 = null;
  	         	 db1 = dbf1.newDocumentBuilder();
  			 	 Document doc1 = null;
  			 	 
  				doc1 = db1.parse(new InputSource(url1.openStream()));
  			 	doc1.getDocumentElement().normalize();
  			 	NodeList nodeList1 = doc1.getElementsByTagName("item");
  			 	WebSettings webSettings = content.getSettings(); 
  			 	webSettings.setSupportZoom(true);
  			 	webSettings.setDefaultFontSize(fsize);
  			 	webSettings.setBuiltInZoomControls(true);
  	        	Node node1 = nodeList1.item(4);
  		        //  content[i]=new WebView(this);
  		     	Element elem = (Element) node1;
  		     	NodeList contentList1 = elem.getElementsByTagName("content");
  		   	    Element contentElement1 = (Element) contentList1.item(0);
  		   	    contentList1 = contentElement1.getChildNodes();
  		   	    
  	  		 		   String text;
  	  				   sign = "Weekly Horoscope"+weekyear+"/"+weekmonth+"/"+fromdate+"to"+todate; 
  	  				   String userAgent = new WebView(getActivity()).getSettings().getUserAgentString();
  	  				   if (userAgent.contains("Mobile")) {
  	  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\">"+" Weekly Horoscope <br>"+"<b><font size=\""+2+"\">"+fromdate+" - "+todate+"</font></b></h4>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+3+"\"   face=\"ms sans serif, verdana\">"+ ((Node) contentList1.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  	  				   		}
  	  				   else
  						{
  	  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h2 align=\"center\">"+" Weekly Horoscope <br>"+"<b><font size=\""+4+"\">"+fromdate+" - "+todate+"</font></b></h2>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\"   face=\"ms sans serif, verdana\">"+ ((Node) contentList1.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  	  		  				
  						}
  					content.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null);  
  	  		 	 }
  				 
  				  catch (Exception e) {
  	             	 System.out.println("XML Pasing Excpetion = " + e);
  	       	   }
  	  	 		   
							 
  			 }
  			 
  			 else if ( (intMonth ==7) || (intMonth ==8) || (intMonth ==9))
  			 {
  				prevyrcontent.setVisibility(View.GONE);
				nextyearcontent.setVisibility(View.GONE);
  				URL url2 = null;
  				try {
  					url2 = new URL("https://www.findyourfate.com/android-horoscope/monthly/"+yr+"/"+mname1+".xml");
  			       DocumentBuilderFactory dbf2 = DocumentBuilderFactory.newInstance();
  	  	      	   DocumentBuilder db2 = null;
  			 		db2 = dbf2.newDocumentBuilder();
  			 	   Document doc2 = null;
  			 		doc2 = db2.parse(new InputSource(url2.openStream()));
  			   	   doc2.getDocumentElement().normalize();
  	  	      	   NodeList nodeList2 = doc2.getElementsByTagName("item");
  	  	       WebSettings webSettings = content.getSettings(); 
 		      webSettings.setSupportZoom(true);
 		     webSettings.setDefaultFontSize(fsize);
 		      webSettings.setBuiltInZoomControls(true);
  	  	   		   
  	  		     Node node2 = nodeList2.item(4);
  	             
  	        	   Element monthelement = (Element) node2;
  	        	   NodeList contentList2 = monthelement.getElementsByTagName("content");
  	      	   Element contentElement2 = (Element) contentList2.item(0);
  	      	   contentList2 = contentElement2.getChildNodes();
  	  			   
  	  				    String text;
  	  				   		sign = "Monthly Horoscope";
  								   String userAgent = new WebView(getActivity()).getSettings().getUserAgentString();
  				  				   if (userAgent.contains("Mobile")) {
  				  				   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\">"+" Monthly Horoscope <br>"+"<b><font size=\""+2+"\">"+month_name1+","+yr+"</font></b></h4>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+3+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList2.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  				  				   }
  				  				   else
  				  				   {
  				  				    text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h2 align=\"center\">"+" Monthly Horoscope <br>"+"<b><font size=\""+4+"\">"+month_name1+","+yr+"</font></b></h2>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList2.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  				  				   }
  						  	   	content.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null);  
  			 	  
  				}
  				  catch (Exception e) {
  	             	 System.out.println("XML Pasing Excpetion = " + e);
  	       	   }
  		 	 }
  			  
  			 else if ( (intMonth == 10) || (intMonth == 11) || (intMonth == 12) ) 
			{
  				 URL url3 = null;
  			try {
  				url3 = new URL("https://www.findyourfate.com/android-horoscope/yearly/"+yr+"/"+yr+".xml");
  			    DocumentBuilderFactory dbf3 = DocumentBuilderFactory.newInstance();
  	  	      	DocumentBuilder db3 = null;
  			 	db3 = dbf3.newDocumentBuilder();
  			  	Document doc3 = null;
  			  	   doc3 = db3.parse(new InputSource(url3.openStream()));
  			   	   doc3.getDocumentElement().normalize();
  	  	      	   NodeList nodeList3 = doc3.getElementsByTagName("item"); 
  	  	       WebSettings webSettings = content.getSettings(); 
 		      webSettings.setSupportZoom(true);
 		      webSettings.setDefaultFontSize(fsize);
 		      webSettings.setBuiltInZoomControls(true);
  	  		   Node node3 = nodeList3.item(4);
  	  		   Element yearelmt = (Element) node3;
  	           NodeList contentList3 = yearelmt.getElementsByTagName("content");
  	      	   Element contentElement3 = (Element) contentList3.item(0);
  	      	   contentList3 = contentElement3.getChildNodes();
  	      	
  	  			 	 String text = null;
  								sign = "Yearly Horoscope";
  								   String userAgent = new WebView(getActivity()).getSettings().getUserAgentString();
  				  				   if (userAgent.contains("Mobile")) {
  				  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\">"+" Yearly Horoscope-"+"<b><font size=\""+2+"\">"+yr+"</font></b></h4>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+3+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList3.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  				  				   }
  				  				   else
  				  				   {
  				  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:751c00; text-align: justify;}</style></head><body bgcolor=\"\"><h2 align=\"center\">"+" Yearly Horoscope-"+"<b><font size=\""+4+"\">"+yr+"</font></b></h2>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList3.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  				   				   }
  					     	   	content.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null);  
  					     	 HttpURLConnection.setFollowRedirects(false);
    		       	    	    
  	       	    	         HttpURLConnection con =  (HttpURLConnection) new URL("https://www.findyourfate.com/android-horoscope/yearly/"+nextyr+"/"+nextyr+".xml").openConnection();
  	       	    	         con.setRequestMethod("HEAD");
  	       	    	         if( (con.getResponseCode() == HttpURLConnection.HTTP_OK) ) 
  	       	    	         {    
  	       	    	        nextyearcontent.setPaintFlags(nextyearcontent.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
  	       	    	        nextyearcontent.setVisibility(View.VISIBLE);
  	      				    nextyearcontent.setText(" "+nextyr);
  	      				    
  	       	     	         }
  				}
  				  catch (Exception e) {
  	             	 System.out.println("XML Pasing Excpetion = " + e);
  	       	   }	
  			
prevyrcontent.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
		 			prevyrcontent.setVisibility(View.GONE);
					nextyearcontent.setVisibility(View.VISIBLE);
					
			 	 URL url3 = null;
		  			try {
		  				url3 = new URL("https://www.findyourfate.com/android-horoscope/yearly/"+yr+"/"+yr+".xml");
		  			    DocumentBuilderFactory dbf3 = DocumentBuilderFactory.newInstance();
		  	  	      	DocumentBuilder db3 = null;
		  			 	db3 = dbf3.newDocumentBuilder();
		  			  	 Document doc3 = null;
		  			 		doc3 = db3.parse(new InputSource(url3.openStream()));
		  			   	   doc3.getDocumentElement().normalize();
		  	  	      	   NodeList nodeList3 = doc3.getElementsByTagName("item"); 
		  	  	      	    WebSettings webSettings3 = content.getSettings(); 
		  	  		       webSettings3.setSupportZoom(true);
		  	  		       webSettings3.setBuiltInZoomControls(true);  
		  	  			  
		  	  		   Node node3 = nodeList3.item(2);
		  	  		   Element yearelmt = (Element) node3;
		  	           NodeList contentList3 = yearelmt.getElementsByTagName("content");
		  	      	   Element contentElement3 = (Element) contentList3.item(0);
		  	      	   contentList3 = contentElement3.getChildNodes();
		  	      	
		  	  		 String text = null;
		  								sign = "Yearly Horoscope";
		  								   String userAgent = new WebView(getActivity()).getSettings().getUserAgentString();
		  				  				   if (userAgent.contains("Mobile")) {
		  				  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:#4f4200; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\">"+" Yearly Horoscope-"+"<b><font size=\""+4+"\">"+yr+"</font></b></h4>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+3+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList3.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
		  				  				   }
		  				  				   else
		  				  				   {
		  				  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:#4f4200; text-align: justify;}</style></head><body bgcolor=\"\"><h2 align=\"center\">"+" Yearly Horoscope-"+"<b><font size=\""+6+"\">"+yr+"</font></b></h2>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList3.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
		  				   				   }
		  					     	   	content.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null);  
		  			 	 
		  				}
		  				  catch (Exception e) {
		  	             	 System.out.println("XML Pasing Excpetion = " + e);
		  	       	   }	
				}
			});
				}
	             }
        	});
        
        nextyearcontent.setOnClickListener(new View.OnClickListener() {
     			@Override
     			public void onClick(View v) {
     				System.out.println("ttttty");
     				 
     				// TODO Auto-generated method stub
     				nextyearcontent.setVisibility(View.GONE);
     				 prevyrcontent.setText(" "+yr);
     				 prevyrcontent.setPaintFlags(prevyrcontent.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
     				 prevyrcontent.setVisibility(View.VISIBLE);
     				 
     				 
     				  final ProgressDialog progressDialog = new ProgressDialog(getActivity());
     		     	  progressDialog.setTitle("Please wait");
     		           progressDialog.setMessage("Loading Content...");
     		              progressDialog.setCancelable(false);
     		           progressDialog.show();

     		           content.setWebViewClient(new WebViewClient() {
     		               @Override
     		               public boolean shouldOverrideUrlLoading(WebView view, String url) {
     		                   view.loadUrl(url);
     		                   return true;
     		               }

     		               @Override
     		               public void onPageFinished(WebView view, String url) {
     		                   if (progressDialog.isShowing()) {
     		                       progressDialog.dismiss();
     		                       
     		                       
     		                       
     		                       
     		                       
     		                       
     		                       
     		                       
     		                       
     		                       
     		                   }
     		               }

     		               @Override
     		               public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
     		                   Toast.makeText(getActivity(), "Error:" + description, Toast.LENGTH_SHORT).show();

     		               }
     		           });
     	
     			  URL url3 = null;
     		  			try {
     		  				url3 = new URL("https://www.findyourfate.com/android-horoscope/yearly/"+nextyr+"/"+nextyr+".xml");
     		  			    DocumentBuilderFactory dbf3 = DocumentBuilderFactory.newInstance();
     		  	  	      	DocumentBuilder db3 = null;
     		  			 	db3 = dbf3.newDocumentBuilder();
     		  			  	 Document doc3 = null;
     		  			 	doc3 = db3.parse(new InputSource(url3.openStream()));
     		  			   	 doc3.getDocumentElement().normalize();
     		  	  	      	  NodeList nodeList3 = doc3.getElementsByTagName("item"); 
     		  	  	      	   WebSettings webSettings3 = content.getSettings(); 
     		  	  		      webSettings3.setSupportZoom(true);
     		  	  		      webSettings3.setBuiltInZoomControls(true);  
     		  	  			  
     		  	  		   Node node3 = nodeList3.item(4);
     		  	  		   Element yearelmt = (Element) node3;
     		  	           NodeList contentList3 = yearelmt.getElementsByTagName("content");
     		  	      	   Element contentElement3 = (Element) contentList3.item(0);
     		  	      	   contentList3 = contentElement3.getChildNodes();
     		  	      	
     		  	  			 	 String text = null;
     		  								sign = "Yearly Horoscope";
     		  								   String userAgent = new WebView(getActivity()).getSettings().getUserAgentString();
     		  				  				   if (userAgent.contains("Mobile")) {
     		  				  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:#4f4200; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\">"+" Yearly Horoscope-"+"<b><font size=\""+4+"\">"+nextyr+"</font></b></h4>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+3+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList3.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
     		  				  				   }
     		  				  				   else
     		  				  				   {
     		  				  					   text = "<html><head><style type=\"text/css\">   @font-face {font-family: MyFont;src: url('file:///android_asset/fonts/MTCORSVA.TTF')}body {font-family: MyFont;color:#4f4200; text-align: justify;}</style></head><body bgcolor=\"\"><h2 align=\"center\">"+" Yearly Horoscope-"+"<b><font size=\""+6+"\">"+nextyr+"</font></b></h2>"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList3.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
     		  				   				   }
     		  					     	   	content.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null);  
     		  			 	 
     		  				}
     		  				  catch (Exception e) {
     		  	             	 System.out.println("XML Pasing Excpetion = " + e);
     		  	       	   }	
     		  	
      			}
     		});

       return rootView;
    }
 	};