import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.RicohGr2InterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.ISonyInterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.wrapper.SonyCameraWrapper;
+import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
public class CameraInterfaceProvider implements IInterfaceProvider
private final OlympusInterfaceProvider olympus;
private final SonyCameraWrapper sony;
private final RicohGr2InterfaceProvider ricohGr2;
+ private final CameraStatusListener statusListener;
public CameraInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider)
{
this.context = context;
+ this.statusListener = new CameraStatusListener();
olympus = new OlympusInterfaceProvider(context, provider);
- sony = new SonyCameraWrapper(context, provider);
+ sony = new SonyCameraWrapper(context, provider, statusListener);
ricohGr2 = new RicohGr2InterfaceProvider(context, provider);
}
@Override
+ public void setUpdateReceiver(@NonNull ICameraStatusUpdateNotify receiver)
+ {
+ try
+ {
+ statusListener.setUpdateReceiver(receiver);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
public IOlympusInterfaceProvider getOlympusInterface()
{
return (olympus);
--- /dev/null
+package net.osdn.gokigen.a01d.camera;
+
+import android.support.annotation.NonNull;
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.CameraChangeListerTemplate;
+import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
+
+public class CameraStatusListener extends CameraChangeListerTemplate implements ICameraStatusUpdateNotify
+{
+ private final String TAG = toString();
+ private ICameraStatusUpdateNotify updateReceiver = null;
+
+
+ CameraStatusListener()
+ {
+ Log.v(TAG, "CameraStatusListener()");
+ }
+
+ void setUpdateReceiver(@NonNull ICameraStatusUpdateNotify receiver)
+ {
+ updateReceiver = receiver;
+ }
+
+ @Override
+ public void onFocusStatusChanged(String focusStatus)
+ {
+ Log.v(TAG, "onFocusStatusChanged() : " + focusStatus);
+ if ((focusStatus == null)||(updateReceiver == null))
+ {
+ Log.v(TAG, "focusStatus or updateReceiver is NULL.");
+ return;
+ }
+ switch (focusStatus)
+ {
+ case "Focused":
+ updateReceiver.updateFocusedStatus(true, true);
+ break;
+ case "Failed":
+ updateReceiver.updateFocusedStatus(false, true);
+ break;
+ case "Focusing":
+ case "Not Focusing":
+ default:
+ updateReceiver.updateFocusedStatus(false, false);
+ break;
+ }
+ }
+
+ @Override
+ public void updateDriveMode(String driveMode)
+ {
+ Log.v(TAG, "updateDriveMode() : " + driveMode);
+ }
+
+ @Override
+ public void updateAeLockState(boolean isAeLocked)
+ {
+
+ }
+
+ @Override
+ public void updateCameraStatus(String message)
+ {
+
+ }
+
+ @Override
+ public void updateLevelGauge(String orientation, float roll, float pitch)
+ {
+
+ }
+
+ @Override
+ public void updatedTakeMode(String mode)
+ {
+
+ }
+
+ @Override
+ public void updatedShutterSpeed(String tv)
+ {
+
+ }
+
+ @Override
+ public void updatedAperture(String av)
+ {
+
+ }
+
+ @Override
+ public void updatedExposureCompensation(String xv)
+ {
+
+ }
+
+ @Override
+ public void updatedMeteringMode(String meteringMode)
+ {
+
+ }
+
+ @Override
+ public void updatedWBMode(String wbMode)
+ {
+
+ }
+
+ @Override
+ public void updateRemainBattery(int percentage)
+ {
+
+ }
+
+ @Override
+ public void updateFocusedStatus(boolean focused, boolean focusLocked)
+ {
+ if (updateReceiver != null)
+ {
+ updateReceiver.updateFocusedStatus(focused, focusLocked);
+ }
+ }
+
+ @Override
+ public void updateIsoSensitivity(String sv)
+ {
+
+ }
+
+ @Override
+ public void updateWarning(String warning)
+ {
+
+ }
+
+ @Override
+ public void updateStorageStatus(String status)
+ {
+
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera;
+
+import android.support.annotation.NonNull;
+
+import java.util.List;
+
+public interface ICameraStatus
+{
+ @NonNull List<String> getStatusList(@NonNull final String key);
+ String getStatus(@NonNull final String key);
+ void setStatus(@NonNull final String key, @NonNull final String value);
+
+ String BATTERY = "battery";
+ String STATE = "state";
+ String FOCUS_MODE = "focusMode";
+ String AF_MODE = "AFMode";
+
+ String RESOLUTION = "reso";
+ String DRIVE_MODE = "shootMode";
+ String WHITE_BALANCE = "WBMode";
+
+ String AE = "meteringMode";
+
+ String AE_STATUS_MULTI = "multi";
+ String AE_STATUS_ESP = "ESP";
+ String AE_STATUS_SPOT = "spot";
+ String AE_STATUS_PINPOINT = "Spot";
+ String AE_STATUS_CENTER = "center";
+ String AE_STATUS_CENTER2 = "Ctr-Weighted";
+
+ String EFFECT = "effect";
+ String TAKE_MODE = "exposureMode";
+ String IMAGESIZE = "stillSize";
+ String MOVIESIZE = "movieSize";
+
+ String APERATURE = "av";
+ String SHUTTER_SPEED = "tv";
+ String ISO_SENSITIVITY = "sv";
+ String EXPREV = "xv";
+ String FLASH_XV = "flashxv";
+
+ String TAKE_MODE_MOVIE = "movie";
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera;
+
+import android.support.annotation.NonNull;
+
+import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
+
+public interface ICameraStatusWatcher
+{
+ void startStatusWatch(@NonNull ICameraStatusUpdateNotify notifier);
+ void stopStatusWatch();
+}
package net.osdn.gokigen.a01d.camera;
+import android.support.annotation.NonNull;
+
import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlympusLiveViewListener;
import net.osdn.gokigen.a01d.camera.olympus.IOlympusInterfaceProvider;
import net.osdn.gokigen.a01d.camera.ricohgr2.IRicohGr2InterfaceProvider;
import net.osdn.gokigen.a01d.camera.sony.ISonyInterfaceProvider;
+import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
/**
*
ISonyInterfaceProvider getSonyInterface();
IRicohGr2InterfaceProvider getRicohGr2Infterface();
+ void setUpdateReceiver(@NonNull ICameraStatusUpdateNotify receiver);
+
ICameraConnection.CameraConnectionMethod getCammeraConnectionMethod();
}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.ricohgr2.status;
+
+import android.support.annotation.NonNull;
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.ICameraStatus;
+import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
+import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatus
+{
+ private final String TAG = toString();
+ private final String statusCheckUrl = "http://192.168.0.1/v1/props";
+ private final String statusSetUrl = "http://192.168.0.1/v1/params/camera";
+ private final String grCommandUrl = "http://192.168.0.1/_gr";
+ private final int sleepMs;
+
+ private final boolean useGrCommand;
+
+ private int timeoutMs = 5000;
+ private boolean whileFetching = false;
+ private RicohGr2StatusHolder statusHolder;
+
+ /**
+ *
+ *
+ */
+ RicohGr2StatusChecker(int sleepMs, boolean useGrCommand)
+ {
+ this.useGrCommand = useGrCommand;
+ this.sleepMs = sleepMs;
+ }
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void startStatusWatch(@NonNull ICameraStatusUpdateNotify notifier)
+ {
+ Log.v(TAG, "startStatusWatch()");
+ try
+ {
+ this.statusHolder = new RicohGr2StatusHolder(notifier);
+ Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ start(statusCheckUrl);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void stopStatusWatch()
+ {
+ Log.v(TAG, "stoptStatusWatch()");
+ whileFetching = false;
+ }
+
+ /**
+ *
+ *
+ */
+ private void start(@NonNull final String watchUrl)
+ {
+ if (whileFetching)
+ {
+ Log.v(TAG, "start() already starting.");
+ return;
+ }
+
+ try
+ {
+ whileFetching = true;
+ Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Log.d(TAG, "Start status watch.");
+ while (whileFetching)
+ {
+ try
+ {
+ statusHolder.updateStatus(SimpleHttpClient.httpGet(watchUrl, timeoutMs));
+ Thread.sleep(sleepMs);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ Log.v(TAG, "STATUS WATCH STOPPED.");
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public @NonNull
+ List<String> getStatusList(@NonNull final String key)
+ {
+ try
+ {
+ if (statusHolder == null)
+ {
+ return (new ArrayList<>());
+ }
+ String listKey = key + "List";
+ return (statusHolder.getAvailableItemList(listKey));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (new ArrayList<>());
+ }
+
+ @Override
+ public String getStatus(@NonNull String key)
+ {
+ try
+ {
+ if (statusHolder == null)
+ {
+ return ("");
+ }
+ return (statusHolder.getItemStatus(key));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return ("");
+ }
+
+ @Override
+ public void setStatus(@NonNull final String key, @NonNull final String value)
+ {
+ Thread thread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try
+ {
+ String response;
+ String postData = key + "=" + value;
+ if ((useGrCommand)&&(key.equals("exposureMode")))
+ {
+ // 撮影モードを変更するときは、GR専用コマンドを送ることにする。
+ postData = "cmd=" + decideButtonCode(value);
+ response = SimpleHttpClient.httpPost(grCommandUrl, postData, timeoutMs);
+ Log.v(TAG, "CHANGE MODE : " + postData + " resp. (" + response.length() + "bytes.)");
+ } else {
+ // 通常の変更コマンド
+ response = SimpleHttpClient.httpPut(statusSetUrl, postData, timeoutMs);
+ Log.v(TAG, "SET PROPERTY : " + postData + " resp. (" + response.length() + "bytes.)");
+ }
+ if (useGrCommand)
+ {
+ // GR専用コマンドで、画面表示をリフレッシュ
+ response = SimpleHttpClient.httpPost(grCommandUrl, "cmd=mode refresh", timeoutMs);
+ Log.v(TAG, "refresh resp. (" + response.length() + "bytes.)");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ try
+ {
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 撮影モードをGRのダイアルコマンドに変更する
+ *
+ */
+ private String decideButtonCode(String exposureMode)
+ {
+ String buttonCode = "bdial AUTO";
+ if (exposureMode == null)
+ {
+ return (buttonCode);
+ }
+ switch (exposureMode)
+ {
+ case "movie":
+ buttonCode = "bdial MOVIE";
+ break;
+ case "M":
+ buttonCode = "bdial M";
+ break;
+ case "TAV":
+ buttonCode = "bdial TAV";
+ break;
+ case "AV":
+ buttonCode = "bdial AV";
+ break;
+ case "TV":
+ buttonCode = "bdial TV";
+ break;
+ case "P":
+ buttonCode = "bdial P";
+ break;
+ case "auto":
+ buttonCode = "bdial AUTO";
+ break;
+ }
+ return (buttonCode);
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.ricohgr2.status;
+
+import android.support.annotation.NonNull;
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RicohGr2StatusHolder
+{
+ private final String TAG = toString();
+ private final ICameraStatusUpdateNotify notifier;
+
+ private JSONObject latestResultObject = null;
+ private boolean focused = false;
+ private boolean focusLocked = false;
+ private String avStatus = "";
+ private String tvStatus = "";
+ private String xvStatus = "";
+ private String exposureModeStatus = "";
+ private String meteringModeStatus = "";
+ private String wbModeStatus = "";
+ private String batteryStatus = "";
+
+ /**
+ *
+ *
+ */
+ RicohGr2StatusHolder(ICameraStatusUpdateNotify notifier)
+ {
+ this.notifier = notifier;
+ }
+
+ /**
+ *
+ *
+ */
+ List<String> getAvailableItemList(@NonNull String key)
+ {
+ List<String> itemList = new ArrayList<>();
+ try
+ {
+ JSONArray array = latestResultObject.getJSONArray(key);
+ if (array == null)
+ {
+ return (itemList);
+ }
+ int nofItems = array.length();
+ for (int index = 0; index < nofItems; index++)
+ {
+ try
+ {
+ itemList.add(array.getString(index));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (itemList);
+ }
+
+ String getItemStatus(@NonNull String key)
+ {
+ try
+ {
+ return (latestResultObject.getString(key));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return ("");
+ }
+
+ private String getStatusString(JSONObject obj, String name)
+ {
+ try
+ {
+ return (obj.getString(name));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return ("");
+ }
+
+ private boolean getBooleanStatus(JSONObject obj, String name)
+ {
+ try {
+ return (obj.getBoolean(name));
+ } catch (Exception e) {
+ //e.printStackTrace();
+ }
+ return (false);
+ }
+
+ /**
+ *
+ *
+ */
+ void updateStatus(String replyString)
+ {
+ if ((replyString == null)||(replyString.length() < 1))
+ {
+ Log.v(TAG, "httpGet() reply is null. ");
+ return;
+ }
+
+ try
+ {
+ latestResultObject = new JSONObject(replyString);
+ String result = getStatusString(latestResultObject,"errMsg");
+ String av = getStatusString(latestResultObject,"av");
+ String tv = getStatusString(latestResultObject,"tv");
+ String xv = getStatusString(latestResultObject,"xv");
+ String exposureMode = getStatusString(latestResultObject,"exposureMode");
+ String meteringMode = getStatusString(latestResultObject,"meteringMode");
+ String wbMode = getStatusString(latestResultObject,"WBMode");
+ String battery = getStatusString(latestResultObject,"battery");
+ boolean focus = getBooleanStatus(latestResultObject,"focused");
+ boolean focusLock = getBooleanStatus(latestResultObject,"focusLocked");
+
+ if (result.contains("OK"))
+ {
+ if (!avStatus.equals(av))
+ {
+ avStatus = av;
+ notifier.updatedAperture(avStatus);
+ }
+ if (!tvStatus.equals(tv))
+ {
+ tvStatus = tv;
+ notifier.updatedShutterSpeed(tvStatus);
+ }
+ if (!xvStatus.equals(xv))
+ {
+ xvStatus = xv;
+ notifier.updatedExposureCompensation(xvStatus);
+ }
+ if (!exposureModeStatus.equals(exposureMode))
+ {
+ exposureModeStatus = exposureMode;
+ notifier.updatedTakeMode(exposureModeStatus);
+ }
+ if (!meteringModeStatus.equals(meteringMode))
+ {
+ meteringModeStatus = meteringMode;
+ notifier.updatedMeteringMode(meteringModeStatus);
+ }
+ if (!wbModeStatus.equals(wbMode))
+ {
+ wbModeStatus = wbMode;
+ notifier.updatedWBMode(wbModeStatus);
+ }
+ if (!batteryStatus.equals(battery))
+ {
+ batteryStatus = battery;
+ notifier.updateRemainBattery(Integer.parseInt(batteryStatus));
+ }
+ if ((focus != focused)||(focusLock != focusLocked))
+ {
+ focused = focus;
+ focusLocked = focusLock;
+ notifier.updateFocusedStatus(focused, focusLocked);
+ }
+ }
+ System.gc();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
JSONObject resultsObj = (isPressed) ? cameraApi.actHalfPressShutter() : cameraApi.cancelHalfPressShutter();
if (resultsObj == null)
{
- Log.v(TAG, "lockAutoFocus() [" + isPressed + "] reply is null.");
+ Log.v(TAG, "halfPressShutter() [" + isPressed + "] reply is null.");
+ }
+ else
+ {
+ indicator.onAfLockUpdate(isPressed);
}
}
catch (Exception e)
private final String TAG = toString();
private final Activity context;
private final ICameraStatusReceiver provider;
+ private final ICameraChangeListener listener;
private ISonyCamera sonyCamera = null;
private ISonyCameraApi sonyCameraApi = null;
private ICameraEventObserver eventObserver = null;
private SonyCameraCaptureControl captureControl = null;
private SonyCameraZoomLensControl zoomControl = null;
- public SonyCameraWrapper(final Activity context, final ICameraStatusReceiver statusReceiver)
+ public SonyCameraWrapper(final Activity context, final ICameraStatusReceiver statusReceiver , final @NonNull ICameraChangeListener listener)
{
this.context = context;
this.provider = statusReceiver;
+ this.listener = listener;
}
@Override
@Override
public ICameraConnection getSonyCameraConnection()
{
- return (new SonyCameraConnection(context, provider, this));
+ return (new SonyCameraConnection(context, provider, this, listener));
}
@Override
import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCamera;
import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCameraHolder;
import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.CameraChangeListerTemplate;
+import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.ICameraChangeListener;
/**
private final ICameraConnection cameraConnection;
private final ISonyCameraHolder cameraHolder;
private final ICameraStatusReceiver cameraStatusReceiver;
+ private final ICameraChangeListener listener;
private final SonySsdpClient client;
- SonyCameraConnectSequence(Activity context, ICameraStatusReceiver statusReceiver, final ICameraConnection cameraConnection, final @NonNull ISonyCameraHolder cameraHolder)
+ SonyCameraConnectSequence(Activity context, ICameraStatusReceiver statusReceiver, final ICameraConnection cameraConnection, final @NonNull ISonyCameraHolder cameraHolder, final @NonNull ICameraChangeListener listener)
{
Log.v(TAG, "SonyCameraConnectSequence");
this.context = context;
this.cameraConnection = cameraConnection;
this.cameraStatusReceiver = statusReceiver;
this.cameraHolder = cameraHolder;
+ this.listener = listener;
client = new SonySsdpClient(context, this, statusReceiver, 1);
}
try
{
cameraHolder.prepare();
- cameraHolder.startEventWatch(new CameraChangeListerTemplate());
+ cameraHolder.startEventWatch(listener);
}
catch (Exception e)
{
import net.osdn.gokigen.a01d.camera.ICameraConnection;
import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
import net.osdn.gokigen.a01d.camera.sony.wrapper.ISonyCameraHolder;
+import net.osdn.gokigen.a01d.camera.sony.wrapper.eventlistener.ICameraChangeListener;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
private final ISonyCameraHolder cameraHolder;
//private final ConnectivityManager connectivityManager;
private final Executor cameraExecutor = Executors.newFixedThreadPool(1);
+ private final ICameraChangeListener listener;
//private final Handler networkConnectionTimeoutHandler;
//private static final int MESSAGE_CONNECTIVITY_TIMEOUT = 1;
private CameraConnectionStatus connectionStatus = CameraConnectionStatus.UNKNOWN;
- public SonyCameraConnection(final Activity context, final ICameraStatusReceiver statusReceiver, @NonNull ISonyCameraHolder cameraHolder)
+ public SonyCameraConnection(final Activity context, final ICameraStatusReceiver statusReceiver, @NonNull ISonyCameraHolder cameraHolder, final @NonNull ICameraChangeListener listener)
{
Log.v(TAG, "SonyCameraConnection()");
this.context = context;
this.statusReceiver = statusReceiver;
this.cameraHolder = cameraHolder;
+ this.listener = listener;
/*
ConnectivityManager connectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
networkConnectionTimeoutHandler = new Handler()
connectionStatus = CameraConnectionStatus.CONNECTING;
try
{
- cameraExecutor.execute(new SonyCameraConnectSequence(context,statusReceiver, this, cameraHolder));
+ cameraExecutor.execute(new SonyCameraConnectSequence(context,statusReceiver, this, cameraHolder, listener));
}
catch (Exception e)
{
}
@Override
+ public void onFocusStatusChanged(String focusStatus)
+ {
+ Log.v(TAG, "onFocusStatusChanged() : " + focusStatus);
+ }
+
+ @Override
public void onResponseError()
{
Log.v(TAG, "onResponseError() ");
private final ISonyCameraApi remoteApi;
private final ReplyJsonParser replyParser;
- private final String eventVersion = "1.0";
+ private String eventVersion = "1.1"; // 初期値を "1.0" から "1.1" に更新
public static ICameraEventObserver newInstance(@NonNull Context context, @NonNull ISonyCameraApi apiClient)
{
break;
case 1: // "Any" error
case 12: // "No such method" error
+ if (eventVersion.equals("1.1"))
+ {
+ // "1.1" でエラーが発生した時には "1.0" にダウングレードして再実行
+ eventVersion = "1.0";
+ continue MONITORLOOP;
+ }
replyParser.fireResponseErrorListener();
break MONITORLOOP; // end monitoring.
void onShootModeChanged(String shootMode);
void onZoomPositionChanged(int zoomPosition);
void onStorageIdChanged(String storageId);
+ void onFocusStatusChanged(String focusStatus);
void onResponseError();
}
private List<String> currentAvailableShootModes = Collections.unmodifiableList(new ArrayList<String>());
private int currentZoomPosition;
private String currentStorageId;
+ private String currentFocusStatus;
ReplyJsonParser(final @NonNull Handler uiHandler)
{
fireStorageIdChangeListener(storageId);
}
+ // focusStatus (v1.1)
+ String focusStatus = findFocusStatus(replyJson);
+ Log.d(TAG, "getEvent focusStatus:" + focusStatus);
+ if (focusStatus != null && !focusStatus.equals(currentFocusStatus)) {
+ currentFocusStatus = focusStatus;
+ fireFocusStatusChangeListener(focusStatus);
+ }
}
void setEventChangeListener(ICameraChangeListener listener)
});
}
+ private void fireFocusStatusChangeListener(final String focusStatus) {
+ uiHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ if (listener != null) {
+ listener.onFocusStatusChanged(focusStatus);
+ }
+ }
+ });
+ }
+
private static List<String> findAvailableApiList(JSONObject replyJson) {
List<String> availableApis = new ArrayList<>();
int indexOfAvailableApiList = 0;
return (storageId);
}
+ private static String findFocusStatus(JSONObject replyJson)
+ {
+ String focusStatus = null;
+ try {
+ int indexOfFocusStatus= 35;
+ JSONArray resultsObj = replyJson.getJSONArray("result");
+ if (!resultsObj.isNull(indexOfFocusStatus)) {
+ JSONObject focustatusObj = resultsObj.getJSONObject(indexOfFocusStatus);
+ String type = focustatusObj.getString("type");
+ if ("focusStatus".equals(type)) {
+ focusStatus = focustatusObj.getString("focusStatus");
+ } else {
+ Log.w(TAG, "Event reply: Illegal Index (21: ShootMode) " + type);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return (focusStatus);
+ }
@Override
public String getCameraStatus()
package net.osdn.gokigen.a01d.camera.utils;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.support.annotation.NonNull;
import android.util.Log;
import java.io.BufferedReader;
{
private static final String TAG = SimpleHttpClient.class.getSimpleName();
private static final int DEFAULT_TIMEOUT = 10 * 1000; // [ms]
+ private static final int BUFFER_SIZE = 131072 * 2; // 256kB
public SimpleHttpClient()
{
*
*
*/
+ public static void httpGetBytes(String url, int timeoutMs, @NonNull IReceivedMessageCallback callback)
+ {
+ HttpURLConnection httpConn = null;
+ InputStream inputStream = null;
+ int timeout = timeoutMs;
+ if (timeoutMs < 0)
+ {
+ timeout = DEFAULT_TIMEOUT;
+ }
+
+ // HTTP GETメソッドで要求を投げる
+ try
+ {
+ final URL urlObj = new URL(url);
+ httpConn = (HttpURLConnection) urlObj.openConnection();
+ httpConn.setRequestMethod("GET");
+ httpConn.setConnectTimeout(timeout);
+ httpConn.setReadTimeout(timeout);
+ httpConn.connect();
+
+ int responseCode = httpConn.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK)
+ {
+ inputStream = httpConn.getInputStream();
+ }
+ if (inputStream == null)
+ {
+ Log.w(TAG, "httpGet: Response Code Error: " + responseCode + ": " + url);
+ callback.onErrorOccurred(new NullPointerException());
+ callback.onCompleted();
+ return;
+ }
+ }
+ catch (Exception e)
+ {
+ Log.w(TAG, "httpGet: " + url + " " + e.getMessage());
+ e.printStackTrace();
+ if (httpConn != null)
+ {
+ httpConn.disconnect();
+ }
+ callback.onErrorOccurred(e);
+ callback.onCompleted();
+ return;
+ }
+
+ // 応答を確認する
+ try
+ {
+ int contentLength = httpConn.getContentLength();
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int readBytes = 0;
+ int readSize = inputStream.read(buffer, 0, BUFFER_SIZE);
+ while (readSize != -1)
+ {
+ callback.onReceive(readBytes, contentLength, readSize, buffer);
+ readBytes += readSize;
+ readSize = inputStream.read(buffer, 0, BUFFER_SIZE);
+ }
+ Log.v(TAG, "RECEIVED " + readBytes + " BYTES. (contentLength : " + contentLength + ")");
+ inputStream.close();
+ }
+ catch (Exception e)
+ {
+ Log.w(TAG, "httpGet: exception: " + e.getMessage());
+ e.printStackTrace();
+ callback.onErrorOccurred(e);
+ }
+ finally
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ callback.onCompleted();
+ }
+
+ /**
+ *
+ *
+ *
+ */
+ public static Bitmap httpGetBitmap(String url, int timeoutMs)
+ {
+ HttpURLConnection httpConn = null;
+ InputStream inputStream = null;
+ Bitmap bmp = null;
+
+ int timeout = timeoutMs;
+ if (timeoutMs < 0)
+ {
+ timeout = DEFAULT_TIMEOUT;
+ }
+
+ // HTTP GETメソッドで要求を投げる
+ try
+ {
+ final URL urlObj = new URL(url);
+ httpConn = (HttpURLConnection) urlObj.openConnection();
+ httpConn.setRequestMethod("GET");
+ httpConn.setConnectTimeout(timeout);
+ httpConn.setReadTimeout(timeout);
+ httpConn.connect();
+
+ int responseCode = httpConn.getResponseCode();
+ if (responseCode == HttpURLConnection.HTTP_OK)
+ {
+ inputStream = httpConn.getInputStream();
+ if (inputStream != null)
+ {
+ bmp = BitmapFactory.decodeStream(inputStream);
+ }
+ }
+ if (inputStream == null)
+ {
+ Log.w(TAG, "httpGet: Response Code Error: " + responseCode + ": " + url);
+ return (null);
+ }
+ inputStream.close();
+ }
+ catch (Exception e)
+ {
+ Log.w(TAG, "httpGet: " + url + " " + e.getMessage());
+ e.printStackTrace();
+ if (httpConn != null)
+ {
+ httpConn.disconnect();
+ }
+ return (null);
+ }
+ return (bmp);
+ }
+
+ /**
+ *
+ *
+ *
+ */
public static String httpPost(String url, String postData, int timeoutMs)
{
+ return (httpCommand(url, "POST", postData, timeoutMs));
+ }
+
+ /**
+ *
+ *
+ *
+ */
+ public static String httpPut(String url, String postData, int timeoutMs)
+ {
+ return (httpCommand(url, "PUT", postData, timeoutMs));
+ }
+
+ /**
+ *
+ *
+ *
+ */
+ private static String httpCommand(String url, String requestMethod, String postData, int timeoutMs)
+ {
HttpURLConnection httpConn = null;
OutputStream outputStream = null;
OutputStreamWriter writer = null;
timeout = DEFAULT_TIMEOUT;
}
- // HTTP Postメソッドで要求を送出
+ // HTTP メソッドで要求を送出
try
{
final URL urlObj = new URL(url);
httpConn = (HttpURLConnection) urlObj.openConnection();
- httpConn.setRequestMethod("POST");
+ httpConn.setRequestMethod(requestMethod);
httpConn.setConnectTimeout(timeout);
httpConn.setReadTimeout(timeout);
httpConn.setDoInput(true);
}
if (inputStream == null)
{
- Log.w(TAG, "httpPost: Response Code Error: " + responseCode + ": " + url);
+ Log.w(TAG, "http " + requestMethod + " : Response Code Error: " + responseCode + ": " + url);
return ("");
}
}
catch (Exception e)
{
- Log.w(TAG, "httpPost: IOException: " + e.getMessage());
+ Log.w(TAG, "http " + requestMethod + " : IOException: " + e.getMessage());
e.printStackTrace();
if (httpConn != null)
{
}
return (replyString);
}
+
+ public interface IReceivedMessageCallback
+ {
+ void onCompleted();
+ void onErrorOccurred(Exception e);
+ void onReceive(int readBytes, int length, int size, byte[] data);
+ }
}
private IPreviewImageConverter bitmapConverter = null;
private IMessageHolder messageHolder;
private IStoreImage storeImage = null;
+ private IFocusLockIndicator focusLockIndicator = null;
public CameraLiveImageView(Context context)
{
return getIntrinsicContentSizeHeight();
}
+ public void setFocuslockIndicator(IFocusLockIndicator focuslockIndicator)
+ {
+ focusLockIndicator = focuslockIndicator;
+ }
private float getIntrinsicContentSizeWidth()
{
@Override
public void onAfLockUpdate(boolean isAfLocked)
{
- //Log.v(TAG, "onAfLockUpdate() : " + isAfLocked);
+ Log.v(TAG, "onAfLockUpdate() : " + isAfLocked);
+ if (focusLockIndicator != null)
+ {
+ focusLockIndicator.updateFocusLockIndicator(isAfLocked, isAfLocked);
+ }
}
@Override
+++ /dev/null
-package net.osdn.gokigen.a01d.liveview;
-
-/**
- *
- */
-public interface ICameraStatusDisplay
-{
- void updateTakeMode();
- void updateDriveMode();
- void updateWhiteBalance();
- void updateBatteryLevel();
- void updateAeMode();
- void updateAeLockState();
- void updateCameraStatus();
- void updateCameraStatus(String message);
- void updateLevelGauge(String orientation, float roll, float pitch);
-}
--- /dev/null
+package net.osdn.gokigen.a01d.liveview;
+
+/**
+ *
+ */
+public interface ICameraStatusUpdateNotify
+{
+ void updateDriveMode(String driveMode);
+ void updateAeLockState(boolean isAeLocked);
+ void updateCameraStatus(String message);
+ void updateLevelGauge(String orientation, float roll, float pitch);
+
+ void updatedTakeMode(String mode);
+ void updatedShutterSpeed(String tv);
+ void updatedAperture(String av);
+ void updatedExposureCompensation(String xv);
+ void updatedMeteringMode(String meteringMode);
+ void updatedWBMode(String wbMode);
+ void updateRemainBattery(final int percentage);
+ void updateFocusedStatus(boolean focused, boolean focusLocked);
+ void updateIsoSensitivity(String sv);
+ void updateWarning(String warning);
+ void updateStorageStatus(String status);
+}
--- /dev/null
+package net.osdn.gokigen.a01d.liveview;
+
+public interface IFocusLockIndicator
+{
+ void updateFocusLockIndicator(final boolean focused, final boolean focusLocked);
+}
void updateStatusView(String message);
void updateLiveViewScale(boolean isChangeScale);
void startLiveView();
+
+ boolean isFocusLocked();
}
*/
private void actionFocusButton()
{
-
-
-
+ try
+ {
+ // シャッターを半押しする
+ if (focusingControl != null)
+ {
+ boolean isHalfPress = !statusViewDrawer.isFocusLocked();
+ focusingControl.halfPressShutter(isHalfPress);
+ Log.v(TAG, " actionFocusButton() : isHalfPress " + isHalfPress);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
/**
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.res.ResourcesCompat;
+import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
* 撮影用ライブビュー画面
*
*/
-public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker
+public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify, IFocusLockIndicator
{
private final String TAG = this.toString();
private static final int COMMAND_MY_PROPERTY = 0x00000100;
private CameraLiveImageView imageView = null;
private ImageView manualFocus = null;
+ private ImageView focusIndicator = null;
private ImageButton showGrid = null;
private ImageButton connectStatus = null;
private Button changeLiveViewScale = null;
private boolean imageViewCreated = false;
private View myView = null;
private String messageValue = "";
+ private boolean focusLocked = false;
private ICameraConnection.CameraConnectionStatus currentConnectionStatus = ICameraConnection.CameraConnectionStatus.UNKNOWN;
}
imageView.setOnClickListener(onClickTouchListener);
imageView.setOnTouchListener(onClickTouchListener);
+ imageView.setFocuslockIndicator(this);
view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
- view.findViewById(R.id.focus_indicator).setOnClickListener(onClickTouchListener);
+ focusIndicator = view.findViewById(R.id.focus_indicator);
+ if (focusIndicator != null)
+ {
+ focusIndicator.setOnClickListener(onClickTouchListener);
+ }
manualFocus = view.findViewById(R.id.focusing_button);
changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
{
view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
+
+ // OPCのときには、フォーカスインジケータのマークを消す。
+ if (focusIndicator != null)
+ {
+ focusIndicator.setVisibility(View.INVISIBLE);
+ }
}
else
{
{
changeLiveViewScale.setVisibility(View.INVISIBLE);
}
+ if (focusIndicator != null)
+ {
+ focusIndicator.setVisibility(View.VISIBLE);
+ }
}
- else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
+ else if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
{
if (changeLiveViewScale != null)
{
changeLiveViewScale.setVisibility(View.VISIBLE);
}
+ if (focusIndicator != null)
+ {
+ focusIndicator.setVisibility(View.INVISIBLE);
+ }
}
}
this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
}
+ interfaceProvider.setUpdateReceiver(this);
}
/**
}
}
+
+ /**
+ * フォーカスロック中かどうか
+ *
+ */
+ @Override
+ public boolean isFocusLocked()
+ {
+ return (this.focusLocked);
+ }
+
/**
* 測光モードをスポットに切り替える
*
}
activity.runOnUiThread(action);
}
+
+ @Override
+ public void updateDriveMode(String driveMode)
+ {
+ Log.v(TAG, "updateDriveMode() : " + driveMode);
+ }
+
+ @Override
+ public void updateAeLockState(boolean isAeLocked)
+ {
+ Log.v(TAG, "updateAeLockState() : " + isAeLocked);
+ }
+
+ @Override
+ public void updateCameraStatus(String message)
+ {
+ Log.v(TAG, "updateCameraStatus() : " + message);
+ }
+
+ @Override
+ public void updateLevelGauge(String orientation, float roll, float pitch)
+ {
+ Log.v(TAG, "updateLevelGauge() : " + orientation + " roll : " + roll + " pitch : " + pitch);
+ }
+
+ @Override
+ public void updatedTakeMode(String mode)
+ {
+ Log.v(TAG, "updatedTakeMode() : " + mode);
+ }
+
+ @Override
+ public void updatedShutterSpeed(String tv)
+ {
+ Log.v(TAG, "updatedShutterSpeed() : " + tv);
+ }
+
+ @Override
+ public void updatedAperture(String av)
+ {
+ Log.v(TAG, "updatedAperture() : " + av);
+ }
+
+ @Override
+ public void updatedExposureCompensation(String xv)
+ {
+ Log.v(TAG, "updatedExposureCompensation() : " + xv);
+ }
+
+ @Override
+ public void updatedMeteringMode(String meteringMode)
+ {
+ Log.v(TAG, "updatedExposureCompensation() : " + meteringMode);
+ }
+
+ @Override
+ public void updatedWBMode(String wbMode)
+ {
+ Log.v(TAG, "updatedWBMode() : " + wbMode);
+ }
+
+ @Override
+ public void updateRemainBattery(int percentage)
+ {
+ Log.v(TAG, "updateRemainBattery() : " + percentage);
+ }
+
+ @Override
+ public void updateFocusedStatus(final boolean focused, final boolean focusLocked)
+ {
+ Log.v(TAG, "updateFocusedStatus() : f: " + focused + " fl: " + focusLocked);
+ this.focusLocked = focusLocked;
+ Activity activity = getActivity();
+ if ((activity == null)||(focusIndicator == null)|| (focusIndicator.getVisibility() != View.VISIBLE))
+ {
+ Log.v(TAG, "updateFocusedStatus() : INVISIBLE");
+ return;
+ }
+
+ try
+ {
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (focused)
+ {
+ Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_center_focus_strong_black_24dp, null);
+ if (icon != null)
+ {
+ DrawableCompat.setTint(icon, Color.GREEN);
+ focusIndicator.setImageDrawable(icon);
+ }
+ }
+ else
+ {
+ Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_crop_free_black_24dp, null);
+ if (icon != null)
+ {
+ int color = Color.BLACK;
+ if (focusLocked)
+ {
+ color = Color.RED;
+ }
+ DrawableCompat.setTint(icon, color);
+ focusIndicator.setImageDrawable(icon);
+ }
+ }
+ focusIndicator.invalidate();
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void updateIsoSensitivity(String sv)
+ {
+ Log.v(TAG, "updateIsoSensitivity() : " + sv);
+ }
+
+ @Override
+ public void updateWarning(String warning)
+ {
+ Log.v(TAG, "updateWarning() : " + warning);
+ }
+
+ @Override
+ public void updateStorageStatus(String status)
+ {
+ Log.v(TAG, "updateStorageStatus() : " + status);
+ }
+
+ @Override
+ public void updateFocusLockIndicator(final boolean focused, final boolean focusLocked)
+ {
+ updateFocusedStatus(focused, focusLocked);
+ }
}