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);
168 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_GET_SCREENNAIL_AS_SMALL_PICTURE)) {
169 editor.putBoolean(IPreferencePropertyAccessor.FUJI_X_GET_SCREENNAIL_AS_SMALL_PICTURE, false);
184 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
186 Log.v(TAG, "onSharedPreferenceChanged() : " + key);
192 case IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA:
193 value = preferences.getBoolean(key, true);
194 Log.v(TAG, " " + key + " , " + value);
197 case IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW:
198 value = preferences.getBoolean(key, true);
199 Log.v(TAG, " CAPTURE BOTH CAMERA AND LIVE VIEW : " + key + " , " + value);
202 case IPreferencePropertyAccessor.USE_PLAYBACK_MENU:
203 value = preferences.getBoolean(key, false);
204 Log.v(TAG, " " + key + " , " + value);
207 case IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW:
208 value = preferences.getBoolean(key, false);
209 Log.v(TAG, " DISPLAY CAMERA VIEW : " + key + " , " + value);
212 case IPreferencePropertyAccessor.FUJI_X_GET_SCREENNAIL_AS_SMALL_PICTURE:
213 value = preferences.getBoolean(key, false);
214 Log.v(TAG, " SMALL IMAGE AS SCREENNAIL : " + key + " , " + value);
217 case IPreferencePropertyAccessor.SHARE_AFTER_SAVE:
218 value = preferences.getBoolean(key, false);
219 Log.v(TAG, " SHARE AFTER SAVE : " + key + " , " + value);
223 String strValue = preferences.getString(key, "");
224 setListPreference(key, key, strValue);
235 public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
237 Log.v(TAG, "onCreatePreferences()");
240 //super.onCreate(savedInstanceState);
241 addPreferencesFromResource(R.xml.preferences_fuji_x);
243 ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
244 if (connectionMethod != null)
246 connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
248 public boolean onPreferenceChange(Preference preference, Object newValue) {
249 preference.setSummary(newValue + " ");
253 connectionMethod.setSummary(connectionMethod.getValue() + " ");
255 Preference exitPreference = findPreference("exit_application");
256 if (exitPreference != null)
258 exitPreference.setOnPreferenceClickListener(powerOffController);
260 Preference debugPreference = findPreference("debug_info");
261 if (debugPreference != null)
263 debugPreference.setOnPreferenceClickListener(logCatViewer);
265 Preference wifiPreference = findPreference("wifi_settings");
266 if (wifiPreference != null)
268 wifiPreference.setOnPreferenceClickListener(this);
282 public void onResume()
285 Log.v(TAG, "onResume() Start");
288 synchronizedProperty();
295 Log.v(TAG, "onResume() End");
303 public void onPause()
306 Log.v(TAG, "onPause() Start");
309 // Preference変更のリスナを解除
310 preferences.unregisterOnSharedPreferenceChangeListener(this);
317 Log.v(TAG, "onPause() End");
321 * ListPreference の表示データを設定
323 * @param pref_key Preference(表示)のキー
324 * @param key Preference(データ)のキー
325 * @param defaultValue Preferenceのデフォルト値
327 private void setListPreference(String pref_key, String key, String defaultValue)
332 pref = findPreference(pref_key);
333 String value = preferences.getString(key, defaultValue);
336 pref.setValue(value);
337 pref.setSummary(value);
347 * BooleanPreference の表示データを設定
349 * @param pref_key Preference(表示)のキー
350 * @param key Preference(データ)のキー
351 * @param defaultValue Preferenceのデフォルト値
353 private void setBooleanPreference(String pref_key, String key, boolean defaultValue)
357 CheckBoxPreference pref = findPreference(pref_key);
359 boolean value = preferences.getBoolean(key, defaultValue);
360 pref.setChecked(value);
373 private void synchronizedProperty()
375 final FragmentActivity activity = getActivity();
376 final boolean defaultValue = true;
377 if (activity != null)
379 activity.runOnUiThread(new Runnable() {
384 // Preferenceの画面に反映させる
385 setBooleanPreference(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, defaultValue);
386 setBooleanPreference(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, defaultValue);
387 setBooleanPreference(IPreferencePropertyAccessor.USE_PLAYBACK_MENU, IPreferencePropertyAccessor.USE_PLAYBACK_MENU, defaultValue);
388 setBooleanPreference(IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW, IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW, false);
389 setBooleanPreference(IPreferencePropertyAccessor.FUJI_X_GET_SCREENNAIL_AS_SMALL_PICTURE, IPreferencePropertyAccessor.FUJI_X_GET_SCREENNAIL_AS_SMALL_PICTURE, false);
390 setBooleanPreference(IPreferencePropertyAccessor.SHARE_AFTER_SAVE, IPreferencePropertyAccessor.SHARE_AFTER_SAVE, defaultValue);
402 public boolean onPreferenceClick(Preference preference)
406 String preferenceKey = preference.getKey();
407 if (preferenceKey.contains("wifi_settings"))
410 Log.v(TAG, " onPreferenceClick : " + preferenceKey);
413 context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));