mirror of
https://github.com/derekbrameyer/MacroDroid.git
synced 2026-07-01 03:54:20 +08:00
New working state...I guess?
This commit is contained in:
@@ -64,6 +64,12 @@
|
||||
android:name=".DayDetailAddFoodMyFoodsTab"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:label="@string/app_name"
|
||||
android:name=".DayDetailAddFoodMyFoodGroupsTab"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:theme="@style/FullHeightDialog"
|
||||
@@ -78,6 +84,12 @@
|
||||
android:name=".DayDetailAddFoodTabActivity"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
<activity
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:label="@string/app_name"
|
||||
android:name=".MyFoodGroupsActivity"
|
||||
android:screenOrientation="portrait" >
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
9
res/drawable/ic_tab_my_food_groups.xml
Normal file
9
res/drawable/ic_tab_my_food_groups.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- When selected, use grey -->
|
||||
<item android:drawable="@drawable/ic_tab_artists_grey" android:state_selected="true"/>
|
||||
<!-- When not selected, use white -->
|
||||
<item android:drawable="@drawable/ic_tab_artists_white"/>
|
||||
|
||||
</selector>
|
||||
11
res/layout/day_detail_add_food_my_food_groups_tab.xml
Normal file
11
res/layout/day_detail_add_food_my_food_groups_tab.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<ListView
|
||||
android:id="@+id/LV_my_food_groups"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -28,7 +28,8 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_add_food_name"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
style="@style/MyMacrosIKnowRightColumnET"
|
||||
android:inputType="textCapWords" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
@@ -39,6 +40,18 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_add_food_serving_size"
|
||||
style="@style/MyMacrosIKnowRightColumnET"
|
||||
android:inputType="text" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/Number_of_Servings" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_add_food_num_servings"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
</TableRow>
|
||||
|
||||
@@ -46,7 +59,7 @@
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/kCal" />
|
||||
android:text="@string/kCal_serving" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_add_food_kCal"
|
||||
@@ -99,7 +112,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/grams"
|
||||
android:text="@string/grams_serving"
|
||||
android:textSize="14sp" />
|
||||
</TableLayout>
|
||||
|
||||
@@ -110,9 +123,9 @@
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/BTN_save"
|
||||
android:id="@+id/BTN_add"
|
||||
style="@style/TwoColumnButtons"
|
||||
android:text="@string/Save" />
|
||||
android:text="@string/Add" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/BTN_cancel"
|
||||
|
||||
@@ -36,6 +36,11 @@
|
||||
style="@style/MainButtons"
|
||||
android:text="@string/main_activity_my_macros" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/BTN_my_food_groups"
|
||||
style="@style/MainButtons"
|
||||
android:text="@string/main_activity_my_food_groups" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/BTN_settings"
|
||||
style="@style/MainButtons"
|
||||
|
||||
27
res/layout/my_food_groups_activity.xml
Normal file
27
res/layout/my_food_groups_activity.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/My_Food_Groups"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/BTN_add"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="@string/Add" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/LV_my_food_groups"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_below="@id/BTN_add" />
|
||||
|
||||
</RelativeLayout>
|
||||
138
res/layout/my_food_groups_list_item.xml
Normal file
138
res/layout/my_food_groups_list_item.xml
Normal file
@@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:paddingTop="5dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:text="ASDTSADFKLJASDFLKASDFJLKSDAFJSLDKFJSDLKFJASDLFKJSADLFKJSDLFKJLKASDJFLSKADJF"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_kCal_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_below="@id/TV_food_groups_name"
|
||||
android:text="@string/my_food_groups_total_kCal_label"
|
||||
android:textSize="12sp"
|
||||
android:gravity="right" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_kCal_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_kCal_label"
|
||||
android:layout_toLeftOf="@id/TV_food_groups_total_kCal_label"
|
||||
android:layout_below="@id/TV_food_groups_name"
|
||||
android:lines="1"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="right"
|
||||
android:text="2500" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_servings_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_kCal_label"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/TV_food_groups_name"
|
||||
android:lines="1"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="left"
|
||||
android:text="2500" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_servings_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_kCal_label"
|
||||
android:layout_toRightOf="@id/TV_food_groups_total_servings_value"
|
||||
android:layout_toLeftOf="@id/TV_food_groups_total_kCal_value"
|
||||
android:layout_below="@id/TV_food_groups_name"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:text="@string/total_servings"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_protein_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/TV_food_groups_total_servings_value"
|
||||
android:text="20"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_protein_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_protein_value"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_toRightOf="@id/TV_food_groups_total_protein_value"
|
||||
android:layout_below="@id/TV_food_groups_total_servings_value"
|
||||
android:text="@string/my_food_groups_total_protein_label"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_carbs_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_protein_value"
|
||||
android:layout_toRightOf="@id/TV_food_groups_total_protein_label"
|
||||
android:layout_below="@id/TV_food_groups_total_servings_value"
|
||||
android:text="1000"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_carbs_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_protein_value"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_toRightOf="@id/TV_food_groups_total_carbs_value"
|
||||
android:layout_below="@id/TV_food_groups_total_servings_value"
|
||||
android:text="@string/my_food_groups_total_carbs_label"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_fat_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_protein_value"
|
||||
android:layout_toRightOf="@id/TV_food_groups_total_carbs_label"
|
||||
android:layout_below="@id/TV_food_groups_total_servings_value"
|
||||
android:text="9001"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_food_groups_total_fat_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBaseline="@id/TV_food_groups_total_protein_value"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_toRightOf="@id/TV_food_groups_total_fat_value"
|
||||
android:layout_below="@id/TV_food_groups_total_servings_value"
|
||||
android:text="@string/my_food_groups_total_fat_label"
|
||||
android:textSize="12sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -9,8 +9,7 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" >
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/BTN_set"
|
||||
@@ -28,8 +27,7 @@
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_above="@id/LL_button_container"
|
||||
android:layout_alignParentTop="true"
|
||||
android:fillViewport="true"
|
||||
android:visibility="gone" >
|
||||
android:fillViewport="true" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
@@ -43,84 +41,219 @@
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredHeaderTV"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/Macros" />
|
||||
android:text="@string/My_Measurements" />
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:text="@string/weight" />
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/my_macros_training_kCal_day" />
|
||||
<EditText
|
||||
android:id="@+id/ET_body_weight_lbs"
|
||||
style="@style/TwoColumnCenteredET" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_training_kCal"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
android:id="@+id/ET_body_weight_kgs"
|
||||
style="@style/TwoColumnCenteredET" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/my_macros_rest_kCal_day" />
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/lbs" />
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/kg" />
|
||||
</TableRow>
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:text="@string/height" />
|
||||
|
||||
<TableRow >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_rest_kCal"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
android:id="@+id/ET_body_height_ins"
|
||||
style="@style/TwoColumnCenteredET" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_body_height_cm"
|
||||
style="@style/TwoColumnCenteredET" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/my_macros_deficit" />
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/in" />
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/cm" />
|
||||
</TableRow>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="10dp" />
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/age"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/gender"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_deficit"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
android:id="@+id/ET_age"
|
||||
style="@style/TwoColumnCenteredET" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/SPNR_gender"
|
||||
style="@style/TwoColumnCenteredET"
|
||||
android:entries="@array/gender" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/my_macros_protein" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_protein"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/years" />
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/my_macros_carbs" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_carbs"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/MyMacrosLeftColumnTL"
|
||||
android:text="@string/my_macros_fat" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_fat"
|
||||
style="@style/MyMacrosIKnowRightColumnET" />
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/RMR" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_RMR"
|
||||
style="@style/CenteredHeaderTV"
|
||||
android:text="@string/RMR"
|
||||
android:color="@android:color/white" />
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/activity_multiplier" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_activity_multiplier"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="50dp"
|
||||
android:layout_marginRight="50dp"
|
||||
android:gravity="center|center_vertical"
|
||||
android:inputType="phone"
|
||||
android:text="1.0"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/BMR" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_BMR"
|
||||
style="@style/CenteredHeaderTV"
|
||||
android:text="@string/BMR"
|
||||
android:color="@android:color/white" />
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/body_fat" />
|
||||
|
||||
<TableRow >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_body_fat"
|
||||
style="@style/ThreeColumnCenteredET" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_body_fat_lbs"
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="27" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_body_fat_kg"
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="12" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="@string/percentage_optional" />
|
||||
|
||||
<TextView
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="@string/lbs" />
|
||||
|
||||
<TextView
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="@string/kg" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/max_deficit" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_max_deficit"
|
||||
style="@style/CenteredHeaderTV"
|
||||
android:text="@string/max_deficit"
|
||||
android:color="@android:color/white" />
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/training_day_kCal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_training_day_kCal"
|
||||
style="@style/CenteredHeaderTV"
|
||||
android:text="@string/training_day_kCal"
|
||||
android:color="@android:color/white" />
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredHeaderTV"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/Macro_Conversions" />
|
||||
|
||||
@@ -157,19 +290,128 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/kCal_g"
|
||||
android:textSize="14sp" />
|
||||
</TableLayout>
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/protein" />
|
||||
|
||||
<TableRow >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_protien_grams_per_pound"
|
||||
style="@style/ThreeColumnCenteredET" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_protein_g"
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="27" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_protein_kCal"
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="12" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="@string/g_per_lb_body" />
|
||||
|
||||
<TextView
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="@string/grams" />
|
||||
|
||||
<TextView
|
||||
style="@style/ThreeColumnCenteredTV"
|
||||
android:text="@string/kCal" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
<TextView
|
||||
style="@style/CenteredSubHeaderTV"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/remaining_carb_fat_split" />
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TableRow >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_percentage_carbs"
|
||||
style="@style/TwoColumnCenteredET" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/ET_percentage_carbs"
|
||||
style="@style/TwoColumnCenteredET" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/percent_carbs" />
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/percent_fat" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_carbs_g"
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="260" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_carbs_kCal"
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="1037" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_fat_g"
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="50" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TV_calculated_fat_kCal"
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="444" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow >
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/grams" />
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/kCal" />
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/grams" />
|
||||
|
||||
<TextView
|
||||
style="@style/TwoColumnCenteredTV"
|
||||
android:text="@string/kCal" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center|center_vertical"
|
||||
android:text="COMING SOON."
|
||||
android:textSize="48sp" />
|
||||
|
||||
</RelativeLayout>
|
||||
9
res/menu/day_detail_menu.xml
Normal file
9
res/menu/day_detail_menu.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/MENU_save_food_group"
|
||||
android:title="Save Food Group"
|
||||
android:titleCondensed="Save"/>
|
||||
|
||||
</menu>
|
||||
@@ -1,3 +1,31 @@
|
||||
Pork Chop
|
||||
1 chop (145 grams)
|
||||
286
|
||||
39
|
||||
0
|
||||
13
|
||||
|
||||
Beef Brisket
|
||||
100 grams
|
||||
277
|
||||
18
|
||||
0
|
||||
22
|
||||
|
||||
Raw Spinach
|
||||
1 cup (30 grams)
|
||||
7
|
||||
1
|
||||
1
|
||||
0
|
||||
|
||||
Wheat Roll
|
||||
1 roll (43 grams)
|
||||
114
|
||||
4
|
||||
22
|
||||
2
|
||||
|
||||
Banana
|
||||
1 medium (7-8", 118g)
|
||||
105
|
||||
|
||||
9
res/values/arrays.xml
Normal file
9
res/values/arrays.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="gender">
|
||||
<item>male</item>
|
||||
<item>female</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
</resources>
|
||||
@@ -2,26 +2,52 @@
|
||||
<resources>
|
||||
|
||||
<string name="hello">Hello World, MainActivity!</string>
|
||||
<string name="activity_multiplier">activity multiplier [1.0-2.0]</string>
|
||||
<string name="age">age</string>
|
||||
<string name="app_name">MacroDroid</string>
|
||||
<string name="body_fat">body fat</string>
|
||||
<string name="gender">gender</string>
|
||||
<string name="weight">weight</string>
|
||||
<string name="height">height</string>
|
||||
<string name="carbs">carbs</string>
|
||||
<string name="cm">cm</string>
|
||||
<string name="deficit">deficit</string>
|
||||
<string name="fat">fat</string>
|
||||
<string name="grams">grams</string>
|
||||
<string name="grams_serving">grams/serving</string>
|
||||
<string name="g_per_lb_body">g/lb. body weight</string>
|
||||
<string name="in">in</string>
|
||||
<string name="kCal">kCal</string>
|
||||
<string name="kCal_serving">kCal/serving</string>
|
||||
<string name="kCal_day">kCal/day</string>
|
||||
<string name="kCal_g">kCal/g</string>
|
||||
<string name="kg">kg</string>
|
||||
<string name="lbs">lbs</string>
|
||||
<string name="max_deficit">max deficit</string>
|
||||
<string name="percentage_optional">% [optional]</string>
|
||||
<string name="percent_carbs">% carbs</string>
|
||||
<string name="percent_fat">% fat</string>
|
||||
<string name="protein">protein</string>
|
||||
<string name="remaining_carb_fat_split">remaining carb/fat split</string>
|
||||
<string name="servings_of">servings of</string>
|
||||
<string name="training_day_kCal">training day kCal</string>
|
||||
<string name="years">years</string>
|
||||
<string name="Add">Add</string>
|
||||
<string name="Add_Food">Add Food</string>
|
||||
<string name="BMR">BMR</string>
|
||||
<string name="Cancel">Cancel</string>
|
||||
<string name="Import">Import</string>
|
||||
<string name="Macros">Macros</string>
|
||||
<string name="Macro_Conversions">Macro Conversions</string>
|
||||
<string name="Measurements">Measurements</string>
|
||||
<string name="My_Food_Groups">My Food Groups</string>
|
||||
<string name="My_Foods">My Foods</string>
|
||||
<string name="My_Measurements">My Measurements</string>
|
||||
<string name="Name">Name</string>
|
||||
<string name="Number_of_Servings">Number of Servings</string>
|
||||
<string name="RMR">RMR</string>
|
||||
<string name="Save">Save</string>
|
||||
<string name="total_servings">total servings</string>
|
||||
<string name="Serving_Size">Serving Size</string>
|
||||
<string name="Set">Set</string>
|
||||
<string name="Todays_Foods">Today\'s Foods</string>
|
||||
@@ -31,7 +57,12 @@
|
||||
<string name="main_activity_previous">Previous</string>
|
||||
<string name="main_activity_my_foods">My Foods</string>
|
||||
<string name="main_activity_my_macros">My Macros</string>
|
||||
<string name="main_activity_my_food_groups">My Food Groups</string>
|
||||
<string name="main_activity_settings">Settings/Info/FAQ</string>
|
||||
<string name="my_food_groups_total_kCal_label">total kCal</string>
|
||||
<string name="my_food_groups_total_protein_label">g protein,</string>
|
||||
<string name="my_food_groups_total_carbs_label">g carbs,</string>
|
||||
<string name="my_food_groups_total_fat_label">g fat</string>
|
||||
<string name="my_foods_list_item_kCal_label">kCal</string>
|
||||
<string name="my_foods_list_item_protein_label">g protein,</string>
|
||||
<string name="my_foods_list_item_carbs_label">g carbs,</string>
|
||||
|
||||
@@ -23,6 +23,24 @@
|
||||
<item name="android:inputType">phone</item>
|
||||
</style>
|
||||
|
||||
<style name="TwoColumnCenteredTV">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
</style>
|
||||
|
||||
<style name="TwoColumnCenteredET">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:gravity">center|center_vertical</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
<item name="android:maxLines">1</item>
|
||||
<item name="android:inputType">phone</item>
|
||||
</style>
|
||||
|
||||
<style name="MyMacrosIKnowRightColumnET">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
@@ -68,6 +86,14 @@
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<style name="CenteredSubHeaderTV">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<style name="MainButtons">
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
@@ -86,8 +112,10 @@
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:layout_marginLeft">10dp</item>
|
||||
<item name="android:layout_marginRight">10dp</item>
|
||||
<item name="android:layout_marginTop">1dp</item>
|
||||
<item name="android:layout_marginBottom">1dp</item>
|
||||
<item name="android:layout_marginLeft">1dp</item>
|
||||
<item name="android:layout_marginRight">1dp</item>
|
||||
<item name="android:paddingBottom">15dp</item>
|
||||
<item name="android:paddingLeft">15dp</item>
|
||||
<item name="android:paddingRight">15dp</item>
|
||||
|
||||
@@ -23,7 +23,9 @@ public class ADay implements Comparable<ADay> {
|
||||
public ADay(Calendar date, boolean isTraining) {
|
||||
this.date = date;
|
||||
this.isTraining = isTraining;
|
||||
foods = new ArrayList<Pair<Float, AFood>>();
|
||||
this.foods = new ArrayList<Pair<Float, AFood>>();
|
||||
this.weight = 0.0f;
|
||||
this.height = 0.0f;
|
||||
}
|
||||
|
||||
public float getWeight() {
|
||||
|
||||
119
src/com/doomonafireball/macrodroid/AFoodGroup.java
Normal file
119
src/com/doomonafireball/macrodroid/AFoodGroup.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package com.doomonafireball.macrodroid;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import android.util.Pair;
|
||||
|
||||
public class AFoodGroup implements Comparable<AFoodGroup> {
|
||||
public long id;
|
||||
private ArrayList<Pair<Float, AFood>> foods;
|
||||
private String name;
|
||||
private Float totalKCal;
|
||||
private Float totalProtein;
|
||||
private Float totalCarbs;
|
||||
private Float totalFat;
|
||||
|
||||
// TODO Array of pictures
|
||||
|
||||
public AFoodGroup(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public AFoodGroup() {
|
||||
this.name = "";
|
||||
this.foods = new ArrayList<Pair<Float, AFood>>();
|
||||
recalculateValues();
|
||||
}
|
||||
|
||||
public AFoodGroup(String name, ArrayList<Pair<Float, AFood>> foods) {
|
||||
this.name = name;
|
||||
this.foods = foods;
|
||||
recalculateValues();
|
||||
}
|
||||
|
||||
public Float getTotalKCal() {
|
||||
return totalKCal;
|
||||
}
|
||||
|
||||
public Float getTotalProtein() {
|
||||
return totalProtein;
|
||||
}
|
||||
|
||||
public Float getTotalCarbs() {
|
||||
return totalCarbs;
|
||||
}
|
||||
|
||||
public Float getTotalFat() {
|
||||
return totalFat;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<Pair<Float, AFood>> getFoods() {
|
||||
return foods;
|
||||
}
|
||||
|
||||
public void setFoods(ArrayList<Pair<Float, AFood>> foods) {
|
||||
this.foods = foods;
|
||||
recalculateValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AFoodGroup arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
if ((this.getName() != null) && (arg0.getName() != null)) {
|
||||
return arg0.getName().compareTo(this.getName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void recalculateValues() {
|
||||
totalKCal = 0.0f;
|
||||
totalProtein = 0.0f;
|
||||
totalCarbs = 0.0f;
|
||||
totalFat = 0.0f;
|
||||
if (this.foods != null) {
|
||||
for (int i = 0; i < foods.size(); i++) {
|
||||
Pair<Float, AFood> currPair = foods.get(i);
|
||||
Float currServings = currPair.first;
|
||||
AFood currFood = currPair.second;
|
||||
totalKCal += currServings * currFood.getFoodKCal();
|
||||
totalProtein += currServings * currFood.getFoodGramsProtein();
|
||||
totalCarbs += currServings * currFood.getFoodGramsCarbs();
|
||||
totalFat += currServings * currFood.getFoodGramsFat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String retVal = "";
|
||||
retVal += "id: " + id + "\n";
|
||||
retVal += "name: " + this.name + "\n";
|
||||
retVal += "kCal: " + this.totalKCal + "\n";
|
||||
retVal += "protein: " + this.totalProtein + "\n";
|
||||
retVal += "carbs: " + this.totalCarbs + "\n";
|
||||
retVal += "fat: " + this.totalFat + "\n";
|
||||
retVal += "foods:" + "\n";
|
||||
if (this.foods != null) {
|
||||
for (int i = 0; i < foods.size(); i++) {
|
||||
Pair<Float, AFood> pair = foods.get(i);
|
||||
Float serving = pair.first;
|
||||
AFood food = pair.second;
|
||||
retVal += "servings: " + Float.toString(serving) + ", food: "
|
||||
+ food.getFoodName() + "\n";
|
||||
}
|
||||
} else {
|
||||
retVal += "null!" + "\n";
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,24 @@ package com.doomonafireball.macrodroid;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -98,7 +103,7 @@ public class DayDetailActivity extends Activity {
|
||||
|
||||
private void renderDetailInfo() {
|
||||
// First, fetch existing ADay object
|
||||
fetchExistingADay();
|
||||
mADay = application.safelyFetchExistingADay(mCalendar);
|
||||
|
||||
refreshViews();
|
||||
}
|
||||
@@ -155,7 +160,88 @@ public class DayDetailActivity extends Activity {
|
||||
+ Float.toString(application.macrosPrefs.getFloat(
|
||||
Tags.MACROS_FAT, 0.0f)) + "g");
|
||||
|
||||
// TODO Set click listeners
|
||||
// Color text red if over
|
||||
if (totalKCal > application.macrosPrefs.getFloat(
|
||||
Tags.MACROS_TRAINING_KCAL, 0.0f)) {
|
||||
caloriesTV.setTextColor(Color.RED);
|
||||
}
|
||||
if (totalProtein > application.macrosPrefs.getFloat(
|
||||
Tags.MACROS_PROTEIN, 0.0f)) {
|
||||
currentProteinTV.setTextColor(Color.RED);
|
||||
}
|
||||
if (totalCarbs > application.macrosPrefs.getFloat(Tags.MACROS_CARBS,
|
||||
0.0f)) {
|
||||
currentCarbsTV.setTextColor(Color.RED);
|
||||
}
|
||||
if (totalFat > application.macrosPrefs.getFloat(Tags.MACROS_FAT, 0.0f)) {
|
||||
currentFatTV.setTextColor(Color.RED);
|
||||
}
|
||||
|
||||
// Buttons
|
||||
weightBTN.setText(Float.toString(mADay.getWeight()));
|
||||
weightBTN.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
|
||||
alert.setTitle("Weight");
|
||||
// Set an EditText view to get user input
|
||||
final EditText input = new EditText(mContext);
|
||||
input.setText("100.0");
|
||||
alert.setView(input);
|
||||
alert.setPositiveButton("Set",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog,
|
||||
int whichButton) {
|
||||
Float weight = Float.parseFloat(input.getText()
|
||||
.toString());
|
||||
mADay.setWeight(weight);
|
||||
application.saveDay(mADay);
|
||||
dialog.dismiss();
|
||||
renderDetailInfo();
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton("Cancel",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog,
|
||||
int whichButton) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
alert.show();
|
||||
}
|
||||
});
|
||||
heightBTN.setText(Float.toString(mADay.getHeight()));
|
||||
heightBTN.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
|
||||
alert.setTitle("Height");
|
||||
// Set an EditText view to get user input
|
||||
final EditText input = new EditText(mContext);
|
||||
input.setText("100.0");
|
||||
alert.setView(input);
|
||||
alert.setPositiveButton("Set",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog,
|
||||
int whichButton) {
|
||||
Float height = Float.parseFloat(input.getText()
|
||||
.toString());
|
||||
mADay.setHeight(height);
|
||||
application.saveDay(mADay);
|
||||
dialog.dismiss();
|
||||
renderDetailInfo();
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton("Cancel",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog,
|
||||
int whichButton) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
alert.show();
|
||||
}
|
||||
});
|
||||
addFoodBTN.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -191,30 +277,44 @@ public class DayDetailActivity extends Activity {
|
||||
mFoodsLV.setOnItemClickListener(mFoodsItemClickListener);
|
||||
}
|
||||
|
||||
private void fetchExistingADay() {
|
||||
if (application.hasData(mContext)) {
|
||||
// Try to find the ADay object
|
||||
List<ADay> possibleCurrDays = application
|
||||
.getADayForCalendar(mCalendar);
|
||||
Log.d(Tags.LOG_TAG,
|
||||
"possibleCurrDays length: " + possibleCurrDays.size());
|
||||
if (!possibleCurrDays.isEmpty()) {
|
||||
// We have a current object
|
||||
Log.d(Tags.LOG_TAG, "We have a current day for today.");
|
||||
mADay = possibleCurrDays.get(0);
|
||||
Log.d(Tags.LOG_TAG, "Got day:\n" + mADay.toString());
|
||||
} else {
|
||||
// Instantiate a new object
|
||||
Log.d(Tags.LOG_TAG, "We don't have a current day for today.");
|
||||
mADay = new ADay(mCalendar, true);
|
||||
application.saveDay(mADay);
|
||||
private void saveToFoodGroup() {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
|
||||
alert.setTitle("Food Group Name");
|
||||
// Set an EditText view to get user input
|
||||
final EditText input = new EditText(mContext);
|
||||
input.setText("");
|
||||
alert.setView(input);
|
||||
alert.setPositiveButton("Save", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
String name = input.getText().toString();
|
||||
AFoodGroup foodGroup = new AFoodGroup(name, mADay.getFoods());
|
||||
application.saveFoodGroup(foodGroup);
|
||||
dialog.dismiss();
|
||||
}
|
||||
} else {
|
||||
// Instantiate a new object
|
||||
Log.d(Tags.LOG_TAG,
|
||||
"We don't even have data! AND We don't have a current day.");
|
||||
mADay = new ADay(mCalendar, true);
|
||||
application.saveDay(mADay);
|
||||
});
|
||||
alert.setNegativeButton("Cancel",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
alert.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.day_detail_menu, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.MENU_save_food_group:
|
||||
saveToFoodGroup();
|
||||
return false;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.doomonafireball.macrodroid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class DayDetailAddFoodMyFoodGroupsTab extends Activity {
|
||||
private MacroDroidApplication application;
|
||||
private Context mContext;
|
||||
private ListView myFoodGroupsLV;
|
||||
private Calendar mCalendar;
|
||||
private MyFoodGroupsAdapter myFoodGroupsAdapter;
|
||||
private ArrayList<AFoodGroup> myFoodGroupsArrayList;
|
||||
private ADay mADay;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.day_detail_add_food_my_food_groups_tab);
|
||||
|
||||
application = ((MacroDroidApplication) getApplication());
|
||||
mContext = this;
|
||||
|
||||
// Parse the extras
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
int mDate = extras.getInt("date");
|
||||
int mMonth = extras.getInt("month");
|
||||
int mYear = extras.getInt("year");
|
||||
mCalendar = Calendar.getInstance();
|
||||
mCalendar.set(Calendar.DATE, mDate);
|
||||
mCalendar.set(Calendar.MONTH, mMonth);
|
||||
mCalendar.set(Calendar.YEAR, mYear);
|
||||
} else {
|
||||
// TODO Something went wrong (this should never happen)
|
||||
}
|
||||
|
||||
myFoodGroupsLV = (ListView) findViewById(R.id.LV_my_food_groups);
|
||||
|
||||
mADay = application.safelyFetchExistingADay(mCalendar);
|
||||
refreshList();
|
||||
|
||||
myFoodGroupsLV.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> av, View v, int position,
|
||||
long id) {
|
||||
final AFoodGroup selectedFoodGroup = (AFoodGroup) myFoodGroupsAdapter
|
||||
.getItem(position);
|
||||
|
||||
// Do something with value!
|
||||
ArrayList<Pair<Float, AFood>> mFoods = mADay.getFoods();
|
||||
ArrayList<Pair<Float, AFood>> selectedFoods = selectedFoodGroup
|
||||
.getFoods();
|
||||
mFoods.addAll(selectedFoods);
|
||||
mADay.setFoods(mFoods);
|
||||
application.saveDay(mADay);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshList() {
|
||||
if (application.hasFoodGroupData(mContext)) {
|
||||
List<AFoodGroup> tempList = application.getFoodGroupsFromDb();
|
||||
myFoodGroupsArrayList = new ArrayList<AFoodGroup>();
|
||||
for (int i = 0; i < tempList.size(); i++) {
|
||||
myFoodGroupsArrayList.add(tempList.get(i));
|
||||
}
|
||||
myFoodGroupsAdapter = new MyFoodGroupsAdapter(mContext,
|
||||
myFoodGroupsArrayList);
|
||||
myFoodGroupsLV.setAdapter(myFoodGroupsAdapter);
|
||||
} else {
|
||||
// No data!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class DayDetailAddFoodMyFoodsTab extends Activity {
|
||||
|
||||
myFoodsLV = (ListView) findViewById(R.id.LV_my_foods);
|
||||
|
||||
fetchExistingADay();
|
||||
mADay = application.safelyFetchExistingADay(mCalendar);
|
||||
refreshList();
|
||||
|
||||
myFoodsLV.setOnItemClickListener(new OnItemClickListener() {
|
||||
@@ -81,7 +81,6 @@ public class DayDetailAddFoodMyFoodsTab extends Activity {
|
||||
mFoods.add(new Pair<Float, AFood>(servingsValue, selectedFood));
|
||||
mADay.setFoods(mFoods);
|
||||
application.saveDay(mADay);
|
||||
// Just changing stuff to re-run
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@@ -97,30 +96,6 @@ public class DayDetailAddFoodMyFoodsTab extends Activity {
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchExistingADay() {
|
||||
if (application.hasData(mContext)) {
|
||||
// Try to find the ADay object
|
||||
List<ADay> possibleCurrDays = application
|
||||
.getADayForCalendar(mCalendar);
|
||||
if (!possibleCurrDays.isEmpty()) {
|
||||
// We have a current object
|
||||
Log.d(Tags.LOG_TAG, "We have a current day for today.");
|
||||
mADay = possibleCurrDays.get(0);
|
||||
} else {
|
||||
// Instantiate a new object
|
||||
Log.d(Tags.LOG_TAG, "We don't have a current day for today.");
|
||||
mADay = new ADay(mCalendar, true);
|
||||
application.saveDay(mADay);
|
||||
}
|
||||
} else {
|
||||
// Instantiate a new object
|
||||
Log.d(Tags.LOG_TAG,
|
||||
"We don't even have data! AND We don't have a current day.");
|
||||
mADay = new ADay(mCalendar, true);
|
||||
application.saveDay(mADay);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshList() {
|
||||
myFoodsArrayList = application.getAllFoods();
|
||||
myFoodsAdapter = new MyFoodsAdapter(mContext, myFoodsArrayList);
|
||||
|
||||
@@ -1,12 +1,31 @@
|
||||
package com.doomonafireball.macrodroid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class DayDetailAddFoodNewFoodTab extends Activity {
|
||||
private MacroDroidApplication application;
|
||||
private Context mContext;
|
||||
private EditText nameET;
|
||||
private EditText servingSizeET;
|
||||
private EditText numServingsET;
|
||||
private EditText kCalET;
|
||||
private EditText proteinET;
|
||||
private EditText carbsET;
|
||||
private EditText fatET;
|
||||
private Button addBTN;
|
||||
private Button cancelBTN;
|
||||
private Calendar mCalendar;
|
||||
private ADay mADay;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
@@ -16,5 +35,70 @@ public class DayDetailAddFoodNewFoodTab extends Activity {
|
||||
|
||||
application = ((MacroDroidApplication) getApplication());
|
||||
mContext = this;
|
||||
|
||||
// Parse the extras
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
int mDate = extras.getInt("date");
|
||||
int mMonth = extras.getInt("month");
|
||||
int mYear = extras.getInt("year");
|
||||
mCalendar = Calendar.getInstance();
|
||||
mCalendar.set(Calendar.DATE, mDate);
|
||||
mCalendar.set(Calendar.MONTH, mMonth);
|
||||
mCalendar.set(Calendar.YEAR, mYear);
|
||||
} else {
|
||||
// TODO Something went wrong (this should never happen)
|
||||
}
|
||||
|
||||
mADay = application.safelyFetchExistingADay(mCalendar);
|
||||
|
||||
nameET = (EditText) findViewById(R.id.ET_add_food_name);
|
||||
servingSizeET = (EditText) findViewById(R.id.ET_add_food_serving_size);
|
||||
numServingsET = (EditText) findViewById(R.id.ET_add_food_num_servings);
|
||||
kCalET = (EditText) findViewById(R.id.ET_add_food_kCal);
|
||||
proteinET = (EditText) findViewById(R.id.ET_add_food_protein);
|
||||
carbsET = (EditText) findViewById(R.id.ET_add_food_carbs);
|
||||
fatET = (EditText) findViewById(R.id.ET_add_food_fat);
|
||||
addBTN = (Button) findViewById(R.id.BTN_add);
|
||||
cancelBTN = (Button) findViewById(R.id.BTN_cancel);
|
||||
|
||||
addBTN.setOnClickListener(addOnClickListener);
|
||||
cancelBTN.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private OnClickListener addOnClickListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// Perist to saved foods
|
||||
AFood food = new AFood();
|
||||
food.setFoodName(nameET.getText().toString());
|
||||
food.setFoodServingSize(servingSizeET.getText().toString());
|
||||
food.setFoodKCal(Float.parseFloat(kCalET.getText().toString()));
|
||||
food.setFoodGramsProtein(Float.parseFloat(proteinET.getText()
|
||||
.toString()));
|
||||
food.setFoodGramsCarbs(Float.parseFloat(carbsET.getText()
|
||||
.toString()));
|
||||
food.setFoodGramsFat(Float.parseFloat(fatET.getText().toString()));
|
||||
|
||||
application.addFoodToInternalStorage(food);
|
||||
|
||||
// Persist to ADay object
|
||||
Float servingsValue = Float.parseFloat(numServingsET.getText()
|
||||
.toString());
|
||||
ArrayList<Pair<Float, AFood>> mFoods = mADay.getFoods();
|
||||
if (mFoods == null) {
|
||||
mFoods = new ArrayList<Pair<Float, AFood>>();
|
||||
}
|
||||
mFoods.add(new Pair<Float, AFood>(servingsValue, food));
|
||||
mADay.setFoods(mFoods);
|
||||
application.saveDay(mADay);
|
||||
|
||||
finish();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -55,9 +55,20 @@ public class DayDetailAddFoodTabActivity extends TabActivity {
|
||||
tabHost.addTab(spec);
|
||||
|
||||
// Do the same for the other tabs
|
||||
intent = new Intent().setClass(this,
|
||||
DayDetailAddFoodMyFoodGroupsTab.class);
|
||||
intent.putExtras(extras);
|
||||
|
||||
spec = tabHost
|
||||
.newTabSpec("my_food_groups")
|
||||
.setIndicator("My Food Groups",
|
||||
res.getDrawable(R.drawable.ic_tab_my_food_groups))
|
||||
.setContent(intent);
|
||||
tabHost.addTab(spec);
|
||||
|
||||
intent = new Intent().setClass(this, DayDetailAddFoodNewFoodTab.class);
|
||||
intent.putExtras(extras);
|
||||
|
||||
|
||||
spec = tabHost
|
||||
.newTabSpec("new_food")
|
||||
.setIndicator("New Food",
|
||||
|
||||
@@ -42,6 +42,8 @@ public class Db4oHelper {
|
||||
// Configure the behavior of the database
|
||||
EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
|
||||
configuration.common().objectClass(ADay.class).cascadeOnUpdate(true);
|
||||
configuration.common().objectClass(AFoodGroup.class)
|
||||
.cascadeOnUpdate(true);
|
||||
// configuration.common().objectClass(ADay.class).objectField("id")
|
||||
// .indexed(true);
|
||||
return configuration;
|
||||
@@ -64,6 +66,14 @@ public class Db4oHelper {
|
||||
new File(db4oDBFullPath(mContext)).delete();
|
||||
}
|
||||
|
||||
public void saveFoodGroup(AFoodGroup foodGroup) {
|
||||
if (foodGroup.id == 0) {
|
||||
foodGroup.id = getNextId();
|
||||
}
|
||||
db().store(foodGroup);
|
||||
db().commit();
|
||||
}
|
||||
|
||||
public void saveDay(ADay day) {
|
||||
if (day.id == 0) {
|
||||
day.id = getNextId();
|
||||
@@ -72,6 +82,14 @@ public class Db4oHelper {
|
||||
db().commit();
|
||||
}
|
||||
|
||||
public void deleteFoodGroup(long id) {
|
||||
ObjectSet<AFoodGroup> result = fetchFoodGroupsById(id);
|
||||
while (result.hasNext()) {
|
||||
db().delete((AFoodGroup) result.next());
|
||||
}
|
||||
db().commit();
|
||||
}
|
||||
|
||||
public void deleteDay(long id) {
|
||||
ObjectSet<ADay> result = fetchDaysById(id);
|
||||
while (result.hasNext()) {
|
||||
@@ -80,6 +98,15 @@ public class Db4oHelper {
|
||||
db().commit();
|
||||
}
|
||||
|
||||
public AFoodGroup fetchFoodGroupById(long id) {
|
||||
ObjectSet<AFoodGroup> result = fetchFoodGroupsById(id);
|
||||
if (result.hasNext()) {
|
||||
return (AFoodGroup) result.next();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ADay fetchDayById(long id) {
|
||||
ObjectSet<ADay> result = fetchDaysById(id);
|
||||
if (result.hasNext()) {
|
||||
@@ -89,11 +116,20 @@ public class Db4oHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public int countFoodGroups(long id) {
|
||||
ObjectSet<AFoodGroup> foodGroups = fetchFoodGroupsById(id);
|
||||
return foodGroups == null ? 0 : foodGroups.size();
|
||||
}
|
||||
|
||||
public int countDays(long id) {
|
||||
ObjectSet<ADay> days = fetchDaysById(id);
|
||||
return days == null ? 0 : days.size();
|
||||
}
|
||||
|
||||
public List<AFoodGroup> fetchAllFoodGroupRows() {
|
||||
return db().query(AFoodGroup.class);
|
||||
}
|
||||
|
||||
public List<ADay> fetchAllDayRows() {
|
||||
return db().query(ADay.class);
|
||||
}
|
||||
@@ -124,6 +160,12 @@ public class Db4oHelper {
|
||||
return result;
|
||||
}
|
||||
|
||||
private ObjectSet<AFoodGroup> fetchFoodGroupsById(long id) {
|
||||
AFoodGroup foodGroup = new AFoodGroup(id);
|
||||
foodGroup.id = id;
|
||||
return db().queryByExample(foodGroup);
|
||||
}
|
||||
|
||||
private ObjectSet<ADay> fetchDaysById(long id) {
|
||||
ADay day = new ADay(id);
|
||||
day.id = id;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MacroDroidApplication extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasData(Context ctx) {
|
||||
public boolean hasDayData(Context ctx) {
|
||||
dbHelper = new Db4oHelper(ctx);
|
||||
if (dbHelper.fetchAllDayRows().isEmpty()) {
|
||||
return false;
|
||||
@@ -50,6 +50,18 @@ public class MacroDroidApplication extends Application {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFoodGroupData(Context ctx) {
|
||||
dbHelper = new Db4oHelper(ctx);
|
||||
if (dbHelper.fetchAllFoodGroupRows() == null) {
|
||||
return true;
|
||||
}
|
||||
if (dbHelper.fetchAllFoodGroupRows().isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteDatabase() {
|
||||
dbHelper.deleteDatabase();
|
||||
@@ -59,46 +71,84 @@ public class MacroDroidApplication extends Application {
|
||||
Log.d(Tags.LOG_TAG, "Saving day: \n" + day.toString());
|
||||
dbHelper.saveDay(day);
|
||||
}
|
||||
|
||||
public void saveFoodGroup(AFoodGroup foodGroup) {
|
||||
Log.d(Tags.LOG_TAG, "Saving food group: \n" + foodGroup.toString());
|
||||
dbHelper.saveFoodGroup(foodGroup);
|
||||
}
|
||||
|
||||
public void deleteFoodGroup(AFoodGroup foodGroup) {
|
||||
dbHelper.deleteFoodGroup(foodGroup.id);
|
||||
}
|
||||
|
||||
public List<ADay> getDaysFromDb() {
|
||||
return dbHelper.fetchAllDayRows();
|
||||
}
|
||||
|
||||
public List<AFoodGroup> getFoodGroupsFromDb() {
|
||||
return dbHelper.fetchAllFoodGroupRows();
|
||||
}
|
||||
|
||||
public List<ADay> getADayForCalendar(Calendar cal) {
|
||||
return dbHelper.fetchFoodsForDate(cal);
|
||||
}
|
||||
|
||||
public ADay safelyFetchExistingADay(Calendar calendar) {
|
||||
if (hasDayData(this)) {
|
||||
// Try to find the ADay object
|
||||
List<ADay> possibleCurrDays = getADayForCalendar(calendar);
|
||||
if (!possibleCurrDays.isEmpty()) {
|
||||
// We have a current object
|
||||
Log.d(Tags.LOG_TAG, "We have a current day for today.");
|
||||
return possibleCurrDays.get(0);
|
||||
} else {
|
||||
// Instantiate a new object
|
||||
Log.d(Tags.LOG_TAG, "We don't have a current day for today.");
|
||||
ADay retDay = new ADay(calendar, true);
|
||||
saveDay(retDay);
|
||||
return retDay;
|
||||
}
|
||||
} else {
|
||||
// Instantiate a new object
|
||||
Log.d(Tags.LOG_TAG,
|
||||
"We don't even have data! AND We don't have a current day.");
|
||||
ADay retDay = new ADay(calendar, true);
|
||||
saveDay(retDay);
|
||||
return retDay;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<AFood> getAllFoods() {
|
||||
byte[] allFoodsByteArray = readInternalStoragePrivate(Tags.MY_FOODS_FILENAME);
|
||||
String allFoodsRaw = new String(allFoodsByteArray);
|
||||
String[] allFoods = allFoodsRaw.split("\\r?\\n");
|
||||
|
||||
|
||||
// Parse the String array into an ArrayList<AFood>
|
||||
ArrayList<AFood> allFoodsArrayList = new ArrayList<AFood>();
|
||||
if (allFoods != null) {
|
||||
if (allFoods.length > 5) {
|
||||
for (int i = 0; i < allFoods.length; i += 7) {
|
||||
AFood food = new AFood();
|
||||
ArrayList<AFood> allFoodsArrayList = new ArrayList<AFood>();
|
||||
if (allFoods != null) {
|
||||
if (allFoods.length > 5) {
|
||||
for (int i = 0; i < allFoods.length; i += 7) {
|
||||
AFood food = new AFood();
|
||||
|
||||
Log.d(Tags.LOG_TAG, "Name: " + allFoods[i]);
|
||||
Log.d(Tags.LOG_TAG, "Serving size: " + allFoods[i + 1]);
|
||||
Log.d(Tags.LOG_TAG, "kCal: " + allFoods[i + 2]);
|
||||
Log.d(Tags.LOG_TAG, "Protein: " + allFoods[i + 3]);
|
||||
Log.d(Tags.LOG_TAG, "Carbs: " + allFoods[i + 4]);
|
||||
Log.d(Tags.LOG_TAG, "Fat: " + allFoods[i + 5]);
|
||||
Log.d(Tags.LOG_TAG, "Name: " + allFoods[i]);
|
||||
Log.d(Tags.LOG_TAG, "Serving size: " + allFoods[i + 1]);
|
||||
Log.d(Tags.LOG_TAG, "kCal: " + allFoods[i + 2]);
|
||||
Log.d(Tags.LOG_TAG, "Protein: " + allFoods[i + 3]);
|
||||
Log.d(Tags.LOG_TAG, "Carbs: " + allFoods[i + 4]);
|
||||
Log.d(Tags.LOG_TAG, "Fat: " + allFoods[i + 5]);
|
||||
|
||||
food.setFoodName(allFoods[i]);
|
||||
food.setFoodServingSize(allFoods[i + 1]);
|
||||
food.setFoodKCal(Float.parseFloat(allFoods[i + 2]));
|
||||
food.setFoodGramsProtein(Float.parseFloat(allFoods[i + 3]));
|
||||
food.setFoodGramsCarbs(Float.parseFloat(allFoods[i + 4]));
|
||||
food.setFoodGramsFat(Float.parseFloat(allFoods[i + 5]));
|
||||
food.setFoodName(allFoods[i]);
|
||||
food.setFoodServingSize(allFoods[i + 1]);
|
||||
food.setFoodKCal(Float.parseFloat(allFoods[i + 2]));
|
||||
food.setFoodGramsProtein(Float.parseFloat(allFoods[i + 3]));
|
||||
food.setFoodGramsCarbs(Float.parseFloat(allFoods[i + 4]));
|
||||
food.setFoodGramsFat(Float.parseFloat(allFoods[i + 5]));
|
||||
|
||||
allFoodsArrayList.add(food);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allFoodsArrayList.add(food);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allFoodsArrayList;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public class MainActivity extends Activity {
|
||||
private Button previousBTN;
|
||||
private Button myFoodsBTN;
|
||||
private Button myMacrosBTN;
|
||||
private Button myFoodGroupsBTN;
|
||||
private Button settingsBTN;
|
||||
private Context mContext;
|
||||
private MacroDroidApplication application;
|
||||
@@ -37,6 +38,7 @@ public class MainActivity extends Activity {
|
||||
previousBTN = (Button) findViewById(R.id.BTN_previous);
|
||||
myFoodsBTN = (Button) findViewById(R.id.BTN_my_foods);
|
||||
myMacrosBTN = (Button) findViewById(R.id.BTN_my_macros);
|
||||
myFoodGroupsBTN = (Button) findViewById(R.id.BTN_my_food_groups);
|
||||
settingsBTN = (Button) findViewById(R.id.BTN_settings);
|
||||
|
||||
todayBTN.setOnClickListener(new OnClickListener() {
|
||||
@@ -90,6 +92,13 @@ public class MainActivity extends Activity {
|
||||
MyMacrosActivity.class));
|
||||
}
|
||||
});
|
||||
myFoodGroupsBTN.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(MainActivity.this,
|
||||
MyFoodGroupsActivity.class));
|
||||
}
|
||||
});
|
||||
settingsBTN.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
100
src/com/doomonafireball/macrodroid/MyFoodGroupsActivity.java
Normal file
100
src/com/doomonafireball/macrodroid/MyFoodGroupsActivity.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.doomonafireball.macrodroid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class MyFoodGroupsActivity extends Activity {
|
||||
private Button addBTN;
|
||||
private ListView myFoodGroupsLV;
|
||||
private MyFoodGroupsAdapter myFoodGroupsAdapter;
|
||||
private MacroDroidApplication application;
|
||||
private Context mContext;
|
||||
private ArrayList<AFoodGroup> myFoodGroupsArrayList;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.my_food_groups_activity);
|
||||
|
||||
application = ((MacroDroidApplication) getApplication());
|
||||
mContext = this;
|
||||
|
||||
addBTN = (Button) findViewById(R.id.BTN_add);
|
||||
myFoodGroupsLV = (ListView) findViewById(R.id.LV_my_food_groups);
|
||||
|
||||
addBTN.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
// startActivity(new Intent(MyFoodGroupsActivity.this,
|
||||
// MyFoodGroupsAddActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
refreshList();
|
||||
|
||||
myFoodGroupsLV.setOnItemLongClickListener(myFoodsItemLongClickListener);
|
||||
}
|
||||
|
||||
private OnItemLongClickListener myFoodsItemLongClickListener = new OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> a, View v, int position,
|
||||
long id) {
|
||||
// TODO Auto-generated method stub
|
||||
final AFoodGroup selectedFoodGroup = (AFoodGroup) myFoodGroupsAdapter
|
||||
.getItem(position);
|
||||
|
||||
final CharSequence[] items = { "Delete" };
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
builder.setTitle("Options");
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
if (item == 0) {
|
||||
// Delete this food
|
||||
application.deleteFoodGroup(selectedFoodGroup);
|
||||
refreshList();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private void refreshList() {
|
||||
if (application.hasFoodGroupData(mContext)) {
|
||||
List<AFoodGroup> tempList = application
|
||||
.getFoodGroupsFromDb();
|
||||
myFoodGroupsArrayList = new ArrayList<AFoodGroup>();
|
||||
for (int i = 0; i < tempList.size(); i++) {
|
||||
myFoodGroupsArrayList.add(tempList.get(i));
|
||||
}
|
||||
myFoodGroupsAdapter = new MyFoodGroupsAdapter(mContext,
|
||||
myFoodGroupsArrayList);
|
||||
myFoodGroupsLV.setAdapter(myFoodGroupsAdapter);
|
||||
} else {
|
||||
// No data!
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
63
src/com/doomonafireball/macrodroid/MyFoodGroupsAdapter.java
Normal file
63
src/com/doomonafireball/macrodroid/MyFoodGroupsAdapter.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package com.doomonafireball.macrodroid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class MyFoodGroupsAdapter extends BaseAdapter {
|
||||
private ArrayList<AFoodGroup> items;
|
||||
private Context mContext;
|
||||
|
||||
public MyFoodGroupsAdapter(Context context, ArrayList<AFoodGroup> items) {
|
||||
super();
|
||||
this.mContext = context;
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return items.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
// TODO Auto-generated method stub
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
|
||||
convertView = inflater.inflate(R.layout.my_food_groups_list_item, parent, false);
|
||||
}
|
||||
TextView nameTV = (TextView) convertView.findViewById(R.id.TV_food_groups_name);
|
||||
TextView kCalTV = (TextView) convertView.findViewById(R.id.TV_food_groups_total_kCal_value);
|
||||
TextView servingSizeTV = (TextView) convertView.findViewById(R.id.TV_food_groups_total_servings_value);
|
||||
TextView proteinTV = (TextView) convertView.findViewById(R.id.TV_food_groups_total_protein_value);
|
||||
TextView carbsTV = (TextView) convertView.findViewById(R.id.TV_food_groups_total_carbs_value);
|
||||
TextView fatTV = (TextView) convertView.findViewById(R.id.TV_food_groups_total_fat_value);
|
||||
|
||||
AFoodGroup foodGroup = items.get(position);
|
||||
|
||||
nameTV.setText(foodGroup.getName());
|
||||
kCalTV.setText(Float.toString(foodGroup.getTotalKCal()));
|
||||
servingSizeTV.setText(Integer.toString(foodGroup.getFoods().size()));
|
||||
proteinTV.setText(Float.toString(foodGroup.getTotalProtein()));
|
||||
carbsTV.setText(Float.toString(foodGroup.getTotalCarbs()));
|
||||
fatTV.setText(Float.toString(foodGroup.getTotalFat()));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user