apply plugin: 'kotlin-android'
android {
- compileSdkVersion 34
defaultConfig {
applicationId "net.osdn.gokigen.pkremote"
minSdkVersion 14
targetSdkVersion 34
- versionCode 10806
- versionName "1.8.6"
+ versionCode 10807
+ versionName "1.8.7"
multiDexEnabled true
}
buildTypes {
package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper;
import android.app.Activity;
+import android.content.Context;
import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.net.LinkProperties;
+import android.net.Network;
+import android.net.RouteInfo;
+import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommunication;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.PtpIpAsyncResponseReceiver;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.PtpIpCommandPublisher;
-import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.PtpIpCommandPublisher0;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.connection.CanonConnection;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.liveview.PtpIpLiveViewControl;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback.CanonPlaybackControl;
import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.status.PtpIpStatusChecker;
import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
+import java.net.InetAddress;
+import java.util.List;
+
public class PtpIpInterfaceProvider implements IPtpIpInterfaceProvider, IDisplayInjector
{
private final String TAG = toString();
int sequenceType = 0;
try
{
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
- ipAddress = preferences.getString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
- if (ipAddress == null)
- {
- ipAddress = "192.168.0.1";
- }
+ ipAddress = getHostAddress(context);
try
{
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String sequenceTypeStr = preferences.getString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
- if (sequenceTypeStr != null)
- {
- sequenceType = Integer.parseInt(sequenceTypeStr);
- }
+ sequenceType = Integer.parseInt(sequenceTypeStr);
}
catch (Exception e)
{
this.informationReceiver = informationReceiver;
}
+ private String getHostAddress(@NonNull Activity context)
+ {
+ String ipAddress = "192.168.0.1";
+ try
+ {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ boolean autoDetactHostIp = preferences.getBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ ipAddress = preferences.getString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
+ if ((autoDetactHostIp)&&(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M))
+ {
+ ConnectivityManager connectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
+ Network activeNetwork = connectivityManager.getActiveNetwork();
+ if (activeNetwork == null)
+ {
+ return (ipAddress);
+ }
+ LinkProperties linkProperties = connectivityManager.getLinkProperties(activeNetwork);
+ if (linkProperties == null)
+ {
+ return (ipAddress);
+ }
+ List<RouteInfo> routes = linkProperties.getRoutes();
+ for (RouteInfo route: routes)
+ {
+ try
+ {
+ InetAddress gateway = route.getGateway();
+ if ((route.isDefaultRoute())&&(gateway != null))
+ {
+ ipAddress = gateway.toString().replace("/","");
+ Log.v(TAG, " --------- default Gateway : ipAddress --------- ");
+ break;
+ }
+
+ }
+ catch (Exception ee)
+ {
+ ee.printStackTrace();
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (ipAddress);
+ }
+
@Override
public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
{
String CANON_HOST_IP = "canon_host_ip";
String CANON_HOST_IP_DEFAULT_VALUE = "192.168.0.1";
+ String CANON_AUTO_DETECT_HOST_IP = "canon_auto_detect_host_ip";
+
String CANON_CONNECTION_SEQUENCE = "canon_connection_mode";
String CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE = "0";
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true);
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
}
IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE
)
}
+ if (!items.containsKey(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP)) {
+ editor?.putBoolean(IPreferencePropertyAccessor.CANON_AUTO_DETECT_HOST_IP, true)
+ }
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
editor?.putString(
IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE,
<string name="canon_get_image_screennail">画像取得中…</string>
<string name="canon_get_image_screennail_done">完了</string>
+ <string name="pref_canon_auto_detect_host_ip">カメラIPアドレスを自動設定</string>
+ <string name="pref_summary_canon_auto_detect_host_ip">通常、ONのままでご使用ください。</string>
+
<string name="pref_nikon_host_ip">カメラIPアドレス</string>
<string name="pref_summary_nikon_host_ip">通常、変更は不要です</string>
<string name="canon_get_image_screennail">Get Image…</string>
<string name="canon_get_image_screennail_done">Done.</string>
+ <string name="pref_canon_auto_detect_host_ip">Set camera ip automatically.</string>
+ <string name="pref_summary_canon_auto_detect_host_ip">Normally to keep ON.</string>
+
<string name="pref_nikon_host_ip">Camera IP Address</string>
<string name="pref_summary_nikon_host_ip"> </string>
android:key="canon_connection_mode"
android:defaultValue="0"/>
+ <CheckBoxPreference
+ android:key="canon_auto_detect_host_ip"
+ android:title="@string/pref_canon_auto_detect_host_ip"
+ android:summary="@string/pref_summary_canon_auto_detect_host_ip" />
+
<!--
<PreferenceScreen