OSDN Git Service

FUJIFILM用画像詳細画面で、タイミングによってはスモールイメージを使用できるようにした。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / preference / olympus / PreferenceSynchronizer.java
1 package net.osdn.gokigen.gr2control.preference.olympus;
2
3 import android.content.SharedPreferences;
4 import android.util.Log;
5
6 import net.osdn.gokigen.gr2control.camera.olympus.wrapper.property.CameraPropertyUtilities;
7 import net.osdn.gokigen.gr2control.camera.olympus.wrapper.property.IOlyCameraProperty;
8 import net.osdn.gokigen.gr2control.camera.olympus.wrapper.property.IOlyCameraPropertyProvider;
9 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
10
11
12 class PreferenceSynchronizer implements Runnable
13 {
14     private final String TAG = toString();
15     private final IOlyCameraPropertyProvider propertyInterface;
16     private final SharedPreferences preference;
17     private final IPropertySynchronizeCallback callback;
18
19     PreferenceSynchronizer(IOlyCameraPropertyProvider propertyInterface, SharedPreferences preference, IPropertySynchronizeCallback callback)
20     {
21         this.propertyInterface = propertyInterface;
22         this.preference = preference;
23         this.callback = callback;
24     }
25
26     private String getPropertyValue(String key)
27     {
28         String propertyValue;
29         try
30         {
31             String value = propertyInterface.getCameraPropertyValue(key);
32             propertyValue = CameraPropertyUtilities.getPropertyValue(value);
33         }
34         catch (Exception e)
35         {
36             e.printStackTrace();
37             propertyValue = "";
38         }
39         Log.v(TAG, "getPropertyValue(" + key + ") : " + propertyValue);
40         return (propertyValue);
41     }
42
43     @Override
44     public void run()
45     {
46         Log.v(TAG, "run()");
47         SharedPreferences.Editor editor = preference.edit();
48         editor.putString(IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL, getPropertyValue(IOlyCameraProperty.SOUND_VOLUME_LEVEL));
49         boolean value = getPropertyValue(IOlyCameraProperty.RAW).equals("ON");
50         editor.putBoolean(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 }