package libra.findyourfate.com;
 
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView; 

public class newevents extends Activity {
	WebView load;
	int fsize=0;
	Button back;
	 private AdView mAdview;
	 ImageView character,card,icon;
	 TextView title;
	 
 	@SuppressLint("SetJavaScriptEnabled")
	@Override
    protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.newevent);
          
           getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
	        getActionBar().setCustomView(R.layout.custombar);
	        
	        icon=(ImageView) findViewById(R.id.iconimage);
	        character=(ImageView) findViewById(R.id.characterlink);
	        card=(ImageView) findViewById(R.id.cardlink);
	        title=(TextView) findViewById(R.id.title);
            	
       String userAgent = new WebView(newevents.this).getSettings().getUserAgentString();
           
           if (userAgent.contains("Mobile")) {
          	fsize=15;
         	} 
         	else 
       	   {
         	fsize=18;
         	}
           
           
           card.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in=new Intent(newevents.this,card.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(newevents.this,signtraits.class);
				in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(in);
			}
		});
             title.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in1=new Intent(newevents.this,MainActivity.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(newevents.this,MainActivity.class);
				in2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(in2);
			}
		});
           load=(WebView)findViewById(R.id.webevent);
           back=(Button) findViewById(R.id.backbutton);
            mAdview = (AdView) findViewById(R.id.adView);
         	mAdview.setAdListener(new ToastAdListener(this));
         	mAdview.loadAd(new AdRequest.Builder().build()); 
     
           WebSettings webSettings = load.getSettings(); 
	    	webSettings.setDefaultFontSize(fsize);
	     	webSettings.setJavaScriptEnabled(true);
		    webSettings.setBuiltInZoomControls(true);
		    load.setClickable(true);
		    load.setFocusableInTouchMode(true); 
		    load.setBackgroundColor(0);
		    
		    
		    ConnectivityManager conMgr = (ConnectivityManager)newevents.this.getSystemService (Context.CONNECTIVITY_SERVICE);
	    	String error1;
	    	    if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { 
	    	    	   load.loadUrl("https://www.findyourfate.com/aspadmin/viewpushnotexml.asp");
	    		   }
	    	    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>";
	     		  load.loadDataWithBaseURL("file:///android_res/drawable/", error1, "text/html", "utf-8",null); 
	     	   }
	     
		    
	     load.setWebViewClient(new WebViewClient() { 
 	   @Override
 	   public boolean shouldOverrideUrlLoading(WebView view, String url) {    
 	          	 view.loadUrl(url); 
                 return true;
          }
       }); 
	   
	   //  load.loadUrl("https://www.findyourfate.com/aspadmin/viewpushnotexml.asp");
        back.setOnClickListener(new View.OnClickListener() {
 	 		@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
			 	newevents.this.finish();
		 		overridePendingTransition(R.anim.left_out, R.anim.right_in);
				}
			});
  	}
}