Commit 80bafb6f authored by CallisteHanriat's avatar CallisteHanriat

Precise progress bar OK + more simplicity to read the code + add comments on class's attributes.

parent e0a73270
...@@ -8,42 +8,66 @@ ...@@ -8,42 +8,66 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical|fill_horizontal" > android:gravity="center_vertical|fill_horizontal"
>
<TextView <LinearLayout
android:id="@+id/respeak_current_time" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:text="0s" /> android:layout_weight="0.5">
<TextView
<TextView android:id="@+id/respeak_current_time"
android:id="@+id/respeak_total_time" android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="0s"
android:text="/0s" /> />
<TextView
android:id="@+id/respeak_total_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/0s" />
<view class="org.lp20.aikuma.ui.InterleavedSeekBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/seek_progression"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxHeight="3dp"
/>
<View </LinearLayout>
<View
android:id="@+id/view1" android:id="@+id/view1"
android:layout_width="0.2dp" android:layout_width="0.2dp"
android:layout_height="40dp" android:layout_height="40dp"
android:visibility="visible" android:visibility="visible"
android:background="@android:color/darker_gray" android:background="@android:color/darker_gray"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" /> android:layout_marginRight="10dp" />
<TextView <LinearLayout
android:id="@+id/textView1" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:text="@string/respeak_previous_segment" /> android:layout_weight="0.5">
<FrameLayout
android:id="@+id/respeak_latest_segment_player"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</FrameLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/respeak_previous_segment" />
<FrameLayout
android:id="@+id/respeak_latest_segment_player"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
<!-- <!--
<Button <Button
android:id="@+id/respeak_delete_segment" android:id="@+id/respeak_delete_segment"
......
...@@ -5,44 +5,71 @@ ...@@ -5,44 +5,71 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
> >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical|fill_horizontal" > android:gravity="center_vertical|fill_horizontal"
>
<TextView <LinearLayout
android:id="@+id/respeak_current_time" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:text="0s" /> android:layout_weight="0.5">
<TextView
<TextView android:id="@+id/respeak_current_time"
android:id="@+id/respeak_total_time" android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="0s"
android:text="/0s" /> />
<View <TextView
android:id="@+id/view1" android:id="@+id/respeak_total_time"
android:layout_width="0.2dp" android:layout_width="wrap_content"
android:layout_height="40dp" android:layout_height="wrap_content"
android:visibility="visible" android:text="/0s" />
android:background="@android:color/darker_gray"
android:layout_marginLeft="10dp" <view class="org.lp20.aikuma.ui.InterleavedSeekBar"
android:layout_marginRight="10dp" /> style="@android:style/Widget.ProgressBar.Horizontal"
android:id="@+id/seek_progression"
<TextView android:layout_width="fill_parent"
android:id="@+id/textView1" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:maxHeight="3dp"
android:layout_height="wrap_content" />
android:text="@string/respeak_previous_segment" />
</LinearLayout>
<FrameLayout
android:id="@+id/respeak_latest_segment_player"
android:layout_width="wrap_content" <View
android:layout_height="match_parent" > android:id="@+id/view1"
android:layout_width="0.2dp"
</FrameLayout> android:layout_height="40dp"
android:visibility="visible"
android:background="@android:color/darker_gray"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0.5">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/respeak_previous_segment" />
<FrameLayout
android:id="@+id/respeak_latest_segment_player"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</LinearLayout>
<!-- <!--
<Button <Button
...@@ -55,7 +82,6 @@ ...@@ -55,7 +82,6 @@
android:onClick="onClickDeleteSegment" /> android:onClick="onClickDeleteSegment" />
--> -->
</LinearLayout>
<view class="org.lp20.aikuma.ui.InterleavedSeekBar" <view class="org.lp20.aikuma.ui.InterleavedSeekBar"
style="@android:style/Widget.ProgressBar.Horizontal" style="@android:style/Widget.ProgressBar.Horizontal"
......
...@@ -17,6 +17,7 @@ import android.view.View.OnClickListener; ...@@ -17,6 +17,7 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.io.File; import java.io.File;
...@@ -56,6 +57,9 @@ public class ThumbRespeakFragment extends Fragment { ...@@ -56,6 +57,9 @@ public class ThumbRespeakFragment extends Fragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.thumb_respeak_fragment, container, false); View v = inflater.inflate(R.layout.thumb_respeak_fragment, container, false);
installButtonBehaviour(v); installButtonBehaviour(v);
textTimeProgression = (TextView) v.findViewById(R.id.respeak_current_time);
totalTime = (TextView) v.findViewById(R.id.respeak_total_time);
seekProgression = (InterleavedSeekBar) v.findViewById(R.id.seek_progression);
seekBar = (InterleavedSeekBar) v.findViewById(R.id.InterleavedSeekBar); seekBar = (InterleavedSeekBar) v.findViewById(R.id.InterleavedSeekBar);
seekBar.setOnSeekBarChangeListener( seekBar.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() { new SeekBar.OnSeekBarChangeListener() {
...@@ -71,8 +75,25 @@ public class ThumbRespeakFragment extends Fragment { ...@@ -71,8 +75,25 @@ public class ThumbRespeakFragment extends Fragment {
originalProgress = seekBar.getProgress(); originalProgress = seekBar.getProgress();
}; };
}); });
seekProgression.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
int originalProgress;
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
if (fromUser) {
seekBar.setProgress(originalProgress);
}
}
public void onStopTrackingTouch(SeekBar _seekBar) {};
public void onStartTrackingTouch(SeekBar _seekBar) {
originalProgress = seekBar.getProgress();
};
});
seekProgression.invalidate();
seekBar.invalidate(); seekBar.invalidate();
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getFragmentManager().beginTransaction();
listenFragment = new ListenFragment(); listenFragment = new ListenFragment();
ft.replace(R.id.respeak_latest_segment_player, listenFragment); ft.replace(R.id.respeak_latest_segment_player, listenFragment);
...@@ -119,6 +140,7 @@ public class ThumbRespeakFragment extends Fragment { ...@@ -119,6 +140,7 @@ public class ThumbRespeakFragment extends Fragment {
final ImageButton respeakButton = (ImageButton) final ImageButton respeakButton = (ImageButton)
v.findViewById(R.id.RespeakButton); v.findViewById(R.id.RespeakButton);
final int greyColor = 0xffd6d6d6; final int greyColor = 0xffd6d6d6;
playButton.setOnTouchListener(new View.OnTouchListener() { playButton.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View view, MotionEvent event) { public boolean onTouch(View view, MotionEvent event) {
...@@ -148,29 +170,16 @@ public class ThumbRespeakFragment extends Fragment { ...@@ -148,29 +170,16 @@ public class ThumbRespeakFragment extends Fragment {
} }
} }
seekBarThread = new Thread(new Runnable() {
public void run() { startProgressionEvolutionBar();
int currentPosition; startProgressionGlobalBar();
while (true) {
currentPosition =
respeaker.getSimplePlayer().getCurrentMsec();
seekBar.setProgress(
(int)(((float)currentPosition/(float)
respeaker.getSimplePlayer().getDurationMsec())*100));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
return;
}
}
}
});
seekBarThread.start();
} }
if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getAction() == MotionEvent.ACTION_UP) {
//playButton.setBackgroundColor(greyColor); //playButton.setBackgroundColor(greyColor);
respeaker.pauseOriginal(); respeaker.pauseOriginal();
stopThread(seekBarThread); stopThread(seekBarThread);
stopThread(threadSeekProgression);
gestureTime = System.currentTimeMillis() - gestureTime; gestureTime = System.currentTimeMillis() - gestureTime;
gestureTimeUpToDown = System.currentTimeMillis(); gestureTimeUpToDown = System.currentTimeMillis();
Log.i("Thumb", ""+ gestureTime); Log.i("Thumb", ""+ gestureTime);
...@@ -257,12 +266,77 @@ public class ThumbRespeakFragment extends Fragment { ...@@ -257,12 +266,77 @@ public class ThumbRespeakFragment extends Fragment {
}); });
} }
// Wrapper to more safely stop threads. /**
* Wrapper to more safely stop threads.
* @param thread which we want to stop
*/
private void stopThread(Thread thread) { private void stopThread(Thread thread) {
if (thread != null) { if (thread != null) {
thread.interrupt(); thread.interrupt();
} }
} }
/**
* Permits to a SeekBar a precise evolution every 0.001 sec
* Permits to update the textview which displays current time of a browsed file.
*/
private void startProgressionEvolutionBar() {
//thread used to update the progression bar and the currentTime textview
threadSeekProgression = new Thread(new Runnable() {
public void run() {
int currentPosition;
while (true) {
currentPosition =
respeaker.getSimplePlayer().getCurrentMsec();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
textTimeProgression.setText(respeaker.getSimplePlayer().getCurrentMsec()/1000 + "s");
}
});
seekProgression.setProgress(
(int)(((float)currentPosition/(float)
respeaker.getSimplePlayer().getDurationMsec())*100));
try {
Thread.sleep(10);
} catch (InterruptedException e) {
return;
}
}
}
});
threadSeekProgression.start();
}
/**
* Permits to the main SeekBar a global evolution every 1 sec
*/
private void startProgressionGlobalBar() {
seekBarThread = new Thread(new Runnable() {
public void run() {
int currentPosition;
while (true) {
currentPosition =
respeaker.getSimplePlayer().getCurrentMsec();
seekBar.setProgress(
(int)(((float)currentPosition/(float)
respeaker.getSimplePlayer().getDurationMsec())*100));
Log.d("changement barre", "barre principale");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
return;
}
}
}
});
seekBarThread.start();
}
/** /**
* Recording mutator. * Recording mutator.
...@@ -299,8 +373,24 @@ public class ThumbRespeakFragment extends Fragment { ...@@ -299,8 +373,24 @@ public class ThumbRespeakFragment extends Fragment {
public void setThumbRespeaker(ThumbRespeaker respeaker) { public void setThumbRespeaker(ThumbRespeaker respeaker) {
this.respeaker = respeaker; this.respeaker = respeaker;
respeaker.getSimplePlayer().setOnCompletionListener(onCompletionListener); respeaker.getSimplePlayer().setOnCompletionListener(onCompletionListener);
updateDurationTextView();
} }
/**
* Called when we need to setText for the duration of a selected wav file.
* Called by setThumbRespeaker
*/
private void updateDurationTextView() {
Log.d("respeaker", Boolean.toString(respeaker != null));
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
totalTime.setText(" / " + respeaker.getSimplePlayer().getDurationMsec()/1000 + "s");
}
});
}
private Player.OnCompletionListener onCompletionListener = private Player.OnCompletionListener onCompletionListener =
new Player.OnCompletionListener() { new Player.OnCompletionListener() {
public void onCompletion(Player _player) { public void onCompletion(Player _player) {
...@@ -311,13 +401,47 @@ public class ThumbRespeakFragment extends Fragment { ...@@ -311,13 +401,47 @@ public class ThumbRespeakFragment extends Fragment {
private ThumbRespeaker respeaker; private ThumbRespeaker respeaker;
private ImageButton playButton; private ImageButton playButton;
private ImageButton respeakButton; private ImageButton respeakButton;
/**
* a global progression bar updated every 0.001 sec
*/
private InterleavedSeekBar seekBar; private InterleavedSeekBar seekBar;
/**
* a precise progression bar updated every 0.001 sec
*/
private InterleavedSeekBar seekProgression;
/**
* thread used in startProgressionEvolutionBar to update a
* seekBar every 0.001 sec
*/
private Thread threadSeekProgression;
/**
* thread used in startProgressionGlobalBar to update a
* seekBar every 1 sec
*/
private Thread seekBarThread; private Thread seekBarThread;
private Recording recording; private Recording recording;
private UUID uuid; private UUID uuid;
private int sampleRate; private int sampleRate;
/**
* listenFragment containing a seekBar, a play and pause button.
*/
private ListenFragment listenFragment; private ListenFragment listenFragment;
/**
* textview which displays the progression every seconds.
*/
private TextView textTimeProgression;
/**
* textview which displays the total time of the selected file.
*/
private TextView totalTime;
private final int VALID_GESTURE_TIME = 250; //0.25sec private final int VALID_GESTURE_TIME = 250; //0.25sec
private long gestureTime = VALID_GESTURE_TIME; private long gestureTime = VALID_GESTURE_TIME;
private long gestureTimeUpToDown = VALID_GESTURE_TIME; private long gestureTimeUpToDown = VALID_GESTURE_TIME;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment