OSDN Git Service

initial
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / preference / PreferenceSynchronizer.java
1 package net.osdn.gokigen.a01d.preference;
2
3 import android.content.SharedPreferences;
4 import android.util.Log;
5
6 import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlyCameraProperty;
7 import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlyCameraPropertyProvider;
8 import net.osdn.gokigen.a01d.camera.olympus.wrapper.CameraPropertyUtilities;
9
10 class PreferenceSynchronizer implements Runnable
11 {
12     private final String TAG = toString();
13     private final IOlyCameraPropertyProvider propertyInterface;
14     private final SharedPreferences preference;
15     private final IPropertySynchronizeCallback callback;
16
17     PreferenceSynchronizer(IOlyCameraPropertyProvider propertyInterface, SharedPreferences preference, IPropertySynchronizeCallback callback)
18     {
19         this.propertyInterface = propertyInterface;
20         this.preference = preference;
21         this.callback = callback;
22     }
23
24     private String getPropertyValue(String key)
25     {
26         String propertyValue;
27         try
28         {
29             String value = propertyInterface.getCameraPropertyValue(key);
30             propertyValue = CameraPropertyUtilities.getPropertyValue(value);
31         }
32         catch (Exception e)
33         {
34             e.printStackTrace();
35             propertyValue = "";
36         }
37         Log.v(TAG, "getPropertyValue(" + key + ") : " + propertyValue);
38         return (propertyValue);
39     }
40
41     @Override
42     public void run()
43     {
44         Log.v(TAG, "run()");
45         SharedPreferences.Editor editor = preference.edit();
46         editor.putString(net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor.TAKE_MODE, getPropertyValue(IOlyCameraProperty.TAKE_MODE));
47         editor.putString(net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL, getPropertyValue(IOlyCameraProperty.SOUND_VOLUME_LEVEL));
48
49         boolean value = getPropertyValue(IOlyCameraProperty.RAW).equals("ON");
50         editor.putBoolean(net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor.RAW, value);
51         editor.apply();
52         if (callback != null)
53         {
54             callback.synchronizedProperty();
55         }
56     }
57
58     interface IPropertySynchronizeCallback
59     {
60         void synchronizedProperty();
61     }
62 }