package  virgo.findyourfate.com;  
 
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
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 org.xml.sax.SAXException;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.app.ActionBar;
import android.app.Activity;  
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;   
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.webkit.WebChromeClient;   
import android.webkit.WebView; 
import android.webkit.WebSettings.PluginState;  
import android.widget.ImageView;
import android.widget.TextView;

public class shownote extends Activity {  
	WebView searchcweb;  
 	URL url;
 	 ImageView character,card,icon,newevent;
	 TextView title1;
	 private AdView mAdview;
	 
	protected void onCreate(Bundle savedInstanceState) {
	  StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() .penaltyLog().build()); 
		super.onCreate(savedInstanceState); 
		
		 setContentView(R.layout.shownote); 
		 String data=getIntent().getExtras().getString("pagelink"); 
		 String title=getIntent().getExtras().getString("pagetitle"); 
		 String desc =getIntent().getExtras().getString("pagedec"); 
		 
	        mAdview = (AdView) findViewById(R.id.adView);
	       	mAdview.setAdListener(new ToastAdListener(this));
	       	mAdview.loadAd(new AdRequest.Builder().build()); 
	  
	       	getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
	       	getActionBar().setCustomView(R.layout.custombar1);
	        
	      icon=(ImageView) findViewById(R.id.iconimage1);
	        character=(ImageView) findViewById(R.id.characterlink1);
	        card=(ImageView) findViewById(R.id.cardlink1);
	        title1=(TextView) findViewById(R.id.title1);
	        newevent=(ImageView) findViewById(R.id.newevents1);
	        
	        card.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent in=new Intent(shownote.this,card.class);
					in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(in);
					}
			    });
	           newevent.setOnClickListener(new View.OnClickListener() {
			 		@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent in=new Intent(shownote.this,newevents.class);
						in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
						startActivity(in);
						}
				    });
	           
	         character.setOnClickListener(new View.OnClickListener() {
		 		@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent in=new Intent(shownote.this,signtraits.class);
					in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(in);
				}
			});
	           
	           title1.setOnClickListener(new View.OnClickListener() {
	 			@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent in1=new Intent(shownote.this,home.class);
					in1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(in1);
				}
			});
	           
	           icon.setOnClickListener(new View.OnClickListener() {
	 			@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent in2=new Intent(shownote.this,home.class);
					in2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(in2);
				}
			});

             searchcweb = (WebView) findViewById(R.id.noteview); 
	        searchcweb.setBackgroundColor(0);
	        searchcweb.getSettings().setBuiltInZoomControls(true);  
	        searchcweb.getSettings().setJavaScriptEnabled(true); 
	        searchcweb.getSettings().setLoadWithOverviewMode(true); 
	        searchcweb.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
	        searchcweb.setScrollbarFadingEnabled(false);
	        searchcweb.getSettings().setPluginState(PluginState.ON);
	        
	        searchcweb.setWebChromeClient(new WebChromeClient() {
                 @Override
                 public void onReceivedTitle(WebView view, String sTitle) {
                     super.onReceivedTitle(view, sTitle);  
                     
                     getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
         	        getActionBar().setCustomView(R.layout.custombar);
         	     
                    }
                 });   
	  
	        try {
		         URL url=new URL("https://www.findyourfate.com/data/pushnote/astro-events/"+data);
            //    URL url=new URL("https://www.findyourfate.com/android-horoscope/daily/"+y+"/"+mname+"/"+y+m+d1+".xml");
	           DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	      	   DocumentBuilder db = dbf.newDocumentBuilder();
	      	   Document doc = db.parse(new InputSource(url.openStream()));
	      	   doc.getDocumentElement().normalize();
	      	   NodeList nodeList = doc.getElementsByTagName("maintag");
	      	    
	      	 String text=null;
	      	  	  
	           for (int i = 0; i < 1; i++)
	      	   {
	      	   Node node = nodeList.item(i); 
	      	   Element fstElmnt = (Element) node;
	      	   NodeList contentList = fstElmnt.getElementsByTagName("content");
	    	   Element contentElement = (Element) contentList.item(0);
	    	   contentList = contentElement.getChildNodes();
	    	   if ((i==0))  
	    	   { 
	    		   String userAgent = new WebView(shownote.this).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:#011d20; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\"><b><font size=\""+4+"\">"+title+"</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:#011d20; text-align: justify;}</style></head><body bgcolor=\"\"><h4 align=\"center\"><b><font size=\""+6+"\">"+title+"</font></b></h4>"+ "<table border='0'><tr><td><p align=\"justify\">" +"<font color=\"#000000\" size=\""+5+"\"   face=\"ms sans serif, verdana\">"+((Node) contentList.item(0)).getNodeValue()+ "</font></p> </td></tr></table>"+ "</body></html>";
	              	}
	              }
	    	   
	 	   searchcweb.setBackgroundColor(0);
		 	searchcweb.loadDataWithBaseURL("file:///android_res/drawable/",text, "text/html", "utf-8",null); 
		
	     }
 		      
	} catch (MalformedURLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SAXException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (ParserConfigurationException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
          
	}   
	
	@Override
   public void onBackPressed() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Are you sure want to leave")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                   	Intent int_home1 = new Intent(shownote.this,RegisterActivity.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();

    }
  
	
     	
    }
 