diff options
Diffstat (limited to 'GymLog/src/main')
19 files changed, 603 insertions, 0 deletions
diff --git a/GymLog/src/main/AndroidManifest.xml b/GymLog/src/main/AndroidManifest.xml new file mode 100644 index 0000000..417ce01 --- /dev/null +++ b/GymLog/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.mikemiller.gymlog" > + + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" + android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > + <activity + android:name="com.mikemiller.gymlog.MainActivity" + android:label="@string/app_name" > + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/GymLog/src/main/ic_launcher-web.png b/GymLog/src/main/ic_launcher-web.png Binary files differnew file mode 100644 index 0000000..f974377 --- /dev/null +++ b/GymLog/src/main/ic_launcher-web.png diff --git a/GymLog/src/main/java/com/mikemiller/gymlog/Activity.java b/GymLog/src/main/java/com/mikemiller/gymlog/Activity.java new file mode 100644 index 0000000..bce8419 --- /dev/null +++ b/GymLog/src/main/java/com/mikemiller/gymlog/Activity.java @@ -0,0 +1,46 @@ +package com.mikemiller.gymlog; + +import java.io.Serializable; + +/** + * Created by Mike on 3/29/14. COPYRIGHT OLIO. + */ +public class Activity implements Serializable { + private String mName; + private int mSets; + private int mRepsLow; + private int mRepsHigh; + private int mWeightDecrement_percent; + private int mRepIncrement; + + public Activity (String name, int sets, int repsLow, int repsHigh, int weightDecrement_percent, int repIncrement) { + mName = name; + mSets = sets; + mRepsLow = repsLow; + mRepsHigh = repsHigh; + mWeightDecrement_percent = weightDecrement_percent; + mRepIncrement = repIncrement; + } + + public String getName() { return mName; } + public int getSets() { return mSets; } + public int getRepsLow() { return mRepsLow; } + public int getRepsHigh() { return mRepsHigh; } + public int getWeightForSet(int set, int setOneWeight) { + double val = (int)(setOneWeight - (set - 1) * setOneWeight * (mWeightDecrement_percent / 100.0)); + return (int) (5*(Math.round(val/5))); // Round to the nearest 5 lbs + } + public int getRepIncrement() { return mRepIncrement; } + + public String getSummary(int setOneWeight, int currentReps) { + String summary = ""; + String reps = getRepsLow() + (getRepsLow() == getRepsHigh() ? "" : " - " + getRepsHigh()); + summary += reps + " reps ("+ currentReps + ")\n\n"; + for (int i = 1; i <= getSets(); i++) { + summary += i + ": " + getWeightForSet(i, setOneWeight); + if (i > 1 && getRepIncrement() > 0) summary += " (+" + getRepIncrement() + " rep)"; + if (i < getSets()) summary += "\n"; + } + return summary; + } +} diff --git a/GymLog/src/main/java/com/mikemiller/gymlog/ActivityFragment.java b/GymLog/src/main/java/com/mikemiller/gymlog/ActivityFragment.java new file mode 100644 index 0000000..a4986ea --- /dev/null +++ b/GymLog/src/main/java/com/mikemiller/gymlog/ActivityFragment.java @@ -0,0 +1,179 @@ +package com.mikemiller.gymlog; + +import android.app.Fragment; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.GestureDetector; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +public class ActivityFragment extends Fragment { + + private Activity mActivity; + private int mWeight = 0; + private int mReps = 0; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_activity, container, false); + + TextView name = (TextView) view.findViewById(R.id.name); + mActivity = (Activity) getArguments().getSerializable("activity"); + name.setText(mActivity.getName()); + + Button summary = (Button) view.findViewById(R.id.summary); + if (savedInstanceState!= null && savedInstanceState.containsKey("count")) { + mWeight = savedInstanceState.getInt("count"); + } + + summary.setText(Integer.toString(mWeight)); + summary.setOnTouchListener(new View.OnTouchListener() { + GestureDetector doubleTapDetector = new GestureDetector(new DoubleTapDetector(getActivity())); + GestureDetector flingDetector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { + @Override + public boolean onDown(MotionEvent e) { + return false; + } + + @Override + public void onShowPress(MotionEvent e) { + + } + + @Override + public boolean onSingleTapUp(MotionEvent e) { + return false; + } + + @Override + public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + return false; + } + + @Override + public void onLongPress(MotionEvent e) { + decrementWeight(); + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + final float minFlingVelocity = 300; + if (velocityY > minFlingVelocity && Math.abs(velocityX) < minFlingVelocity) { + decrementReps(); + } else if (velocityY < -minFlingVelocity && Math.abs(velocityX) < minFlingVelocity ) { + incrementReps(); + } + return true; + } + }); + + @Override + public boolean onTouch(View v, MotionEvent event) { + if (flingDetector.onTouchEvent(event)) { + return true; + } + if (doubleTapDetector.onTouchEvent(event)) { + // A double tap occurred. + incrementWeight(); + return true; + } + return false; + } + }); + + + /* + count.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + incrementWeight(); + } + });*/ + + return view; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putInt("weight", mWeight); + } + + @Override + public void onViewStateRestored(Bundle savedInstanceState) { + super.onViewStateRestored(savedInstanceState); + + if (savedInstanceState!= null && savedInstanceState.containsKey("weight")) { + setWeight(savedInstanceState.getInt("weight")); + } + } + + private void setWeight(int weight) { + mWeight = weight; + Button summaryButton = (Button) getView().findViewById(R.id.summary); + summaryButton.setText(getSummary()); + } + private void setReps(int reps) { + mReps = reps; + Button summaryButton = (Button) getView().findViewById(R.id.summary); + summaryButton.setText(getSummary()); + } + + private String getSummary() { + return mActivity.getSummary(mWeight, mReps); + } + + public void incrementWeight() { + setWeight(mWeight + 5); + } + public void decrementWeight() { + setWeight(mWeight - 5); + } + public void incrementReps() { + setReps(mReps + 1); + } + public void decrementReps() { + setReps(mReps - 1); + } + + public static ActivityFragment newInstance(Activity activity) { + + ActivityFragment f = new ActivityFragment(); + Bundle b = new Bundle(); + b.putSerializable("activity", activity); + f.setArguments(b); + + return f; + } + + @Override + public void onStop() { + super.onStop(); + saveData(); + } + + private void saveData() { + SharedPreferences.Editor outState = getActivity().getSharedPreferences(getSharedpreferencesName(), Context.MODE_APPEND).edit(); + outState.putInt("weight", mWeight); + outState.putInt("reps", mReps); + outState.commit(); + } + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + SharedPreferences activity_data = getActivity().getSharedPreferences(getSharedpreferencesName(), Context.MODE_APPEND); + setWeight(activity_data.getInt("weight", 0)); + setReps(activity_data.getInt("reps", 0)); + } + + private String getSharedpreferencesName() { + return "activity_data_" + mActivity.getName(); + } +}
\ No newline at end of file diff --git a/GymLog/src/main/java/com/mikemiller/gymlog/DoubleTapDetector.java b/GymLog/src/main/java/com/mikemiller/gymlog/DoubleTapDetector.java new file mode 100644 index 0000000..4b42bc4 --- /dev/null +++ b/GymLog/src/main/java/com/mikemiller/gymlog/DoubleTapDetector.java @@ -0,0 +1,30 @@ +package com.mikemiller.gymlog; + +import android.content.Context; +import android.view.GestureDetector; +import android.view.MotionEvent; + +/** + * Created by Mike on 3/29/14. COPYRIGHT OLIO. + */ +public class DoubleTapDetector extends GestureDetector.SimpleOnGestureListener { + public Context context; + public String phno; + + public DoubleTapDetector(Context con) + { + this.context=con; + } + @Override + public boolean onDown(MotionEvent e) { + return false; + } + @Override + public boolean onDoubleTap(MotionEvent e) { + return true; + } + @Override + public boolean onSingleTapUp(MotionEvent e) { + return false; + } +}
\ No newline at end of file diff --git a/GymLog/src/main/java/com/mikemiller/gymlog/MainActivity.java b/GymLog/src/main/java/com/mikemiller/gymlog/MainActivity.java new file mode 100644 index 0000000..e7c8f60 --- /dev/null +++ b/GymLog/src/main/java/com/mikemiller/gymlog/MainActivity.java @@ -0,0 +1,92 @@ +package com.mikemiller.gymlog; + +import android.app.Fragment; +import android.app.FragmentManager; +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; +import android.support.v13.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; + +import java.util.Arrays; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +public class MainActivity extends FragmentActivity { + + SimpleCounterFragment mEpisodeFragment; + + // 1 = Sunday + final Map<Integer[], Activity[]> mDaysOfWeekToActivity = new HashMap<Integer[], Activity[]>(){{ + put(new Integer[]{2, 3}, new Activity[]{ + new Activity("Barbell Deadlifts", 3, 4, 6, 10, 1), + new Activity("Assisted Chin-ups", 3, 4, 6, 10, 1), + new Activity("Pendlay Rows", 2, 4, 6, 10, 1) }); + put(new Integer[]{4, 5}, new Activity[]{ + new Activity("Flat Dumbell Bench Press", 3, 6, 10, 10, 1), + new Activity("Incline Dumbell Bench Press", 2, 8, 12, 10, 1), + new Activity("Barbell Curls", 3, 0, 8, 0, 0)}); + put(new Integer[]{6, 7, 1}, new Activity[]{ + new Activity("Barbell Squats", 2, 6, 8, 10, 1), + new Activity("Widowmaker Squats", 1, 20, 20, 0, 0), + new Activity("Stiff Legged Deadlifts", 2, 15, 20, 10, 1), + new Activity("Tricep Pushdown", 3, 0, 8, 0, 0), + new Activity("Weighted Ab Cable Crunches", 1, 10, 20, 0, 0)}); + }}; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + ViewPager pager = (ViewPager) findViewById(R.id.viewPager); + pager.setAdapter(new MyPagerAdapter(getFragmentManager())); + + mEpisodeFragment = SimpleCounterFragment.newInstance("Whose Line"); + } + + // 1 = Sunday + private int getDayOfWeek() { + Calendar calendar = Calendar.getInstance(); + return calendar.get(Calendar.DAY_OF_WEEK); + } + + private Activity[] getActivitiesForDayOfWeek(int dayOfWeek) { + for(Integer[] key : mDaysOfWeekToActivity.keySet()) { + if (Arrays.asList(key).contains(dayOfWeek)) { + return mDaysOfWeekToActivity.get(key); + } + } + return new Activity[]{}; + } + + private Activity[] getActivitiesForTody() { + return getActivitiesForDayOfWeek(getDayOfWeek()); + } + + + private class MyPagerAdapter extends FragmentPagerAdapter { + + public MyPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int pos) { + Activity[] activities = getActivitiesForTody(); + + if (pos == 0) { + return mEpisodeFragment; + } + + if (pos > activities.length) pos = activities.length; + + return ActivityFragment.newInstance(activities[pos - 1]); + } + + @Override + public int getCount() { + return getActivitiesForTody().length + 1; + } + } +}
\ No newline at end of file diff --git a/GymLog/src/main/java/com/mikemiller/gymlog/SimpleCounterFragment.java b/GymLog/src/main/java/com/mikemiller/gymlog/SimpleCounterFragment.java new file mode 100644 index 0000000..a6870d0 --- /dev/null +++ b/GymLog/src/main/java/com/mikemiller/gymlog/SimpleCounterFragment.java @@ -0,0 +1,123 @@ +package com.mikemiller.gymlog; + +import android.app.Fragment; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.GestureDetector; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +public class SimpleCounterFragment extends Fragment { + + private String mShow = ""; + private int mCount = 0; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_simple_counter, container, false); + + TextView show = (TextView) view.findViewById(R.id.show); + mShow = getArguments().getString("show"); + show.setText(mShow); + + Button count = (Button) view.findViewById(R.id.count); + if (savedInstanceState!= null && savedInstanceState.containsKey("count")) { + mCount = savedInstanceState.getInt("count"); + } + + count.setText(Integer.toString(mCount)); + + count.setOnTouchListener(new View.OnTouchListener() { + GestureDetector doubleTapDetector = new GestureDetector(new DoubleTapDetector(getActivity())); + + @Override + public boolean onTouch(View v, MotionEvent event) { + if (doubleTapDetector.onTouchEvent(event)) { + // A double tap occurred. + increment(); + return true; + } + return false; + } + }); + + count.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + decrement(); + return true; + } + }); + + return view; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putInt("count", mCount); + } + + @Override + public void onViewStateRestored(Bundle savedInstanceState) { + super.onViewStateRestored(savedInstanceState); + + if (savedInstanceState!= null && savedInstanceState.containsKey("count")) { + setCount(savedInstanceState.getInt("count")); + } + } + + private void setCount(int count) { + mCount = count; + Button countButton = (Button) getView().findViewById(R.id.count); + countButton.setText(Integer.toString(mCount)); + + } + + public void increment() { + setCount(mCount + 1); + } + public void decrement() { + setCount(mCount - 1); + } + + public static SimpleCounterFragment newInstance(String show) { + + SimpleCounterFragment f = new SimpleCounterFragment(); + Bundle b = new Bundle(); + b.putString("show", show); + f.setArguments(b); + + return f; + } + + @Override + public void onStop() { + super.onStop(); + saveData(); + } + + private void saveData() { + + SharedPreferences.Editor outState = getActivity().getSharedPreferences(getSharedpreferencesName(), Context.MODE_APPEND).edit(); + outState.putInt("count", mCount); + outState.commit(); + } + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + SharedPreferences counter_data = getActivity().getSharedPreferences(getSharedpreferencesName(), Context.MODE_APPEND); + setCount(counter_data.getInt("count", 0)); + } + + private String getSharedpreferencesName() { + return "counter_data_" + mShow; + } +}
\ No newline at end of file diff --git a/GymLog/src/main/res/drawable-hdpi/ic_launcher.png b/GymLog/src/main/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..7776dab --- /dev/null +++ b/GymLog/src/main/res/drawable-hdpi/ic_launcher.png diff --git a/GymLog/src/main/res/drawable-mdpi/ic_launcher.png b/GymLog/src/main/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..688a96b --- /dev/null +++ b/GymLog/src/main/res/drawable-mdpi/ic_launcher.png diff --git a/GymLog/src/main/res/drawable-xhdpi/ic_launcher.png b/GymLog/src/main/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..cb6451d --- /dev/null +++ b/GymLog/src/main/res/drawable-xhdpi/ic_launcher.png diff --git a/GymLog/src/main/res/drawable-xxhdpi/ic_launcher.png b/GymLog/src/main/res/drawable-xxhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..cb0b645 --- /dev/null +++ b/GymLog/src/main/res/drawable-xxhdpi/ic_launcher.png diff --git a/GymLog/src/main/res/layout/activity_main.xml b/GymLog/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e5bad81 --- /dev/null +++ b/GymLog/src/main/res/layout/activity_main.xml @@ -0,0 +1,8 @@ +<android.support.v4.view.ViewPager + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/viewPager" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@android:color/black" + />
\ No newline at end of file diff --git a/GymLog/src/main/res/layout/fragment_activity.xml b/GymLog/src/main/res/layout/fragment_activity.xml new file mode 100644 index 0000000..5ae1af5 --- /dev/null +++ b/GymLog/src/main/res/layout/fragment_activity.xml @@ -0,0 +1,31 @@ +<?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="match_parent" + android:orientation="vertical" + android:gravity="center_horizontal" + android:background="@android:color/black" > + + <Button + android:id="@+id/summary" + android:layout_above="@+id/name" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_centerHorizontal="false" + android:gravity="center_vertical" + android:textSize="40dp" + android:text="0" + android:textColor="@android:color/holo_blue_dark" + android:background="@android:color/black" /> + <TextView + android:id="@+id/name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_centerHorizontal="true" + android:gravity="center_horizontal" + android:textSize="30dp" + android:text="Activity Name" + android:textColor="@android:color/holo_blue_dark" /> +</RelativeLayout>
\ No newline at end of file diff --git a/GymLog/src/main/res/layout/fragment_simple_counter.xml b/GymLog/src/main/res/layout/fragment_simple_counter.xml new file mode 100644 index 0000000..327677a --- /dev/null +++ b/GymLog/src/main/res/layout/fragment_simple_counter.xml @@ -0,0 +1,34 @@ +<?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="match_parent" + android:orientation="vertical" + android:gravity="center_horizontal" + android:background="@android:color/black" > + + + <Button + android:id="@+id/count" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_centerHorizontal="true" + android:layout_centerVertical="true" + android:textSize="166dp" + android:text="0" + android:textColor="@android:color/holo_blue_dark" + android:background="@android:color/black" /> + <View + android:layout_width="match_parent" + android:layout_height="10dp"/> + <TextView + android:id="@+id/show" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentBottom="true" + android:layout_centerHorizontal="true" + android:gravity="center_horizontal" + android:textSize="26dp" + android:text="Show Name" + android:textColor="@android:color/holo_blue_dark" /> +</RelativeLayout>
\ No newline at end of file diff --git a/GymLog/src/main/res/menu/main.xml b/GymLog/src/main/res/menu/main.xml new file mode 100644 index 0000000..e6ab32e --- /dev/null +++ b/GymLog/src/main/res/menu/main.xml @@ -0,0 +1,10 @@ +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + tools:context="com.mikemiller.gymlog.MainActivity" > + + <item android:id="@+id/action_settings" + android:title="@string/action_settings" + android:orderInCategory="100" + app:showAsAction="never" /> +</menu> diff --git a/GymLog/src/main/res/values-w820dp/dimens.xml b/GymLog/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/GymLog/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ +<resources> + <!-- Example customization of dimensions originally defined in res/values/dimens.xml + (such as screen margins) for screens with more than 820dp of available width. This + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> + <dimen name="activity_horizontal_margin">64dp</dimen> +</resources> diff --git a/GymLog/src/main/res/values/dimens.xml b/GymLog/src/main/res/values/dimens.xml new file mode 100644 index 0000000..a0171a7 --- /dev/null +++ b/GymLog/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ +<resources> + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="activity_horizontal_margin">16dp</dimen> + <dimen name="activity_vertical_margin">16dp</dimen> + + </resources> diff --git a/GymLog/src/main/res/values/strings.xml b/GymLog/src/main/res/values/strings.xml new file mode 100644 index 0000000..530eeb9 --- /dev/null +++ b/GymLog/src/main/res/values/strings.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="app_name">GymLog</string> + <string name="hello_world">Hello world!</string> + <string name="action_settings">Settings</string> + <string name="hello_blank_fragment">Hello blank fragment</string> + +</resources> diff --git a/GymLog/src/main/res/values/styles.xml b/GymLog/src/main/res/values/styles.xml new file mode 100644 index 0000000..766ab99 --- /dev/null +++ b/GymLog/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <!-- Customize your theme here. --> + </style> + +</resources> |