Android Open Source - HastingsMobileAndroid Single Menu Item Nutrition Facts Activity






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.tabfragments;
//ww  w.j a va 2  s.co m
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

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

import edu.hastings.hastingscollege.R;
import edu.hastings.hastingscollege.googleanalytics.MyApplication;

public class SingleMenuItemNutritionFactsActivity extends Activity {

    final String KEY_ITEM_NAME = "item_name";
    final String KEY_INGREDIENT = "ingredient";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ScrollView nutritionLayout = (ScrollView) inflater.inflate(R.layout.nutrition_facts_item, null);

        LinearLayout nutritionLinearLayout = (LinearLayout) nutritionLayout.findViewById(R.id.nutritionLayout);

        Intent in = getIntent();
        String[] menuItemKeys = getResources().getStringArray(R.array.sodexo_menu_item_keys);
        String[] menuItemLabels = getResources().getStringArray(R.array.sodexo_menu_item_labels);
        float scale = getResources().getDisplayMetrics().density;
        int dpAsPixels = (int) (6 * scale + 0.5f);

        String itemName = in.getStringExtra(KEY_ITEM_NAME);
        TextView txtHeader = (TextView) nutritionLinearLayout.findViewById(R.id.list_item_menu_header_textview);
        txtHeader.setText(itemName);

        for (int i = 5, j = 0; i < menuItemKeys.length; j++, i++){
            LinearLayout itemAttributeLayout = new LinearLayout(SingleMenuItemNutritionFactsActivity.this);
            itemAttributeLayout.setPadding(dpAsPixels, 0, 0, 0);
            itemAttributeLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

            TextView itemAttributeLabel = new TextView(SingleMenuItemNutritionFactsActivity.this);
            itemAttributeLabel.setText(menuItemLabels[j] + " ");
            itemAttributeLabel.setTypeface(Typeface.DEFAULT_BOLD);
            itemAttributeLabel.setTextColor(Color.parseColor("#5d5d5d"));
            itemAttributeLabel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
            itemAttributeLayout.addView(itemAttributeLabel);

            String itemAttribute = in.getStringExtra(menuItemKeys[i]);
            if (menuItemKeys[i].equals(KEY_INGREDIENT)) {
                LinearLayout ingredientLayout = new LinearLayout(SingleMenuItemNutritionFactsActivity.this);
                ingredientLayout.setPadding(dpAsPixels, 0, 0, 0);
                ingredientLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

                TextView ingredients = new TextView(SingleMenuItemNutritionFactsActivity.this);
                ingredients.setText(itemAttribute);
                ingredients.setTypeface(Typeface.DEFAULT_BOLD);
                ingredients.setTextColor(Color.parseColor("#acacac"));
                ingredients.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                ingredientLayout.addView(ingredients);
                nutritionLinearLayout.addView(itemAttributeLayout);
                nutritionLinearLayout.addView(ingredientLayout);
            }
            else {
                TextView itemAttributeContent = new TextView(SingleMenuItemNutritionFactsActivity.this);
                itemAttributeContent.setText(itemAttribute);
                itemAttributeContent.setTypeface(Typeface.DEFAULT_BOLD);
                itemAttributeContent.setTextColor(Color.parseColor("#acacac"));
                itemAttributeContent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                itemAttributeLayout.addView(itemAttributeContent);
                nutritionLinearLayout.addView(itemAttributeLayout);
            }
        }
        setContentView(nutritionLayout);

        getActionBar().setDisplayHomeAsUpEnabled(true);

        Tracker t = ((MyApplication) getApplication()).getTracker(MyApplication.TrackerName.APP_TRACKER);
        t.setScreenName("Nutrition Facts");
        t.send(new HitBuilders.AppViewBuilder().build());
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        finish();
        return true;
    }
}




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