@@ -46,7 +46,6 @@ public class PreCallTest extends BaseFragment implements View.OnClickListener {
4646 private static final Integer MAX_COUNT_DOWN = 8 ;
4747 private int num ;
4848 private Timer timer ;
49- private TimerTask task ;
5049
5150 @ Override
5251 public void onCreate (@ Nullable Bundle savedInstanceState ) {
@@ -110,26 +109,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
110109 btn_lastmile .setOnClickListener (this );
111110 lastmileQuality = view .findViewById (R .id .lastmile_quality );
112111 lastmileResult = view .findViewById (R .id .lastmile_result );
113- task = new TimerTask (){
114- public void run () {
115- num ++;
116- if (num >= MAX_COUNT_DOWN * 2 ){
117- handler .post (() -> {
118- btn_echo .setEnabled (true );
119- btn_echo .setText ("Start" );
120- });
121- engine .stopEchoTest ();
122- timer .cancel ();
123- task .cancel ();
124- }
125- else if (num >= MAX_COUNT_DOWN ) {
126- handler .post (() -> btn_echo .setText ("PLaying with " + (MAX_COUNT_DOWN * 2 - num ) + "Seconds" ));
127- }
128- else {
129- handler .post (() -> btn_echo .setText ("Recording with " + (MAX_COUNT_DOWN - num ) + "Seconds" ));
130- }
131- }
132- };
133112 }
134113
135114 @ Override
@@ -153,11 +132,29 @@ public void onClick(View v) {
153132 }
154133 else if (v .getId () == R .id .btn_echo ){
155134 num = 0 ;
156- engine .startEchoTest ();
135+ engine .startEchoTest (MAX_COUNT_DOWN );
157136 btn_echo .setEnabled (false );
158137 btn_echo .setText ("Recording on Microphone ..." );
159138 timer = new Timer (true );
160- timer .schedule (task , 1000 , 1000 );
139+ timer .schedule (new TimerTask (){
140+ public void run () {
141+ num ++;
142+ if (num >= MAX_COUNT_DOWN * 2 ){
143+ handler .post (() -> {
144+ btn_echo .setEnabled (true );
145+ btn_echo .setText ("Start" );
146+ });
147+ engine .stopEchoTest ();
148+ timer .cancel ();
149+ }
150+ else if (num >= MAX_COUNT_DOWN ) {
151+ handler .post (() -> btn_echo .setText ("PLaying with " + (MAX_COUNT_DOWN * 2 - num ) + "Seconds" ));
152+ }
153+ else {
154+ handler .post (() -> btn_echo .setText ("Recording with " + (MAX_COUNT_DOWN - num ) + "Seconds" ));
155+ }
156+ }
157+ }, 1000 , 1000 );
161158 }
162159 }
163160
0 commit comments