OSDN Git Service

簡単な画面表示のロジックまで作りこんだ。
[gokigen/A01c.git] / app / src / main / java / jp / sfjp / gokigen / a01c / preference / CameraPropertyLoadSaveOperations.java
1 package jp.sfjp.gokigen.a01c.preference;
2
3 import android.app.Activity;
4 import android.app.ProgressDialog;
5 import android.util.Log;
6 import android.widget.Toast;
7
8 import jp.sfjp.gokigen.a01c.R;
9 import jp.sfjp.gokigen.a01c.olycamerawrapper.ICameraStatusDisplay;
10 import jp.sfjp.gokigen.a01c.olycamerawrapper.ILoadSaveCameraProperties;
11
12 /**
13  *   カメラプロパティの保存、展開を実行する
14  *
15  *
16  */
17 public class CameraPropertyLoadSaveOperations implements ICameraPropertyLoadSaveOperations
18 {
19     private final String TAG = toString();
20     private final ILoadSaveCameraProperties loadSaveProperties;
21     private final ICameraStatusDisplay cameraStatusDisplay;
22     private final Activity activity;
23
24     public CameraPropertyLoadSaveOperations(final Activity activity, ILoadSaveCameraProperties loadSaveProperties, ICameraStatusDisplay cameraStatusDisplay)
25     {
26         this.loadSaveProperties = loadSaveProperties;
27         this.cameraStatusDisplay = cameraStatusDisplay;
28         this.activity = activity;
29     }
30
31     @Override
32     public void loadProperties(final String id, final String name)
33     {
34         //Log.v(TAG, "PROPERTY RESTORE ENTER : (" + id + ") " + name);
35
36         //
37         // BUSYダイアログを表示する
38         //
39         final ProgressDialog busyDialog = new ProgressDialog(activity);
40         busyDialog.setMessage(activity.getString(R.string.dialog_start_load_property_message));
41         busyDialog.setTitle(activity.getString(R.string.dialog_start_load_property_title));
42         busyDialog.setIndeterminate(false);
43         busyDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
44         busyDialog.show();
45
46         try
47         {
48             Thread thread = new Thread(new Runnable()
49             {
50                 @Override
51                 public void run()
52                 {
53                     final boolean toast = restoreCameraSettings(id, name);
54                     busyDialog.dismiss();
55
56                     activity.runOnUiThread(new Runnable()
57                     {
58                         @Override
59                         public void run()
60                         {
61                             cameraStatusDisplay.updateCameraStatus();
62
63                             // Toast で展開したよのメッセージを表示
64                             if (toast)
65                             {
66                                 String restoredMessage = activity.getString(R.string.restored_my_props) + name;
67                                 Toast.makeText(activity, restoredMessage, Toast.LENGTH_SHORT).show();
68                             }
69
70                         }
71                     });
72
73                 }
74             });
75             thread.start();
76         }
77         catch (Exception e)
78         {
79             e.printStackTrace();
80         }
81         //Log.v(TAG, "PROPERTY RESTORE EXIT : (" + id + ") " + name);
82     }
83
84     @Override
85     public void saveProperties(final String id, final String name)
86     {
87         //
88         // BUSYダイアログを表示する
89         //
90         final ProgressDialog busyDialog = new ProgressDialog(activity);
91         busyDialog.setMessage(activity.getString(R.string.dialog_start_save_property_message));
92         busyDialog.setTitle(activity.getString(R.string.dialog_start_save_property_title));
93         busyDialog.setIndeterminate(false);
94         busyDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
95         busyDialog.show();
96
97         try
98         {
99             Thread thread = new Thread(new Runnable()
100             {
101                 @Override
102                 public void run()
103                 {
104                     final boolean toast = storeCameraSettings(id, name);
105                     busyDialog.dismiss();
106
107                     activity.runOnUiThread(new Runnable()
108                     {
109                         @Override
110                         public void run()
111                         {
112                             cameraStatusDisplay.updateCameraStatus();
113
114                             // Toast で保存したよのメッセージを表示
115                             if (toast)
116                             {
117                                 String storedMessage = activity.getString(R.string.saved_my_props) + name;
118                                 Toast.makeText(activity, storedMessage, Toast.LENGTH_SHORT).show();
119                             }
120                         }
121                     });
122
123                 }
124             });
125             thread.start();
126         }
127         catch (Exception e)
128         {
129             e.printStackTrace();
130         }
131         Log.v(TAG, "PROPERTY STORED : " + id + " " + name);
132     }
133
134     private boolean storeCameraSettings(String itemId, String restoredDataName)
135     {
136         boolean toast = false;
137         //Log.v(TAG, "storeCameraSettings() : START");
138         try
139         {
140             if (loadSaveProperties != null)
141             {
142                 if (itemId.contentEquals("000"))
143                 {
144                     Log.v(TAG, "AUTO SAVE DATA AREA...(NOT STORE PROPERTIES)");
145                 }
146                 else
147                 {
148                     // データを保管する
149                     loadSaveProperties.saveCameraSettings(itemId, restoredDataName);
150                     Log.v(TAG, "STORED : (" + itemId + ") " + restoredDataName);
151                     toast = true;
152                 }
153             }
154             else
155             {
156                 Log.v(TAG, "STORE INTERFACE IS NULL...");
157             }
158         }
159         catch (Exception e)
160         {
161             e.printStackTrace();
162             Log.v(TAG, "STORE FAILED...");
163         }
164         //Log.v(TAG, "storeCameraSettings() : END");
165         return (toast);
166     }
167
168     private boolean restoreCameraSettings(String itemId, String restoredDataName)
169     {
170         boolean toast = false;
171         //Log.v(TAG, "restoreCameraSettings() : START");
172         try
173         {
174             if (loadSaveProperties != null)
175             {
176                 if (itemId.contentEquals("000"))
177                 {
178                     loadSaveProperties.loadCameraSettings("");
179                     Log.v(TAG, "RESTORED AUTO SAVE DATA...");
180                 }
181                 else
182                 {
183                     loadSaveProperties.loadCameraSettings(itemId);
184                     Log.v(TAG, "RESTORED : (" + itemId + ") " + restoredDataName);
185                 }
186                 toast = true;
187             }
188             else
189             {
190                 Log.v(TAG, "RESTORE INTERFACE IS NULL...");
191             }
192         }
193         catch (Exception e)
194         {
195             e.printStackTrace();
196             Log.v(TAG, "RESTORE FAILED...");
197         }
198         //Log.v(TAG, "restoreCameraSettings() : END");
199         return (toast);
200     }
201 }