Skip to content

Commit

Permalink
- Split heart beating coping skill into two
Browse files Browse the repository at this point in the history
  • Loading branch information
pdille committed Jan 24, 2020
1 parent 19ec264 commit 80aea83
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 118 deletions.
83 changes: 41 additions & 42 deletions ...oping_skills/post_coping_skills/post_coping_skill_heart_beating/HeartBeatingActivity.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,28 @@
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import org.cmucreatelab.android.flutterprek.Constants;
import org.cmucreatelab.android.flutterprek.GlobalHandler;
import org.cmucreatelab.android.flutterprek.R;
import org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.PostCopingSkillActivity;
import org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments.HeartBeatingFragment;
import org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments.HowFastIsHeartBeatingFragment;
import org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments.PlaceHandOnHeartFragment;
import org.cmucreatelab.android.flutterprek.audio.AudioPlayer;

import static org.cmucreatelab.android.flutterprek.SessionTracker.ITINERARY_INDEX;

public class HeartBeatingActivity extends PostCopingSkillActivity {
public class HeartBeatingActivity extends PostCopingSkillActivity implements HeartBeatingFragment.ActivityCallback {

private int itineraryIndex;


private void goToNextPostCopingSkillActivity() {
Intent intent = GlobalHandler.getInstance(getApplicationContext()).getSessionTracker().getNextIntentFromItinerary(this, itineraryIndex);
startActivity(intent);
}
private PlaceHandOnHeartFragment placeHandOnHeartFragment;
private HowFastIsHeartBeatingFragment howFastIsHeartBeatingFragment;


@Override
public String getAudioFileForPostCopingSkillTitle() {
return "etc/audio_prompts/audio_heart_beating_how_fast.wav";
return null;
}


Expand All @@ -48,36 +44,39 @@ protected void onCreate(Bundle savedInstanceState) {
GlobalHandler.getInstance(getApplicationContext()).endCurrentSession(this);
}

Animation slow = AnimationUtils.loadAnimation(this, R.anim.heart_beat_slow);
Animation fast = AnimationUtils.loadAnimation(this, R.anim.heart_beat_fast);
ImageView heartSlow = findViewById(R.id.imageViewBeatingSlow);
ImageView heartFast = findViewById(R.id.imageViewBeatingFast);

heartSlow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!activityShouldHandleOnClickEvents()) {
Log.w(Constants.LOG_TAG, "ignoring onclick event when activityShouldHandleOnClickEvents is false");
return;
}
GlobalHandler.getInstance(getApplicationContext()).getSessionTracker().onSelectedHeartBeat("slow");
goToNextPostCopingSkillActivity();
}
});
heartFast.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!activityShouldHandleOnClickEvents()) {
Log.w(Constants.LOG_TAG, "ignoring onclick event when activityShouldHandleOnClickEvents is false");
return;
}
GlobalHandler.getInstance(getApplicationContext()).getSessionTracker().onSelectedHeartBeat("fast");
goToNextPostCopingSkillActivity();
}
});

heartSlow.startAnimation(slow);
heartFast.startAnimation(fast);
this.placeHandOnHeartFragment = (PlaceHandOnHeartFragment) (getSupportFragmentManager().findFragmentById(R.id.placeHandOnHeartFragment));
this.howFastIsHeartBeatingFragment = (HowFastIsHeartBeatingFragment) (getSupportFragmentManager().findFragmentById(R.id.howFastIsHeartBeatingFragment));
}

@Override
public void setFragment(HeartBeatingFragment.FragmentState fragmentState) {
String audioToPlay;
if (fragmentState == HeartBeatingFragment.FragmentState.PLACE_HAND_ON_HEART) {
placeHandOnHeartFragment.displayFragment(true, this);
howFastIsHeartBeatingFragment.displayFragment(false, this);
audioToPlay = "etc/audio_prompts/audio_place_hand_on_heart.wav";
} else {
placeHandOnHeartFragment.displayFragment(false, this);
howFastIsHeartBeatingFragment.displayFragment(true, this);
audioToPlay = "etc/audio_prompts/audio_how_fast_is_heart_beating.wav";
}
AudioPlayer.getInstance(getApplicationContext()).stop();
playAudio(audioToPlay);
restartOverlayTimers();
}


@Override
public void goToNextActivity() {
Intent intent = GlobalHandler.getInstance(getApplicationContext()).getSessionTracker().getNextIntentFromItinerary(this, itineraryIndex);
startActivity(intent);
finish();
}

@Override
protected void onResume() {
setFragment(HeartBeatingFragment.FragmentState.PLACE_HAND_ON_HEART);
super.onResume();
}

}
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();


}
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);
}
}
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);
}


}
89 changes: 14 additions & 75 deletions android/app/src/main/res/layout/_coping_skill__activity_heart_beating.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,88 +16,27 @@
android:layout_width="match_parent"
android:layout_height="65sp" />

<android.support.constraint.ConstraintLayout

<fragment
android:id="@+id/placeHandOnHeartFragment"
android:name="org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments.PlaceHandOnHeartFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
style="@style/StudentSectionLayoutWithText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/StudentSectionText"
android:text="@string/heart_beating_prompt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textTitle">

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/viewBeatingSlow"
style="@style/NonGridViewItem">

<ImageView
android:id="@+id/imageViewBeatingSlow"
android:src="@drawable/heart"
android:padding="20sp"
style="@style/GridViewItemThumbnail.FitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/text1"
android:text="@string/heart_beating_slow"
style="@style/GridViewItemLowerTitle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/viewBeatingFast"
style="@style/NonGridViewItem">
app:layout_constraintTop_toBottomOf="@+id/appHeader" />

<ImageView
android:id="@+id/imageViewBeatingFast"
android:src="@drawable/heart"
android:padding="20sp"
style="@style/GridViewItemThumbnail.FitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/text2"
android:text="@string/heart_beating_fast"
style="@style/GridViewItemLowerTitle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>

</LinearLayout>

</android.support.constraint.ConstraintLayout>
<fragment
android:id="@+id/howFastIsHeartBeatingFragment"
android:name="org.cmucreatelab.android.flutterprek.activities.student_section.coping_skills.post_coping_skills.post_coping_skill_heart_beating.fragments.HowFastIsHeartBeatingFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appHeader" />

</android.support.constraint.ConstraintLayout>

Expand Down
Loading

0 comments on commit 80aea83

Please sign in to comment.