Large diffs are not rendered by default.

@@ -194,12 +194,18 @@ public void run() {
Log.d(TAG, "start() exec.");
// Call getEvent API continuously.
boolean firstCall = true;
MONITORLOOP: while (mWhileEventMonitoring) {
while (mWhileEventMonitoring) {

// At first, call as non-Long Polling.
boolean longPolling = !firstCall;

try {
// Retry after 5 sec.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// do nothing.
}
// Call getEvent API.
JSONObject replyJson = mRemoteApi.getEvent(longPolling);

@@ -213,23 +219,23 @@ public void run() {
case 1: // "Any" error
case 12: // "No such method" error
fireResponseErrorListener();
break MONITORLOOP; // end monitoring.
continue; // end monitoring.
case 2: // "Timeout" error
// Re-call immediately.
continue MONITORLOOP;
continue;
case 40402: // "Already polling" error
// Retry after 5 sec.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// do nothing.
}
continue MONITORLOOP;
continue;
default:
Log.w(TAG, "SimpleCameraEventObserver: Unexpected error: "
+ errorCode);
fireResponseErrorListener();
break MONITORLOOP; // end monitoring.
break; // end monitoring.
}

List<String> availableApis = findAvailableApiList(replyJson);
@@ -245,14 +251,6 @@ public void run() {
fireCameraStatusChangeListener(cameraStatus);
}

// LiveviewStatus
Boolean liveviewStatus = findLiveviewStatus(replyJson);
Log.d(TAG, "getEvent liveviewStatus: " + liveviewStatus);
if (liveviewStatus != null && !liveviewStatus.equals(mLiveviewStatus)) {
mLiveviewStatus = liveviewStatus;
fireLiveviewStatusChangeListener(liveviewStatus);
}

// ShootMode
String shootMode = findShootMode(replyJson);
Log.d(TAG, "getEvent shootMode: " + shootMode);
@@ -266,34 +264,13 @@ public void run() {
fireShootModeChangeListener(shootMode);
}

// zoomPosition
int zoomPosition = findZoomInformation(replyJson);
Log.d(TAG, "getEvent zoomPosition: " + zoomPosition);
if (zoomPosition != -1) {
mZoomPosition = zoomPosition;
fireZoomInformationChangeListener(0, 0, zoomPosition, 0);
}

// storageId
String storageId = findStorageId(replyJson);
Log.d(TAG, "getEvent storageId:" + storageId);
if (storageId != null && !storageId.equals(mStorageId)) {
mStorageId = storageId;
fireStorageIdChangeListener(storageId);
}

// :
// : add implementation for Event data as necessary.

} catch (IOException e) {
// Occurs when the server is not available now.
Log.d(TAG, "getEvent timeout by client trigger.");
fireResponseErrorListener();
break MONITORLOOP;
} catch (JSONException e) {
Log.w(TAG, "getEvent: JSON format error. " + e.getMessage());
fireResponseErrorListener();
break MONITORLOOP;
}

firstCall = false;
@@ -95,21 +95,7 @@ private void log(String msg) {
* Exception.
*/
public JSONObject getAvailableApiList() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "getAvailableApiList")
.put("params", new JSONArray()).put("id", id())
.put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("getAvailableApiList");
}

/**
@@ -130,21 +116,7 @@ public JSONObject getAvailableApiList() throws IOException {
* Exception.
*/
public JSONObject getApplicationInfo() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "getApplicationInfo") //
.put("params", new JSONArray()).put("id", id()) //
.put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("getApplicationInfo");
}

/**
@@ -165,20 +137,7 @@ public JSONObject getApplicationInfo() throws IOException {
* Exception.
*/
public JSONObject getShootMode() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "getShootMode").put("params", new JSONArray()) //
.put("id", id()).put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("getShootMode");
}

/**
@@ -234,11 +193,17 @@ public JSONObject setShootMode(String shootMode) throws IOException {
* @throws all errors and exception are wrapped by this Exception.
*/
public JSONObject getAvailableShootMode() throws IOException {
String getAvailableShootMode = "getAvailableShootMode";
return execute(getAvailableShootMode);
}

private JSONObject execute(String getAvailableShootMode) throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "getAvailableShootMode") //
.put("params", new JSONArray()).put("id", id()) //
new JSONObject().put("method", getAvailableShootMode)
.put("params", new JSONArray())
.put("id", id())
.put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

@@ -269,21 +234,7 @@ public JSONObject getAvailableShootMode() throws IOException {
* Exception.
*/
public JSONObject getSupportedShootMode() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "getSupportedShootMode") //
.put("params", new JSONArray()).put("id", id()) //
.put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("getSupportedShootMode");
}

/**
@@ -304,20 +255,7 @@ public JSONObject getSupportedShootMode() throws IOException {
* Exception.
*/
public JSONObject startLiveview() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "startLiveview").put("params", new JSONArray()) //
.put("id", id()).put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("startLiveview");
}

/**
@@ -338,20 +276,7 @@ public JSONObject startLiveview() throws IOException {
* Exception.
*/
public JSONObject stopLiveview() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "stopLiveview").put("params", new JSONArray()) //
.put("id", id()).put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("stopLiveview");
}

/**
@@ -372,20 +297,7 @@ public JSONObject stopLiveview() throws IOException {
* Exception.
*/
public JSONObject startRecMode() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "startRecMode").put("params", new JSONArray()) //
.put("id", id()).put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("startRecMode");
}

/**
@@ -405,20 +317,7 @@ public JSONObject startRecMode() throws IOException {
* @throws IOException
*/
public JSONObject actTakePicture() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "actTakePicture").put("params", new JSONArray()) //
.put("id", id()).put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("actTakePicture");
}

/**
@@ -439,20 +338,7 @@ public JSONObject actTakePicture() throws IOException {
* Exception.
*/
public JSONObject startMovieRec() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "startMovieRec").put("params", new JSONArray()) //
.put("id", id()).put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("startMovieRec");
}

/**
@@ -473,20 +359,7 @@ public JSONObject startMovieRec() throws IOException {
* Exception.
*/
public JSONObject stopMovieRec() throws IOException {
String service = "camera";
try {
JSONObject requestJson =
new JSONObject().put("method", "stopMovieRec").put("params", new JSONArray()) //
.put("id", id()).put("version", "1.0");
String url = findActionListUrl(service) + "/" + service;

log("Request: " + requestJson.toString());
String responseJson = SimpleHttpClient.httpPost(url, requestJson.toString());
log("Response: " + responseJson);
return new JSONObject(responseJson);
} catch (JSONException e) {
throw new IOException(e);
}
return execute("stopMovieRec");
}

/**
@@ -635,6 +508,18 @@ public JSONObject getCameraMethodTypes() throws IOException {
}
}

public JSONObject getAvailableShutterSpeed() throws IOException {
return execute("getAvailableShutterSpeed");
}

public JSONObject startBulbShooting() throws IOException {
return execute("startBulbShooting");
}

public JSONObject stopBulbShooting() throws IOException {
return execute("stopBulbShooting");
}

// Avcontent APIs

/**
@@ -4,26 +4,48 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:orientation="vertical">

<android.support.constraint.ConstraintLayout
android:id="@+id/linearLayout"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66FFFFFF">
android:gravity="top"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@id/shutterSpeed"
android:text="@string/shutter_speed" />

<EditText
android:id="@+id/shutterSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:text="30" />

<Button
android:id="@+id/button_take_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:enabled="false"
android:enabled="true"
android:text="@string/button_take_picture"
android:textAppearance="?android:attr/textAppearanceSmall"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:textAppearance="?android:attr/textAppearanceSmall" />

<Button
android:id="@+id/check_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="true"
android:text="@string/check_status"
android:textAppearance="?android:attr/textAppearanceSmall" />


</android.support.constraint.ConstraintLayout>
</LinearLayout>

<TextView
android:id="@+id/text_camera_status"
@@ -28,5 +28,7 @@
<string name="title_activity_contents_grid">Contents</string>
<string name="title_activity_still_content">Still</string>
<string name="title_activity_movie_content">Movie</string>
<string name="shutter_speed">Shutter Speed:</string>
<string name="check_status">Check Status</string>

</resources>