-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Split heart beating coping skill into two
- Loading branch information
Showing
8 changed files
with
320 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ls/post_coping_skills/post_coping_skill_heart_beating/fragments/HeartBeatingFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments; | ||
|
||
import android.media.MediaPlayer; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.view.View; | ||
|
||
import org.cmucreatelab.android.flutterprek.activities.fragments.AbstractFragment; | ||
|
||
public abstract class HeartBeatingFragment extends AbstractFragment { | ||
|
||
private HeartBeatingFragment.ActivityCallback activityCallback; | ||
private @NonNull View fragmentView; | ||
|
||
public enum FragmentState { | ||
PLACE_HAND_ON_HEART, HOW_FAST_IS_HEART_BEATING | ||
} | ||
|
||
public interface ActivityCallback extends MediaPlayer.OnCompletionListener { | ||
|
||
void setFragment(HeartBeatingFragment.FragmentState fragmentState); | ||
|
||
void goToNextActivity(); | ||
|
||
void releaseOverlayTimers(); | ||
|
||
void restartOverlayTimers(); | ||
|
||
} | ||
|
||
|
||
@Override | ||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
this.fragmentView = view; | ||
fragmentView.setVisibility(View.GONE); | ||
} | ||
|
||
|
||
public void displayFragment(boolean display, HeartBeatingFragment.ActivityCallback activity) { | ||
this.activityCallback = activity; | ||
fragmentView.setVisibility(display ? View.VISIBLE : View.GONE); | ||
if (display) { | ||
initializeFragment(); | ||
} | ||
} | ||
|
||
|
||
public HeartBeatingFragment.ActivityCallback getActivityCallback() { | ||
return activityCallback; | ||
} | ||
|
||
|
||
@NonNull | ||
public View getFragmentView() { | ||
return fragmentView; | ||
} | ||
|
||
|
||
/** this method runs to initialize the displayed fragment (example: visibility on views, class logic). */ | ||
public abstract void initializeFragment(); | ||
|
||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...oping_skills/post_coping_skill_heart_beating/fragments/HowFastIsHeartBeatingFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments; | ||
|
||
import android.view.View; | ||
import android.view.animation.Animation; | ||
import android.view.animation.AnimationUtils; | ||
import android.widget.ImageView; | ||
|
||
import org.cmucreatelab.android.flutterprek.GlobalHandler; | ||
import org.cmucreatelab.android.flutterprek.R; | ||
|
||
public class HowFastIsHeartBeatingFragment extends HeartBeatingFragment { | ||
|
||
@Override | ||
public int getInflatedLayoutResource() { | ||
return R.layout._coping_skill__fragment_how_fast_is_heart_beating; | ||
} | ||
|
||
|
||
@Override | ||
public void initializeFragment() { | ||
View fragmentView = getFragmentView(); | ||
Animation slow = AnimationUtils.loadAnimation(getActivity(), R.anim.heart_beat_slow); | ||
Animation fast = AnimationUtils.loadAnimation(getActivity(), R.anim.heart_beat_fast); | ||
ImageView heartSlow = fragmentView.findViewById(R.id.imageViewBeatingSlow); | ||
ImageView heartFast = fragmentView.findViewById(R.id.imageViewBeatingFast); | ||
|
||
final HeartBeatingFragment.ActivityCallback activityCallback = getActivityCallback(); | ||
getFragmentView().findViewById(R.id.imageViewBeatingSlow).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
GlobalHandler.getInstance(getActivity().getApplicationContext()).getSessionTracker().onSelectedHeartBeat("slow"); | ||
activityCallback.goToNextActivity(); | ||
} | ||
}); | ||
getFragmentView().findViewById(R.id.imageViewBeatingFast).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
GlobalHandler.getInstance(getActivity().getApplicationContext()).getSessionTracker().onSelectedHeartBeat("fast"); | ||
activityCallback.goToNextActivity(); | ||
} | ||
}); | ||
|
||
heartSlow.startAnimation(slow); | ||
heartFast.startAnimation(fast); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ost_coping_skills/post_coping_skill_heart_beating/fragments/PlaceHandOnHeartFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments; | ||
|
||
import android.media.MediaPlayer; | ||
import android.view.View; | ||
import android.widget.VideoView; | ||
|
||
import org.cmucreatelab.android.flutterprek.R; | ||
import org.cmucreatelab.android.flutterprek.video.VideoPlayer; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
public class PlaceHandOnHeartFragment extends HeartBeatingFragment { | ||
|
||
public String getFilePathForVideo() { | ||
return "android.resource://" + getActivity().getPackageName() + "/" + R.raw.hand_on_heart; | ||
} | ||
|
||
private final MediaPlayer.OnCompletionListener listener = new MediaPlayer.OnCompletionListener() { | ||
@Override | ||
public void onCompletion(MediaPlayer mp) { | ||
getActivityCallback().setFragment(FragmentState.HOW_FAST_IS_HEART_BEATING); | ||
} | ||
}; | ||
|
||
@Override | ||
public int getInflatedLayoutResource() { | ||
return R.layout._coping_skill__fragment_place_hand_on_heart; | ||
} | ||
|
||
@Override | ||
public void initializeFragment() { | ||
View fragmentView = getFragmentView(); | ||
VideoView videoView = fragmentView.findViewById(R.id.videoView); | ||
|
||
VideoPlayer videoPlayer = VideoPlayer.getInstance(getActivity().getApplicationContext()); | ||
videoPlayer.prepareViewWithVideo(getActivity(), videoView, getFilePathForVideo()); | ||
videoPlayer.playVideo(false,listener); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.