Added a ton of ActionBarSherlock functionality, refactored Calendar view widget, added compliment generator.

This commit is contained in:
Derek Brameyer
2012-01-08 19:50:18 -05:00
parent 8d20eada9c
commit bcb17a21b1
59 changed files with 1671 additions and 516 deletions

View File

@@ -4,92 +4,117 @@
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="14" />
<application
android:name=".MacroDroidApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".MacroDroidApplication"
android:theme="@android:style/Theme.NoTitleBar" >
android:theme="@style/MacroDroidTheme" >
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".MainActivity"
android:screenOrientation="portrait" >
<intent-filter >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".MyMacrosActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".MyMacrosCalculateActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".MyMacrosIKnowActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".MyFoodsActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".DayDetailActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".DayDetailAddFoodNewFoodTab"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".DayDetailAddFoodMyFoodsTab"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:name=".DayDetailAddFoodMyFoodGroupsTab"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:theme="@style/FullHeightDialog"
android:label="@string/app_name"
android:name=".MyFoodsAddActivity"
android:screenOrientation="portrait" >
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/FullHeightDialog" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:theme="@style/FullHeightDialog"
android:label="@string/app_name"
android:name=".DayDetailAddFoodTabActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/FullHeightDialog" >
</activity>
<activity
android:name=".MyFoodGroupsActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.exina.android.calendar.CalendarActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/FullHeightDialog" >
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.exina.android.calendar.date" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.dir/vnd.exina.android.calendar.date" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -8,4 +8,5 @@
# project structure.
# Project target.
target=android-7
target=android-15
android.library.reference.1=../ActionBarSherlock/library

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="270"
android:endColor="@android:color/white"
android:startColor="@android:color/white" />
</shape>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="270"
android:endColor="@color/action_bar_bottom_color"
android:startColor="@color/action_bar_top_color" />
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@@ -4,40 +4,10 @@
android:layout_height="fill_parent"
android:gravity="center|top" >
<LinearLayout
android:id="@+id/LL_date_and_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/TV_day_detail_date"
style="@style/CenteredHeaderTV"
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:gravity="center"
android:text="9/20/11" />
<Button
android:id="@+id/BTN_training_day"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1.0"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="Training Day"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/TV_day_detail_calories"
style="@style/CenteredHeaderTV"
android:layout_width="fill_parent"
android:layout_below="@id/LL_date_and_type"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="1000/2000 kCal" />
@@ -112,44 +82,11 @@
android:text="of 250g" />
</LinearLayout>
<LinearLayout
android:id="@+id/LL_actions_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/LL_macro_data"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="@+id/BTN_pics"
style="@style/FourColumnButtons"
android:layout_weight="1.0"
android:text="PICS" />
<Button
android:id="@+id/BTN_weight"
style="@style/FourColumnButtons"
android:layout_weight="1.0"
android:text="WEIGHT" />
<Button
android:id="@+id/BTN_height"
style="@style/FourColumnButtons"
android:layout_weight="1.0"
android:text="HEIGHT" />
<Button
android:id="@+id/BTN_add_food"
style="@style/FourColumnButtons"
android:layout_weight="1.0"
android:text="FOOD" />
</LinearLayout>
<TextView
android:id="@+id/TV_todays_foods"
style="@style/CenteredHeaderTV"
android:layout_width="fill_parent"
android:layout_below="@id/LL_actions_container"
android:layout_below="@id/LL_macro_data"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="@string/Todays_Foods" />
@@ -166,8 +103,8 @@
style="@style/CenteredHeaderTV"
android:layout_width="fill_parent"
android:layout_below="@id/TV_todays_foods"
android:visibility="gone"
android:gravity="center"
android:text="@string/day_detail_activity_no_foods_yet" />
android:text="@string/day_detail_activity_no_foods_yet"
android:visibility="gone" />
</RelativeLayout>

View File

@@ -7,8 +7,7 @@
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
@@ -18,8 +17,7 @@
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>

46
res/layout/main.xml Normal file
View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.exina.android.calendar.CalendarView
android:id="@+id/calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingBottom="13dp"
android:layout_centerHorizontal="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/BTN_prev_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Prev" />
<Button
android:id="@+id/BTN_next_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Next" />
<TextView
android:id="@+id/TV_month_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/BTN_next_month"
android:layout_toRightOf="@id/BTN_prev_month"
android:gravity="center"
android:text="ASDFASDF"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>

View File

@@ -1,50 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center|center_vertical" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal" >
<LinearLayout
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center|center_vertical"
android:orientation="vertical" >
android:layout_height="wrap_content"
android:layout_centerVertical="true" >
<TextView
style="@style/CenteredHeaderTV"
android:layout_marginBottom="20dp"
android:layout_marginTop="40dp"
android:text="@string/app_name" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/BTN_today"
style="@style/MainButtons"
android:text="@string/main_activity_today" />
<Button
android:id="@+id/BTN_today"
style="@style/MainButtons"
android:text="@string/main_activity_today" />
<Button
android:id="@+id/BTN_previous"
style="@style/MainButtons"
android:text="@string/main_activity_previous" />
<Button
android:id="@+id/BTN_previous"
style="@style/MainButtons"
android:text="@string/main_activity_previous" />
<Button
android:id="@+id/BTN_my_foods"
style="@style/MainButtons"
android:text="@string/main_activity_my_foods" />
<Button
android:id="@+id/BTN_my_foods"
style="@style/MainButtons"
android:text="@string/main_activity_my_foods" />
<Button
android:id="@+id/BTN_my_macros"
style="@style/MainButtons"
android:text="@string/main_activity_my_macros" />
<Button
android:id="@+id/BTN_my_macros"
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_my_food_groups"
style="@style/MainButtons"
android:text="@string/main_activity_my_food_groups" />
<Button
android:id="@+id/BTN_settings"
style="@style/MainButtons"
android:text="@string/main_activity_settings" />
</LinearLayout>
<Button
android:id="@+id/BTN_settings"
style="@style/MainButtons"
android:text="@string/main_activity_settings" />
</LinearLayout>
</ScrollView>
</ScrollView>
</RelativeLayout>

View File

@@ -3,25 +3,9 @@
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" />
android:layout_height="fill_parent" />
</RelativeLayout>

View File

@@ -3,32 +3,9 @@
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_Foods"
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" />
<Button
android:id="@+id/BTN_import"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/BTN_add"
android:text="@string/Import" />
<ListView
android:id="@+id/LV_my_foods"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_below="@id/BTN_add" />
android:layout_height="fill_parent" />
</RelativeLayout>

View File

@@ -49,14 +49,6 @@
android:layout_height="wrap_content"
android:visibility="gone" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/Macros"
android:textSize="24sp"
android:textStyle="bold" />
<TableRow >
<TextView

View File

@@ -4,28 +4,9 @@
android:layout_height="fill_parent"
android:gravity="center|center_vertical" >
<LinearLayout
android:id="@+id/LL_button_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="@+id/BTN_set"
style="@style/TwoColumnButtons"
android:text="@string/Set" />
<Button
android:id="@+id/BTN_cancel"
style="@style/TwoColumnButtons"
android:text="@string/Cancel" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/LL_button_container"
android:layout_alignParentTop="true"
android:fillViewport="true" >

View File

@@ -4,28 +4,9 @@
android:layout_height="fill_parent"
android:gravity="center|center_vertical" >
<LinearLayout
android:id="@+id/LL_button_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="@+id/BTN_set"
style="@style/TwoColumnButtons"
android:text="@string/Set" />
<Button
android:id="@+id/BTN_cancel"
style="@style/TwoColumnButtons"
android:text="@string/Cancel" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/LL_button_container"
android:layout_alignParentTop="true"
android:fillViewport="true" >
@@ -39,12 +20,6 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
style="@style/CenteredHeaderTV"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:text="@string/Macros" />
<TableRow >
<TextView
@@ -118,8 +93,8 @@
<TextView
style="@style/CenteredHeaderTV"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="@string/Macro_Conversions" />
<TableRow >

View File

@@ -1,9 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/MENU_photos"
android:icon="@android:drawable/ic_menu_camera"
android:showAsAction="ifRoom"
android:title="@string/Photos"/>
<item
android:id="@+id/MENU_weight"
android:icon="@android:drawable/ic_menu_recent_history"
android:showAsAction="ifRoom"
android:title="@string/Weight"/>
<item
android:id="@+id/MENU_add_food"
android:icon="@android:drawable/ic_menu_add"
android:showAsAction="ifRoom"
android:title="@string/Add_Food"
android:titleCondensed="@string/Add"/>
<item
android:id="@+id/MENU_change_day_type"
android:icon="@android:drawable/ic_menu_set_as"
android:showAsAction="ifRoom"
android:title="@string/Change_Day_Type"
android:titleCondensed="@string/Day_Type"/>
<item
android:id="@+id/MENU_save_food_group"
android:title="Save Food Group"
android:titleCondensed="Save"/>
android:icon="@android:drawable/ic_menu_save"
android:showAsAction="ifRoom"
android:title="@string/Save_Food_Group"/>
</menu>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/MENU_add_food_group"
android:icon="@android:drawable/ic_menu_add"
android:showAsAction="ifRoom"
android:title="@string/Add_Food_Group"
android:titleCondensed="@string/Add"/>
</menu>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/MENU_import"
android:icon="@drawable/ic_menu_archive"
android:showAsAction="ifRoom"
android:title="@string/Import_From_File"
android:titleCondensed="@string/Import"/>
<item
android:id="@+id/MENU_add_food"
android:icon="@android:drawable/ic_menu_add"
android:showAsAction="ifRoom"
android:title="@string/Add_Food"
android:titleCondensed="@string/Add"/>
</menu>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/MENU_cancel"
android:icon="@drawable/ic_menu_close_clear_cancel"
android:showAsAction="ifRoom"
android:title="@string/Cancel"/>
<item
android:id="@+id/MENU_set"
android:icon="@drawable/ic_menu_mark"
android:showAsAction="ifRoom"
android:title="@string/Set"/>
</menu>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/MENU_cancel"
android:icon="@drawable/ic_menu_close_clear_cancel"
android:showAsAction="ifRoom"
android:title="@string/Cancel"/>
<item
android:id="@+id/MENU_set"
android:icon="@drawable/ic_menu_mark"
android:showAsAction="ifRoom"
android:title="@string/Set"/>
</menu>

View File

@@ -0,0 +1,11 @@
K 25
svn:wc:ra_dav:version-url
V 38
/svn/!svn/ver/16/trunk/res/values-hdpi
END
dimens.xml
K 25
svn:wc:ra_dav:version-url
V 49
/svn/!svn/ver/16/trunk/res/values-hdpi/dimens.xml
END

View File

@@ -0,0 +1,62 @@
10
dir
36
https://android-calendar-view.googlecode.com/svn/trunk/res/values-hdpi
https://android-calendar-view.googlecode.com/svn
2011-03-18T14:52:10.992523Z
16
outlooksyncwizard@gmail.com
e2d3c141-846a-bc16-5981-dca600b91f1b
dimens.xml
file
2011-07-14T15:01:28.000000Z
40749ed1f294a955d7a9b110d7b8c28d
2011-03-18T14:52:10.992523Z
16
outlooksyncwizard@gmail.com
356

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">74px</dimen>
<dimen name="week_left_margin">40px</dimen>
<dimen name="cell_width">58px</dimen>
<dimen name="cell_heigh">53px</dimen>
<dimen name="cell_margin_top">92px</dimen>
<dimen name="cell_margin_left">39px</dimen>
<dimen name="cell_text_size">26px</dimen>
</resources>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">74px</dimen>
<dimen name="week_left_margin">40px</dimen>
<dimen name="cell_width">58px</dimen>
<dimen name="cell_heigh">53px</dimen>
<dimen name="cell_margin_top">92px</dimen>
<dimen name="cell_margin_left">39px</dimen>
<dimen name="cell_text_size">26px</dimen>
</resources>

View File

@@ -0,0 +1,11 @@
K 25
svn:wc:ra_dav:version-url
V 38
/svn/!svn/ver/16/trunk/res/values-ldpi
END
dimens.xml
K 25
svn:wc:ra_dav:version-url
V 49
/svn/!svn/ver/16/trunk/res/values-ldpi/dimens.xml
END

View File

@@ -0,0 +1,62 @@
10
dir
36
https://android-calendar-view.googlecode.com/svn/trunk/res/values-ldpi
https://android-calendar-view.googlecode.com/svn
2011-03-18T14:52:10.992523Z
16
outlooksyncwizard@gmail.com
e2d3c141-846a-bc16-5981-dca600b91f1b
dimens.xml
file
2011-07-14T15:01:28.000000Z
9e3f4a89ee03699720d687353a68eaa6
2011-03-18T14:52:10.992523Z
16
outlooksyncwizard@gmail.com
362

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">37px</dimen>
<dimen name="week_left_margin">20px</dimen>
<dimen name="cell_width">29px</dimen>
<dimen name="cell_heigh">26.5px</dimen>
<dimen name="cell_margin_top">46px</dimen>
<dimen name="cell_margin_left">19.5px</dimen>
<dimen name="cell_text_size">13.0px</dimen>
</resources>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">37px</dimen>
<dimen name="week_left_margin">20px</dimen>
<dimen name="cell_width">29px</dimen>
<dimen name="cell_heigh">26.5px</dimen>
<dimen name="cell_margin_top">46px</dimen>
<dimen name="cell_margin_left">19.5px</dimen>
<dimen name="cell_text_size">13.0px</dimen>
</resources>

View File

@@ -0,0 +1,11 @@
K 25
svn:wc:ra_dav:version-url
V 38
/svn/!svn/ver/16/trunk/res/values-mdpi
END
dimens.xml
K 25
svn:wc:ra_dav:version-url
V 49
/svn/!svn/ver/16/trunk/res/values-mdpi/dimens.xml
END

View File

@@ -0,0 +1,62 @@
10
dir
36
https://android-calendar-view.googlecode.com/svn/trunk/res/values-mdpi
https://android-calendar-view.googlecode.com/svn
2011-03-18T14:52:10.992523Z
16
outlooksyncwizard@gmail.com
e2d3c141-846a-bc16-5981-dca600b91f1b
dimens.xml
file
2011-07-14T15:01:28.000000Z
917b94ebd1a6ee35ffec54c5207b2be4
2011-03-18T14:52:10.992523Z
16
outlooksyncwizard@gmail.com
368

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">49.3px</dimen>
<dimen name="week_left_margin">26.3px</dimen>
<dimen name="cell_width">38.3px</dimen>
<dimen name="cell_heigh">35.3px</dimen>
<dimen name="cell_margin_top">61.3px</dimen>
<dimen name="cell_margin_left">26px</dimen>
<dimen name="cell_text_size">17.3px</dimen>
</resources>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">49.3px</dimen>
<dimen name="week_left_margin">26.3px</dimen>
<dimen name="cell_width">38.3px</dimen>
<dimen name="cell_heigh">35.3px</dimen>
<dimen name="cell_margin_top">61.3px</dimen>
<dimen name="cell_margin_left">26px</dimen>
<dimen name="cell_text_size">17.3px</dimen>
</resources>

View File

@@ -0,0 +1,11 @@
K 25
svn:wc:ra_dav:version-url
V 39
/svn/!svn/ver/36/trunk/res/values-xhdpi
END
Dimens.xml
K 25
svn:wc:ra_dav:version-url
V 50
/svn/!svn/ver/36/trunk/res/values-xhdpi/Dimens.xml
END

View File

@@ -0,0 +1,69 @@
10
dir
36
https://android-calendar-view.googlecode.com/svn/trunk/res/values-xhdpi
https://android-calendar-view.googlecode.com/svn
2011-07-14T15:42:40.113838Z
36
outlooksyncwizard@gmail.com
svn:special svn:externals svn:needs-lock
e2d3c141-846a-bc16-5981-dca600b91f1b
0
Dimens.xml
file
2011-07-14T16:23:15.000000Z
64b2e68b46205836887987f0a978ecca
2011-07-14T15:42:40.113838Z
36
outlooksyncwizard@gmail.com
358

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">74px</dimen>
<dimen name="week_left_margin">116px</dimen>
<dimen name="cell_width">58px</dimen>
<dimen name="cell_heigh">53px</dimen>
<dimen name="cell_margin_top">92px</dimen>
<dimen name="cell_margin_left">115px</dimen>
<dimen name="cell_text_size">26px</dimen>
</resources>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="week_top_margin">74px</dimen>
<dimen name="week_left_margin">116px</dimen>
<dimen name="cell_width">58px</dimen>
<dimen name="cell_heigh">53px</dimen>
<dimen name="cell_margin_top">92px</dimen>
<dimen name="cell_margin_left">115px</dimen>
<dimen name="cell_text_size">26px</dimen>
</resources>

View File

@@ -4,6 +4,28 @@
<item>male</item>
<item>female</item>
</string-array>
<string-array name="compliments">
<item>Lookin\' good!</item>
<item>Hello good-lookin\'.</item>
<item>Hey gorgeous.</item>
<item>You look hot.</item>
<item>&lt;3 &lt;3 &lt;3</item>
<item>;) ;) ;)</item>
<item>Whoa. Sexy.</item>
<item>Hey hot stuff.</item>
<item>\@-&gt;-- (It\'s a rose. Just for you.)</item>
<item>Keep up the good work!</item>
<item>Look at you, being all healthy and stuff.</item>
<item>Have you been working out?</item>
<item>You\'re the greatest phone owner I could ever have.</item>
<item>Fact: You look good. Really good.</item>
<item>Eating right feels great, doesn\'t it?</item>
<item>You look like the lovechild of Bruce Lee and Angelina Jolie.</item>
<item>Really really ridiculously good-looking.</item>
<item>Serious question: Are you a model?</item>
<item>You rock.</item>
<item>(╯°□°)╯︵ ┻━┻</item>
</string-array>
</resources>

8
res/values/colors.xml Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="action_bar_top_color">#000000</color>
<color name="action_bar_bottom_color">#333333</color>
<color name="action_bar_title_color">#DDDDDD</color>
</resources>

View File

@@ -16,6 +16,7 @@
<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="hint">Touch the first or last day of month to navigate months.</string>
<string name="in">in</string>
<string name="kCal">kCal</string>
<string name="kCal_serving">kCal/serving</string>
@@ -34,23 +35,35 @@
<string name="years">years</string>
<string name="Add">Add</string>
<string name="Add_Food">Add Food</string>
<string name="Add_Food_Group">Add Food Group</string>
<string name="BMR">BMR</string>
<string name="Calculate">Calculate</string>
<string name="Cancel">Cancel</string>
<string name="Change_Day_Type">Change Day Type</string>
<string name="Day_Type">Day Type</string>
<string name="I_Know_Them">It\'s a UNIX system! I know this!</string>
<string name="Import">Import</string>
<string name="Import_From_File">Import From File</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_Macros">My Macros</string>
<string name="My_Measurements">My Measurements</string>
<string name="Name">Name</string>
<string name="Number_of_Servings">Number of Servings</string>
<string name="Photos">Photos</string>
<string name="Rest_Day">Rest Day</string>
<string name="RMR">RMR</string>
<string name="Save">Save</string>
<string name="Save_Food_Group">Save Food Group</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>
<string name="Training_Day">Training Day</string>
<string name="Weight">Weight</string>
<string name="Your_macros_have_been_saved">Your macros have been saved!</string>
<string name="day_detail_activity_no_foods_yet">You haven\'t added any foods yet!</string>
<string name="main_activity_today">Today</string>

View File

@@ -1,6 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MacroDroidTheme" parent="Theme.Sherlock">
<item name="actionBarSize">48dp</item>
<item name="abDivider">@drawable/action_bar_divider</item>
<item name="abBackground">@drawable/action_bar_gradient</item>
<item name="abTitleTextStyle">@style/TV_action_bar_title</item>
<item name="abSubtitleTextStyle">@style/TV_action_bar_subtitle</item>
</style>
<style name="TV_action_bar_title">
<item name="android:layout_marginLeft">4dp</item>
<item name="android:textColor">@color/action_bar_title_color</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">@android:color/white</item>
<item name="android:shadowDx">1.0</item>
<item name="android:shadowDy">1.0</item>
<item name="android:shadowRadius">1.0</item>
</style>
<style name="TV_action_bar_subtitle">
<item name="android:paddingBottom">5dp</item>
<item name="android:textColor">@color/action_bar_title_color</item>
<item name="android:textSize">12sp</item>
<item name="android:shadowColor">@android:color/white</item>
<item name="android:shadowDx">1.0</item>
<item name="android:shadowDy">1.0</item>
<item name="android:shadowRadius">1.0</item>
</style>
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
</style>

View File

@@ -1,37 +1,41 @@
package com.doomonafireball.macrodroid;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
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;
import android.widget.Toast;
public class DayDetailActivity extends Activity {
public class DayDetailActivity extends FragmentActivity {
private static final String DATE_FORMAT = "MM/dd/yyyy";
private static final String SAVE_DATE_FORMAT = "MMddyyyy";
private static final int CAMERA_PIC_REQUEST = 1337;
private MacroDroidApplication application;
private Context mContext;
private Calendar mCalendar; // purely for setup
private ADay mADay;
private TextView dateTV;
private Button trainingBTN;
private TextView noFoodsYetTV;
private TextView caloriesTV;
private TextView currentProteinTV;
@@ -40,12 +44,9 @@ public class DayDetailActivity extends Activity {
private TextView macroProteinTV;
private TextView macroCarbsTV;
private TextView macroFatTV;
private Button picsBTN;
private Button weightBTN;
private Button heightBTN;
private Button addFoodBTN;
private DayDetailFoodsAdapter mFoodsAdapter;
private ListView mFoodsLV;
private String mFilePath;
/** Called when the activity is first created. */
@Override
@@ -56,9 +57,12 @@ public class DayDetailActivity extends Activity {
application = ((MacroDroidApplication) getApplication());
mContext = this;
final ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
noFoodsYetTV = (TextView) findViewById(R.id.TV_no_foods_yet);
dateTV = (TextView) findViewById(R.id.TV_day_detail_date);
trainingBTN = (Button) findViewById(R.id.BTN_training_day);
caloriesTV = (TextView) findViewById(R.id.TV_day_detail_calories);
currentProteinTV = (TextView) findViewById(R.id.TV_day_detail_current_protein);
currentCarbsTV = (TextView) findViewById(R.id.TV_day_detail_current_carbs);
@@ -66,10 +70,6 @@ public class DayDetailActivity extends Activity {
macroProteinTV = (TextView) findViewById(R.id.TV_day_detail_macro_protein);
macroCarbsTV = (TextView) findViewById(R.id.TV_day_detail_macro_carbs);
macroFatTV = (TextView) findViewById(R.id.TV_day_detail_macro_fat);
picsBTN = (Button) findViewById(R.id.BTN_pics);
weightBTN = (Button) findViewById(R.id.BTN_weight);
heightBTN = (Button) findViewById(R.id.BTN_height);
addFoodBTN = (Button) findViewById(R.id.BTN_add_food);
mFoodsLV = (ListView) findViewById(R.id.LV_day_detail_foods);
// Parse the extras
@@ -92,7 +92,7 @@ public class DayDetailActivity extends Activity {
OnItemClickListener mFoodsItemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View v, int position, long id) {
// TODO Auto-generated method stub
// TODO Quick Options
ArrayList<Pair<Float, AFood>> mFoods = mADay.getFoods();
mFoods.remove(position);
mADay.setFoods(mFoods);
@@ -111,7 +111,12 @@ public class DayDetailActivity extends Activity {
private void refreshViews() {
// Refresh the date!
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
dateTV.setText(sdf.format(mADay.getDate().getTime()));
final ActionBar ab = getSupportActionBar();
ab.setTitle(sdf.format(mADay.getDate().getTime()));
// dateTV.setText(sdf.format(mADay.getDate().getTime()));
SimpleDateFormat sdf2 = new SimpleDateFormat(SAVE_DATE_FORMAT);
mFilePath = sdf2.format(mADay.getDate().getTime());
// Refresh the Views
float totalKCal = 0.0f;
@@ -164,116 +169,35 @@ public class DayDetailActivity extends Activity {
if (totalKCal > application.macrosPrefs.getFloat(
Tags.MACROS_TRAINING_KCAL, 0.0f)) {
caloriesTV.setTextColor(Color.RED);
} else {
caloriesTV.setTextColor(Color.GRAY);
}
if (totalProtein > application.macrosPrefs.getFloat(
Tags.MACROS_PROTEIN, 0.0f)) {
currentProteinTV.setTextColor(Color.RED);
} else {
currentProteinTV.setTextColor(Color.GRAY);
}
if (totalCarbs > application.macrosPrefs.getFloat(Tags.MACROS_CARBS,
0.0f)) {
currentCarbsTV.setTextColor(Color.RED);
} else {
currentCarbsTV.setTextColor(Color.GRAY);
}
if (totalFat > application.macrosPrefs.getFloat(Tags.MACROS_FAT, 0.0f)) {
currentFatTV.setTextColor(Color.RED);
} else {
currentFatTV.setTextColor(Color.GRAY);
}
// 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) {
// TODO Auto-generated method stub
// Convert current date and pass it to intent
Intent i = new Intent(DayDetailActivity.this,
DayDetailAddFoodTabActivity.class);
i.putExtra("date", mADay.getDate().get(Calendar.DATE));
i.putExtra("month", mADay.getDate().get(Calendar.MONTH));
i.putExtra("year", mADay.getDate().get(Calendar.YEAR));
startActivity(i);
}
});
// /weightBTN.setText(Float.toString(mADay.getWeight()));
if (mADay.isTraining()) {
trainingBTN.setText("Training Day");
ab.setSubtitle(getResources().getString(R.string.Training_Day));
} else {
trainingBTN.setText("Rest Day");
ab.setSubtitle(getResources().getString(R.string.Rest_Day));
}
trainingBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mADay.isTraining()) {
mADay.setTraining(false);
trainingBTN.setText("Rest Day");
application.saveDay(mADay);
} else {
mADay.setTraining(true);
trainingBTN.setText("Training Day");
application.saveDay(mADay);
}
}
});
mFoodsLV.setOnItemClickListener(mFoodsItemClickListener);
}
@@ -301,6 +225,29 @@ public class DayDetailActivity extends Activity {
alert.show();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
Log.d(Tags.LOG_TAG, "CAMERA_PIC_REQUEST result.");
Bitmap bmp = (Bitmap) data.getExtras().get("data");
String saveBmpResults = application.saveBitmapToFile(
bmp,
Tags.PHOTOS_PATH,
mFilePath
+ "_"
+ application.numPicsForDay(Tags.PHOTOS_PATH,
mFilePath) + ".png");
if (saveBmpResults.length() > 0) {
Toast.makeText(mContext, "Saved picture to " + saveBmpResults,
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(
mContext,
"Could not save the picture. Please make sure your SD card is mounted.",
Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.day_detail_menu, menu);
@@ -310,9 +257,95 @@ public class DayDetailActivity extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.MENU_photos:
if (application.numPicsForDay(Tags.PHOTOS_PATH, mFilePath) > 0) {
// We already have some pictures for this day
final CharSequence[] items = { "View photos",
"Take another photo" };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose an option");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item == 0) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://"
+ File.separator + Tags.PHOTOS_PATH), "image/*");
startActivity(intent);
} else {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,
CAMERA_PIC_REQUEST);
}
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
// We have no pictures for this day
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
return false;
case R.id.MENU_weight:
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.append("100.0");
alert.setView(input);
alert.setPositiveButton("Set Weight",
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();
return false;
case R.id.MENU_add_food:
Intent i = new Intent(DayDetailActivity.this,
DayDetailAddFoodTabActivity.class);
i.putExtra("date", mADay.getDate().get(Calendar.DATE));
i.putExtra("month", mADay.getDate().get(Calendar.MONTH));
i.putExtra("year", mADay.getDate().get(Calendar.YEAR));
startActivity(i);
return false;
case R.id.MENU_save_food_group:
saveToFoodGroup();
return false;
case R.id.MENU_change_day_type:
final ActionBar ab = getSupportActionBar();
if (mADay.isTraining()) {
mADay.setTraining(false);
ab.setSubtitle(getResources().getString(R.string.Rest_Day));
application.saveDay(mADay);
} else {
mADay.setTraining(true);
ab.setSubtitle(getResources().getString(R.string.Training_Day));
application.saveDay(mADay);
}
return false;
default:
return super.onOptionsItemSelected(item);
}

View File

@@ -1,6 +1,7 @@
package com.doomonafireball.macrodroid;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -12,8 +13,13 @@ import java.util.List;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
public class MacroDroidApplication extends Application {
private static final String MACROS_PREFS = "MacroDroidMacrosPrefs";
@@ -42,6 +48,84 @@ public class MacroDroidApplication extends Application {
}
}
public String getRandomCompliment() {
String[] complimentArray = getResources().getStringArray(
R.array.compliments);
int i = (int) (Math.random() * complimentArray.length);
return complimentArray[i];
}
public int numPicsForDay(String path, String day) {
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return 0;
} else {
File dir = new File(Environment.getExternalStorageDirectory()
+ File.separator + path);
dir.mkdirs();
String[] files = dir.list();
int dayCount = 0;
for (int i = 0; i < files.length; i++) {
String s = files[i];
if (s.contains(day)) {
dayCount++;
}
}
return dayCount;
}
}
public int directoryExists(String path) {
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return -1;
} else {
File dir = new File(Environment.getExternalStorageDirectory()
+ File.separator + path);
if (dir.exists()) {
return dir.list().length;
} else {
return -1;
}
}
}
public String saveBitmapToFile(Bitmap bmp, String path, String filename) {
// Make sure to declare WRITE_EXTERNAL_STORAGE permission
// bmp - self-explanatory
// path - e.g "myapp/firstfolder/secondfolder" (no leading or trailing
// seps)
// filename - e.g. "081012.png" (no leading seps)
// Output would be "sdcard/myapp/firstfolder/secondfolder/081012.png"
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
return "";
} else {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, bytes);
File dir = new File(Environment.getExternalStorageDirectory()
+ File.separator + path);
dir.mkdirs();
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + path + File.separator + filename);
Log.d(Tags.LOG_TAG, "Filedir: " + f.getAbsolutePath());
try {
// write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
return f.getAbsolutePath();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
}
public boolean hasDayData(Context ctx) {
dbHelper = new Db4oHelper(ctx);
if (dbHelper.fetchAllDayRows().isEmpty()) {
@@ -50,7 +134,7 @@ public class MacroDroidApplication extends Application {
return true;
}
}
public boolean hasFoodGroupData(Context ctx) {
dbHelper = new Db4oHelper(ctx);
if (dbHelper.fetchAllFoodGroupRows() == null) {
@@ -71,12 +155,12 @@ 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);
}
@@ -84,7 +168,7 @@ public class MacroDroidApplication extends Application {
public List<ADay> getDaysFromDb() {
return dbHelper.fetchAllDayRows();
}
public List<AFoodGroup> getFoodGroupsFromDb() {
return dbHelper.fetchAllFoodGroupRows();
}

View File

@@ -1,21 +1,21 @@
package com.doomonafireball.macrodroid;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import com.exina.android.calendar.CalendarActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
public class MainActivity extends Activity {
public class MainActivity extends FragmentActivity {
private Button todayBTN;
private Button previousBTN;
private Button myFoodsBTN;
@@ -34,6 +34,12 @@ public class MainActivity extends Activity {
mContext = this;
application = ((MacroDroidApplication) getApplication());
final ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.setSubtitle(application.getRandomCompliment());
todayBTN = (Button) findViewById(R.id.BTN_today);
previousBTN = (Button) findViewById(R.id.BTN_previous);
myFoodsBTN = (Button) findViewById(R.id.BTN_my_foods);
@@ -56,6 +62,11 @@ public class MainActivity extends Activity {
previousBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Calendar Widget
startActivityForResult(new Intent(Intent.ACTION_PICK)
.setDataAndType(null, CalendarActivity.MIME_TYPE), 100);
/*
// DatePickerDialog
int year = Calendar.getInstance().get(Calendar.YEAR);
int month = Calendar.getInstance().get(Calendar.MONTH);
@@ -75,7 +86,7 @@ public class MainActivity extends Activity {
}
}, year, month, date);
datePicker.show();
datePicker.show();*/
}
});
myFoodsBTN.setOnClickListener(new OnClickListener() {
@@ -107,4 +118,27 @@ public class MainActivity extends Activity {
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
int year = data.getIntExtra("year", 0); // get number of year
int month = data.getIntExtra("month", 0); // get number of month
// 0..11
int day = data.getIntExtra("day", 0); // get number of day 0..31
Intent i = new Intent(MainActivity.this, DayDetailActivity.class);
i.putExtra("date", day);
i.putExtra("month", month);
i.putExtra("year", year);
startActivity(i);
}
}
@Override
public void onResume() {
final ActionBar ab = getSupportActionBar();
ab.setSubtitle(application.getRandomCompliment());
super.onResume();
}
}

View File

@@ -3,11 +3,15 @@ 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.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
@@ -15,8 +19,7 @@ import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.ListView;
public class MyFoodGroupsActivity extends Activity {
private Button addBTN;
public class MyFoodGroupsActivity extends FragmentActivity {
private ListView myFoodGroupsLV;
private MyFoodGroupsAdapter myFoodGroupsAdapter;
private MacroDroidApplication application;
@@ -31,19 +34,15 @@ public class MyFoodGroupsActivity extends Activity {
application = ((MacroDroidApplication) getApplication());
mContext = this;
addBTN = (Button) findViewById(R.id.BTN_add);
final ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.setTitle(getResources().getString(R.string.My_Food_Groups));
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);
@@ -97,4 +96,21 @@ public class MyFoodGroupsActivity extends Activity {
super.onResume();
refreshList();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_food_groups_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.MENU_add_food_group:
// TODO
return false;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -2,12 +2,15 @@ package com.doomonafireball.macrodroid;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
@@ -17,86 +20,96 @@ import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class MyFoodsActivity extends Activity {
private Button addBTN;
private Button importBTN;
private ListView myFoodsLV;
private MyFoodsAdapter myFoodsAdapter;
private MacroDroidApplication application;
private Context mContext;
private ArrayList<AFood> myFoodsArrayList;
public class MyFoodsActivity extends FragmentActivity {
private ListView myFoodsLV;
private MyFoodsAdapter myFoodsAdapter;
private MacroDroidApplication application;
private Context mContext;
private ArrayList<AFood> myFoodsArrayList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_foods_activity);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_foods_activity);
application = ((MacroDroidApplication) getApplication());
mContext = this;
application = ((MacroDroidApplication) getApplication());
mContext = this;
addBTN = (Button) findViewById(R.id.BTN_add);
importBTN = (Button) findViewById(R.id.BTN_import);
myFoodsLV = (ListView) findViewById(R.id.LV_my_foods);
final ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.setTitle(getResources().getString(R.string.My_Foods));
addBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(MyFoodsActivity.this, MyFoodsAddActivity.class));
}
});
importBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
application.writeInternalStoragePrivate(Tags.MY_FOODS_FILENAME,
application.defaultFoodsToByteArray());
refreshList();
}
});
myFoodsLV = (ListView) findViewById(R.id.LV_my_foods);
refreshList();
refreshList();
myFoodsLV.setOnItemLongClickListener(myFoodsItemLongClickListener);
}
myFoodsLV.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 AFood selectedFood = (AFood) myFoodsAdapter.getItem(position);
private OnItemLongClickListener myFoodsItemLongClickListener = new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> a, View v, int position,
long id) {
// TODO Auto-generated method stub
final AFood selectedFood = (AFood) myFoodsAdapter.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
myFoodsArrayList.remove(selectedFood);
application.writeFoodsToInternalStorage(myFoodsArrayList);
refreshList();
dialog.dismiss();
}
}
});
AlertDialog alert = builder.create();
alert.show();
return false;
}
};
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
myFoodsArrayList.remove(selectedFood);
application
.writeFoodsToInternalStorage(myFoodsArrayList);
refreshList();
dialog.dismiss();
}
}
});
AlertDialog alert = builder.create();
alert.show();
return false;
}
};
private void refreshList() {
myFoodsArrayList = application.getAllFoods();
myFoodsAdapter = new MyFoodsAdapter(mContext, myFoodsArrayList);
myFoodsLV.setAdapter(myFoodsAdapter);
private void refreshList() {
myFoodsArrayList = application.getAllFoods();
myFoodsAdapter = new MyFoodsAdapter(mContext, myFoodsArrayList);
myFoodsLV.setAdapter(myFoodsAdapter);
}
}
@Override
public void onResume() {
super.onResume();
refreshList();
}
@Override
public void onResume() {
super.onResume();
refreshList();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_foods_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.MENU_add_food:
startActivity(new Intent(MyFoodsActivity.this,
MyFoodsAddActivity.class));
return false;
case R.id.MENU_import:
// TODO Import from file
application.writeInternalStoragePrivate(Tags.MY_FOODS_FILENAME,
application.defaultFoodsToByteArray());
refreshList();
return false;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -1,15 +1,16 @@
package com.doomonafireball.macrodroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;
public class MyMacrosActivity extends Activity {
public class MyMacrosActivity extends FragmentActivity {
private Button calculateBTN;
private Button iKnowBTN;
private TextView noInputTV;
@@ -29,6 +30,12 @@ public class MyMacrosActivity extends Activity {
setContentView(R.layout.my_macros_activity);
application = ((MacroDroidApplication) getApplication());
final ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.setTitle(getResources().getString(R.string.My_Macros));
calculateBTN = (Button) findViewById(R.id.BTN_calculate);
iKnowBTN = (Button) findViewById(R.id.BTN_i_know);

View File

@@ -1,15 +1,48 @@
package com.doomonafireball.macrodroid;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
public class MyMacrosCalculateActivity extends Activity {
public class MyMacrosCalculateActivity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_macros_calculate_activity);
final ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.setTitle(getResources().getString(R.string.My_Macros));
ab.setSubtitle(getResources().getString(R.string.Calculate));
}
private void setMacros() {
// TODO This
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_macros_calculate_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.MENU_cancel:
finish();
return false;
case R.id.MENU_set:
setMacros();
return false;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -1,18 +1,20 @@
package com.doomonafireball.macrodroid;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MyMacrosIKnowActivity extends Activity {
public class MyMacrosIKnowActivity extends FragmentActivity {
private MacroDroidApplication application;
private Button setBTN;
private Button cancelBTN;
private EditText trainingKCalET;
private EditText restKCalET;
private EditText deficitET;
@@ -33,8 +35,13 @@ public class MyMacrosIKnowActivity extends Activity {
application = ((MacroDroidApplication) getApplication());
mContext = this;
setBTN = (Button) findViewById(R.id.BTN_set);
cancelBTN = (Button) findViewById(R.id.BTN_cancel);
final ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setDisplayShowHomeEnabled(false);
ab.setTitle(getResources().getString(R.string.My_Macros));
ab.setSubtitle(getResources().getString(R.string.I_Know_Them));
trainingKCalET = (EditText) findViewById(R.id.ET_training_kCal);
restKCalET = (EditText) findViewById(R.id.ET_rest_kCal);
deficitET = (EditText) findViewById(R.id.ET_deficit);
@@ -46,69 +53,78 @@ public class MyMacrosIKnowActivity extends Activity {
fatConversionET = (EditText) findViewById(R.id.ET_fat_conversion);
// Populate existing data
trainingKCalET.setText(Float.toString(application.macrosPrefs.getFloat(
trainingKCalET.append(Float.toString(application.macrosPrefs.getFloat(
Tags.MACROS_TRAINING_KCAL, 0)));
restKCalET.setText(Float.toString(application.macrosPrefs
restKCalET.append(Float.toString(application.macrosPrefs
.getFloat(Tags.MACROS_REST_KCAL, 0)));
deficitET.setText(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_DEFICIT, 0.0f)));
proteinET.setText(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_PROTEIN, 0.0f)));
carbsET.setText(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_CARBS, 0.0f)));
fatET.setText(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_FAT, 0.0f)));
proteinConversionET.setText(Float.toString(application.macrosPrefs.getFloat(
deficitET.append(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_DEFICIT, 0.0f)));
proteinET.append(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_PROTEIN, 0.0f)));
carbsET.append(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_CARBS, 0.0f)));
fatET.append(Float.toString(application.macrosPrefs.getFloat(Tags.MACROS_FAT, 0.0f)));
proteinConversionET.append(Float.toString(application.macrosPrefs.getFloat(
Tags.MACRO_CONVERSION_PROTEIN,
DefaultValues.MACRO_CONVERSION_PROTEIN)));
carbsConversionET.setText(Float.toString(application.macrosPrefs.getFloat(
carbsConversionET.append(Float.toString(application.macrosPrefs.getFloat(
Tags.MACRO_CONVERSION_CARBS,
DefaultValues.MACRO_CONVERSION_CARBS)));
fatConversionET.setText(Float.toString(application.macrosPrefs.getFloat(
fatConversionET.append(Float.toString(application.macrosPrefs.getFloat(
Tags.MACRO_CONVERSION_FAT,
DefaultValues.MACRO_CONVERSION_FAT)));
setBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Validate data entry
application.macrosPrefsEditor.putFloat(Tags.MACROS_TRAINING_KCAL,
Float.parseFloat(trainingKCalET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_REST_KCAL,
Float.parseFloat(restKCalET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_DEFICIT,
Float.parseFloat(deficitET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_PROTEIN,
Float.parseFloat(proteinET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_CARBS,
Float.parseFloat(carbsET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_FAT,
Float.parseFloat(fatET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACRO_CONVERSION_PROTEIN,
Float.parseFloat(proteinConversionET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACRO_CONVERSION_CARBS,
Float.parseFloat(carbsConversionET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACRO_CONVERSION_FAT,
Float.parseFloat(fatConversionET.getText()
.toString()));
application.macrosPrefsEditor.commit();
Toast.makeText(mContext,
getResources().getString(R.string.Your_macros_have_been_saved),
Toast.LENGTH_SHORT).show();
finish();
}
});
cancelBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Auto-generated method stub
finish();
}
});
}
private void setMacros() {
// TODO Validate data entry
application.macrosPrefsEditor.putFloat(Tags.MACROS_TRAINING_KCAL,
Float.parseFloat(trainingKCalET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_REST_KCAL,
Float.parseFloat(restKCalET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_DEFICIT,
Float.parseFloat(deficitET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_PROTEIN,
Float.parseFloat(proteinET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_CARBS,
Float.parseFloat(carbsET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACROS_FAT,
Float.parseFloat(fatET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACRO_CONVERSION_PROTEIN,
Float.parseFloat(proteinConversionET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACRO_CONVERSION_CARBS,
Float.parseFloat(carbsConversionET.getText()
.toString()));
application.macrosPrefsEditor.putFloat(Tags.MACRO_CONVERSION_FAT,
Float.parseFloat(fatConversionET.getText()
.toString()));
application.macrosPrefsEditor.commit();
Toast.makeText(mContext,
getResources().getString(R.string.Your_macros_have_been_saved),
Toast.LENGTH_SHORT).show();
finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_macros_i_know_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.MENU_cancel:
finish();
return false;
case R.id.MENU_set:
setMacros();
return false;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -4,6 +4,9 @@ public class Tags {
// Application logging
public static final String LOG_TAG = "MacroDroid";
// External things
public static final String PHOTOS_PATH = "MacroDroid/photos";
// Macros SharedPreferences tags
public static final String MACROS_TRAINING_KCAL = "macros_training_kcal";
public static final String MACROS_REST_KCAL = "macros_rest_kcal";

View File

@@ -0,0 +1,116 @@
/*
* Copyright (C) 2011 Chris Gao <chris@exina.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exina.android.calendar;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.doomonafireball.macrodroid.R;
public class CalendarActivity extends Activity implements
CalendarView.OnCellTouchListener {
public static final String MIME_TYPE = "vnd.android.cursor.dir/vnd.exina.android.calendar.date";
CalendarView mView = null;
TextView mHit;
TextView monthYearTV;
Button prevMonthBTN;
Button nextMonthBTN;
SimpleDateFormat monthYearFormat;
Handler mHandler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mView = (CalendarView) findViewById(R.id.calendar);
mView.setOnCellTouchListener(this);
monthYearTV = (TextView) findViewById(R.id.TV_month_year);
prevMonthBTN = (Button) findViewById(R.id.BTN_prev_month);
nextMonthBTN = (Button) findViewById(R.id.BTN_next_month);
monthYearFormat = new SimpleDateFormat("MMMMM yyyy");
prevMonthBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mView.previousMonth();
setMonthYearText();
}
});
nextMonthBTN.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mView.nextMonth();
setMonthYearText();
}
});
setMonthYearText();
/*if (getIntent().getAction().equals(Intent.ACTION_PICK))
findViewById(R.id.hint).setVisibility(View.INVISIBLE);*/
}
private void setMonthYearText() {
Date d = new Date();
d.setMonth(mView.getMonth());
d.setYear(mView.getYear() - 1900);
monthYearTV.setText(monthYearFormat.format(d));
}
public void onTouch(Cell cell) {
Intent intent = getIntent();
String action = intent.getAction();
if (action.equals(Intent.ACTION_PICK)
|| action.equals(Intent.ACTION_GET_CONTENT)) {
Intent ret = new Intent();
ret.putExtra("year", mView.getYear());
ret.putExtra("month", mView.getMonth());
ret.putExtra("day", cell.getDayOfMonth());
this.setResult(RESULT_OK, ret);
finish();
return;
}
int day = cell.getDayOfMonth();
if (mView.firstDay(day))
mView.previousMonth();
else if (mView.lastDay(day))
mView.nextMonth();
else
return;
mHandler.post(new Runnable() {
public void run() {
Toast.makeText(
CalendarActivity.this,
DateUtils.getMonthString(mView.getMonth(),
DateUtils.LENGTH_LONG) + " " + mView.getYear(),
Toast.LENGTH_SHORT).show();
}
});
}
}

View File

@@ -0,0 +1,267 @@
/*
* Copyright (C) 2011 Chris Gao <chris@exina.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exina.android.calendar;
import com.doomonafireball.macrodroid.R;
import java.util.Calendar;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.MonthDisplayHelper;
import android.view.MotionEvent;
import android.widget.ImageView;
public class CalendarView extends ImageView {
private static int WEEK_TOP_MARGIN = 74;
private static int WEEK_LEFT_MARGIN = 40;
private static int CELL_WIDTH = 58;
private static int CELL_HEIGH = 53;
private static int CELL_MARGIN_TOP = 92;
private static int CELL_MARGIN_LEFT = 39;
private static float CELL_TEXT_SIZE;
private static final String TAG = "CalendarView";
private Calendar mRightNow = null;
private Drawable mWeekTitle = null;
private Cell mToday = null;
private Cell[][] mCells = new Cell[6][7];
private OnCellTouchListener mOnCellTouchListener = null;
MonthDisplayHelper mHelper;
Drawable mDecoration = null;
public interface OnCellTouchListener {
public void onTouch(Cell cell);
}
public CalendarView(Context context) {
this(context, null);
}
public CalendarView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CalendarView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mDecoration = context.getResources().getDrawable(
R.drawable.typeb_calendar_today);
initCalendarView();
}
private void initCalendarView() {
mRightNow = Calendar.getInstance();
// prepare static vars
Resources res = getResources();
WEEK_TOP_MARGIN = (int) res.getDimension(R.dimen.week_top_margin);
WEEK_LEFT_MARGIN = (int) res.getDimension(R.dimen.week_left_margin);
CELL_WIDTH = (int) res.getDimension(R.dimen.cell_width);
CELL_HEIGH = (int) res.getDimension(R.dimen.cell_heigh);
CELL_MARGIN_TOP = (int) res.getDimension(R.dimen.cell_margin_top);
CELL_MARGIN_LEFT = (int) res.getDimension(R.dimen.cell_margin_left);
CELL_TEXT_SIZE = res.getDimension(R.dimen.cell_text_size);
// set background
setImageResource(R.drawable.background);
mWeekTitle = res.getDrawable(R.drawable.calendar_week);
mHelper = new MonthDisplayHelper(mRightNow.get(Calendar.YEAR),
mRightNow.get(Calendar.MONTH));
}
private void initCells() {
class _calendar {
public int day;
public boolean thisMonth;
public _calendar(int d, boolean b) {
day = d;
thisMonth = b;
}
public _calendar(int d) {
this(d, false);
}
}
;
_calendar tmp[][] = new _calendar[6][7];
for (int i = 0; i < tmp.length; i++) {
int n[] = mHelper.getDigitsForRow(i);
for (int d = 0; d < n.length; d++) {
if (mHelper.isWithinCurrentMonth(i, d))
tmp[i][d] = new _calendar(n[d], true);
else
tmp[i][d] = new _calendar(n[d]);
}
}
Calendar today = Calendar.getInstance();
int thisDay = 0;
mToday = null;
if (mHelper.getYear() == today.get(Calendar.YEAR)
&& mHelper.getMonth() == today.get(Calendar.MONTH)) {
thisDay = today.get(Calendar.DAY_OF_MONTH);
}
// build cells
Rect Bound = new Rect(CELL_MARGIN_LEFT, CELL_MARGIN_TOP, CELL_WIDTH
+ CELL_MARGIN_LEFT, CELL_HEIGH + CELL_MARGIN_TOP);
for (int week = 0; week < mCells.length; week++) {
for (int day = 0; day < mCells[week].length; day++) {
if (tmp[week][day].thisMonth) {
if (day == 0 || day == 6)
mCells[week][day] = new RedCell(tmp[week][day].day,
new Rect(Bound), CELL_TEXT_SIZE);
else
mCells[week][day] = new Cell(tmp[week][day].day,
new Rect(Bound), CELL_TEXT_SIZE);
} else
mCells[week][day] = new GrayCell(tmp[week][day].day,
new Rect(Bound), CELL_TEXT_SIZE);
Bound.offset(CELL_WIDTH, 0); // move to next column
// get today
if (tmp[week][day].day == thisDay && tmp[week][day].thisMonth) {
mToday = mCells[week][day];
mDecoration.setBounds(mToday.getBound());
}
}
Bound.offset(0, CELL_HEIGH); // move to next row and first column
Bound.left = CELL_MARGIN_LEFT;
Bound.right = CELL_MARGIN_LEFT + CELL_WIDTH;
}
}
@Override
public void onLayout(boolean changed, int left, int top, int right,
int bottom) {
android.util.Log.d(TAG, "left=" + left);
Rect re = getDrawable().getBounds();
WEEK_LEFT_MARGIN = CELL_MARGIN_LEFT = (right - left - re.width()) / 2;
mWeekTitle.setBounds(WEEK_LEFT_MARGIN, WEEK_TOP_MARGIN,
WEEK_LEFT_MARGIN + mWeekTitle.getMinimumWidth(),
WEEK_TOP_MARGIN + mWeekTitle.getMinimumHeight());
initCells();
super.onLayout(changed, left, top, right, bottom);
}
public void setTimeInMillis(long milliseconds) {
mRightNow.setTimeInMillis(milliseconds);
initCells();
this.invalidate();
}
public int getYear() {
return mHelper.getYear();
}
public int getMonth() {
return mHelper.getMonth();
}
public void nextMonth() {
mHelper.nextMonth();
initCells();
invalidate();
}
public void previousMonth() {
mHelper.previousMonth();
initCells();
invalidate();
}
public boolean firstDay(int day) {
return day == 1;
}
public boolean lastDay(int day) {
return mHelper.getNumberOfDaysInMonth() == day;
}
public void goToday() {
Calendar cal = Calendar.getInstance();
mHelper = new MonthDisplayHelper(cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH));
initCells();
invalidate();
}
public Calendar getDate() {
return mRightNow;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mOnCellTouchListener != null) {
for (Cell[] week : mCells) {
for (Cell day : week) {
if (day.hitTest((int) event.getX(), (int) event.getY())) {
mOnCellTouchListener.onTouch(day);
}
}
}
}
return super.onTouchEvent(event);
}
public void setOnCellTouchListener(OnCellTouchListener p) {
mOnCellTouchListener = p;
}
@Override
protected void onDraw(Canvas canvas) {
// draw background
super.onDraw(canvas);
mWeekTitle.draw(canvas);
// draw cells
for (Cell[] week : mCells) {
for (Cell day : week) {
day.draw(canvas);
}
}
// draw today
if (mDecoration != null && mToday != null) {
mDecoration.draw(canvas);
}
}
private class GrayCell extends Cell {
public GrayCell(int dayOfMon, Rect rect, float s) {
super(dayOfMon, rect, s);
mPaint.setColor(Color.LTGRAY);
}
}
private class RedCell extends Cell {
public RedCell(int dayOfMon, Rect rect, float s) {
super(dayOfMon, rect, s);
mPaint.setColor(0xdddd0000);
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2011 Chris Gao <chris@exina.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.exina.android.calendar;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.Log;
public class Cell {
private static final String TAG = "Cell";
protected Rect mBound = null;
protected int mDayOfMonth = 1; // from 1 to 31
protected Paint mPaint = new Paint(Paint.SUBPIXEL_TEXT_FLAG
| Paint.ANTI_ALIAS_FLAG);
int dx, dy;
public Cell(int dayOfMon, Rect rect, float textSize, boolean bold) {
mDayOfMonth = dayOfMon;
mBound = rect;
mPaint.setTextSize(textSize/*26f*/);
mPaint.setColor(Color.BLACK);
if (bold)
mPaint.setFakeBoldText(true);
dx = (int) mPaint.measureText(String.valueOf(mDayOfMonth)) / 2;
dy = (int) (-mPaint.ascent() + mPaint.descent()) / 2;
}
public Cell(int dayOfMon, Rect rect, float textSize) {
this(dayOfMon, rect, textSize, false);
}
protected void draw(Canvas canvas) {
canvas.drawText(String.valueOf(mDayOfMonth), mBound.centerX() - dx,
mBound.centerY() + dy, mPaint);
}
public int getDayOfMonth() {
return mDayOfMonth;
}
public boolean hitTest(int x, int y) {
return mBound.contains(x, y);
}
public Rect getBound() {
return mBound;
}
public String toString() {
return String.valueOf(mDayOfMonth) + "(" + mBound.toString() + ")";
}
}