package astrology.findyourfate.com;

import java.io.File;
import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;
import com.google.analytics.tracking.android.EasyTracker;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Calendar;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
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 android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color; 
import android.os.Bundle;
import android.os.StrictMode;
import android.text.Html;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.ShareActionProvider;
import android.widget.TextView;
import android.widget.Toast;

public class horoscope extends Activity{
	final Context context = this;
    String modetext = null; 
	 String mname=null;
	 String title="What's special today for you";
	 String modeview=null;
			String fname="myfile.xml";
			 LinearLayout layouts;
			// private AdView mAdview;
			 private AdLayout adView;
			 private ShareActionProvider mShareActionProvider;
			 private EasyTracker easyTracker = null;
			 int fsize=0;
		@Override
		public void onCreate(Bundle savedInstanceState) { 
		 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() .penaltyLog().build()); 
       	super.onCreate(savedInstanceState);
    	setContentView(R.layout.findzodiac);
		//  mAdview = (AdView) findViewById(R.id.adView);
		    easyTracker = EasyTracker.getInstance(horoscope.this);
	   //   mAdview.setAdListener(new ToastAdListener(this));
			DisplayMetrics metrics = new DisplayMetrics(); 
			Activity activity = (Activity) context;
		    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
		   if (metrics.densityDpi <= DisplayMetrics.DENSITY_LOW) {
		        	//Toast.makeText(this, "low screen",Toast.LENGTH_LONG).show();
		        	fsize=2;
		   } else if (metrics.densityDpi <= DisplayMetrics.DENSITY_HIGH) {
		        	// Toast.makeText(this, "high screen",Toast.LENGTH_LONG).show();
		        	fsize=4;
		  } else if (metrics.densityDpi <= DisplayMetrics.DENSITY_MEDIUM) {
		        // Toast.makeText(this, "medium screen",Toast.LENGTH_LONG).show();
		        	fsize=3;
		        }
		        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=4;
		        }
		        else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXXHIGH) {
		        	 
		        	fsize=5; 
		        }
		        else {
		        	fsize=3;
		        }
			 
		  AdRegistration.setAppKey("fbce94eb2ff347e5a855d4496106f125");
	 	  this.adView = (AdLayout) findViewById(R.id.ad_view);
		  AdTargetingOptions adOptions = new AdTargetingOptions();
		  AdRegistration.enableLogging(false);
		  AdRegistration.enableTesting(false);
		 
     	 	 TextView resultday,resultday1;
	  		 WebView[] content;
	  		 TextView other,other1;
	  		 TextView text,text1;
	  		 WebView[] newcon;
	  		 
	  		layouts=(LinearLayout) findViewById(R.id.layout);
        	
	  	getActionBar().setDisplayHomeAsUpEnabled(true); 
	  	final ScrollView home_scroll = new ScrollView(this); 
		home_scroll.setBackgroundColor(Color.WHITE);  
		final LinearLayout layout=new  LinearLayout(this);
		layout.setOrientation(LinearLayout.VERTICAL);
		layout.setGravity(Gravity.CENTER);
		layout.setPadding(20, 20, 20, 30);
	// layout.setBackgroundColor(Color.WHITE);
	
  final String modeday = getIntent().getStringExtra("modeday"); 
    try {
		 final Calendar cal = Calendar.getInstance();
		 final int m=cal.get(Calendar.MONTH) + 1 ;
         int d=cal.get(Calendar.DAY_OF_MONTH) ;
         final int y=cal.get(Calendar.YEAR);
         int d1=0;
         
         if (modeday.equals("Nextday"))
         {
      	 d1=d+1; 
      	 modetext="Today";
         }
         else if (modeday.equals("Today"))
         {
      	 d1=d ;  
      	 modetext="Nextday";
         }
       URL url=new URL("http://www.findyourfate.com/rss/horoscope-astrology-feed.asp?mode=view&todate="+m+"/"+d1+"/"+y);
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	   DocumentBuilder db = dbf.newDocumentBuilder();
	   Document doc = db.parse(new InputSource(url.openStream()));
	   doc.getDocumentElement().normalize();
	   NodeList nodeList = doc.getElementsByTagName("item");
	   text = new TextView(this);
	   text.setGravity(Gravity.CENTER);
	   resultday = new TextView(this);
	   resultday.setGravity(Gravity.RIGHT);
	   other = new TextView(this);
	
     other.setGravity(Gravity.CENTER);
     content=new WebView[3];
	 text.setText(Html.fromHtml("<h1 align=\"left\">"+"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+"("+m+"/"+d1+"/"+y+")"+"<br/><br/>"+"<b>"+"Today's Numerology "+"<br>"+"</b></font></h1>"));
	 layout.addView(text);
	for (int i = 0; i <3; i++)
	   {
	   Node node = nodeList.item(i);
       content[i]=new WebView(this);
       Element fstElmnt = (Element) node;
       NodeList contentList = fstElmnt.getElementsByTagName("description");
  	   Element contentElement=(Element) contentList.item(0);
  	   contentList = contentElement.getChildNodes();
  	   String texts = null;
  		if ((i==0) && (title.equals("What's special today for you")))  
  	   {
  		   texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
  		   content[i].loadData(texts, "text/html", "utf-8");
  		   layout.addView(content[i]);
  	   }
	   }
     resultday.setText(Html.fromHtml("<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+"<b><u>"+modetext+"</u></b></font><br>"));
     layout.addView(resultday);
     resultday.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			  if (modeday.equals("Nextday"))
              {
            	 modetext="Today";
              }
              else if (modeday.equals("Today"))
              {
           	  modetext="Nextday";
              }
		        Intent intent = new Intent(context,horoscope.class);
			   intent.putExtra("modeday",modetext); 
			   startActivity(intent);   
		}
	});
		}catch(Exception e){
			System.out.println("hai! there is a problem");
		}
		 String sign = getIntent().getStringExtra("key"); 
	  if(sign!=null)
	  {
     try {
		  final Calendar cal = Calendar.getInstance();
		   final int m=cal.get(Calendar.MONTH) + 1 ;
          int d=cal.get(Calendar.DAY_OF_MONTH) ;
          final int y=cal.get(Calendar.YEAR);
          int d1=0;
       if (m==1)
       {
       	  mname="jan";
       }
       else if(m==2)
       {
       	mname="feb";
       }
       else if(m==3)
       {
       	mname="mar";
       }
       else if(m==4)
       {
       	mname="apr";
       }
       else if(m==5)
       {
       	mname="may";
       }
       else if(m==6)
       {
       	mname="jun";
       }
       else if(m==7)
       {
       	mname="jul";
       }
       else if(m==8)
       {
       	mname="aug";
       }
       else if(m==9)
       {
       	mname="sep";
       }
       else if(m==10)
       {
       	mname="oct";
       }
       else if(m==11)
       {
       	mname="nov";
       }
       else if(m==12)
       {
       	mname="dec";
       } 
       
	 if (modeday.equals("Nextday"))
      {
   	  d1=d+1; 
      modetext="Today";
      }
      else if (modeday.equals("Today"))
      {
   	  d1=d ;  
   	  modetext="Nextday";
      }
      
     URL url1=new URL("http://www.findyourfate.com/android-horoscope/daily/"+y+"/"+mname+"/"+y+m+d1+".xml");
   		
     DocumentBuilderFactory dbf1 = DocumentBuilderFactory.newInstance();
	   DocumentBuilder db1 = dbf1.newDocumentBuilder();
	   Document doc1 = db1.parse(new InputSource(url1.openStream()));
	   doc1.getDocumentElement().normalize();
	   NodeList nodeList = doc1.getElementsByTagName("item");
	   text1 = new TextView(this);
	   text1.setGravity(Gravity.CENTER);
	   resultday1 = new TextView(this);
	   resultday1.setGravity(Gravity.RIGHT);
	   other1 = new TextView(this);
	   other1.setGravity(Gravity.CENTER);
	   newcon=new WebView[12];
	   text1.setText(Html.fromHtml("<h1 align=\"left\">"+"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+"("+m+"/"+d1+"/"+y+")"+"<br/><br/>"+"<b>"+"Today Horoscope for- "+sign+"<br>"+"</b></font></h1>"));
	   layout.addView(text1);
	
  for (int i = 0; i < 12; i++)
	   {
	   Node node = nodeList.item(i);
       newcon[i]=new WebView(this);
 	   Element fstElmnt = (Element) node;
 	   NodeList contentList = fstElmnt.getElementsByTagName("content");
	   Element contentElement = (Element) contentList.item(0);
	   contentList = contentElement.getChildNodes();
	   String texts = null;
	   
if ((i==0) && (sign.equals("Aries")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==1)&& (sign.equals("Taurus")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==2)&& (sign.equals("Gemini")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==3)&& (sign.equals("Cancer")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==4)&& (sign.equals("Leo")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==5)&& (sign.equals("Virgo")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==6)&& (sign.equals("Libra")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==7)&& (sign.equals("Scorpio")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==8)&& (sign.equals("Sagittarius")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==9)&& (sign.equals("Capricorn")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==10)&& (sign.equals("Aquarius")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
else if ((i==11)&& (sign.equals("Pisces")))  
{
texts = "<html><body bgcolor=\"#ffffff\">"+ "<p align=\"justify\">" +"<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+ ((Node) contentList.item(0)).getNodeValue()+ "</font></p> "+ "</body></html>";
newcon[i].loadData(texts, "text/html", "utf-8");
layout.addView(newcon[i]);
}
	   }
  resultday1.setText(Html.fromHtml("<font color=\"#000000\" size=\""+fsize+"\" face=\"ms sans serif, verdana\">"+"<b><u>"+modetext+"</u></b></font><br>"));
  layout.addView(resultday1);
  TextView brtext=new TextView(this);
  brtext.setText(Html.fromHtml("<br><br><br><br>"));
  layout.addView(brtext);
 
  resultday1.setOnClickListener(new OnClickListener() {
		@Override
		 public void onClick(View v) {
	     String sign = getIntent().getStringExtra("key"); 
    	    if (modeday.equals("Nextday"))
             {
           	 modetext="Today";
             }
             else if (modeday.equals("Today"))
             {
          	  modetext="Nextday";
             }
		        Intent intent = new Intent(context,horoscope.class);
			   intent.putExtra("key",sign);
			   intent.putExtra("modeday",modetext); 
			   startActivity(intent);   
	            }
	  });     
     }catch(Exception e)
     {
     }
	  }
     boolean hasActionBar = android.os.Build.VERSION.SDK_INT >= 11;
     if (hasActionBar) {
             ActionBar actionBar = getActionBar();
             actionBar.setHomeButtonEnabled(true);
             actionBar.setDisplayHomeAsUpEnabled(true);
               actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
            	        | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
            
             actionBar.show();
             
         } else {
          }
     this.adView.loadAd(adOptions);
	// mAdview.loadAd(new AdRequest.Builder().build()); 
 home_scroll.addView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
     
  //   setContentView(home_scroll);
 
		 layouts.removeAllViews();
		 
		 layouts.addView(home_scroll);
      	}
		@Override
	    public void onStart() {
	        super.onStart();
	        EasyTracker.getInstance(this).activityStart(this);
	    }
	 
	    @Override
	    public void onStop() {
	        super.onStop();
	        EasyTracker.getInstance(this).activityStop(this);
	    }
	    @Override
		public void onBackPressed() {
		             	  horoscope.this.finish();
	}
		 @Override
			public boolean onCreateOptionsMenu(Menu menu) {
				MenuInflater menuInflater = getMenuInflater();
		        menuInflater.inflate(R.menu.main, menu);
		    
		        return super.onCreateOptionsMenu(menu);
			}
			    
	 		@Override
		public boolean onOptionsItemSelected(MenuItem item) {
			
		
			if (item.getItemId() == android.R.id.home)
			{
				Intent int_ab = new Intent(this,MainActivity.class);
	            int_ab.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            startActivity(int_ab);
			}
	            else if (item.getItemId() == R.id.drawer)
	            {
				Intent int_sear = new Intent(this,MainActivity.class);
				int_sear.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(int_sear);
	            }
				 else if (item.getItemId() == R.id.service)
				 {
				  Intent int_ser = new Intent(this,ourservices.class);
		            int_ser.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		            startActivity(int_ser);
				 }
		            else if (item.getItemId() == R.id.astrology)
		            {
				File myFile = new File(getFilesDir() + "/" + fname);
				
					        if (myFile.exists()) 
				            {
					        	try {
					    			
					        FileInputStream file = new FileInputStream(new File(getFilesDir() + "/" + fname));
						           // FileInputStream file = new FileInputStream(new File("D:/new/SlidingMenu/data/astrology.findyourfate.com/files/myfile.xml"));
						    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
						             
						   DocumentBuilder builder =  builderFactory.newDocumentBuilder();
						             
						   Document xmlDocument = builder.parse(file);
						 
						   XPath xPath =  XPathFactory.newInstance().newXPath();
						   
						            System.out.println("*************************");
						          String   expression = "/root/zodiac";
						            System.out.println(expression);
						            NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
						            for (int i = 0; i < nodeList.getLength(); i++) {
						               String value=nodeList.item(i).getLastChild().getNodeValue(); 
						               if(value.length() == 0)
						               {
						               Intent int_ast = new Intent(this,astology.class);
							            int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
							            startActivity(int_ast);
						               }
						               else
						               {
										Intent in= new Intent(this,horoscope.class);
										  in.putExtra("key", value);
										  in.putExtra("modeday","Today");							
										startActivity(in);
							     
						            	}
						           	
									}   

								}catch (FileNotFoundException e) {
						            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();
								} catch (XPathExpressionException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}			
 
				            }
				                    
					        else
				            {
				            	 Intent int_ast = new Intent(this,astology.class);
						            int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
						            startActivity(int_ast);
						
				            }
			}
			
			else if (item.getItemId() == R.id.setup)
			{
				File myFile1 = new File(getFilesDir() + "/" + fname);
				
					        if (myFile1.exists()) 
				            {
					        	
					        	try {  	
					        	FileInputStream file = new FileInputStream(new File(getFilesDir() + "/" + fname));
						           // FileInputStream file = new FileInputStream(new File("D:/new/SlidingMenu/data/astrology.findyourfate.com/files/myfile.xml"));
							           
						            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
						             
						            DocumentBuilder builder =  builderFactory.newDocumentBuilder();
						             
						            Document xmlDocument = builder.parse(file);
						 
						            XPath xPath =  XPathFactory.newInstance().newXPath();
						   
						            System.out.println("*************************");
						          String   expression = "/root/zodiac";
						          System.out.println(expression);
						            String   expressio = "/root/dob";
							           System.out.println(expressio);
							         
							              NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
							            
							            for (int i = 0; i < nodeList.getLength(); i++) {
							            	
							                     	
							               String value=nodeList.item(i).getFirstChild().getNodeValue(); 
							               
							             
							               NodeList nodeList1 = (NodeList) xPath.compile(expressio).evaluate(xmlDocument, XPathConstants.NODESET);
								            
								            for (int i1 = 0; i1 < nodeList1.getLength(); i1++) {
								            	
								                     	
								               String val=nodeList1.item(i1).getLastChild().getNodeValue(); 
								             
								     if(value.length() == 0)
						               {
						               Intent int_ast = new Intent(this,astology.class);
							            int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
							            startActivity(int_ast);
						               }
						               else
						               {
										Intent in= new Intent(this,setuppage.class);
										 in.putExtra("date",val);
										  in.putExtra("key", value);
											startActivity(in);
							          	}
						            }   
							    }
				           }catch (FileNotFoundException e) {
					            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();
							} catch (XPathExpressionException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
				            }
						          
				            else
				            {
				            	 Intent int_ast = new Intent(this,astology.class);
						            int_ast.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
						            startActivity(int_ast);
				            }       
			}
			 else if (item.getItemId() == R.id.exit)
			  {
				 AlertDialog.Builder builder = new AlertDialog.Builder(this);
				    builder.setMessage("Are you sure  want to exit?")
				           .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 alert = builder.create();
				    alert.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, "Astrology by findyourfate.com");
			        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hi,I would like to suggest, this  Astrology by findyourfate.com App to you. \n Click this Link to Download app \"http://goo.gl/iexPxk\"\n\n Regards");
			    	startActivity(emailIntent);  
				
			 }	
			 else if (item.getItemId() == R.id.in)
			  {
				  AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(horoscope.this);
				    alertDialogBuilder.setTitle("Horoscope Compatibility");
				    alertDialogBuilder.setMessage("Compatibility of zodiac signs for love and romantic relationship. Search what zodiac signs are compatible. Find quality results here!No two sun signs are alike and totally compatible. A degree of incompatibility always exists because that is how we have been made.Marriages are made in heaven BUT!!! Compatible Love Matches are made here through this app.The paid in-app compatibility report is \"the best buy\".");
				     alertDialogBuilder.setPositiveButton("Open",new DialogInterface.OnClickListener() {
				       public void onClick(DialogInterface dialog,int id) {
				         final String appPackageName = "compatibility.findyourfate.com"; // getPackageName() from Context or Activity object
				        	 try {
				        	       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
				        	     } catch (android.content.ActivityNotFoundException anfe) {
				        	        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
				        	         }
				        	   }
				       });
				          alertDialogBuilder.setNeutralButton("Already/Never",new DialogInterface.OnClickListener() {
				                  public void onClick(DialogInterface dialog,int id) {	  
				                    //  MainActivity.this.finish();
				                	  dialog.cancel();
				                  }
				              });
				            // set negative button: No message
						alertDialogBuilder.setNegativeButton("Later",new DialogInterface.OnClickListener() {
			                  public void onClick(DialogInterface dialog,int id) {
				                      // cancel the alert box and put a Toast to the user
				                      dialog.cancel();                    
				                  }
				              });
				           AlertDialog alertDialog = alertDialogBuilder.create();
				           // show alert
				           alertDialog.show();			  
				      }*/
					 else
					 {
					 }
				return true;		
		}
		public boolean fileExistance(String fname){
		    File myfile = getBaseContext().getFileStreamPath(fname);
		    return myfile.exists();
		}
     }


	
	

