Bug fix for: a spinner is shown on VoiceIME startup
The last change did not solve the bug completely, the spinner was still shown at times when no initialization dialog was shown Change-Id: I43a5f8df4e333ffb6deb727c3bf45ed7b7a54069
This commit is contained in:
parent
66a787b953
commit
7131a5a969
1 changed files with 31 additions and 40 deletions
|
@ -52,12 +52,6 @@ import java.util.List;
|
||||||
public class RecognitionView {
|
public class RecognitionView {
|
||||||
private static final String TAG = "RecognitionView";
|
private static final String TAG = "RecognitionView";
|
||||||
|
|
||||||
// If there's a significant delay between starting up voice search and the
|
|
||||||
// onset of audio recording, show the "initializing" screen first. If not,
|
|
||||||
// jump directly to the "speak now" screen to avoid flashing "initializing"
|
|
||||||
// quickly.
|
|
||||||
private static final boolean EXPECT_RECORDING_DELAY = true;
|
|
||||||
|
|
||||||
private Handler mUiHandler; // Reference to UI thread
|
private Handler mUiHandler; // Reference to UI thread
|
||||||
private View mView;
|
private View mView;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@ -148,29 +142,18 @@ public class RecognitionView {
|
||||||
public void showInitializing() {
|
public void showInitializing() {
|
||||||
mUiHandler.post(new Runnable() {
|
mUiHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mProgress.setVisibility(View.GONE); // make sure we show no spinner on startup
|
prepareDialog(false, mContext.getText(R.string.voice_initializing), mInitializing,
|
||||||
mText.setText(R.string.voice_initializing);
|
mContext.getText(R.string.cancel));
|
||||||
mImage.setImageDrawable(mInitializing);
|
|
||||||
mButtonText.setText(mContext.getText(R.string.cancel));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showStartState() {
|
|
||||||
if (EXPECT_RECORDING_DELAY) {
|
|
||||||
showInitializing();
|
|
||||||
} else {
|
|
||||||
showListening();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showListening() {
|
public void showListening() {
|
||||||
mState = State.LISTENING;
|
|
||||||
mUiHandler.post(new Runnable() {
|
mUiHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mText.setText(R.string.voice_listening);
|
mState = State.LISTENING;
|
||||||
mImage.setImageDrawable(mSpeakNow.get(0));
|
prepareDialog(false, mContext.getText(R.string.voice_listening), mSpeakNow.get(0),
|
||||||
mButtonText.setText(mContext.getText(R.string.cancel));
|
mContext.getText(R.string.cancel));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mUiHandler.postDelayed(mUpdateVolumeRunnable, 50);
|
mUiHandler.postDelayed(mUpdateVolumeRunnable, 50);
|
||||||
|
@ -181,13 +164,10 @@ public class RecognitionView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showError(final String message) {
|
public void showError(final String message) {
|
||||||
mState = State.READY;
|
|
||||||
mUiHandler.post(new Runnable() {
|
mUiHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
exitWorking();
|
mState = State.READY;
|
||||||
mText.setText(message);
|
prepareDialog(false, message, mError, mContext.getText(R.string.ok));
|
||||||
mImage.setImageDrawable(mError);
|
|
||||||
mButtonText.setText(mContext.getText(R.string.ok));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -197,15 +177,13 @@ public class RecognitionView {
|
||||||
final int speechStartPosition,
|
final int speechStartPosition,
|
||||||
final int speechEndPosition) {
|
final int speechEndPosition) {
|
||||||
|
|
||||||
mState = State.WORKING;
|
|
||||||
|
|
||||||
mUiHandler.post(new Runnable() {
|
mUiHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
mText.setText(R.string.voice_working);
|
mState = State.WORKING;
|
||||||
mImage.setVisibility(View.GONE);
|
prepareDialog(true, mContext.getText(R.string.voice_working), null, mContext
|
||||||
mProgress.setVisibility(View.VISIBLE);
|
.getText(R.string.cancel));
|
||||||
final ShortBuffer buf = ByteBuffer.wrap(waveBuffer.toByteArray())
|
final ShortBuffer buf = ByteBuffer.wrap(waveBuffer.toByteArray()).order(
|
||||||
.order(ByteOrder.nativeOrder()).asShortBuffer();
|
ByteOrder.nativeOrder()).asShortBuffer();
|
||||||
buf.position(0);
|
buf.position(0);
|
||||||
waveBuffer.reset();
|
waveBuffer.reset();
|
||||||
showWave(buf, speechStartPosition / 2, speechEndPosition / 2);
|
showWave(buf, speechStartPosition / 2, speechEndPosition / 2);
|
||||||
|
@ -213,6 +191,20 @@ public class RecognitionView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareDialog(boolean spinVisible, CharSequence text, Drawable image,
|
||||||
|
CharSequence btnTxt) {
|
||||||
|
if (spinVisible) {
|
||||||
|
mProgress.setVisibility(View.VISIBLE);
|
||||||
|
mImage.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
mProgress.setVisibility(View.GONE);
|
||||||
|
mImage.setImageDrawable(image);
|
||||||
|
mImage.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
mText.setText(text);
|
||||||
|
mButtonText.setText(btnTxt);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return an average abs of the specified buffer.
|
* @return an average abs of the specified buffer.
|
||||||
*/
|
*/
|
||||||
|
@ -305,13 +297,12 @@ public class RecognitionView {
|
||||||
|
|
||||||
|
|
||||||
public void finish() {
|
public void finish() {
|
||||||
mState = State.READY;
|
|
||||||
mUiHandler.post(new Runnable() {
|
mUiHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
mState = State.READY;
|
||||||
exitWorking();
|
exitWorking();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
showStartState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exitWorking() {
|
private void exitWorking() {
|
||||||
|
|
Loading…
Reference in a new issue