OSDN Git Service

initial
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / camera / olympus / cameraproperty / CameraPropertyLoader.java
1 package net.osdn.gokigen.a01d.camera.olympus.cameraproperty;
2
3
4 import android.util.Log;
5
6 import net.osdn.gokigen.a01d.R;
7 import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlyCameraPropertyProvider;
8
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.Comparator;
12 import java.util.Set;
13
14 public class CameraPropertyLoader implements Runnable
15 {
16     private final String TAG = toString();
17     private final IOlyCameraPropertyProvider propertyInterface;
18     private final IPropertyLoaderCallback callback;
19     private ArrayList<CameraPropertyArrayItem> propertyItems = null;
20
21     public CameraPropertyLoader(IOlyCameraPropertyProvider propertyInterface, IPropertyLoaderCallback callback)
22     {
23         this.propertyInterface = propertyInterface;
24         this.callback = callback;
25     }
26
27     @Override
28     public void run()
29     {
30         Log.v(TAG, "CameraPropertyLoader::run() START");
31
32         propertyItems = new ArrayList<>();
33
34         // カメラプロパティを設定する
35         Set<String> names = propertyInterface.getCameraPropertyNames();
36         for (String name : names)
37         {
38             String title = propertyInterface.getCameraPropertyTitle(name);
39             String value = propertyInterface.getCameraPropertyValue(name);
40             String rawValue = propertyInterface.getCameraPropertyValueTitle(value);
41             int iconId = (propertyInterface.canSetCameraProperty(name)) ? R.drawable.ic_web_asset_black_24dp : R.drawable.ic_block_black_24dp;
42
43             propertyItems.add(new CameraPropertyArrayItem(name, title, rawValue, value, iconId));
44         }
45
46         // プロパティ名でソートしてしまおう。。。
47         Collections.sort(propertyItems, new Comparator<CameraPropertyArrayItem>() {
48             public int compare(CameraPropertyArrayItem o1, CameraPropertyArrayItem o2) {
49                 return o1.getPropertyName().compareTo(o2.getPropertyName());
50             }
51         });
52
53
54
55         // 終了通知
56         callback.finished();
57
58         Log.v(TAG, "CameraPropertyLoader::run() END");
59     }
60
61     public void resetProperty()
62     {
63         Log.v(TAG, "CameraPropertyLoader::resetProperty() START");
64
65         for (CameraPropertyArrayItem item : propertyItems)
66         {
67             item.resetValue();
68         }
69         callback.resetProperty();
70         Log.v(TAG, "CameraPropertyLoader::resetProperty() END");
71
72     }
73
74     /**
75      *   プロパティ一覧を応答
76      *
77      */
78     public ArrayList<CameraPropertyArrayItem> getItemList()
79     {
80         return (propertyItems);
81     }
82
83     public interface IPropertyLoaderCallback
84     {
85         void finished();
86         void resetProperty();
87     }
88 }