Merge "Fix minor bugs:" into nyc-dev

am: 28af5fcdc9

* commit '28af5fcdc9047909eb31babc8ea18d2c39e4c93b':
  Fix minor bugs:
This commit is contained in:
Arunesh Mishra
2016-02-20 00:01:49 +00:00
committed by android-build-merger
4 changed files with 39 additions and 15 deletions

View File

@@ -198,6 +198,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
return STATUS_ERROR;
}
modelData.setHandle(handle[0]);
modelData.setLoaded();
}
modelData.setCallback(callback);
modelData.setRecognitionConfig(recognitionConfig);
@@ -346,7 +347,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
return STATUS_ERROR;
}
if (currentCallback == null || !modelData.modelStarted()) {
if (currentCallback == null || !modelData.isModelStarted()) {
// startRecognition hasn't been called or it failed.
Slog.w(TAG, "Attempting stopRecognition without a successful startRecognition");
return STATUS_ERROR;
@@ -451,7 +452,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
// Stop all generic recognition models.
for (ModelData model : mGenericModelDataMap.values()) {
if (model.modelStarted()) {
if (model.isModelStarted()) {
int status = stopGenericRecognitionLocked(model,
false /* do not notify for synchronous calls */);
if (status != STATUS_OK) {
@@ -970,7 +971,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
}
for (UUID modelId : mGenericModelDataMap.keySet()) {
ModelData modelData = mGenericModelDataMap.get(modelId);
if (modelData.modelStarted()) {
if (modelData.isModelStarted()) {
mRecognitionRunning = true;
return mRecognitionRunning;
}
@@ -1001,7 +1002,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
// to SoundModel.TYPE_UNKNOWN;
private int mModelType = SoundModel.TYPE_UNKNOWN;
private IRecognitionStatusCallback mCallback = null;
private SoundModel mSoundModel = null;
private RecognitionConfig mRecognitionConfig = null;
@@ -1026,8 +1026,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
}
synchronized boolean isModelLoaded() {
return (mModelState == MODEL_LOADED || mModelState == MODEL_STARTED) &&
mSoundModel != null;
return (mModelState == MODEL_LOADED || mModelState == MODEL_STARTED);
}
synchronized void setStarted() {
@@ -1038,13 +1037,16 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
mModelState = MODEL_LOADED;
}
synchronized boolean modelStarted() {
synchronized void setLoaded() {
mModelState = MODEL_LOADED;
}
synchronized boolean isModelStarted() {
return mModelState == MODEL_STARTED;
}
synchronized void clearState() {
mModelState = MODEL_NOTLOADED;
mSoundModel = null;
mModelHandle = INVALID_VALUE;
}

View File

@@ -66,6 +66,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:checkedButton="@+id/model_one"
android:orientation="vertical">
<RadioButton android:id="@+id/model_one"
android:layout_width="wrap_content"
@@ -84,15 +85,21 @@
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
<TextView
android:id="@+id/console"
android:gravity="left"
<ScrollView
android:id="@+id/scroller_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView
android:id="@+id/console"
android:paddingTop="20pt"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:maxLines="40"
android:layout_width="fill_parent"
android:textSize="14dp"
android:scrollbars = "vertical"
android:layout_weight="1.0"
android:text="@string/none">
</TextView>
</ScrollView>
</LinearLayout>

View File

@@ -24,5 +24,5 @@
<string name="model_one">Model One</string>
<string name="model_two">Model Two</string>
<string name="model_three">Model Three</string>
<string name="none">Debug messages appear here:</string>
<string name="none">Debug messages appear here:\n</string>
</resources>

View File

@@ -32,6 +32,7 @@ import android.os.UserManager;
import android.util.Log;
import android.view.View;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
@@ -52,6 +53,7 @@ public class TestSoundTriggerActivity extends Activity {
private TextView mDebugView = null;
private int mSelectedModelId = 1;
private ScrollView mScrollView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -59,6 +61,7 @@ public class TestSoundTriggerActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDebugView = (TextView) findViewById(R.id.console);
mScrollView = (ScrollView) findViewById(R.id.scroller_id);
mDebugView.setText(mDebugView.getText(), TextView.BufferType.EDITABLE);
mDebugView.setMovementMethod(new ScrollingMovementMethod());
mSoundTriggerUtil = new SoundTriggerUtil(this);
@@ -68,6 +71,18 @@ public class TestSoundTriggerActivity extends Activity {
private void postMessage(String msg) {
Log.i(TAG, "Posted: " + msg);
((Editable) mDebugView.getText()).append(msg + "\n");
if ((mDebugView.getMeasuredHeight() - mScrollView.getScrollY()) <=
(mScrollView.getHeight() + mDebugView.getLineHeight())) {
scrollToBottom();
}
}
private void scrollToBottom() {
mScrollView.post(new Runnable() {
public void run() {
mScrollView.smoothScrollTo(0, mDebugView.getBottom());
}
});
}
private UUID getSelectedUuid() {