diff --git a/PenPal/gen/edu/berkeley/cs160/off_by_1/R.java b/PenPal/gen/edu/berkeley/cs160/off_by_1/R.java
index f768e85..b4982b2 100644
--- a/PenPal/gen/edu/berkeley/cs160/off_by_1/R.java
+++ b/PenPal/gen/edu/berkeley/cs160/off_by_1/R.java
@@ -1079,8 +1079,8 @@ public static final class id {
public static final int questionButton=0x7f07004f;
public static final int radio=0x7f07002f;
public static final int receivedContainer=0x7f070060;
- public static final int recordButton=0x7f07006c;
- public static final int recordProgressBar=0x7f07006b;
+ public static final int recordButton=0x7f07006b;
+ public static final int recordProgressBar=0x7f07006c;
public static final int recordTimer=0x7f07006d;
public static final int reply=0x7f07005f;
public static final int research=0x7f070057;
@@ -1266,10 +1266,10 @@ public static final class string {
public static final int green=0x7f0c0030;
public static final int hello_user=0x7f0c001a;
public static final int home_button=0x7f0c0016;
- public static final int internet_error=0x7f0c003f;
+ public static final int internet_error=0x7f0c0043;
public static final int language=0x7f0c003c;
public static final int largesize=0x7f0c0038;
- public static final int loading=0x7f0c0040;
+ public static final int loading=0x7f0c0044;
public static final int location=0x7f0c003b;
public static final int medsize=0x7f0c0037;
public static final int message_sent_text=0x7f0c0020;
@@ -1280,10 +1280,14 @@ public static final class string {
public static final int red=0x7f0c002b;
public static final int reply_button=0x7f0c0026;
public static final int research_pen_pal=0x7f0c0028;
- public static final int send_another=0x7f0c0041;
+ public static final int send_another=0x7f0c0045;
public static final int send_message_button=0x7f0c0029;
public static final int send_message_text=0x7f0c001f;
public static final int smallsize=0x7f0c0036;
+ public static final int start_play=0x7f0c0041;
+ public static final int start_record=0x7f0c003f;
+ public static final int stop_play=0x7f0c0042;
+ public static final int stop_record=0x7f0c0040;
public static final int stroke=0x7f0c003a;
public static final int text_message=0x7f0c0021;
public static final int title_activity_friend_list=0x7f0c000e;
@@ -1294,7 +1298,7 @@ public static final class string {
public static final int title_activity_receive_message=0x7f0c0011;
public static final int title_activity_send_message=0x7f0c0013;
public static final int to_user=0x7f0c0025;
- public static final int undo=0x7f0c0042;
+ public static final int undo=0x7f0c0046;
public static final int user_profile=0x7f0c002a;
public static final int voice_message=0x7f0c0023;
public static final int yellow=0x7f0c002e;
diff --git a/PenPal/res/layout/voice_message.xml b/PenPal/res/layout/voice_message.xml
index a0e75d4..0de5a5e 100644
--- a/PenPal/res/layout/voice_message.xml
+++ b/PenPal/res/layout/voice_message.xml
@@ -4,16 +4,6 @@
android:layout_height="match_parent"
android:orientation="vertical" >
-
-
+ android:text="@string/start_record"
+ android:visibility="visible"
+ />
+ android:layout_marginTop="140dp"
+ android:text="@string/start_play"
+ android:visibility="invisible" />
+
+
-
+
\ No newline at end of file
diff --git a/PenPal/res/values/strings.xml b/PenPal/res/values/strings.xml
index ac7911f..1e4db88 100644
--- a/PenPal/res/values/strings.xml
+++ b/PenPal/res/values/strings.xml
@@ -57,6 +57,12 @@
%1$s speaks %2$s
Throw me a question!
Hi Jack Jack,\n How are you doing today?
+ Record Message
+ Stop Recording
+ Play Message
+ "Stop Playing"
+
+
- What are you learning in school?
- What did you eat for breakfast?
diff --git a/PenPal/src/edu/berkeley/cs160/off_by_1/MessageFragment.java b/PenPal/src/edu/berkeley/cs160/off_by_1/MessageFragment.java
index d99da37..2449ef6 100644
--- a/PenPal/src/edu/berkeley/cs160/off_by_1/MessageFragment.java
+++ b/PenPal/src/edu/berkeley/cs160/off_by_1/MessageFragment.java
@@ -18,7 +18,7 @@ public class MessageFragment extends Fragment{
MessageFragment fragment;
boolean draw = false;
- Activity con;
+ Activity act;
public MessageFragment() {
@@ -38,7 +38,7 @@ public MessageFragment(String type) {
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
- con = activity;
+ act = activity;
Log.d("debug", "hello onattach");
}
@@ -48,15 +48,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
//return inflater.inflate(R.layout.text_message, container, false);
- if (draw) {
+ //if (draw) {
Log.d("debug", "it's drawing");
Log.d("debug", getActivity().toString());
- onAttach(getActivity());
- fragment.onAttach(con);
- draw = false;
+ //onAttach(getActivity());
+ fragment.onAttach(act);
+ //draw = false;
return fragment.onCreateView(inflater, container, savedInstanceState);
- }
- return fragment.onCreateView(inflater, container, savedInstanceState);
+ //}
+ //return fragment.onCreateView(inflater, container, savedInstanceState);
}
Intent getIntent() {
diff --git a/PenPal/src/edu/berkeley/cs160/off_by_1/VoiceMessageFragment.java b/PenPal/src/edu/berkeley/cs160/off_by_1/VoiceMessageFragment.java
index 677e651..fef0d84 100644
--- a/PenPal/src/edu/berkeley/cs160/off_by_1/VoiceMessageFragment.java
+++ b/PenPal/src/edu/berkeley/cs160/off_by_1/VoiceMessageFragment.java
@@ -1,4 +1,4 @@
- package edu.berkeley.cs160.off_by_1;
+package edu.berkeley.cs160.off_by_1;
import java.io.File;
@@ -23,192 +23,203 @@
import android.widget.TextView;
public class VoiceMessageFragment extends MessageFragment {
-
- TextView time;
- Button recordButton;
- Button playButton;
- String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/voicemessage.mp4";
- MediaRecorder recorder;
- MediaPlayer player;
- ProgressBar progress;
- Handler handler = new Handler();
- Timer timer;
- int record = 0;
-
- AsyncTask task;
-
- int x = 0;
- long delay;
- long cap;
- boolean cancel = false;
-
- boolean recording = false;
- boolean playing = false;
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- Log.d("debug", "inflating voice message");
- View v = inflater.inflate(R.layout.voice_message, container, false);
- recordButton = (Button) v.findViewById(R.id.recordButton);
- recordButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- recordMessage(recording);
- recording = !recording;
+
+ TextView time;
+ Button recordButton;
+ Button playButton;
+ String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/voicemessage.mp4";
+ MediaRecorder recorder;
+ MediaPlayer player;
+ ProgressBar progress;
+ Handler handler = new Handler();
+ Timer timer;
+ int record = 0;
+ String startPlay;
+
+ AsyncTask task;
+
+ int x = 0;
+ long delay;
+ long cap;
+ boolean cancel = false;
+
+ boolean recording = false;
+ boolean playing = false;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ Log.d("debug", "inflating voice message");
+ View v = inflater.inflate(R.layout.voice_message, container, false);
+ startPlay = act.getString(R.string.start_play);
+ recordButton = (Button) v.findViewById(R.id.recordButton);
+ Log.d("debug", "recordButton" + recordButton);
+ recordButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ recordMessage(recording);
+ recording = !recording;
+ }
+ });
+ //setPlayButton();
+
+ time = (TextView) v.findViewById(R.id.recordTimer);
+ setTime(":15");
+
+ progress = (ProgressBar) v.findViewById(R.id.recordProgressBar);
+ timer = new Timer();
+
+ cap = progress.getMax();
+ delay = (15 * 1000) / cap;
+ return v;
+ }
+
+ void startRecording() {
+ record++;
+ recordButton.setText(act.getString(R.string.stop_record));
+ recorder = new MediaRecorder();
+ recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+ recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
+ recorder.setOutputFile(fileName);
+ recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
+ try {
+ recorder.prepare();
+ } catch (IOException e) {
+ Log.e("error", "voicemessage recorder.prepare() failed");
+ }
+ cancel = false;
+ setProgressTask();
+ task.execute();
+ recorder.start();
+ }
+
+
+ void stopRecording() {
+ record++;
+ if (recorder != null) {
+ recorder.stop();
+ recorder.release();
+ recorder = null;
+ }
+ cancel = true;
+ //recordButton.setText("Record Again");
+ recordButton.setVisibility(View.INVISIBLE);
+
+ }
+
+ void startPlaying() {
+ player = new MediaPlayer();
+ try {
+ playButton.setText("Stop Playing");
+ player.setDataSource(fileName);
+ player.prepare();
+ player.start();
+ player.setOnCompletionListener(new OnCompletionListener() {
+ @Override
+ public void onCompletion(MediaPlayer arg0) {
+ playing = false;
+ playButton.setText(startPlay);
+ }
+ });
+ } catch (IOException e) {
+ Log.e("error", "voicemessage player.prepare() failed");
+ }
+
+ }
+
+ void stopPlaying() {
+ playButton.setText(startPlay);
+ player.release();
+ player = null;
+ }
+
+ void playMessage(boolean stop) {
+ if (stop) {
+ stopPlaying();
+ } else {
+ startPlaying();
+ }
+ }
+
+ void setPlayButton() {
+ playButton = (Button) act.findViewById(R.id.playButton);
+ playButton.setVisibility(View.VISIBLE);
+ playButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ playMessage(playing);
+ playing = !playing;
+ }
+ });
+
+ }
+
+ void recordMessage(boolean stop) {
+ if (stop) {
+ stopRecording();
+ } else {
+ startRecording();
+ }
+ }
+
+ void setTime(String s) {
+ time.setText(s);
+ }
+
+ void setProgressTask() {
+ task = new AsyncTask() {
+ int p = 0;
+
+ @Override
+ protected Integer doInBackground(Integer... arg0) {
+ while (p < cap && !cancel) {
+ try {
+ Thread.sleep(delay);
+ } catch (Exception e) {
}
- });
-
- playButton = (Button) v.findViewById(R.id.playButton);
- playButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- playMessage(playing);
- playing = !playing;
+ p++;
+ publishProgress(p);
+ }
+ return null;
+ }
+
+ @Override
+ protected void onProgressUpdate(Integer... values) {
+ setTime(":" + String.valueOf(15-p*15/cap));
+ handler.post(new Runnable() {
+ public void run() {
+ progress.setProgress(p);
}
});
-
- time = (TextView) v.findViewById(R.id.recordTimer);
- setTime(":15");
-
- progress = (ProgressBar) v.findViewById(R.id.recordProgressBar);
- timer = new Timer();
-
- cap = progress.getMax();
- delay = (15 * 1000) / cap;
- playButton.setVisibility(View.INVISIBLE);
- return v;
- }
-
- void startRecording() {
- record++;
- recordButton.setText("Stop Recording");
- recorder = new MediaRecorder();
- recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
- recorder.setOutputFile(fileName);
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- try {
- recorder.prepare();
- } catch (IOException e) {
- Log.e("error", "voicemessage recorder.prepare() failed");
- }
- cancel = false;
- setProgressTask();
- task.execute();
- recorder.start();
- }
-
- void stopRecording() {
- record++;
- if (recorder != null) {
- recorder.stop();
- recorder.release();
- recorder = null;
- }
- cancel = true;
- recordButton.setText("Record Again");
- playButton.setVisibility(View.VISIBLE);
- }
-
- void startPlaying() {
- player = new MediaPlayer();
- try {
- playButton.setText("Stop Playing");
- player.setDataSource(fileName);
- player.prepare();
- player.start();
- player.setOnCompletionListener(new OnCompletionListener() {
- @Override
- public void onCompletion(MediaPlayer arg0) {
- playing = false;
- playButton.setText("Play Button");
- }
- });
- } catch (IOException e) {
- Log.e("error", "voicemessage player.prepare() failed");
- }
-
- }
-
- void stopPlaying() {
- playButton.setText("Play Button");
- player.release();
- player = null;
- }
-
- void playMessage(boolean stop) {
- if (stop) {
- stopPlaying();
- } else {
- startPlaying();
- }
- }
-
- void recordMessage(boolean stop) {
- if (stop) {
- stopRecording();
- } else {
- startRecording();
- }
- }
-
- void setTime(String s) {
- time.setText(s);
- }
-
- void setProgressTask() {
- task = new AsyncTask() {
- int p = 0;
-
- @Override
- protected Integer doInBackground(Integer... arg0) {
- while (p < cap && !cancel) {
- try {
- Thread.sleep(delay);
- } catch (Exception e) {
- }
- p++;
- publishProgress(p);
- }
- return null;
- }
-
- @Override
- protected void onProgressUpdate(Integer... values) {
- setTime(":" + String.valueOf(15-p*15/cap));
- handler.post(new Runnable() {
- public void run() {
- progress.setProgress(p);
- }
- });
- }
-
- @Override
- protected void onPostExecute(Integer x) {
- stopRecording();
- }
- };
- }
-
- Intent getIntent() {
- Intent i = new Intent();
- return i;
- }
-
- @Override
- void clear() {
- if(recorder != null) {
- recorder.stop();
- }
- timer = new Timer();
- File f = new File(fileName);
- f.delete();
- record = 0;
- recordButton.setText("Record Button");
- playButton.setVisibility(View.INVISIBLE);
- progress.setProgress(0);
- time.setText(":15");
- }
+ }
+
+ @Override
+ protected void onPostExecute(Integer x) {
+ stopRecording();
+ setPlayButton();
+ }
+ };
+ }
+
+ Intent getIntent() {
+ Intent i = new Intent();
+ return i;
+ }
+
+ @Override
+ void clear() {
+ if(recorder != null) {
+ recorder.stop();
}
+ timer = new Timer();
+ File f = new File(fileName);
+ f.delete();
+ record = 0;
+ recordButton.setText("Record Button");
+ recordButton.setVisibility(View.VISIBLE);
+ playButton.setVisibility(View.INVISIBLE);
+ progress.setProgress(0);
+ time.setText(":15");
+ }
+}
diff --git a/appcompat/bin/android-support-v7-appcompat.jar b/appcompat/bin/android-support-v7-appcompat.jar
index 31b0271..532aaf6 100644
Binary files a/appcompat/bin/android-support-v7-appcompat.jar and b/appcompat/bin/android-support-v7-appcompat.jar differ