diff --git a/app/src/main/java/com/example/leo/fitnessdiy/BlankFragment.java b/app/src/main/java/com/example/leo/fitnessdiy/BlankFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..5a047ea49daa72384157ec82c36e18ac296f9b8e --- /dev/null +++ b/app/src/main/java/com/example/leo/fitnessdiy/BlankFragment.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 BlankFragment.OnFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link BlankFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class BlankFragment 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 BlankFragment() { + // 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 BlankFragment. + */ + // TODO: Rename and change types and number of parameters + public static BlankFragment newInstance(String param1, String param2) { + BlankFragment fragment = new BlankFragment(); + 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_blank, 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 ea1a0671b61f969a1549e00b74a26a46593adbac..9b797d343d235f0dd394a210d5b1bafc5cc305fd 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/HomeActivity.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/HomeActivity.java @@ -12,7 +12,8 @@ import android.support.v4.app.FragmentTransaction; public class HomeActivity extends AppCompatActivity implements ExerciseFragment.OnFragmentInteractionListener, - HistoryFragment.OnFragmentInteractionListener{ + HistoryFragment.OnFragmentInteractionListener, + BlankFragment.OnFragmentInteractionListener{ private FloatingActionButton chatButton; @Override @@ -38,12 +39,19 @@ public class HomeActivity extends AppCompatActivity public void changeFragment(View view){ Fragment fragment; +// fragment = getSupportFragmentManager().findFragmentById(R.id.home_fragment); +// FragmentManager manager = getSupportFragmentManager(); +// if (fragment != null) { +// getSupportFragmentManager().beginTransaction().remove(fragment).commit(); +// manager.popBackStack(); +// } 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.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); } else if(view == findViewById(R.id.exercise_button)){ @@ -51,6 +59,8 @@ public class HomeActivity extends AppCompatActivity FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.home_fragment, fragment); + ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); + ft.commit(); } } diff --git a/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java b/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java index d7fc235b742bdbbf7258277e26b080af8ed783fb..c6fdfb270d99e562b2c5b5779b339eb9fd847d74 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/PlankActivity.java @@ -1,5 +1,7 @@ package com.example.leo.fitnessdiy; +import android.content.Intent; +import android.net.Uri; import android.os.CountDownTimer; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; @@ -14,12 +16,21 @@ public class PlankActivity extends AppCompatActivity { setContentView(R.layout.activity_plank); } + public String milisecondToMinutes(long l){ + long minutes = (l/1000)/60; + long seconds = (l/1000)%60; + if (seconds >= 10) + return minutes+" : "+seconds; + else + return minutes+" : 0"+seconds; + } + public void countDownPlank(View view) { final TextView countText = findViewById(R.id.count_timer); - new CountDownTimer(60000, 1000){ + new CountDownTimer(120000, 1000){ @Override public void onTick(long l) { - String waktu = Long.toString(l/1000); + String waktu = milisecondToMinutes(l); countText.setText(waktu); } @@ -29,4 +40,15 @@ public class PlankActivity extends AppCompatActivity { } }.start(); } + + public void openVideo(View view) { + String url = (String)view.getTag(); + + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + + intent.setData(Uri.parse(url)); + startActivity(intent); + } } diff --git a/app/src/main/res/drawable/plank_video_1.PNG b/app/src/main/res/drawable/plank_video_1.PNG new file mode 100644 index 0000000000000000000000000000000000000000..f0a8e23b8452dd87593021d4179a450fa409aa1a Binary files /dev/null and b/app/src/main/res/drawable/plank_video_1.PNG differ diff --git a/app/src/main/res/drawable/plank_video_2.PNG b/app/src/main/res/drawable/plank_video_2.PNG new file mode 100644 index 0000000000000000000000000000000000000000..647a0a8372c82077f14d73d982e1eee420ad7b05 Binary files /dev/null and b/app/src/main/res/drawable/plank_video_2.PNG differ diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 8f7f8fa2c90587ce8a1431d5409694bc5b4f8689..7b77666d02d3eb399e52ac097026d93abca83c1a 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -30,7 +30,7 @@ <fragment android:id="@+id/home_fragment" - android:name="com.example.leo.fitnessdiy.ExerciseFragment" + android:name="com.example.leo.fitnessdiy.BlankFragment" android:layout_width="match_parent" android:layout_height="471dp" /> diff --git a/app/src/main/res/layout/activity_plank.xml b/app/src/main/res/layout/activity_plank.xml index 1424f0db93c95d215df0f673304fa5514be36dee..b4941ba5686e7365bc8a362dfdf3050d674059fe 100644 --- a/app/src/main/res/layout/activity_plank.xml +++ b/app/src/main/res/layout/activity_plank.xml @@ -12,19 +12,73 @@ android:layout_height="wrap_content" android:layout_marginBottom="100dp" android:text="@string/plank" /> + <Button + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:layout_marginBottom="30dp" + android:onClick="countDownPlank" + android:text="start" /> <TextView android:id="@+id/count_timer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" - android:text="1:00" /> + android:textSize="32sp" + android:text="2 : 00" /> - <Button + <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="center_horizontal" - android:onClick="countDownPlank" - android:text="start" /> + android:layout_marginBottom="30dp" + android:text="@string/plank_video" /> + + + + <!--<ScrollView--> + <!--android:layout_width="wrap_content"--> + <!--android:layout_height="wrap_content">--> + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:tag="https://www.youtube.com/watch?v=TvxNkmjdhMM" + android:clickable="true" + android:focusable="true" + android:onClick="openVideo" + android:layout_margin="4dp" + > + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/plank_video_1"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="How to Plank"/> + </LinearLayout> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:tag="https://www.youtube.com/watch?v=_nZgpZLf7ZA" + android:clickable="true" + android:focusable="true" + android:onClick="openVideo" + android:layout_margin="4dp"> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/plank_video_2"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Benefits of Plank"/> + </LinearLayout> + + <!--</ScrollView>--> + </LinearLayout> diff --git a/app/src/main/res/layout/fragment_blank.xml b/app/src/main/res/layout/fragment_blank.xml new file mode 100644 index 0000000000000000000000000000000000000000..13773b2e564b6b6310c013a23e9354c1fb69a6a3 --- /dev/null +++ b/app/src/main/res/layout/fragment_blank.xml @@ -0,0 +1,7 @@ +<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.BlankFragment"> + +</FrameLayout> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f48c5d9bc069f0452ca7d9404b228ea7d0b2fd33..5a9d178bb7cd510f517b1ff1ee73cfe28c4d30ab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,4 +17,5 @@ <!-- TODO: Remove or change this placeholder text --> <string name="hello_blank_fragment">Hello blank fragment</string> + <string name="plank_video">Plank Video</string> </resources>