Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Laurent Besacier
lig-aikuma
Commits
80bafb6f
Commit
80bafb6f
authored
Apr 20, 2016
by
CallisteHanriat
Browse files
Precise progress bar OK + more simplicity to read the code + add comments on class's attributes.
parent
e0a73270
Changes
3
Hide whitespace changes
Inline
Side-by-side
Aikuma/res/layout-xlarge/thumb_respeak_fragment.xml
View file @
80bafb6f
...
...
@@ -8,42 +8,66 @@
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_vertical|fill_horizontal"
>
android:gravity=
"center_vertical|fill_horizontal"
>
<TextView
android:id=
"@+id/respeak_current_time"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"0s"
/>
<TextView
android:id=
"@+id/respeak_total_time"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"/0s"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:layout_weight=
"0.5"
>
<TextView
android:id=
"@+id/respeak_current_time"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
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:layout_width=
"0.2dp"
android:layout_width=
"0.2dp"
android:layout_height=
"40dp"
android:visibility=
"visible"
android:background=
"@android:color/darker_gray"
android:layout_marginLeft=
"10dp"
android:layout_marginRight=
"10dp"
/>
<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=
"wrap_content"
android:layout_height=
"match_parent"
>
</FrameLayout>
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>
<!--
<Button
android:id="@+id/respeak_delete_segment"
...
...
Aikuma/res/layout/thumb_respeak_fragment.xml
View file @
80bafb6f
...
...
@@ -5,44 +5,71 @@
android:layout_height=
"fill_parent"
>
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_vertical|fill_horizontal"
>
android:gravity=
"center_vertical|fill_horizontal"
>
<TextView
android:id=
"@+id/respeak_current_time"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"0s"
/>
<TextView
android:id=
"@+id/respeak_total_time"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"/0s"
/>
<View
android:id=
"@+id/view1"
android:layout_width=
"0.2dp"
android:layout_height=
"40dp"
android:visibility=
"visible"
android:background=
"@android:color/darker_gray"
android:layout_marginLeft=
"10dp"
android:layout_marginRight=
"10dp"
/>
<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=
"wrap_content"
android:layout_height=
"match_parent"
>
</FrameLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:layout_weight=
"0.5"
>
<TextView
android:id=
"@+id/respeak_current_time"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
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"
/>
</LinearLayout>
<View
android:id=
"@+id/view1"
android:layout_width=
"0.2dp"
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
...
...
@@ -55,7 +82,6 @@
android:onClick="onClickDeleteSegment" />
-->
</LinearLayout>
<view
class=
"org.lp20.aikuma.ui.InterleavedSeekBar"
style=
"@android:style/Widget.ProgressBar.Horizontal"
...
...
Aikuma/src/org/lp20/aikuma/ui/ThumbRespeakFragment.java
View file @
80bafb6f
...
...
@@ -17,6 +17,7 @@ import android.view.View.OnClickListener;
import
android.view.ViewGroup
;
import
android.widget.ImageButton
;
import
android.widget.SeekBar
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
java.io.File
;
...
...
@@ -56,6 +57,9 @@ public class ThumbRespeakFragment extends Fragment {
Bundle
savedInstanceState
)
{
View
v
=
inflater
.
inflate
(
R
.
layout
.
thumb_respeak_fragment
,
container
,
false
);
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
.
setOnSeekBarChangeListener
(
new
SeekBar
.
OnSeekBarChangeListener
()
{
...
...
@@ -71,8 +75,25 @@ public class ThumbRespeakFragment extends Fragment {
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
();
FragmentTransaction
ft
=
getFragmentManager
().
beginTransaction
();
listenFragment
=
new
ListenFragment
();
ft
.
replace
(
R
.
id
.
respeak_latest_segment_player
,
listenFragment
);
...
...
@@ -119,6 +140,7 @@ public class ThumbRespeakFragment extends Fragment {
final
ImageButton
respeakButton
=
(
ImageButton
)
v
.
findViewById
(
R
.
id
.
RespeakButton
);
final
int
greyColor
=
0xffd6d6d6
;
playButton
.
setOnTouchListener
(
new
View
.
OnTouchListener
()
{
@Override
public
boolean
onTouch
(
View
view
,
MotionEvent
event
)
{
...
...
@@ -148,29 +170,16 @@ public class ThumbRespeakFragment extends Fragment {
}
}
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
));
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
return
;
}
}
}
});
seekBarThread
.
start
();
startProgressionEvolutionBar
();
startProgressionGlobalBar
();
}
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_UP
)
{
//playButton.setBackgroundColor(greyColor);
respeaker
.
pauseOriginal
();
stopThread
(
seekBarThread
);
stopThread
(
threadSeekProgression
);
gestureTime
=
System
.
currentTimeMillis
()
-
gestureTime
;
gestureTimeUpToDown
=
System
.
currentTimeMillis
();
Log
.
i
(
"Thumb"
,
""
+
gestureTime
);
...
...
@@ -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
)
{
if
(
thread
!=
null
)
{
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.
...
...
@@ -299,8 +373,24 @@ public class ThumbRespeakFragment extends Fragment {
public
void
setThumbRespeaker
(
ThumbRespeaker
respeaker
)
{
this
.
respeaker
=
respeaker
;
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
=
new
Player
.
OnCompletionListener
()
{
public
void
onCompletion
(
Player
_player
)
{
...
...
@@ -311,13 +401,47 @@ public class ThumbRespeakFragment extends Fragment {
private
ThumbRespeaker
respeaker
;
private
ImageButton
playButton
;
private
ImageButton
respeakButton
;
/**
* a global progression bar updated every 0.001 sec
*/
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
Recording
recording
;
private
UUID
uuid
;
private
int
sampleRate
;
/**
* listenFragment containing a seekBar, a play and pause button.
*/
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
long
gestureTime
=
VALID_GESTURE_TIME
;
private
long
gestureTimeUpToDown
=
VALID_GESTURE_TIME
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment