import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;
-import android.widget.Toast;
import net.osdn.gokigen.a01d.camera.CameraInterfaceProvider;
import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
import net.osdn.gokigen.a01d.preference.fujix.FujiXPreferenceFragment;
import net.osdn.gokigen.a01d.preference.olympus.PreferenceFragment;
import net.osdn.gokigen.a01d.preference.panasonic.PanasonicPreferenceFragment;
-import net.osdn.gokigen.a01d.preference.phonecamera.PhoneCameraPreferenceFragment;
+import net.osdn.gokigen.a01d.preference.olympuspen.OlympusPreferenceFragment;
import net.osdn.gokigen.a01d.preference.ricohgr2.RicohGr2PreferenceFragment;
import net.osdn.gokigen.a01d.preference.sony.SonyPreferenceFragment;
preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
} else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC) {
preferenceFragment = PanasonicPreferenceFragment.newInstance(this, this);
- } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PHONE_CAMERA) {
- preferenceFragment = PhoneCameraPreferenceFragment.newInstance(this, this);
+ } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS) {
+ preferenceFragment = OlympusPreferenceFragment.newInstance(this, this);
} else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X) {
preferenceFragment = FujiXPreferenceFragment.newInstance(this, this);
} else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
{
ret = ICameraConnection.CameraConnectionMethod.PANASONIC;
}
- else if (connectionMethod.contains("PHONE"))
+ else if (connectionMethod.contains("OLYMPUS"))
{
- ret = ICameraConnection.CameraConnectionMethod.PHONE_CAMERA;
+ ret = ICameraConnection.CameraConnectionMethod.OLYMPUS;
}
}
catch (Exception e)
RICOH_GR2,
FUJI_X,
PANASONIC,
- PHONE_CAMERA,
+ OLYMPUS,
}
enum CameraConnectionStatus
*/
public interface ICameraHardwareStatus
{
+ boolean isAvailableHardwareStatus();
+
String getLensMountStatus();
String getMediaMountStatus();
}
@Override
+ public boolean isAvailableHardwareStatus()
+ {
+ return (true);
+ }
+
+ @Override
public String getLensMountStatus()
{
String message;
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen;
+
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraInformation;
+import net.osdn.gokigen.a01d.camera.ICameraStatus;
+import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
+import net.osdn.gokigen.a01d.camera.ICaptureControl;
+import net.osdn.gokigen.a01d.camera.IDisplayInjector;
+import net.osdn.gokigen.a01d.camera.IFocusingControl;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.IZoomLensControl;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraHardwareStatus;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraRunMode;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
+
+/**
+ *
+ */
+public interface IOlympusPenInterfaceProvider
+{
+ ICameraConnection getOlyCameraConnection();
+ ILiveViewControl getLiveViewControl();
+ ILiveViewListener getLiveViewListener();
+ IFocusingControl getFocusingControl();
+ ICameraInformation getCameraInformation();
+ IZoomLensControl getZoomLensControl();
+ ICaptureControl getCaptureControl();
+ IDisplayInjector getDisplayInjector();
+
+ ICameraStatus getCameraStatusListHolder();
+ ICameraStatusWatcher getCameraStatusWatcher();
+ //IPlaybackControl getPlaybackControl();
+
+ ICameraHardwareStatus getHardwareStatus();
+ ICameraRunMode getCameraRunMode();
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen.operation;
+
+import android.content.Context;
+
+import androidx.preference.Preference;
+
+import net.osdn.gokigen.a01d.ConfirmationDialog;
+import net.osdn.gokigen.a01d.IChangeScene;
+import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
+
+/**
+ * Preferenceがクリックされた時に処理するクラス
+ *
+ */
+public class OlympusPenCameraPowerOff implements Preference.OnPreferenceClickListener, ConfirmationDialog.Callback
+{
+ private final Context context;
+ private final IChangeScene changeScene;
+ private String preferenceKey = null;
+
+ /**
+ * コンストラクタ
+ *
+ */
+ public OlympusPenCameraPowerOff(Context context, IChangeScene changeScene)
+ {
+ this.context = context;
+ this.changeScene = changeScene;
+ }
+
+ /**
+ * クラスの準備
+ *
+ */
+ public void prepare()
+ {
+ // 何もしない
+ }
+
+ /**
+ *
+ *
+ * @param preference クリックしたpreference
+ * @return false : ハンドルしない / true : ハンドルした
+ */
+ @Override
+ public boolean onPreferenceClick(Preference preference)
+ {
+ if (!preference.hasKey())
+ {
+ return (false);
+ }
+
+ preferenceKey = preference.getKey();
+ if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
+ {
+
+ // 確認ダイアログの生成と表示
+ ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
+ dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, this);
+ return (true);
+ }
+ return (false);
+ }
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void confirm()
+ {
+ if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
+ {
+ // カメラの電源をOFFにしたうえで、アプリケーションを終了する。
+ changeScene.exitApplication();
+ }
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.preference.PreferenceManager;
+
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraInformation;
+import net.osdn.gokigen.a01d.camera.ICameraStatus;
+import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
+import net.osdn.gokigen.a01d.camera.ICaptureControl;
+import net.osdn.gokigen.a01d.camera.IDisplayInjector;
+import net.osdn.gokigen.a01d.camera.IFocusingControl;
+import net.osdn.gokigen.a01d.camera.IFocusingModeNotify;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.IZoomLensControl;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraHardwareStatus;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraRunMode;
+import net.osdn.gokigen.a01d.camera.olympuspen.IOlympusPenInterfaceProvider;
+import net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection.OlympusPenConnection;
+import net.osdn.gokigen.a01d.camera.olympuspen.wrapper.hardware.OlympusPenHardwareStatus;
+import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
+import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
+
+/**
+ *
+ *
+ */
+public class OlympusPenInterfaceProvider implements IOlympusPenInterfaceProvider, IDisplayInjector
+{
+ private final String TAG = toString();
+ private final OlympusPenConnection olympusPenConnection;
+ private final OlympusPenHardwareStatus hardwareStatus;
+ private final OlympusPenRunMode runMode;
+
+ /**
+ *
+ *
+ */
+ public OlympusPenInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider)
+ {
+/*
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ int communicationTimeoutMs = 10000; // デフォルトは 10000ms とする
+ try
+ {
+ communicationTimeoutMs = Integer.parseInt(preferences.getString(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE)) * 1000;
+ if (communicationTimeoutMs < 3000)
+ {
+ communicationTimeoutMs = 3000; // 最小値は 3000msとする。
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+*/
+ //this.activity = context;
+ //this.provider = provider;
+ olympusPenConnection = new OlympusPenConnection(context, provider);
+ hardwareStatus = new OlympusPenHardwareStatus();
+ runMode = new OlympusPenRunMode();
+ }
+
+ public void prepare()
+ {
+ Log.v(TAG, "prepare()");
+ }
+
+ @Override
+ public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
+ {
+ Log.v(TAG, "injectDisplay()");
+ }
+
+ @Override
+ public ICameraConnection getOlyCameraConnection()
+ {
+ return (olympusPenConnection);
+ }
+
+ @Override
+ public ILiveViewControl getLiveViewControl()
+ {
+ return (null);
+ }
+
+ @Override
+ public ILiveViewListener getLiveViewListener()
+ {
+ return (null);
+ }
+
+ @Override
+ public IFocusingControl getFocusingControl()
+ {
+ return (null);
+ }
+
+ @Override
+ public ICameraInformation getCameraInformation()
+ {
+ return (null);
+ }
+
+ @Override
+ public IZoomLensControl getZoomLensControl()
+ {
+ return (null);
+ }
+
+ @Override
+ public ICaptureControl getCaptureControl()
+ {
+ return (null);
+ }
+
+ @Override
+ public IDisplayInjector getDisplayInjector() {
+ return (this);
+ }
+
+ @Override
+ public ICameraStatus getCameraStatusListHolder()
+ {
+ return (null);
+ }
+
+ @Override
+ public ICameraStatusWatcher getCameraStatusWatcher() {
+ return (null);
+ }
+
+ @Override
+ public ICameraHardwareStatus getHardwareStatus()
+ {
+ return (hardwareStatus);
+ }
+
+ @Override
+ public ICameraRunMode getCameraRunMode()
+ {
+ return (runMode);
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper;
+
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraRunMode;
+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OlympusPenRunMode implements ICameraRunMode
+{
+ private final String TAG = this.toString();
+
+ @Override
+ public void changeRunMode(final boolean isRecording)
+ {
+ final int TIMEOUT_MS = 5000;
+ try
+ {
+ final Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ // カメラとの接続確立を通知する
+ Map<String, String> headerMap = new HashMap<>();
+ headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
+ headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
+
+ String playModeUrl = "http://192.168.0.10/switch_cameramode.cgi";
+ if (isRecording)
+ {
+ playModeUrl = playModeUrl + "?mode=rec";
+ }
+ else
+ {
+ playModeUrl = playModeUrl + "?mode=play";
+ }
+ String response = SimpleHttpClient.httpGetWithHeader(playModeUrl, headerMap, null, TIMEOUT_MS);
+ Log.v(TAG, " " + playModeUrl + " " + response);
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public boolean isRecordingMode()
+ {
+ return (true);
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection;
+
+import android.app.Activity;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+class OlympusPenCameraConnectSequence implements Runnable
+{
+ private final String TAG = this.toString();
+ private final Activity context;
+ private final ICameraConnection cameraConnection;
+ private final ICameraStatusReceiver cameraStatusReceiver;
+
+ OlympusPenCameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection)
+ {
+ Log.v(TAG, "OlympusPenCameraConnectSequence");
+ this.context = context;
+ this.cameraConnection = cameraConnection;
+ this.cameraStatusReceiver = statusReceiver;
+ }
+
+ @Override
+ public void run()
+ {
+ final String camInfoUrl = "http://192.168.0.10/get_caminfo.cgi";
+ final String getCommandListUrl = "http://192.168.0.10/get_commandlist.cgi";
+ final String getConnectModeUrl = "http://192.168.0.10/get_connectmode.cgi";
+
+ final int TIMEOUT_MS = 5000;
+ try
+ {
+ Map<String, String> headerMap = new HashMap<>();
+ headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
+ headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
+
+ String response = SimpleHttpClient.httpGetWithHeader(getConnectModeUrl, headerMap, null, TIMEOUT_MS);
+ Log.v(TAG, " " + getConnectModeUrl + " " + response);
+ if (response.length() > 0)
+ {
+ String response2 = SimpleHttpClient.httpGetWithHeader(getCommandListUrl, headerMap, null, TIMEOUT_MS);
+ Log.v(TAG, " " + getCommandListUrl + " " + response2);
+
+ String response3 = SimpleHttpClient.httpGetWithHeader(camInfoUrl, headerMap, null, TIMEOUT_MS);
+ Log.v(TAG, " " + camInfoUrl + " " + response3);
+
+ onConnectNotify();
+ }
+ else
+ {
+ onConnectError(context.getString(R.string.camera_not_found));
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ onConnectError(e.getLocalizedMessage());
+ }
+ }
+
+ private void onConnectNotify()
+ {
+ try
+ {
+ final Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ // カメラとの接続確立を通知する
+ cameraStatusReceiver.onStatusNotify(context.getString(R.string.connect_connected));
+ cameraStatusReceiver.onCameraConnected();
+ Log.v(TAG, "onConnectNotify()");
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void onConnectError(String reason)
+ {
+ cameraConnection.alertConnectingFailed(reason);
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection;
+
+
+import android.app.Activity;
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OlympusPenCameraDisconnectSequence implements Runnable
+{
+ private final String TAG = this.toString();
+ private final Activity activity;
+ private final boolean powerOff;
+
+ OlympusPenCameraDisconnectSequence(Activity activity, boolean isOff)
+ {
+ this.activity = activity;
+ this.powerOff = isOff;
+ }
+
+ @Override
+ public void run()
+ {
+ // カメラをPowerOffして接続を切る
+ try
+ {
+ Map<String, String> headerMap = new HashMap<>();
+ headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
+ headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
+
+ if (powerOff)
+ {
+ final String cameraPowerOffUrl = "http://192.168.0.10/exec_pwoff.cgi";
+ final int TIMEOUT_MS = 5000;
+ String response = SimpleHttpClient.httpGetWithHeader(cameraPowerOffUrl, headerMap, null, TIMEOUT_MS);
+ Log.v(TAG, " " + cameraPowerOffUrl + " " + response);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection;
+
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.ConnectivityManager;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.provider.Settings;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
+
+import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+/**
+ *
+ *
+ */
+public class OlympusPenConnection implements ICameraConnection
+{
+ private final String TAG = toString();
+ private final Activity context;
+ private final ICameraStatusReceiver statusReceiver;
+ private final BroadcastReceiver connectionReceiver;
+ //private final ConnectivityManager connectivityManager;
+ private final Executor cameraExecutor = Executors.newFixedThreadPool(1);
+ //private final Handler networkConnectionTimeoutHandler;
+ //private static final int MESSAGE_CONNECTIVITY_TIMEOUT = 1;
+ private CameraConnectionStatus connectionStatus = CameraConnectionStatus.UNKNOWN;
+
+
+ /**
+ *
+ *
+ */
+ public OlympusPenConnection(@NonNull final Activity context, @NonNull final ICameraStatusReceiver statusReceiver)
+ {
+ Log.v(TAG, "OlympusPenConnection()");
+ this.context = context;
+ this.statusReceiver = statusReceiver;
+ connectionReceiver = new BroadcastReceiver()
+ {
+ @Override
+ public void onReceive(Context context, Intent intent)
+ {
+ onReceiveBroadcastOfConnection(context, intent);
+ }
+ };
+ }
+
+ /**
+ *
+ *
+ */
+ private void onReceiveBroadcastOfConnection(Context context, Intent intent)
+ {
+ statusReceiver.onStatusNotify(context.getString(R.string.connect_check_wifi));
+ Log.v(TAG,context.getString(R.string.connect_check_wifi));
+
+ String action = intent.getAction();
+ if (action == null)
+ {
+ //
+ Log.v(TAG, "intent.getAction() : null");
+ return;
+ }
+
+ try
+ {
+ if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION))
+ {
+ Log.v(TAG, "onReceiveBroadcastOfConnection() : CONNECTIVITY_ACTION");
+
+ WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+ if (wifiManager != null) {
+ WifiInfo info = wifiManager.getConnectionInfo();
+ if (wifiManager.isWifiEnabled() && info != null)
+ {
+ if (info.getNetworkId() != -1)
+ {
+ Log.v(TAG, "Network ID is -1, there is no currently connected network.");
+ }
+ // 自動接続が指示されていた場合は、カメラとの接続処理を行う
+ connectToCamera();
+ } else {
+ if (info == null)
+ {
+ Log.v(TAG, "NETWORK INFO IS NULL.");
+ } else {
+ Log.v(TAG, "isWifiEnabled : " + wifiManager.isWifiEnabled() + " NetworkId : " + info.getNetworkId());
+ }
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ Log.w(TAG, "onReceiveBroadcastOfConnection() EXCEPTION" + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void startWatchWifiStatus(Context context)
+ {
+ Log.v(TAG, "startWatchWifiStatus()");
+ statusReceiver.onStatusNotify("prepare");
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ context.registerReceiver(connectionReceiver, filter);
+ }
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void stopWatchWifiStatus(Context context)
+ {
+ Log.v(TAG, "stopWatchWifiStatus()");
+ context.unregisterReceiver(connectionReceiver);
+ disconnect(false);
+ }
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void disconnect(boolean powerOff)
+ {
+ Log.v(TAG, "disconnect()");
+ disconnectFromCamera(powerOff);
+ connectionStatus = CameraConnectionStatus.DISCONNECTED;
+ statusReceiver.onCameraDisconnected();
+ }
+
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void connect()
+ {
+ Log.v(TAG, "connect()");
+ connectToCamera();
+ }
+
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void alertConnectingFailed(String message)
+ {
+ Log.v(TAG, "alertConnectingFailed() : " + message);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context)
+ .setTitle(context.getString(R.string.dialog_title_connect_failed))
+ .setMessage(message)
+ .setPositiveButton(context.getString(R.string.dialog_title_button_retry), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which)
+ {
+ connect();
+ }
+ })
+ .setNeutralButton(R.string.dialog_title_button_network_settings, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which)
+ {
+ try
+ {
+ // Wifi 設定画面を表示する
+ context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+ }
+ catch (android.content.ActivityNotFoundException ex)
+ {
+ // Activity が存在しなかった...設定画面が起動できなかった
+ Log.v(TAG, "android.content.ActivityNotFoundException...");
+
+ // この場合は、再試行と等価な動きとする
+ connect();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ context.runOnUiThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ builder.show();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ @Override
+ public CameraConnectionStatus getConnectionStatus()
+ {
+ Log.v(TAG, "getConnectionStatus()");
+ return (connectionStatus);
+ }
+
+ /**
+ *
+ *
+ */
+ @Override
+ public void forceUpdateConnectionStatus(CameraConnectionStatus status)
+ {
+ Log.v(TAG, "forceUpdateConnectionStatus()");
+ connectionStatus = status;
+ }
+
+ /**
+ * カメラとの切断処理
+ */
+ private void disconnectFromCamera(final boolean powerOff)
+ {
+ Log.v(TAG, "disconnectFromCamera()");
+ try
+ {
+ cameraExecutor.execute(new OlympusPenCameraDisconnectSequence(context, powerOff));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * カメラとの接続処理
+ */
+ private void connectToCamera()
+ {
+ Log.v(TAG, "connectToCamera()");
+ connectionStatus = CameraConnectionStatus.CONNECTING;
+ try
+ {
+ cameraExecutor.execute(new OlympusPenCameraConnectSequence(context, statusReceiver, this));
+ }
+ catch (Exception e)
+ {
+ Log.v(TAG, "connectToCamera() EXCEPTION : " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.hardware;
+
+
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraHardwareStatus;
+
+import java.util.Map;
+
+public class OlympusPenHardwareStatus implements ICameraHardwareStatus
+{
+ @Override
+ public boolean isAvailableHardwareStatus()
+ {
+ return (false);
+ }
+
+ @Override
+ public String getLensMountStatus()
+ {
+ return (null);
+ }
+
+ @Override
+ public String getMediaMountStatus()
+ {
+ return (null);
+ }
+
+ @Override
+ public float getMinimumFocalLength()
+ {
+ return (0);
+ }
+
+ @Override
+ public float getMaximumFocalLength()
+ {
+ return (0);
+ }
+
+ @Override
+ public float getActualFocalLength()
+ {
+ return (0);
+ }
+
+ @Override
+ public Map<String, Object> inquireHardwareInformation()
+ {
+ return (null);
+ }
+
+}
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.List;
+import java.util.Map;
import androidx.annotation.NonNull;
*
*
*/
- public static void httpGetBytes(String url, int timeoutMs, @NonNull IReceivedMessageCallback callback)
+ public static void httpGetBytes(String url, Map<String, String> setProperty, int timeoutMs, @NonNull IReceivedMessageCallback callback)
{
HttpURLConnection httpConn = null;
InputStream inputStream = null;
final URL urlObj = new URL(url);
httpConn = (HttpURLConnection) urlObj.openConnection();
httpConn.setRequestMethod("GET");
+ if (setProperty != null)
+ {
+ for (String key : setProperty.keySet())
+ {
+ String value = setProperty.get(key);
+ httpConn.setRequestProperty(key, value);
+ }
+ }
httpConn.setConnectTimeout(timeout);
httpConn.setReadTimeout(timeout);
httpConn.connect();
try
{
int contentLength = httpConn.getContentLength();
+ if (contentLength < 0)
+ {
+ // コンテンツ長が取れない場合の処理...
+ try
+ {
+ Map<String, List<String>> headers = httpConn.getHeaderFields();
+
+ /*
+ // 応答ヘッダをすべてダンプするロジック...
+ for (String key : headers.keySet())
+ {
+ final List<String> valueList = headers.get(key);
+ Log.v(TAG, " " + key + " : " + getValue(valueList));
+ }
+ */
+
+ // コンテンツ長さが取れない場合は、HTTP応答ヘッダから取得する
+ List<String> valueList = headers.get("X-FILE_SIZE");
+ try
+ {
+ if (valueList != null)
+ {
+ contentLength = Integer.parseInt(getValue(valueList));
+ }
+ }
+ catch (Exception ee)
+ {
+ ee.printStackTrace();
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
byte[] buffer = new byte[BUFFER_SIZE];
int readBytes = 0;
int readSize = inputStream.read(buffer, 0, BUFFER_SIZE);
callback.onCompleted();
}
+ public static String getValue(List<String> valueList)
+ {
+ // 応答ヘッダの値切り出し用...
+ boolean isFirst = true;
+ final StringBuilder values = new StringBuilder();
+ for (String value : valueList)
+ {
+ values.append(value);
+ if (isFirst)
+ {
+ isFirst = false;
+ }
+ else
+ {
+ values.append(" ");
+ }
+ }
+ return (values.toString());
+ }
+
/**
*
*
*
*/
- public static Bitmap httpGetBitmap(String url, int timeoutMs)
+ public static Bitmap httpGetBitmap(String url, Map<String, String> setProperty, int timeoutMs)
{
HttpURLConnection httpConn = null;
InputStream inputStream = null;
final URL urlObj = new URL(url);
httpConn = (HttpURLConnection) urlObj.openConnection();
httpConn.setRequestMethod("GET");
+ if (setProperty != null)
+ {
+ for (String key : setProperty.keySet())
+ {
+ String value = setProperty.get(key);
+ httpConn.setRequestProperty(key, value);
+ }
+ }
httpConn.setConnectTimeout(timeout);
httpConn.setReadTimeout(timeout);
httpConn.connect();
*/
public static String httpPost(String url, String postData, int timeoutMs)
{
- return (httpCommand(url, "POST", postData, timeoutMs));
+ return (httpCommand(url, "POST", postData, null, null, timeoutMs));
+ }
+
+
+ /**
+ *
+ *
+ *
+ */
+ public static String httpGetWithHeader(String url, Map<String, String> headerMap, String contentType, int timeoutMs)
+ {
+ return (httpCommand(url, "GET", null, headerMap, contentType, timeoutMs));
+ }
+
+ /**
+ *
+ *
+ *
+ */
+ public static String httpPostWithHeader(String url, String postData, Map<String, String> headerMap, String contentType, int timeoutMs)
+ {
+ return (httpCommand(url, "POST", postData, headerMap, contentType, timeoutMs));
}
/**
*/
public static String httpPut(String url, String postData, int timeoutMs)
{
- return (httpCommand(url, "PUT", postData, timeoutMs));
+ return (httpCommand(url, "PUT", postData, null, null, timeoutMs));
}
/**
*/
public static String httpOptions(String url, String postData, int timeoutMs)
{
- return (httpCommand(url, "OPTIONS", postData, timeoutMs));
+ return (httpCommand(url, "OPTIONS", postData, null, null, timeoutMs));
}
/**
*
*
*/
- private static String httpCommand(String url, String requestMethod, String postData, int timeoutMs)
+ private static String httpCommand(String url, String requestMethod, String postData, Map<String, String> setProperty, String contentType, int timeoutMs)
{
HttpURLConnection httpConn = null;
OutputStream outputStream = null;
final URL urlObj = new URL(url);
httpConn = (HttpURLConnection) urlObj.openConnection();
httpConn.setRequestMethod(requestMethod);
+ if (setProperty != null)
+ {
+ for (String key : setProperty.keySet())
+ {
+ String value = setProperty.get(key);
+ httpConn.setRequestProperty(key, value);
+ }
+ }
+ if (contentType != null)
+ {
+ httpConn.setRequestProperty("Content-Type", contentType);
+ }
httpConn.setConnectTimeout(timeout);
httpConn.setReadTimeout(timeout);
- httpConn.setDoInput(true);
- httpConn.setDoOutput(true);
-
- outputStream = httpConn.getOutputStream();
- writer = new OutputStreamWriter(outputStream, "UTF-8");
- writer.write(postData);
- writer.flush();
- writer.close();
- writer = null;
- outputStream.close();
- outputStream = null;
+ if (postData == null)
+ {
+ httpConn.connect();
+ }
+ else
+ {
+ httpConn.setDoInput(true);
+ httpConn.setDoOutput(true);
+ outputStream = httpConn.getOutputStream();
+ writer = new OutputStreamWriter(outputStream, "UTF-8");
+ writer.write(postData);
+ writer.flush();
+ writer.close();
+ writer = null;
+ outputStream.close();
+ outputStream = null;
+ }
int responseCode = httpConn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
-package net.osdn.gokigen.a01d.preference.phonecamera;
+package net.osdn.gokigen.a01d.preference.olympuspen;
import android.content.Context;
import android.content.SharedPreferences;
import net.osdn.gokigen.a01d.IChangeScene;
import net.osdn.gokigen.a01d.R;
-import net.osdn.gokigen.a01d.camera.panasonic.operation.CameraPowerOffPanasonic;
+import net.osdn.gokigen.a01d.camera.olympuspen.operation.OlympusPenCameraPowerOff;
import net.osdn.gokigen.a01d.logcat.LogCatViewer;
import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
*
*
*/
-public class PhoneCameraPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
+public class OlympusPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
{
private final String TAG = toString();
private SharedPreferences preferences = null;
- private CameraPowerOffPanasonic powerOffController = null;
+ private OlympusPenCameraPowerOff powerOffController = null;
private LogCatViewer logCatViewer = null;
//private PanasonicCameraApiListViewer cameraApiListViewer = null;
*
*
*/
- public static PhoneCameraPreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
+ public static OlympusPreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
{
- PhoneCameraPreferenceFragment instance = new PhoneCameraPreferenceFragment();
+ OlympusPreferenceFragment instance = new OlympusPreferenceFragment();
instance.prepare(context, changeScene);
// パラメータはBundleにまとめておく
{
try
{
- powerOffController = new CameraPowerOffPanasonic(context, changeScene);
+ powerOffController = new OlympusPenCameraPowerOff(context, changeScene);
powerOffController.prepare();
logCatViewer = new LogCatViewer(changeScene);
*
*/
@Override
- public void onAttach(Context activity)
+ public void onAttach(@NonNull Context activity)
{
super.onAttach(activity);
Log.v(TAG, "onAttach()");
try
{
//super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.preferences_panasonic);
+ addPreferencesFromResource(R.xml.preferences_olympuspen);
- ListPreference connectionMethod = (ListPreference) findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
+ ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
{
try
{
- CheckBoxPreference pref = (CheckBoxPreference) findPreference(pref_key);
+ CheckBoxPreference pref = findPreference(pref_key);
if (pref != null) {
boolean value = preferences.getBoolean(key, defaultValue);
pref.setChecked(value);
<item>Ricoh GR Series / PENTAX</item>
<item >Fuji X Series</item>
<item >Panasonic</item>
- <item >Phone</item>
+ <item >Olympus Pen/OM-D</item>
</string-array>
<string-array name="connection_method_value">
<item >RICOH_GR2</item>
<item >FUJI_X</item>
<item >PANASONIC</item>
- <item >PHONE</item>
+ <item >OLYMPUS</item>
</string-array>
<string name="pref_exit_power_off">アプリ終了(とカメラOFF)</string>
<string name="pref_exit_power_off_sony">アプリ終了</string>
<string name="pref_exit_power_off_panasonic">アプリ終了</string>
- <string name="pref_exit_power_off_camera">アプリ終了</string>
+ <string name="pref_exit_power_off_olympuspen">アプリ終了(とカメラOFF)</string>
<string name="pref_exit_power_off_fujix">アプリ終了</string>
<string name="pref_fujix_display_camera_view">LVをカメラでも表示</string>
<item>Ricoh GR Series / PENTAX</item>
<item >Fuji X Series</item>
<item >Panasonic</item>
- <item >Phone</item>
+ <item >Olympus Pen/OM-D</item>
</string-array>
<string-array name="connection_method_value">
<item >RICOH_GR2</item>
<item >FUJI_X</item>
<item >PANASONIC</item>
- <item >PHONE</item>
+ <item >OLYMPUS</item>
</string-array>
<string-array name="gr2_display_mode">
<string name="pref_exit_power_off">Exit Application(and Camera OFF)</string>
<string name="pref_exit_power_off_sony">Exit Application</string>
<string name="pref_exit_power_off_panasonic">Exit Application</string>
- <string name="pref_exit_power_off_camera">Exit Application</string>
+ <string name="pref_exit_power_off_olympuspen">Exit Application(and Camera OFF)</string>
<string name="pref_exit_power_off_fujix">Exit Application</string>
<string name="pref_fujix_display_camera_view">Use Camera Display</string>
<PreferenceScreen
android:key="exit_application"
android:icon="@drawable/ic_power_settings_new_black_24dp"
- android:title="@string/pref_exit_power_off_camera" />
+ android:title="@string/pref_exit_power_off_olympuspen" />
<ListPreference
android:title="@string/pref_connection_method"