|
@@ -65,18 +65,13 @@ public class MusicTunerActivity extends BaseActivity<ActivityMusicTunerLayoutBin
|
|
|
@Override
|
|
|
public void onResult(float pitchInHz) {
|
|
|
VoiceToneBean voiceToneBean = VoiceDataUtils.getInstance().searchTarget(pitchInHz);
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- if (voiceToneBean != null) {
|
|
|
- viewBinding.tvResult.setText(getResultText(voiceToneBean));
|
|
|
- viewBinding.tvResultVoiceTones.setText(voiceToneBean.name);
|
|
|
- viewBinding.tvBeforeResultVoiceTones.setText(voiceToneBean.beforeName);
|
|
|
- viewBinding.tvAfter.setText(voiceToneBean.afterName);
|
|
|
- long differenceText = getDifferenceText(voiceToneBean.difference);
|
|
|
- viewBinding.tvDifference.setText(differenceText != -1 ? String.format("%d¢", differenceText) : "");
|
|
|
- viewBinding.viewDashBoard.setProgress((int) differenceText);
|
|
|
- }
|
|
|
+ updateUI(voiceToneBean);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -85,6 +80,21 @@ public class MusicTunerActivity extends BaseActivity<ActivityMusicTunerLayoutBin
|
|
|
mMusicTunerHelper.start();
|
|
|
}
|
|
|
|
|
|
+ private void updateUI(VoiceToneBean voiceToneBean) {
|
|
|
+ if (voiceToneBean != null) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ viewBinding.tvResult.setText(getResultText(voiceToneBean));
|
|
|
+ viewBinding.tvResultVoiceTones.setText(voiceToneBean.name);
|
|
|
+ viewBinding.tvBeforeResultVoiceTones.setText(voiceToneBean.beforeName);
|
|
|
+ viewBinding.tvAfter.setText(voiceToneBean.afterName);
|
|
|
+ long differenceText = getDifferenceText(voiceToneBean.difference);
|
|
|
+ viewBinding.tvDifference.setText(differenceText != -1 ? String.format("%d¢", differenceText) : "");
|
|
|
+ viewBinding.viewDashBoard.setProgress((int) differenceText);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private String getResultText(VoiceToneBean voiceToneBean) {
|
|
|
if (voiceToneBean != null) {
|
|
|
int value = (int) voiceToneBean.voiceFrequencyValue;
|