diff --git a/app/build.gradle b/app/build.gradle index 95fce09484b490f11676737b2a39c9bba242eec0..a86e27e60a98c4c55022980556826e76a6b9ff6b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,6 +22,7 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' + implementation 'com.android.support:support-v4:26.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 27bc10704a1a474159fe11be310713736ed772f7..d7e8703990ab8307d0c15a3741d8d1561a25dfad 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,7 +23,8 @@ <activity android:name=".HIstoryActivity" /> <activity android:name=".HomeActivity" /> <activity android:name=".PlankActivity" /> - <activity android:name=".LevelActivity"></activity> + <activity android:name=".LevelActivity" /> + <activity android:name=".ExerciseActivity"></activity> </application> </manifest> \ No newline at end of file diff --git a/app/src/main/java/com/example/leo/fitnessdiy/ExerciseActivity.java b/app/src/main/java/com/example/leo/fitnessdiy/ExerciseActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..9dc8570903d0dd352cec7ff1704a479547dfa815 --- /dev/null +++ b/app/src/main/java/com/example/leo/fitnessdiy/ExerciseActivity.java @@ -0,0 +1,13 @@ +package com.example.leo.fitnessdiy; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +public class ExerciseActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_exercise); + } +} diff --git a/app/src/main/java/com/example/leo/fitnessdiy/ExerciseFragment.java b/app/src/main/java/com/example/leo/fitnessdiy/ExerciseFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..41f289e5f3fc6a8d51a006d08df760d32338c62c --- /dev/null +++ b/app/src/main/java/com/example/leo/fitnessdiy/ExerciseFragment.java @@ -0,0 +1,108 @@ +package com.example.leo.fitnessdiy; + +import android.content.Context; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + + +/** + * A simple {@link Fragment} subclass. + * Activities that contain this fragment must implement the + * {@link ExerciseFragment.OnFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link ExerciseFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class ExerciseFragment extends Fragment { + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + private OnFragmentInteractionListener mListener; + + public ExerciseFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment ExerciseFragment. + */ + // TODO: Rename and change types and number of parameters + public static ExerciseFragment newInstance(String param1, String param2) { + ExerciseFragment fragment = new ExerciseFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_exercise, container, false); + } + + // TODO: Rename method, update argument and hook method into UI event + public void onButtonPressed(Uri uri) { + if (mListener != null) { + mListener.onFragmentInteraction(uri); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnFragmentInteractionListener) { + mListener = (OnFragmentInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated + * to the activity and potentially other fragments contained in that + * activity. + * <p> + * See the Android Training lesson <a href= + * "http://developer.android.com/training/basics/fragments/communicating.html" + * >Communicating with Other Fragments</a> for more information. + */ + public interface OnFragmentInteractionListener { + // TODO: Update argument type and name + void onFragmentInteraction(Uri uri); + } +} diff --git a/app/src/main/java/com/example/leo/fitnessdiy/HistoryFragment.java b/app/src/main/java/com/example/leo/fitnessdiy/HistoryFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..0a72bb647b501191105b2354e94507f5ceccfae0 --- /dev/null +++ b/app/src/main/java/com/example/leo/fitnessdiy/HistoryFragment.java @@ -0,0 +1,108 @@ +package com.example.leo.fitnessdiy; + +import android.content.Context; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + + +/** + * A simple {@link Fragment} subclass. + * Activities that contain this fragment must implement the + * {@link HistoryFragment.OnFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link HistoryFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class HistoryFragment extends Fragment { + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + private OnFragmentInteractionListener mListener; + + public HistoryFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment HistoryFragment. + */ + // TODO: Rename and change types and number of parameters + public static HistoryFragment newInstance(String param1, String param2) { + HistoryFragment fragment = new HistoryFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_history, container, false); + } + + // TODO: Rename method, update argument and hook method into UI event + public void onButtonPressed(Uri uri) { + if (mListener != null) { + mListener.onFragmentInteraction(uri); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnFragmentInteractionListener) { + mListener = (OnFragmentInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated + * to the activity and potentially other fragments contained in that + * activity. + * <p> + * See the Android Training lesson <a href= + * "http://developer.android.com/training/basics/fragments/communicating.html" + * >Communicating with Other Fragments</a> for more information. + */ + public interface OnFragmentInteractionListener { + // TODO: Update argument type and name + void onFragmentInteraction(Uri uri); + } +} diff --git a/app/src/main/java/com/example/leo/fitnessdiy/HomeActivity.java b/app/src/main/java/com/example/leo/fitnessdiy/HomeActivity.java index cc26c29b106e96efb618a95a15bfb428efab6883..11bedcf53226f31e3f73e2321a2c8f512e650919 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/HomeActivity.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/HomeActivity.java @@ -1,11 +1,23 @@ package com.example.leo.fitnessdiy; import android.content.Intent; +import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; + +public class HomeActivity extends AppCompatActivity + implements ExerciseFragment.OnFragmentInteractionListener, + HistoryFragment.OnFragmentInteractionListener{ + + @Override + public void onFragmentInteraction(Uri uri) { + + } -public class HomeActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { @@ -17,4 +29,29 @@ public class HomeActivity extends AppCompatActivity { Intent i = new Intent(getApplicationContext(), HIstoryActivity.class); startActivity(i); } + + public void startExcercise(View view) { + Intent i = new Intent(getApplicationContext(), ExerciseActivity.class); + startActivity(i); + } + + public void changeFragment(View view){ + Fragment fragment; + + if(view == findViewById(R.id.history_button)){ + fragment = new HistoryFragment(); + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction ft = fm.beginTransaction(); + ft.replace(R.id.home_fragment, fragment); + ft.commit(); + } + if(view == findViewById(R.id.exercise_button)){ + fragment = new ExerciseFragment(); + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction ft = fm.beginTransaction(); + ft.replace(R.id.home_fragment, fragment); + ft.commit(); + } + } + } diff --git a/app/src/main/res/layout/activity_exercise.xml b/app/src/main/res/layout/activity_exercise.xml new file mode 100644 index 0000000000000000000000000000000000000000..d8569bcb0b57c1e9af591fdacd85f0cc00079a17 --- /dev/null +++ b/app/src/main/res/layout/activity_exercise.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout 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" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="com.example.leo.fitnessdiy.ExerciseActivity" + android:orientation="vertical"> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Plank"/> + +</LinearLayout> diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index fb02bf5a261ba0d76114836b1eb7c6d753c8f585..47a494b687e61427a45fdde798eca0211f7bf127 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -4,14 +4,36 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.example.leo.fitnessdiy.HomeActivity" - android:orientation="vertical"> + android:orientation="vertical" + tools:context="com.example.leo.fitnessdiy.HomeActivity"> - <Button - android:layout_width="wrap_content" + <LinearLayout + android:layout_width="match_parent" android:layout_height="wrap_content" - android:id="@+id/history-button" - android:text="@string/history" - android:onClick="openHistory"/> + android:orientation="horizontal"> + <Button + android:id="@+id/history_button" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:onClick="changeFragment" + android:layout_weight="1" + android:text="@string/history" + /> + <Button + android:id="@+id/exercise_button" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:text="@string/exercise" + android:onClick="changeFragment"/> + </LinearLayout> + <fragment + android:name="com.example.leo.fitnessdiy.ExerciseFragment" + android:id="@+id/home_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + /> + + </LinearLayout> diff --git a/app/src/main/res/layout/fragment_exercise.xml b/app/src/main/res/layout/fragment_exercise.xml new file mode 100644 index 0000000000000000000000000000000000000000..83fbd4042372fea4a797d9d2c8b08814da1dbb1b --- /dev/null +++ b/app/src/main/res/layout/fragment_exercise.xml @@ -0,0 +1,13 @@ +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="com.example.leo.fitnessdiy.ExerciseFragment"> + + <!-- TODO: Update blank fragment layout --> + <TextView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:text="EXERCISE" /> + +</FrameLayout> diff --git a/app/src/main/res/layout/fragment_history.xml b/app/src/main/res/layout/fragment_history.xml new file mode 100644 index 0000000000000000000000000000000000000000..102649b2c114b2522e12815d800533abb186b776 --- /dev/null +++ b/app/src/main/res/layout/fragment_history.xml @@ -0,0 +1,13 @@ +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="com.example.leo.fitnessdiy.HistoryFragment"> + + <!-- TODO: Update blank fragment layout --> + <TextView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:text="HISTORY" /> + +</FrameLayout> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 817cf0db14ceeedd7ed5fe864242003a88cbc359..f48c5d9bc069f0452ca7d9404b228ea7d0b2fd33 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,4 +13,8 @@ <string name="advanced">Advanced</string> <string name="history">History</string> <string name="plank">Plank</string> + <string name="exercise">Start Exercise</string> + + <!-- TODO: Remove or change this placeholder text --> + <string name="hello_blank_fragment">Hello blank fragment</string> </resources>