package net.osdn.gokigen.pkremote.camera.vendor.visionkids.wrapper.playback
+import android.content.Context
+import android.net.ConnectivityManager
+import android.net.RouteInfo
+import android.os.Build
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent
import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback
import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor
+import java.net.Inet6Address
-class VisionKidsCameraContentProvider(context: AppCompatActivity) : IFtpServiceCallback
+class VisionKidsCameraContentProvider(private val context: AppCompatActivity) : IFtpServiceCallback
{
private val ftpClient = MyFtpClient(this)
private val preferences = PreferenceManager.getDefaultSharedPreferences(context)
}
}
+ fun getHostAddress() : String
+ {
+ val autoHost = preferences.getBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true)
+ var address = preferences.getString(IPreferencePropertyAccessor.VISIONKIDS_HOST_IP, IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE)?: IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE
+ try
+ {
+ if ((autoHost)&&(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M))
+ {
+ val connectivityManager = context.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
+ val activeNetwork = connectivityManager.activeNetwork?: return (address)
+ val routes: List<RouteInfo> = connectivityManager.getLinkProperties(activeNetwork)?.routes ?: return (address)
+ for (route in routes)
+ {
+ val gateway = route.gateway
+ if ((route.isDefaultRoute) && (!(gateway is Inet6Address))&&(gateway != null))
+ {
+ address = gateway.toString().replace("/","")
+ Log.v(TAG, " --------- default Gateway : $address --------- ")
+ break
+ }
+ }
+ }
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ return (address)
+ }
fun getContentList(callback: ICameraContentListCallback)
{
try
{
- val address = preferences.getString(IPreferencePropertyAccessor.VISIONKIDS_HOST_IP, IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE)?: IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE
+ val address = getHostAddress()
this.callback = callback
ftpClient.connect(address)
}
import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient
import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient.IReceivedMessageCallback
import net.osdn.gokigen.pkremote.camera.vendor.visionkids.wrapper.connection.IVisionKidsConnection
-import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor
import java.util.Date
class VisionKidsPlaybackControl(activity: AppCompatActivity, private val provider: ICameraStatusReceiver, private val informationReceiver: IInformationReceiver, timeoutMs: Int = DEFAULT_TIMEOUT): IPlaybackControl, IVisionKidsConnection
{
private val contentProvider = VisionKidsCameraContentProvider(activity)
- private val preferences = PreferenceManager.getDefaultSharedPreferences(activity)
private val timeoutValue = Math.max(DEFAULT_TIMEOUT, timeoutMs)
override fun getRawFileSuffix(): String
{
try
{
- val address = preferences.getString(IPreferencePropertyAccessor.VISIONKIDS_HOST_IP, IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE)?: IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE
+ val address = contentProvider.getHostAddress()
val urlToGet = "http://$address/DCIM/T/$path".replace("//","/")
Log.v(TAG, "downloadContentThumbnail($path) : $urlToGet")
{
// 取得先URLを特定する
val dataType = if (isSmallSize) { "T" } else { "O" }
- val address = preferences.getString(IPreferencePropertyAccessor.VISIONKIDS_HOST_IP, IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE)?: IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE
+ val address = contentProvider.getHostAddress()
val urlToGet = "http://$address/DCIM/$dataType/$path".replace("//","/")
Log.v(TAG, "downloadContent($path, $isSmallSize) : $urlToGet")
String VISIONKIDS_LIST_TIMEOUT = "visionkids_get_pics_list_timeout";
String VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE = "30";
-
+ String VISIONKIDS_AUTO_SET_HOST_IP = "visionkids_auto_detect_ip_host";
/*
//String GR2_DISPLAY_MODE = "gr2_display_mode";
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
editor.putString(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT, IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE);
}
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP))
+ {
+ editor.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true);
+ }
editor.apply();
}
catch (Exception e)
private fun initializePreferences() {
try {
val items = preferences!!.all
- val editor = preferences!!.edit()
+ val editor = preferences?.edit()
if (!items.containsKey(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA)) {
- editor.putBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true)
+ editor?.putBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true)
}
if (!items.containsKey(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW)) {
- editor.putBoolean(
+ editor?.putBoolean(
IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW,
true
)
}
if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.CONNECTION_METHOD,
IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.GET_SMALL_PICTURE_AS_VGA)) {
- editor.putBoolean(IPreferencePropertyAccessor.GET_SMALL_PICTURE_AS_VGA, false)
+ editor?.putBoolean(IPreferencePropertyAccessor.GET_SMALL_PICTURE_AS_VGA, false)
}
if (!items.containsKey(IPreferencePropertyAccessor.USE_SMARTPHONE_TRANSFER_MODE)) {
- editor.putBoolean(IPreferencePropertyAccessor.USE_SMARTPHONE_TRANSFER_MODE, false)
+ editor?.putBoolean(IPreferencePropertyAccessor.USE_SMARTPHONE_TRANSFER_MODE, false)
}
if (!items.containsKey(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT,
IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.USE_OSC_THETA_V21)) {
- editor.putBoolean(IPreferencePropertyAccessor.USE_OSC_THETA_V21, false)
+ editor?.putBoolean(IPreferencePropertyAccessor.USE_OSC_THETA_V21, false)
}
if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_HOST_IP)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.PIXPRO_HOST_IP,
IPreferencePropertyAccessor.PIXPRO_HOST_IP_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT,
IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT,
IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE,
IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.CANON_HOST_IP,
IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE,
IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.CANON_SMALL_PICTURE_TYPE)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.CANON_SMALL_PICTURE_TYPE,
IPreferencePropertyAccessor.CANON_SMALL_PICTURE_TYPE_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_HOST_IP)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.VISIONKIDS_HOST_IP,
IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_FTP_USER)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.VISIONKIDS_FTP_USER,
IPreferencePropertyAccessor.VISIONKIDS_FTP_USER_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_FTP_PASS)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.VISIONKIDS_FTP_PASS,
IPreferencePropertyAccessor.VISIONKIDS_FTP_PASS_DEFAULT_VALUE
)
}
if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT)) {
- editor.putString(
+ editor?.putString(
IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT,
IPreferencePropertyAccessor.VISIONKIDS_LIST_TIMEOUT_DEFAULT_VALUE
)
}
- editor.apply()
+ if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP)) {
+ editor?.putBoolean(IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP, true)
+ }
+ editor?.apply()
}
catch (e: Exception)
{
Log.v(TAG, " $key , $value")
}
- IPreferencePropertyAccessor.USE_OSC_THETA_V21 -> {
- value = preferences?.getBoolean(key, false)?: false
+ IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP -> {
+ value = preferences?.getBoolean(key, true)?: true
Log.v(TAG, " $key , $value")
}
/**
* BooleanPreference の表示データを設定
*
- * @param pref_key Preference(表示)のキー
- * @param key Preference(データ)のキー
- * @param defaultValue Preferenceのデフォルト値
*/
- private fun setBooleanPreference(pref_key: String, key: String, defaultValue: Boolean)
+ private fun setBooleanPreference(prefKey: String, key: String, defaultValue: Boolean)
{
try
{
- val pref = findPreference<CheckBoxPreference>(pref_key)
+ val pref = findPreference<CheckBoxPreference>(prefKey)
if (pref != null)
{
val value = preferences?.getBoolean(key, defaultValue)?: defaultValue
IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA,
defaultValue
)
+ setBooleanPreference(
+ IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP,
+ IPreferencePropertyAccessor.VISIONKIDS_AUTO_SET_HOST_IP,
+ defaultValue
+ )
}
catch (e: Exception)
{
<string name="pref_summary_canon_small_picture_type">スモール画像がうまく取得できない場合、設定を変更してみてください。 (初期値: TYPE0)</string>
<string name="pref_visionkids_host_ip">カメラIP(初期値:192.168.4.100)</string>
- <string name="pref_summary_visionkids_host_ip">VisionKids:192.168.4.100, myFirst:192.168.1.1 </string>
+ <string name="pref_summary_visionkids_host_ip">カメラIPを設定するときのアドレス\nVisionKids:192.168.4.100, myFirst:192.168.1.1 </string>
<string name="pref_visionkids_ftp_user">カメラアクセス用設定(User)</string>
<string name="pref_summary_visionkids_ftp_user">通常、変更は不要です (初期値:ftp)</string>
<string name="pref_visionkids_get_pics_list_timeout">撮影画像一覧取得時のタイムアウト(単位:秒)</string>
<string name="pref_summary_visionkids_get_pics_list_timeout">通常、変更は不要です (初期値:30)</string>
+ <string name="pref_visionkids_auto_detect_ip_host">カメラIPアドレスを自動設定</string>
+ <string name="pref_summary_visionkids_auto_detect_ip_host">通常、ONのままでご使用ください。</string>
+
</resources>
<string name="pref_visionkids_get_pics_list_timeout">Get Pics List Timeout(unit: sec.)</string>
<string name="pref_summary_visionkids_get_pics_list_timeout">If the camera has many number of Pics, increase number.</string>
+ <string name="pref_visionkids_auto_detect_ip_host">Set camera ip automatically.</string>
+ <string name="pref_summary_visionkids_auto_detect_ip_host">Normally to keep ON.</string>
</resources>
<PreferenceCategory
android:title="@string/pref_cat_camera">
+ <CheckBoxPreference
+ android:key="visionkids_auto_detect_ip_host"
+ android:title="@string/pref_visionkids_auto_detect_ip_host"
+ android:summary="@string/pref_summary_visionkids_auto_detect_ip_host" />
+
<EditTextPreference
android:key="visionkids_host_ip"
android:title="@string/pref_visionkids_host_ip"