Skip to content

Commit

Permalink
Merge pull request #1 from ricohapi/release/v1.05.00
Browse files Browse the repository at this point in the history
Release of version 1.05.00
  • Loading branch information
kkushimoto authored Dec 6, 2018
2 parents 680b091 + fb7fcd0 commit 2755742
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ adb install -r app-debug.apk
13. Press the Mode Button more than 2 seconds to finish this plugin.

# 6. History
* ver.1.0.13 (2018/07/25): Initial version for github.
* ver.1.01.00 (2018/07/25): Initial version for github.
* ver.1.02.00 (2018/08/08): Bug fix.
* ver.1.03.00 (2018/10/05): Bug fix.
* ver.1.04.00 (2018/11/05): Check remaining space of Theta.
* ver.1.05.00 (2018/12/04): Terminate the plug-in when there is no space for Theta to take picture.

---

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.theta360.automaticfaceblur"
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0.13"
versionCode 4
versionName "1.05.00"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
35 changes: 31 additions & 4 deletions app/src/main/java/com/theta360/automaticfaceblur/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.os.Environment;
import android.text.TextUtils;
import android.view.KeyEvent;

import com.koushikdutta.async.http.server.AsyncHttpServerResponse;
import com.theta360.automaticfaceblur.network.WebServer;
import com.theta360.automaticfaceblur.network.model.commands.CommandsName;
Expand All @@ -31,6 +32,7 @@
import com.theta360.automaticfaceblur.network.model.values.State;
import com.theta360.automaticfaceblur.network.model.values.Status;
import com.theta360.automaticfaceblur.task.GetOptionsTask;
import com.theta360.automaticfaceblur.task.GetRemainingSpaceTask;
import com.theta360.automaticfaceblur.task.ImageProcessorTask;
import com.theta360.automaticfaceblur.task.SetOptionsTask;
import com.theta360.automaticfaceblur.task.ShowLiveViewTask;
Expand All @@ -43,9 +45,11 @@
import com.theta360.pluginlibrary.receiver.KeyReceiver;
import com.theta360.pluginlibrary.values.LedColor;
import com.theta360.pluginlibrary.values.LedTarget;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import timber.log.Timber;

/**
Expand Down Expand Up @@ -102,6 +106,7 @@ public void onKeyLongPress(int keyCode, KeyEvent event) {

}
});
new GetRemainingSpaceTask(mGetRemainingSpaceTaskCallback).execute();
}

/**
Expand Down Expand Up @@ -133,7 +138,7 @@ protected void onPause() {
mUpdatePreviewTask = null;
}
mWebServer.stop();
mCanFinishPlugin = true;
setAutoClose(true);
super.onPause();
}

Expand All @@ -143,7 +148,7 @@ protected void onPause() {
TakePictureTask.Callback mTakePictureTaskCallback = new Callback() {
@Override
public void onPreExecute() {
mCanFinishPlugin = false;
setAutoClose(false);
}

@Override
Expand Down Expand Up @@ -173,17 +178,20 @@ public void onSendCommand(AsyncHttpServerResponse response, CommandsRequest comm
mWebServer.sendError(response, errors, commandsName);
}
}
if (errors != null) {
notificationError(errors.getMessage());
}
}

@Override
public void onCompleted() {
mCanFinishPlugin = true;
setAutoClose(true);
}

@Override
public void onTakePictureFailed() {
notificationError(getResources().getString(R.string.error));
mCanFinishPlugin = true;
setAutoClose(true);
}
};

Expand Down Expand Up @@ -306,6 +314,25 @@ public void onError(boolean isCancelled) {
}
};

private GetRemainingSpaceTask.Callback mGetRemainingSpaceTaskCallback = new GetRemainingSpaceTask.Callback() {
@Override
public void onStorageFew() {
notificationLedShow(LedTarget.LED8);
}
@Override
public void onStorageVeryFew() {
notificationLedBlink(LedTarget.LED8, null, 2000);
}
@Override
public void onStorageEnough() {
notificationLedHide(LedTarget.LED8);
}
@Override
public void onError() {
notificationError("error");
}
};

/**
* WebServer Callback
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.theta360.automaticfaceblur.network;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -59,9 +60,14 @@ public ShootResult takePicture(HttpEventListener listener) {
ShootResult result = ShootResult.FAIL_DEVICE_BUSY;

// set capture mode to image
String errorMessage = setImageCaptureMode();
if (errorMessage != null) {
listener.onError(errorMessage);
String setCaptureModeErrorMessage = setImageCaptureMode();
String setExposureDelayErrorMessage = setExposureDelay();
if (setCaptureModeErrorMessage != null || setExposureDelayErrorMessage != null) {
if (setCaptureModeErrorMessage != null) {
listener.onError(setCaptureModeErrorMessage);
} else {
listener.onError(setExposureDelayErrorMessage);
}
result = ShootResult.FAIL_DEVICE_BUSY;
return result;
}
Expand Down Expand Up @@ -190,7 +196,6 @@ private String setImageCaptureMode() {
JSONObject parameters = new JSONObject();
JSONObject options = new JSONObject();
options.put("captureMode", "image");
options.put("exposureDelay", 0);
parameters.put("options", options);
input.put("parameters", parameters);

Expand Down Expand Up @@ -348,6 +353,84 @@ public String getOptions(String commands) {
return responseData;
}

/**
* Set exposure delay
*
* @return errorMessage
*/
public String setExposureDelay() {
HttpURLConnection postConnection = createHttpConnection("POST", "/osc/commands/execute");
String responseData;
String errorMessage = null;
InputStream is = null;

try {
// send HTTP POST
JSONObject input = new JSONObject();
input.put("name", "camera.setOptions");
JSONObject parameters = new JSONObject();
JSONObject options = new JSONObject();
options.put("exposureDelay", 0);
parameters.put("options", options);
input.put("parameters", parameters);

OutputStream os = postConnection.getOutputStream();
os.write(input.toString().getBytes());
postConnection.connect();
os.flush();
os.close();

is = postConnection.getInputStream();
responseData = InputStreamToString(is);

// parse JSON data
JSONObject output = new JSONObject(responseData);
String status = output.getString("state");

if (status.equals("error")) {
JSONObject errors = output.getJSONObject("error");
errorMessage = errors.getString("message");
}
} catch (IOException e) {
e.printStackTrace();
errorMessage = e.toString();
InputStream es = postConnection.getErrorStream();
try {
if (es != null) {
String errorData = InputStreamToString(es);
JSONObject output = new JSONObject(errorData);
JSONObject errors = output.getJSONObject("error");
errorMessage = errors.getString("message");
}
} catch (IOException e1) {
e1.printStackTrace();
} catch (JSONException e1) {
e1.printStackTrace();
} finally {
if (es != null) {
try {
es.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
errorMessage = e.toString();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

return errorMessage;
}

/**
* Generate connection destination URL
*
Expand Down Expand Up @@ -500,4 +583,79 @@ public InputStream getLivePreview() throws IOException, JSONException {

return is;
}

public long getRemainingSpaces() {
HttpURLConnection postConnection = createHttpConnection("POST", "/osc/commands/execute");
JSONObject input = new JSONObject();
String responseData;
String errorMessage = null;
InputStream is = null;
long remainingSpace = -1;
try {
// send HTTP POST
input.put("name", "camera.getOptions");
JSONObject parameters = new JSONObject();
JSONArray optionNames = new JSONArray();
optionNames.put("remainingSpace");
parameters.put("optionNames", optionNames);
input.put("parameters", parameters);

OutputStream os = postConnection.getOutputStream();
os.write(input.toString().getBytes());
postConnection.connect();
os.flush();
os.close();

is = postConnection.getInputStream();
responseData = InputStreamToString(is);

// parse JSON data
JSONObject output = new JSONObject(responseData);
remainingSpace = output.getJSONObject("results").getJSONObject("options").getLong("remainingSpace");

String status = output.getString("state");

if (status.equals("error")) {
JSONObject errors = output.getJSONObject("error");
errorMessage = errors.getString("message");
}
} catch (IOException e) {
e.printStackTrace();
errorMessage = e.toString();
InputStream es = postConnection.getErrorStream();
try {
if (es != null) {
String errorData = InputStreamToString(es);
JSONObject output = new JSONObject(errorData);
JSONObject errors = output.getJSONObject("error");
errorMessage = errors.getString("message");
}
} catch (IOException e1) {
e1.printStackTrace();
} catch (JSONException e1) {
e1.printStackTrace();
} finally {
if (es != null) {
try {
es.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
errorMessage = e.toString();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

return remainingSpace;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.theta360.automaticfaceblur.task;

import android.os.AsyncTask;

import com.theta360.automaticfaceblur.network.HttpConnector;

public class GetRemainingSpaceTask extends AsyncTask<Void, Void, Long> {

private static final long THRESHOLD_VERY_FEW = 2 * 1073741824L; // 2GB
private static final long THRESHOLD_FEW = 5 * 1073741824L; // 5GB

private Callback mCallback;
private HttpConnector mCamera;

public GetRemainingSpaceTask(Callback callback) {
this.mCallback = callback;
}


@Override
protected void onPreExecute() {

}

@Override
protected Long doInBackground(Void... params) {
mCamera = new HttpConnector();
return mCamera.getRemainingSpaces();
}

@Override
protected void onPostExecute(Long remainingSpace) {
if (remainingSpace == -1) {
mCallback.onError();
} else if (remainingSpace <= THRESHOLD_VERY_FEW) {
mCallback.onStorageVeryFew();
} else if ((THRESHOLD_VERY_FEW < remainingSpace) && (remainingSpace <= THRESHOLD_FEW)) {
mCallback.onStorageFew();
} else {
mCallback.onStorageEnough();
}
}

@Override
protected void onCancelled(Long result) {
mCamera = null;
}

public interface Callback {
void onStorageFew();

void onStorageVeryFew();

void onStorageEnough();

void onError();
}

}
Loading

0 comments on commit 2755742

Please sign in to comment.