package edu.purdue.app.dining;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.GregorianCalendar;
import java.util.Locale;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import edu.purdue.app.R;
public class DiningCourts extends FragmentActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
* will keep every loaded fragment in memory. If this becomes too memory
* intensive, it may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
Document document;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dining_courts_two);
// Create the adapter that will return a fragment for each of the three
// primary sections of the application
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dining_courts, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId() ){
case R.id.diningInfo:
WebUpdater wu = new WebUpdater(this);
wu.update(new GregorianCalendar(), Meal.Location.earhart);
MenuDialog md = new MenuDialog();
md.show(getFragmentManager(), "menu_show");
break;
}
return super.onOptionsItemSelected(item);
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
public int openedPage(){
int page = mSectionsPagerAdapter.getCount();
System.out.println(page);
return page;
}
@Override
public Fragment getItem(int position){
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
switch(position){
case 0:
Fragment fragment1 = new EarhartFragment();
Bundle args1 = new Bundle();
args1.putInt(EarhartFragment.ARG_SECTION_NUMBER, position + 1);
fragment1.setArguments(args1);
return fragment1;
case 1:
Fragment fragment2 = new FordFragment();
Bundle args2 = new Bundle();
args2.putInt(FordFragment.ARG_SECTION_NUMBER, position + 2);
fragment2.setArguments(args2);
return fragment2;
case 2:
Fragment fragment3 = new HillenbrandFragment();
Bundle args3 = new Bundle();
args3.putInt(HillenbrandFragment.ARG_SECTION_NUMBER, position + 3);
fragment3.setArguments(args3);
return fragment3;
case 3:
Fragment fragment4 = new WileyFragment();
Bundle args4 = new Bundle();
args4.putInt(WileyFragment.ARG_SECTION_NUMBER, position + 4);
fragment4.setArguments(args4);
return fragment4;
case 4:
Fragment fragment5 = new WindsorFragment();
Bundle args5 = new Bundle();
args5.putInt(WindsorFragment.ARG_SECTION_NUMBER, position + 5);
fragment5.setArguments(args5);
return fragment5;
default:
return null;
}
}
@Override
public int getCount() {
return 5;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.Earhart).toUpperCase(l);
case 1:
return getString(R.string.Ford).toUpperCase(l);
case 2:
return getString(R.string.Hillenbrand).toUpperCase(l);
case 3:
return getString(R.string.Wiley).toUpperCase(l);
case 4:
return getString(R.string.Windsor).toUpperCase(l);
}
return null;
}
}
/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class EarhartFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public EarhartFragment() {
//figure out what this does
}
FragmentManager fm = getFragmentManager();
private View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_dining_courts_two_dummy,container, false);
setRatingBars();
return rootView;
}
public void setRatingBars(){
final RatingBar rb1 = (RatingBar)rootView.findViewById(R.id.ratingBar1);
final RatingBar rb2 = (RatingBar)rootView.findViewById(R.id.ratingBar2);
final RatingBar rb3 = (RatingBar)rootView.findViewById(R.id.ratingBar3);
rb1.setIsIndicator(true);
rb2.setIsIndicator(true);
rb3.setIsIndicator(true);
rb1.setRating(4.2f);
rb2.setRating(4.0f);
rb3.setRating(4.8f);
}
}
public static class FordFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public FordFragment() {
//figure out what this does
}
FragmentManager fm = getFragmentManager();
private View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_dining_courts_two_dummy,container, false);
setRatingBars();
return rootView;
}
public void setRatingBars(){
final RatingBar rb1 = (RatingBar)rootView.findViewById(R.id.ratingBar1);
final RatingBar rb2 = (RatingBar)rootView.findViewById(R.id.ratingBar2);
final RatingBar rb3 = (RatingBar)rootView.findViewById(R.id.ratingBar3);
rb1.setIsIndicator(true);
rb2.setIsIndicator(true);
rb3.setIsIndicator(true);
rb1.setRating(3.2f);
rb2.setRating(1.0f);
rb3.setRating(4.8f);
}
}
public static class HillenbrandFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public HillenbrandFragment() {
//figure out what this does
}
FragmentManager fm = getFragmentManager();
private View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_dining_courts_two_dummy,container, false);
setRatingBars();
return rootView;
}
public void setRatingBars(){
final RatingBar rb1 = (RatingBar)rootView.findViewById(R.id.ratingBar1);
final RatingBar rb2 = (RatingBar)rootView.findViewById(R.id.ratingBar2);
final RatingBar rb3 = (RatingBar)rootView.findViewById(R.id.ratingBar3);
rb1.setIsIndicator(true);
rb2.setIsIndicator(true);
rb3.setIsIndicator(true);
rb1.setRating(1.4f);
rb2.setRating(1.0f);
rb3.setRating(4.5f);
}
}
public static class WileyFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public WileyFragment() {
//figure out what this does
}
FragmentManager fm = getFragmentManager();
private View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_dining_courts_two_dummy,container, false);
setRatingBars();
return rootView;
}
public void setRatingBars(){
final RatingBar rb1 = (RatingBar)rootView.findViewById(R.id.ratingBar1);
final RatingBar rb2 = (RatingBar)rootView.findViewById(R.id.ratingBar2);
final RatingBar rb3 = (RatingBar)rootView.findViewById(R.id.ratingBar3);
rb1.setIsIndicator(true);
rb2.setIsIndicator(true);
rb3.setIsIndicator(true);
rb1.setRating(5.0f);
rb2.setRating(1.5f);
rb3.setRating(3.0f);
}
}
public static class WindsorFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
public WindsorFragment() {
//figure out what this does
}
FragmentManager fm = getFragmentManager();
private View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_dining_courts_two_dummy,container, false);
setRatingBars();
return rootView;
}
public void setRatingBars(){
final RatingBar rb1 = (RatingBar)rootView.findViewById(R.id.ratingBar1);
final RatingBar rb2 = (RatingBar)rootView.findViewById(R.id.ratingBar2);
final RatingBar rb3 = (RatingBar)rootView.findViewById(R.id.ratingBar3);
rb1.setIsIndicator(true);
rb2.setIsIndicator(true);
rb3.setIsIndicator(true);
rb1.setRating(0.5f);
rb2.setRating(1.0f);
rb3.setRating(1.5f);
}
}
}