1 package net.osdn.gokigen.gr2control.preference.fuji_x;
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;
10 import net.osdn.gokigen.gr2control.R;
11 import net.osdn.gokigen.gr2control.camera.fuji_x.operation.FujiXCameraPowerOff;
12 import net.osdn.gokigen.gr2control.logcat.LogCatViewer;
13 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
14 import net.osdn.gokigen.gr2control.scene.IChangeScene;
18 import androidx.annotation.NonNull;
19 import androidx.appcompat.app.AppCompatActivity;
20 import androidx.fragment.app.FragmentActivity;
21 import androidx.preference.CheckBoxPreference;
22 import androidx.preference.ListPreference;
23 import androidx.preference.Preference;
24 import androidx.preference.PreferenceFragmentCompat;
25 import androidx.preference.PreferenceManager;
27 public class FujiXPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener, Preference.OnPreferenceClickListener
29 private final String TAG = toString();
30 private AppCompatActivity context = null;
31 private SharedPreferences preferences = null;
32 private FujiXCameraPowerOff powerOffController = null;
33 private LogCatViewer logCatViewer = null;
39 public static FujiXPreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
41 FujiXPreferenceFragment instance = new FujiXPreferenceFragment();
42 instance.prepare(context, changeScene);
44 // パラメータはBundleにまとめておく
45 Bundle arguments = new Bundle();
46 //arguments.putString("title", title);
47 //arguments.putString("message", message);
48 instance.setArguments(arguments);
57 private void prepare(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
61 powerOffController = new FujiXCameraPowerOff(context, changeScene);
62 powerOffController.prepare();
64 logCatViewer = new LogCatViewer(changeScene);
65 logCatViewer.prepare();
67 this.context = context;
80 public void onAttach(@NonNull Context activity)
82 super.onAttach(activity);
83 Log.v(TAG, "onAttach()");
87 preferences = PreferenceManager.getDefaultSharedPreferences(activity);
90 initializePreferences();
92 preferences.registerOnSharedPreferenceChangeListener(this);
104 private void initializePreferences()
108 Map<String, ?> items = preferences.getAll();
109 SharedPreferences.Editor editor = preferences.edit();
110 if (!items.containsKey(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT))
112 editor.putString(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE);
114 if (!items.containsKey(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY))
116 editor.putString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE);
118 if (!items.containsKey(IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL))
120 editor.putString(IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL, IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL_DEFAULT_VALUE);
122 if (!items.containsKey(IPreferencePropertyAccessor.RAW))
124 editor.putBoolean(IPreferencePropertyAccessor.RAW, true);
126 if (!items.containsKey(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA))
128 editor.putBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
130 if (!items.containsKey(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW))
132 editor.putBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
134 if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD))
136 editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
138 if (!items.containsKey(IPreferencePropertyAccessor.SHARE_AFTER_SAVE)) {
139 editor.putBoolean(IPreferencePropertyAccessor.SHARE_AFTER_SAVE, false);
141 if (!items.containsKey(IPreferencePropertyAccessor.USE_PLAYBACK_MENU)) {
142 editor.putBoolean(IPreferencePropertyAccessor.USE_PLAYBACK_MENU, true);
144 if (!items.containsKey(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW)) {
145 editor.putBoolean(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, true);
147 if (!items.containsKey(IPreferencePropertyAccessor.GR2_LCD_SLEEP)) {
148 editor.putBoolean(IPreferencePropertyAccessor.GR2_LCD_SLEEP, false);
150 if (!items.containsKey(IPreferencePropertyAccessor.USE_GR2_SPECIAL_COMMAND)) {
151 editor.putBoolean(IPreferencePropertyAccessor.USE_GR2_SPECIAL_COMMAND, true);
153 if (!items.containsKey(IPreferencePropertyAccessor.PENTAX_CAPTURE_AFTER_AF)) {
154 editor.putBoolean(IPreferencePropertyAccessor.PENTAX_CAPTURE_AFTER_AF, false);
156 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW)) {
157 editor.putBoolean(IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW, false);
159 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_FOCUS_XY)) {
160 editor.putString(IPreferencePropertyAccessor.FUJI_X_FOCUS_XY, IPreferencePropertyAccessor.FUJI_X_FOCUS_XY_DEFAULT_VALUE);
162 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_LIVEVIEW_WAIT)) {
163 editor.putString(IPreferencePropertyAccessor.FUJI_X_LIVEVIEW_WAIT, IPreferencePropertyAccessor.FUJI_X_LIVEVIEW_WAIT_DEFAULT_VALUE);
165 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_COMMAND_POLLING_WAIT)) {
166 editor.putString(IPreferencePropertyAccessor.FUJI_X_COMMAND_POLLING_WAIT, IPreferencePropertyAccessor.FUJI_X_COMMAND_POLLING_WAIT_DEFAULT_VALUE);
181 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
183 Log.v(TAG, "onSharedPreferenceChanged() : " + key);
189 case IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA:
190 value = preferences.getBoolean(key, true);
191 Log.v(TAG, " " + key + " , " + value);
194 case IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW:
195 value = preferences.getBoolean(key, true);
196 Log.v(TAG, " CAPTURE BOTH CAMERA AND LIVE VIEW : " + key + " , " + value);
199 case IPreferencePropertyAccessor.USE_PLAYBACK_MENU:
200 value = preferences.getBoolean(key, false);
201 Log.v(TAG, " " + key + " , " + value);
204 case IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW:
205 value = preferences.getBoolean(key, false);
206 Log.v(TAG, " DISPLAY CAMERA VIEW : " + key + " , " + value);
209 case IPreferencePropertyAccessor.SHARE_AFTER_SAVE:
210 value = preferences.getBoolean(key, false);
211 Log.v(TAG, " SHARE AFTER SAVE : " + key + " , " + value);
215 String strValue = preferences.getString(key, "");
216 setListPreference(key, key, strValue);
227 public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
229 Log.v(TAG, "onCreatePreferences()");
232 //super.onCreate(savedInstanceState);
233 addPreferencesFromResource(R.xml.preferences_fuji_x);
235 ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
236 if (connectionMethod != null)
238 connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
240 public boolean onPreferenceChange(Preference preference, Object newValue) {
241 preference.setSummary(newValue + " ");
245 connectionMethod.setSummary(connectionMethod.getValue() + " ");
247 Preference exitPreference = findPreference("exit_application");
248 if (exitPreference != null)
250 exitPreference.setOnPreferenceClickListener(powerOffController);
252 Preference debugPreference = findPreference("debug_info");
253 if (debugPreference != null)
255 debugPreference.setOnPreferenceClickListener(logCatViewer);
257 Preference wifiPreference = findPreference("wifi_settings");
258 if (wifiPreference != null)
260 wifiPreference.setOnPreferenceClickListener(this);
274 public void onResume()
277 Log.v(TAG, "onResume() Start");
280 synchronizedProperty();
287 Log.v(TAG, "onResume() End");
295 public void onPause()
298 Log.v(TAG, "onPause() Start");
301 // Preference変更のリスナを解除
302 preferences.unregisterOnSharedPreferenceChangeListener(this);
309 Log.v(TAG, "onPause() End");
313 * ListPreference の表示データを設定
315 * @param pref_key Preference(表示)のキー
316 * @param key Preference(データ)のキー
317 * @param defaultValue Preferenceのデフォルト値
319 private void setListPreference(String pref_key, String key, String defaultValue)
324 pref = findPreference(pref_key);
325 String value = preferences.getString(key, defaultValue);
328 pref.setValue(value);
329 pref.setSummary(value);
339 * BooleanPreference の表示データを設定
341 * @param pref_key Preference(表示)のキー
342 * @param key Preference(データ)のキー
343 * @param defaultValue Preferenceのデフォルト値
345 private void setBooleanPreference(String pref_key, String key, boolean defaultValue)
349 CheckBoxPreference pref = findPreference(pref_key);
351 boolean value = preferences.getBoolean(key, defaultValue);
352 pref.setChecked(value);
365 private void synchronizedProperty()
367 final FragmentActivity activity = getActivity();
368 final boolean defaultValue = true;
369 if (activity != null)
371 activity.runOnUiThread(new Runnable() {
376 // Preferenceの画面に反映させる
377 setBooleanPreference(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, defaultValue);
378 setBooleanPreference(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, defaultValue);
379 setBooleanPreference(IPreferencePropertyAccessor.USE_PLAYBACK_MENU, IPreferencePropertyAccessor.USE_PLAYBACK_MENU, defaultValue);
380 setBooleanPreference(IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW, IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW, false);
381 setBooleanPreference(IPreferencePropertyAccessor.SHARE_AFTER_SAVE, IPreferencePropertyAccessor.SHARE_AFTER_SAVE, defaultValue);
393 public boolean onPreferenceClick(Preference preference)
397 String preferenceKey = preference.getKey();
398 if (preferenceKey.contains("wifi_settings"))
401 Log.v(TAG, " onPreferenceClick : " + preferenceKey);
404 context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));