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

import java.util.HashMap;
import java.util.List;

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.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class  chineseastro  extends Fragment {
	
	public chineseastro(){}
	ListView mDrawerList; 
	WebView content;
	String text = "";
	int fsize=0;
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
 
        View rootView = inflater.inflate(R.layout.fragment_chinese, container, false);
        mDrawerList = (ListView)rootView.findViewById(R.id.zodiac);  
        content = (WebView)rootView.findViewById(R.id.myview);   
        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;
               }
           
         String[] items = getResources().getStringArray(R.array.ChineseAstrology);
          
         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/chineseastro/chineseastro.html");
                setContentView(content);
            }
            if(position==1)
            {
            	content.loadUrl("http://www.findyourfate.com/android-fyf/chineseastro/fourpillars.html");
                setContentView(content);
            }
            if(position==2)
            {
            	content.loadUrl("http://www.findyourfate.com/android-fyf/chineseastro/flyingstar.html");
                setContentView(content);
            }
            if(position==3)
            {
            	content.loadUrl("http://www.findyourfate.com/android-fyf/chineseastro/fengshui.html");
                setContentView(content);
            }
            if(position==4)
            {
            	content.loadUrl("http://www.findyourfate.com/android-fyf/chineseastro/iching.html");
            	setContentView(content);
            }
            if(position==5)
            {
            	content.loadUrl("http://www.findyourfate.com/android-fyf/chineseastro/ichingmethods.html");
            	setContentView(content);
            }
            if(position==6)
            {
            	content.loadUrl("http://www.findyourfate.com/android-fyf/chineseastro/chinlegend.html");
            	setContentView(content);
            }
           }
            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;
      	    }

      	  }
      	
      	 
      	} 