OSDN Git Service

Preferenceの初期化部分を統合した。
[gokigen/PKRemote.git] / app / src / main / java / net / osdn / gokigen / pkremote / preference / canon / CanonPreferenceFragment.java
index a82a1f8..f07d7e3 100644 (file)
@@ -22,6 +22,7 @@ import net.osdn.gokigen.pkremote.R;
 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.operation.PtpIpCameraPowerOff;
 import net.osdn.gokigen.pkremote.logcat.LogCatViewer;
 import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
+import net.osdn.gokigen.pkremote.preference.PreferencePropertyInitializer;
 import net.osdn.gokigen.pkremote.scene.IChangeScene;
 
 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.DEBUG_INFO;
@@ -96,7 +97,8 @@ public class CanonPreferenceFragment  extends PreferenceFragmentCompat implement
             preferences = PreferenceManager.getDefaultSharedPreferences(activity);
 
             // Preference を初期設定する
-            initializePreferences();
+            PreferencePropertyInitializer initializer = new PreferencePropertyInitializer(activity);
+            initializer.initializePreferences();
 
             preferences.registerOnSharedPreferenceChangeListener(this);
         }
@@ -107,109 +109,6 @@ public class CanonPreferenceFragment  extends PreferenceFragmentCompat implement
     }
 
     /**
-     * Preferenceの初期化...
-     *
-     */
-    private void initializePreferences()
-    {
-        try
-        {
-            Map<String, ?> items = preferences.getAll();
-            SharedPreferences.Editor editor = preferences.edit();
-
-            if (!items.containsKey(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA))
-            {
-                editor.putBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW))
-            {
-                editor.putBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD))
-            {
-                editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.CANON_RAW_SUFFIX))
-            {
-                editor.putString(IPreferencePropertyAccessor.CANON_RAW_SUFFIX, IPreferencePropertyAccessor.CANON_RAW_SUFFIX_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.CANON_RECEIVE_WAIT))
-            {
-                editor.putString(IPreferencePropertyAccessor.CANON_RECEIVE_WAIT, IPreferencePropertyAccessor.CANON_RECEIVE_WAIT_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.CANON_USE_SCREENNAIL_AS_SMALL))
-            {
-                editor.putBoolean(IPreferencePropertyAccessor.CANON_USE_SCREENNAIL_AS_SMALL, false);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.GET_SMALL_PICTURE_AS_VGA))
-            {
-                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);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT))
-            {
-                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);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_HOST_IP))
-            {
-                editor.putString(IPreferencePropertyAccessor.PIXPRO_HOST_IP, IPreferencePropertyAccessor.PIXPRO_HOST_IP_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT))
-            {
-                editor.putString(IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT, IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT))
-            {
-                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(IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE, IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE_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_SMALL_PICTURE_TYPE)) {
-                editor.putString(IPreferencePropertyAccessor.CANON_SMALL_PICTURE_TYPE, IPreferencePropertyAccessor.CANON_SMALL_PICTURE_TYPE_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_HOST_IP)) {
-                editor.putString(IPreferencePropertyAccessor.VISIONKIDS_HOST_IP, IPreferencePropertyAccessor.VISIONKIDS_HOST_IP_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_FTP_USER)) {
-                editor.putString(IPreferencePropertyAccessor.VISIONKIDS_FTP_USER, IPreferencePropertyAccessor.VISIONKIDS_FTP_USER_DEFAULT_VALUE);
-            }
-            if (!items.containsKey(IPreferencePropertyAccessor.VISIONKIDS_FTP_PASS)) {
-                editor.putString(IPreferencePropertyAccessor.VISIONKIDS_FTP_PASS, IPreferencePropertyAccessor.VISIONKIDS_FTP_PASS_DEFAULT_VALUE);
-            }
-            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)
-        {
-            e.printStackTrace();
-        }
-    }
-
-    /**
      *
      *
      */
@@ -220,23 +119,19 @@ public class CanonPreferenceFragment  extends PreferenceFragmentCompat implement
         boolean value;
         if (key != null)
         {
-            switch (key)
-            {
-                case IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA:
-                case IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW:
+            switch (key) {
+                case IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW -> {
                     value = preferences.getBoolean(key, true);
                     Log.v(TAG, " " + key + " , " + value);
-                    break;
-
-                case IPreferencePropertyAccessor.CANON_USE_SCREENNAIL_AS_SMALL:
+                }
+                case IPreferencePropertyAccessor.CANON_USE_SCREENNAIL_AS_SMALL -> {
                     value = preferences.getBoolean(key, false);
                     Log.v(TAG, " " + key + " , " + value);
-                    break;
-
-                default:
+                }
+                default -> {
                     String strValue = preferences.getString(key, "");
                     setListPreference(key, key, strValue);
-                    break;
+                }
             }
         }
     }