oboe: cleaned up ErrorOrValue

Inverted boolean operators.
More generic constructors.
diff --git a/include/oboe/ErrorOrValue.h b/include/oboe/ErrorOrValue.h
index 73c5ad7..956e1bd 100644
--- a/include/oboe/ErrorOrValue.h
+++ b/include/oboe/ErrorOrValue.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2018 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,8 +29,8 @@
             , mError(error) {}
 
     explicit ErrorOrValue(T value)
-            : mValue(value < 0 ? 0 : value)
-            , mError(value < 0 ? static_cast<Result>(value) : oboe::Result::OK) {}
+            : mValue(value)
+            , mError(oboe::Result::OK) {}
 
     oboe::Result error() const {
         return mError;
@@ -41,12 +41,21 @@
     }
 
     /**
-     * Quick way to check for an error.
-     * @return true if an error occurred  // TODO does this seem backwards?
+     * @return true if OK
      */
-    explicit operator bool() const { return mError != oboe::Result::OK; }
+    explicit operator bool() const { return mError == oboe::Result::OK; }
 
-    bool operator !() const { return mError == oboe::Result::OK; }
+    /**
+     * Quick way to check for an error.
+     *
+     * The caller could write something like this:
+     * <code>
+     *     if (!result) { printf("Got error %s\n", convertToText(result.error())); }
+     * </code>
+     *
+     * @return true if an error occurred
+     */
+    bool operator !() const { return mError != oboe::Result::OK; }
 
 private:
     const T             mValue;
diff --git a/src/aaudio/AudioStreamAAudio.cpp b/src/aaudio/AudioStreamAAudio.cpp
index 90d932d..0bc6588 100644
--- a/src/aaudio/AudioStreamAAudio.cpp
+++ b/src/aaudio/AudioStreamAAudio.cpp
@@ -264,7 +264,6 @@
     }
 }
 
-// TODO: Update to return tuple of Result and framesWritten (avoids cast)
 ErrorOrValue<int32_t>   AudioStreamAAudio::write(const void *buffer,
                                      int32_t numFrames,
                                      int64_t timeoutNanoseconds) {
@@ -272,7 +271,11 @@
     if (stream != nullptr) {
         int32_t result = mLibLoader->stream_write(mAAudioStream, buffer,
                                                   numFrames, timeoutNanoseconds);
-        return ErrorOrValue<int32_t>(result);
+        if (result < 0) {
+            return ErrorOrValue<int32_t>(static_cast<Result>(result));
+        } else {
+            return ErrorOrValue<int32_t>(result);
+        }
     } else {
         return ErrorOrValue<int32_t>(Result::ErrorNull);
     }
@@ -285,7 +288,11 @@
     if (stream != nullptr) {
         int32_t result = mLibLoader->stream_read(mAAudioStream, buffer,
                                                  numFrames, timeoutNanoseconds);
-        return ErrorOrValue<int32_t>(result);
+        if (result < 0) {
+            return ErrorOrValue<int32_t>(static_cast<Result>(result));
+        } else {
+            return ErrorOrValue<int32_t>(result);
+        }
     } else {
         return ErrorOrValue<int32_t>(Result::ErrorNull);
     }
diff --git a/src/opensles/AudioStreamBuffered.cpp b/src/opensles/AudioStreamBuffered.cpp
index 80a6cf0..1cb721f 100644
--- a/src/opensles/AudioStreamBuffered.cpp
+++ b/src/opensles/AudioStreamBuffered.cpp
@@ -110,7 +110,7 @@
         LOGE("AudioStreamBuffered::%s(): numFrames is negative", __func__);
         return ErrorOrValue<int32_t>(Result::ErrorOutOfRange);
     } else if (numFrames == 0) {
-        return ErrorOrValue<int32_t>(0);
+        return ErrorOrValue<int32_t>(numFrames);
     }
     if (timeoutNanoseconds < 0) {
         LOGE("AudioStreamBuffered::%s(): timeoutNanoseconds is negative", __func__);