package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.connection;
-import android.app.Activity;
import android.graphics.Color;
import android.util.Log;
import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
import net.osdn.gokigen.pkremote.R;
import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
public class CanonCameraConnectSequenceForPlayback implements Runnable, IPtpIpCommandCallback, IPtpIpMessages
{
private final String TAG = this.toString();
-
- private final Activity context;
+ private final AppCompatActivity context;
private final ICameraConnection cameraConnection;
private final ICameraStatusReceiver cameraStatusReceiver;
private final IPtpIpInterfaceProvider interfaceProvider;
private final IPtpIpCommandPublisher commandIssuer;
private final PtpIpStatusChecker statusChecker;
- private boolean isDumpLog = false;
+ private final boolean isDumpLog;
- CanonCameraConnectSequenceForPlayback(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IPtpIpInterfaceProvider interfaceProvider, @NonNull PtpIpStatusChecker statusChecker)
+ CanonCameraConnectSequenceForPlayback(@NonNull AppCompatActivity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IPtpIpInterfaceProvider interfaceProvider, @NonNull PtpIpStatusChecker statusChecker, boolean isDumpLog)
{
Log.v(TAG, " CanonCameraConnectSequenceForPlayback");
this.context = context;
this.interfaceProvider = interfaceProvider;
this.commandIssuer = interfaceProvider.getCommandPublisher();
this.statusChecker = statusChecker;
+ this.isDumpLog = isDumpLog;
}
+
@Override
public void run()
{
IPtpIpCommandPublisher issuer = interfaceProvider.getCommandPublisher();
if (!issuer.isConnected())
{
- if (!interfaceProvider.getCommandCommunication().connect())
+ if (!interfaceProvider.getCommandCommunication().connect(interfaceProvider.getIpAddress(), interfaceProvider.getControlPortNumber()))
{
// 接続失敗...
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.dialog_title_connect_failed_canon), false, true, Color.RED);
@Override
public void receivedMessage(int id, byte[] rx_body)
{
- switch (id)
- {
- case SEQ_REGISTRATION:
- if (checkRegistrationMessage(rx_body))
- {
+ switch (id) {
+ case SEQ_REGISTRATION -> {
+ if (checkRegistrationMessage(rx_body)) {
sendInitEventRequest(rx_body);
- }
- else
- {
+ } else {
onConnectError(context.getString(R.string.connect_error_message));
}
- break;
-
- case SEQ_EVENT_INITIALIZE:
- if (checkEventInitialize(rx_body))
- {
+ }
+ case SEQ_EVENT_INITIALIZE -> {
+ if (checkEventInitialize(rx_body)) {
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting1), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_OPEN_SESSION, isDumpLog, 0, 0x1002, 4, 0x41));
- }
- else
- {
+ } else {
onConnectError(context.getString(R.string.connect_error_message));
}
- break;
-
- case SEQ_OPEN_SESSION:
+ }
+ case SEQ_OPEN_SESSION -> {
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting2), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_INIT_SESSION, isDumpLog, 0, 0x902f));
- break;
-
- case SEQ_INIT_SESSION:
+ }
+ case SEQ_INIT_SESSION -> {
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting3), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHANGE_REMOTE, isDumpLog, 0, 0x9114, 4, 0x15));
- break;
-
- case SEQ_CHANGE_REMOTE:
+ }
+ case SEQ_CHANGE_REMOTE -> {
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting4), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_SET_EVENT_MODE, isDumpLog, 0, 0x902f, 4, 0x02));
- break;
-
- case SEQ_SET_EVENT_MODE:
+ }
+ case SEQ_SET_EVENT_MODE -> {
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting5), false, false, 0);
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.connect_connect_finished), false, false, 0);
connectFinished();
Log.v(TAG, "CHANGED PLAYBACK MODE : DONE.");
- break;
-
- default:
+ }
+ default -> {
Log.v(TAG, "RECEIVED UNKNOWN ID : " + id);
onConnectError(context.getString(R.string.connect_receive_unknown_message));
- break;
+ }
}
}
{
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()");
- }
+ final Thread thread = new Thread(() -> {
+ // カメラとの接続確立を通知する
+ cameraStatusReceiver.onStatusNotify(context.getString(R.string.connect_connected));
+ cameraStatusReceiver.onCameraConnected();
+ Log.v(TAG, " onConnectNotify()");
});
thread.start();
}