1 package net.osdn.gokigen.pkremote.preference.fujix;
3 import android.content.Context;
4 import android.content.Intent;
5 import android.content.SharedPreferences;
6 import android.os.Bundle;
7 import android.provider.Settings;
8 import android.util.Log;
12 import androidx.annotation.NonNull;
13 import androidx.appcompat.app.AppCompatActivity;
14 import androidx.fragment.app.FragmentActivity;
15 import androidx.preference.CheckBoxPreference;
16 import androidx.preference.ListPreference;
17 import androidx.preference.Preference;
18 import androidx.preference.PreferenceFragmentCompat;
19 import androidx.preference.PreferenceManager;
21 import net.osdn.gokigen.pkremote.R;
22 import net.osdn.gokigen.pkremote.camera.vendor.fujix.operation.CameraPowerOffFujiX;
23 import net.osdn.gokigen.pkremote.logcat.LogCatViewer;
24 import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
25 import net.osdn.gokigen.pkremote.scene.IChangeScene;
27 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.DEBUG_INFO;
28 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.EXIT_APPLICATION;
29 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.WIFI_SETTINGS;
35 public class FujiXPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceClickListener
37 private final String TAG = toString();
38 private AppCompatActivity context = null;
39 private SharedPreferences preferences = null;
40 private CameraPowerOffFujiX powerOffController = null;
41 private LogCatViewer logCatViewer = null;
47 public static FujiXPreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
49 FujiXPreferenceFragment instance = new FujiXPreferenceFragment();
50 instance.prepare(context, changeScene);
52 // パラメータはBundleにまとめておく
53 Bundle arguments = new Bundle();
54 //arguments.putString("title", title);
55 //arguments.putString("message", message);
56 instance.setArguments(arguments);
65 private void prepare(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
69 powerOffController = new CameraPowerOffFujiX(context, changeScene);
70 powerOffController.prepare();
72 logCatViewer = new LogCatViewer(changeScene);
73 logCatViewer.prepare();
75 this.context = context;
88 public void onAttach(Context activity)
90 super.onAttach(activity);
91 Log.v(TAG, "onAttach()");
96 preferences = PreferenceManager.getDefaultSharedPreferences(activity);
99 initializePreferences();
101 preferences.registerOnSharedPreferenceChangeListener(this);
113 private void initializePreferences()
117 Map<String, ?> items = preferences.getAll();
118 SharedPreferences.Editor editor = preferences.edit();
120 if (!items.containsKey(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA)) {
121 editor.putBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
123 if (!items.containsKey(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW)) {
124 editor.putBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
126 if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW)) {
127 editor.putBoolean(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, false);
129 if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_FOCUS_XY)) {
130 editor.putString(IPreferencePropertyAccessor.FUJIX_FOCUS_XY, IPreferencePropertyAccessor.FUJIX_FOCUS_XY_DEFAULT_VALUE);
132 if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT)) {
133 editor.putString(IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT, IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT_DEFAULT_VALUE);
135 if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_COMMAND_POLLING_WAIT)) {
136 editor.putString(IPreferencePropertyAccessor.FUJIX_COMMAND_POLLING_WAIT, IPreferencePropertyAccessor.FUJIX_COMMAND_POLLING_WAIT_DEFAULT_VALUE);
138 if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD)) {
139 editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
141 if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_CONNECTION_FOR_READ)) {
142 editor.putBoolean(IPreferencePropertyAccessor.FUJIX_CONNECTION_FOR_READ, false);
144 if (!items.containsKey(IPreferencePropertyAccessor.GET_SMALL_PICTURE_AS_VGA))
146 editor.putBoolean(IPreferencePropertyAccessor.GET_SMALL_PICTURE_AS_VGA, false);
148 if (!items.containsKey(IPreferencePropertyAccessor.USE_SMARTPHONE_TRANSFER_MODE))
150 editor.putBoolean(IPreferencePropertyAccessor.USE_SMARTPHONE_TRANSFER_MODE, false);
152 if (!items.containsKey(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT))
154 editor.putString(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE);
156 if (!items.containsKey(IPreferencePropertyAccessor.USE_OSC_THETA_V21))
158 editor.putBoolean(IPreferencePropertyAccessor.USE_OSC_THETA_V21, false);
160 if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_HOST_IP))
162 editor.putString(IPreferencePropertyAccessor.PIXPRO_HOST_IP, IPreferencePropertyAccessor.PIXPRO_HOST_IP_DEFAULT_VALUE);
164 if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT))
166 editor.putString(IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT, IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT_DEFAULT_VALUE);
168 if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT))
170 editor.putString(IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE);
172 if (!items.containsKey(IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE))
174 editor.putString(IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE, IPreferencePropertyAccessor.THUMBNAIL_IMAGE_CACHE_SIZE_DEFAULT_VALUE);
176 if (!items.containsKey(IPreferencePropertyAccessor.CANON_HOST_IP)) {
177 editor.putString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
179 if (!items.containsKey(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE)) {
180 editor.putString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
195 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
197 Log.v(TAG, "onSharedPreferenceChanged() : " + key);
203 case IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA:
204 value = preferences.getBoolean(key, true);
205 Log.v(TAG, " " + key + " , " + value);
208 case IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW:
209 value = preferences.getBoolean(key, true);
210 Log.v(TAG, " " + key + " , " + value);
213 case IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW:
214 value = preferences.getBoolean(key, false);
215 Log.v(TAG, " " + key + " , " + value);
218 case IPreferencePropertyAccessor.FUJIX_CONNECTION_FOR_READ:
219 value = preferences.getBoolean(key, false);
220 Log.v(TAG, " " + key + " , " + value);
224 String strValue = preferences.getString(key, "");
225 setListPreference(key, key, strValue);
236 public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
238 Log.v(TAG, "onCreatePreferences()");
241 //super.onCreate(savedInstanceState);
242 addPreferencesFromResource(R.xml.preferences_fuji_x);
244 ListPreference connectionMethod = (ListPreference) findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
245 connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
247 public boolean onPreferenceChange(Preference preference, Object newValue) {
248 preference.setSummary(newValue + " ");
252 connectionMethod.setSummary(connectionMethod.getValue() + " ");
254 findPreference(EXIT_APPLICATION).setOnPreferenceClickListener(powerOffController);
255 findPreference(DEBUG_INFO).setOnPreferenceClickListener(logCatViewer);
256 findPreference(WIFI_SETTINGS).setOnPreferenceClickListener(this);
269 public void onResume()
272 Log.v(TAG, "onResume() Start");
276 synchronizedProperty();
283 Log.v(TAG, "onResume() End");
292 public void onPause()
295 Log.v(TAG, "onPause() Start");
299 // Preference変更のリスナを解除
300 preferences.unregisterOnSharedPreferenceChangeListener(this);
307 Log.v(TAG, "onPause() End");
311 * ListPreference の表示データを設定
313 * @param pref_key Preference(表示)のキー
314 * @param key Preference(データ)のキー
315 * @param defaultValue Preferenceのデフォルト値
317 private void setListPreference(String pref_key, String key, String defaultValue)
322 pref = (ListPreference) findPreference(pref_key);
323 String value = preferences.getString(key, defaultValue);
326 pref.setValue(value);
327 pref.setSummary(value);
337 * BooleanPreference の表示データを設定
339 * @param pref_key Preference(表示)のキー
340 * @param key Preference(データ)のキー
341 * @param defaultValue Preferenceのデフォルト値
343 private void setBooleanPreference(String pref_key, String key, boolean defaultValue)
347 CheckBoxPreference pref = (CheckBoxPreference) findPreference(pref_key);
349 boolean value = preferences.getBoolean(key, defaultValue);
350 pref.setChecked(value);
363 private void synchronizedProperty()
365 final FragmentActivity activity = getActivity();
366 if (activity != null)
368 activity.runOnUiThread(new Runnable() {
373 // Preferenceの画面に反映させる
374 setBooleanPreference(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
375 setBooleanPreference(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
376 setBooleanPreference(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, false);
377 setBooleanPreference(IPreferencePropertyAccessor.FUJIX_CONNECTION_FOR_READ, IPreferencePropertyAccessor.FUJIX_CONNECTION_FOR_READ, false);
389 public boolean onPreferenceClick(Preference preference)
393 String preferenceKey = preference.getKey();
394 if (preferenceKey.contains(WIFI_SETTINGS))
397 Log.v(TAG, " onPreferenceClick : " + preferenceKey);
400 context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));