Android Open Source - HastingsMobileAndroid Fragment Dining Hall






From Project

Back to project page HastingsMobileAndroid.

License

The source code is released under:

Apache License

If you think the Android project HastingsMobileAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.hastings.hastingscollege.navdrawerfragments;
//from   w ww.  j a  v  a  2 s .com
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import edu.hastings.hastingscollege.R;
import edu.hastings.hastingscollege.adapter.CustomSodexoWeekMenuAdapter;
import edu.hastings.hastingscollege.googleanalytics.MyApplication;
import edu.hastings.hastingscollege.model.Data;

public class FragmentDiningHall extends Fragment {


    public static final String TAG = "FragmentDiningHall";
    public Tracker tracker;

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        this.tracker = ((MyApplication) getActivity().getApplication()).getTracker(MyApplication.TrackerName.APP_TRACKER);
        this.tracker.setScreenName("Dining Hall");
        this.tracker.send(new HitBuilders.AppViewBuilder().build());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.sodexo, container, false);
        ListView mDaysOfWeekList = (ListView) view.findViewById(R.id.days_of_week_list);

        if (Data.mondayMenu.size() > 0) {
            String[] mDaysOfWeek = getResources().getStringArray(R.array.days_of_week);

            final String KEY_ITEM_DATE = "menudate";
            final String KEY_DAY = "dayname";
            final String[] dates = formatDates(Data.dates);
            final List<HashMap<String, String>> daysList = new ArrayList<>();
            for (int i = 0; i < mDaysOfWeek.length; i++) {
                HashMap<String, String> dayOfWeek = new HashMap<>();
                dayOfWeek.put(KEY_DAY, mDaysOfWeek[i]);
                dayOfWeek.put(KEY_ITEM_DATE, dates[i]);
                daysList.add(dayOfWeek);
            }

            mDaysOfWeekList.addHeaderView(new View(getActivity()));
            mDaysOfWeekList.addFooterView(new View(getActivity()));
            CustomSodexoWeekMenuAdapter adapter = new CustomSodexoWeekMenuAdapter(daysList);
            mDaysOfWeekList.setAdapter(adapter);

            TextView txtHeaderText = (TextView) view.findViewById(R.id.list_item_menu_header_textview);
            String headerDate = dates[0];
            String headerText = "Menu for the week of: " + headerDate;
            txtHeaderText.setText(headerText);
        }
        else {
            mDaysOfWeekList.setVisibility(View.GONE);
            view.findViewById(R.id.header_layout).setVisibility(View.GONE);
            view.findViewById(R.id.error_text).setVisibility(View.VISIBLE);
        }

        return view;
    }

    private String[] formatDates(String[] dates) {
        SimpleDateFormat fromDate = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat toDate = new SimpleDateFormat("MMMM dd, yyyy");
        String[] formattedDates = new String[7];

        for (int i=0; i< dates.length; i++) {
            try {
                String reformattedDate = toDate.format(fromDate.parse(dates[i]));
                formattedDates[i] = reformattedDate;
            } catch (ParseException e) {
                Log.v("Sodexo Fragment", e.toString());
            }
        }
        return formattedDates;
    }
}




Java Source Code List

edu.hastings.hastingscollege.BuildConfig.java
edu.hastings.hastingscollege.BuildConfig.java
edu.hastings.hastingscollege.MainActivity.java
edu.hastings.hastingscollege.SettingsActivity.java
edu.hastings.hastingscollege.SodexoXmlParser.java
edu.hastings.hastingscollege.SplashActivity.java
edu.hastings.hastingscollege.adapter.ContactsDataModel.java
edu.hastings.hastingscollege.adapter.CustomEContactsAdapter.java
edu.hastings.hastingscollege.adapter.CustomEventsAdapter.java
edu.hastings.hastingscollege.adapter.CustomSodexoWeekMenuAdapter.java
edu.hastings.hastingscollege.adapter.HelperExpandListView.java
edu.hastings.hastingscollege.adapter.TabsPagerAdapter.java
edu.hastings.hastingscollege.connection.Connection.java
edu.hastings.hastingscollege.connection.HttpAuthenticationDialog.java
edu.hastings.hastingscollege.connection.ServiceHandler.java
edu.hastings.hastingscollege.googleanalytics.MyApplication.java
edu.hastings.hastingscollege.map_db.LocationsDB.java
edu.hastings.hastingscollege.model.Data.java
edu.hastings.hastingscollege.model.EventModel.java
edu.hastings.hastingscollege.model.MapLocation.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentAbout.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentAthletics.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentBroncoboard.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentCampusEvents.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentDiningHall.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentEmergencyContacts.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentHome.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentMap.java
edu.hastings.hastingscollege.navdrawerfragments.FragmentTwitter.java
edu.hastings.hastingscollege.tabfragments.BreakfastFragment.java
edu.hastings.hastingscollege.tabfragments.DinnerFragment.java
edu.hastings.hastingscollege.tabfragments.LunchFragment.java
edu.hastings.hastingscollege.tabfragments.SingleMenuItemNutritionFactsActivity.java
edu.hastings.hastingscollege.tabfragments.SodexoMenu.java