package astrology.findyourfate.com;
import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class indianastro extends Fragment  {
	
public indianastro(){}
ListView mDrawerList; 
WebView content;
String text = "";
int fsize=0;

	@SuppressLint("JavascriptInterface")
	

	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
		 View rootView = inflater.inflate(R.layout.frag_number, container, false);
		  DisplayMetrics metrics = new DisplayMetrics(); 
    		getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
      	   if (metrics.densityDpi <= DisplayMetrics.DENSITY_LOW) {
          	//Toast.makeText(getActivity(), "low screen",Toast.LENGTH_LONG).show();
            	fsize=15;
             } else if (metrics.densityDpi <= DisplayMetrics.DENSITY_HIGH) {
            	// Toast.makeText(getActivity(), "high screen",Toast.LENGTH_LONG).show();
            	fsize=19;
             }
            else if (metrics.densityDpi <= DisplayMetrics.DENSITY_MEDIUM) {
            	/// Toast.makeText(getActivity(), "medium screen",Toast.LENGTH_LONG).show();
            	fsize=18;
             }
            else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XHIGH) {
           // Toast.makeText(getActivity(), "xLarge screen",Toast.LENGTH_LONG).show();
            	fsize=20;
             }
            else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXHIGH) {
           // Toast.makeText(getActivity(), "xxLarge screen",Toast.LENGTH_LONG).show();
            	fsize=23;
             }
            else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXXHIGH) {
            	fsize=25;
             }
            else {
            	fsize=20;
             }
         
		
		 
	        mDrawerList = (ListView)rootView.findViewById(R.id.zodiac);  
	        content = (WebView)rootView.findViewById(R.id.myview);   
	        
	        content.setWebViewClient(new WebViewClient());

	        content.setWebChromeClient(new WebChromeClient());
	        WebSettings webSettings = content.getSettings();
	        webSettings.setJavaScriptEnabled(true);
	        WebChromeClient myWebChromeClient = new WebChromeClient();
	        content.setWebChromeClient(myWebChromeClient);
	      String[] items = getResources().getStringArray(R.array.IndianAstrology);
	         
	         final ArrayList<String> list = new ArrayList<String>();
	         for (int i = 0; i < items.length; ++i) {
	           list.add(items[i]);
	         }
            
         
         final StableArrayAdapter adapter = new StableArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, list);
         mDrawerList.setAdapter(adapter); 
        mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {        	 
          @Override
          public void onItemClick(AdapterView<?> parent,  View view,
              int position, long id) {
             String item = (String) parent.getItemAtPosition(position);
             
              mDrawerList.setVisibility(View.GONE);
              
             content.setVisibility(View.VISIBLE);
             final WebSettings webSettings = content.getSettings();
             webSettings.setDefaultFontSize(fsize);
    
          
             if(position==0) 
  			{
            	
              	content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/indianast.html");
                setContentView(content);
                getActivity().getActionBar().setTitle("Indian astrology");
                getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
                getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE);
          
  			}
             if(position==1) 
   			{
               	
               	content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/indianwestern.html");
                 setContentView(content);
                 getActivity().getActionBar().setTitle("Indian vs Western astrology");
                 getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
                 getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE);
    		    }
             if(position==2)
             {
                  	content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/vastu.html");
                      setContentView(content);
                      getActivity().getActionBar().setTitle("Vastu-Indian astrology");
                     getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE);  		   
             }
           if(position==3)
           {
        	   content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/rasi.html");
               setContentView(content);
               getActivity().getActionBar().setTitle("Rasi-Indian astrology");
               getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE);  		   
           }
           if(position==4)
           {
        	   content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/rasicharacter.html");
               setContentView(content);
               getActivity().getActionBar().setTitle(" Characteristics of Rasis");
               getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE);  
           }
           if(position==5)
           {
        	   content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/grahas.html");
               setContentView(content);
               getActivity().getActionBar().setTitle(" Grahas-Indian Astrology");
               getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE);  
           }
           if(position==6)
           {
        	   content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/months.html");
               setContentView(content);
               getActivity().getActionBar().setTitle("Months & Tithis-Indian Astrology");
               getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE); 
           }
           if(position==7)
           {
        	   content.loadUrl("http://www.findyourfate.com/android-fyf/indianastro/nakshatras.html");
               setContentView(content);
               getActivity().getActionBar().setTitle("Nakshatras (Stars)-Indian Astrology");
               getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE); 
           }
          }

		private void setContentView(WebView content) {
			// TODO Auto-generated method stub
			
		}
         	 
             });
          return rootView;  
          
       
        }
 	private class StableArrayAdapter extends ArrayAdapter<String> {

 	    HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

 	    public StableArrayAdapter(Context context, int textViewResourceId,
 	        List<String> objects) {
 	      super(context, textViewResourceId, objects);
 	      for (int i = 0; i < objects.size(); ++i) {
 	        mIdMap.put(objects.get(i), i);
 	      }
 	    }

 	    @Override
 	    public long getItemId(int position) {
 	      String item = getItem(position);
 	      
 	      return mIdMap.get(item);
 	    }

 	    @Override
 	    public boolean hasStableIds() {
 	      return true;
 	    }

 	  }
        
    }


