1 package net.osdn.gokigen.gr2control.preference.ricohgr2;
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.ricohgr2.operation.CameraPowerOffRicohGr2;
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 RicohGr2PreferenceFragment 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 CameraPowerOffRicohGr2 powerOffController = null;
33 private LogCatViewer logCatViewer = null;
39 public static RicohGr2PreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
41 RicohGr2PreferenceFragment instance = new RicohGr2PreferenceFragment();
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 CameraPowerOffRicohGr2(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();
111 if (!items.containsKey(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT))
113 editor.putString(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE);
115 if (!items.containsKey(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY))
117 editor.putString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE);
119 if (!items.containsKey(IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL))
121 editor.putString(IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL, IPreferencePropertyAccessor.SOUND_VOLUME_LEVEL_DEFAULT_VALUE);
123 if (!items.containsKey(IPreferencePropertyAccessor.RAW))
125 editor.putBoolean(IPreferencePropertyAccessor.RAW, true);
127 if (!items.containsKey(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA))
129 editor.putBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
131 if (!items.containsKey(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW))
133 editor.putBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
135 if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD))
137 editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
139 if (!items.containsKey(IPreferencePropertyAccessor.SHARE_AFTER_SAVE)) {
140 editor.putBoolean(IPreferencePropertyAccessor.SHARE_AFTER_SAVE, false);
142 if (!items.containsKey(IPreferencePropertyAccessor.USE_PLAYBACK_MENU)) {
143 editor.putBoolean(IPreferencePropertyAccessor.USE_PLAYBACK_MENU, false);
145 if (!items.containsKey(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW)) {
146 editor.putBoolean(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, true);
148 if (!items.containsKey(IPreferencePropertyAccessor.GR2_LCD_SLEEP)) {
149 editor.putBoolean(IPreferencePropertyAccessor.GR2_LCD_SLEEP, false);
151 if (!items.containsKey(IPreferencePropertyAccessor.USE_GR2_SPECIAL_COMMAND)) {
152 editor.putBoolean(IPreferencePropertyAccessor.USE_GR2_SPECIAL_COMMAND, true);
154 if (!items.containsKey(IPreferencePropertyAccessor.PENTAX_CAPTURE_AFTER_AF)) {
155 editor.putBoolean(IPreferencePropertyAccessor.PENTAX_CAPTURE_AFTER_AF, false);
157 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW)) {
158 editor.putBoolean(IPreferencePropertyAccessor.FUJI_X_DISPLAY_CAMERA_VIEW, false);
160 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_FOCUS_XY)) {
161 editor.putString(IPreferencePropertyAccessor.FUJI_X_FOCUS_XY, IPreferencePropertyAccessor.FUJI_X_FOCUS_XY_DEFAULT_VALUE);
163 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_LIVEVIEW_WAIT)) {
164 editor.putString(IPreferencePropertyAccessor.FUJI_X_LIVEVIEW_WAIT, IPreferencePropertyAccessor.FUJI_X_LIVEVIEW_WAIT_DEFAULT_VALUE);
166 if (!items.containsKey(IPreferencePropertyAccessor.FUJI_X_COMMAND_POLLING_WAIT)) {
167 editor.putString(IPreferencePropertyAccessor.FUJI_X_COMMAND_POLLING_WAIT, IPreferencePropertyAccessor.FUJI_X_COMMAND_POLLING_WAIT_DEFAULT_VALUE);
182 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
184 Log.v(TAG, "onSharedPreferenceChanged() : " + key);
190 case IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA:
191 value = preferences.getBoolean(key, true);
192 Log.v(TAG, " " + key + " , " + value);
195 case IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW:
196 value = preferences.getBoolean(key, true);
197 Log.v(TAG, " BOTH LV : " + key + " , " + value);
200 case IPreferencePropertyAccessor.USE_PLAYBACK_MENU:
201 value = preferences.getBoolean(key, false);
202 Log.v(TAG, " " + key + " , " + value);
205 case IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW:
206 value = preferences.getBoolean(key, true);
207 Log.v(TAG, " GR2 DISPLAY : " + key + " , " + value);
210 case IPreferencePropertyAccessor.GR2_LCD_SLEEP:
211 value = preferences.getBoolean(key, false);
212 Log.v(TAG, " GR2 LCD : " + key + " , " + value);
215 case IPreferencePropertyAccessor.SHARE_AFTER_SAVE:
216 value = preferences.getBoolean(key, false);
217 Log.v(TAG, " SHARE : " + key + " , " + value);
220 case IPreferencePropertyAccessor.USE_GR2_SPECIAL_COMMAND:
221 value = preferences.getBoolean(key, true);
222 Log.v(TAG, " GR2 SPECIAL : " + key + " , " + value);
225 case IPreferencePropertyAccessor.PENTAX_CAPTURE_AFTER_AF:
226 value = preferences.getBoolean(key, false);
227 Log.v(TAG, " PENTAX AFTER AF : " + key + " , " + value);
231 String strValue = preferences.getString(key, "");
232 setListPreference(key, key, strValue);
243 public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
245 Log.v(TAG, "onCreatePreferences()");
248 //super.onCreate(savedInstanceState);
249 addPreferencesFromResource(R.xml.preferences_ricoh_gr2);
251 ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
252 if (connectionMethod != null)
254 connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
256 public boolean onPreferenceChange(Preference preference, Object newValue) {
257 preference.setSummary(newValue + " ");
261 connectionMethod.setSummary(connectionMethod.getValue() + " ");
264 Preference exitApplication = findPreference("exit_application");
265 if (exitApplication != null)
267 exitApplication.setOnPreferenceClickListener(powerOffController);
270 Preference debug = findPreference("debug_info");
273 debug.setOnPreferenceClickListener(logCatViewer);
276 Preference wifi = findPreference("wifi_settings");
279 wifi.setOnPreferenceClickListener(this);
293 public void onResume()
296 Log.v(TAG, "onResume() Start");
299 synchronizedProperty();
306 Log.v(TAG, "onResume() End");
314 public void onPause()
317 Log.v(TAG, "onPause() Start");
320 // Preference変更のリスナを解除
321 preferences.unregisterOnSharedPreferenceChangeListener(this);
328 Log.v(TAG, "onPause() End");
332 * ListPreference の表示データを設定
334 * @param pref_key Preference(表示)のキー
335 * @param key Preference(データ)のキー
336 * @param defaultValue Preferenceのデフォルト値
338 private void setListPreference(String pref_key, String key, String defaultValue)
343 pref = findPreference(pref_key);
344 String value = preferences.getString(key, defaultValue);
347 pref.setValue(value);
348 pref.setSummary(value);
358 * BooleanPreference の表示データを設定
360 * @param pref_key Preference(表示)のキー
361 * @param key Preference(データ)のキー
362 * @param defaultValue Preferenceのデフォルト値
364 private void setBooleanPreference(String pref_key, String key, boolean defaultValue)
368 CheckBoxPreference pref = findPreference(pref_key);
371 boolean value = preferences.getBoolean(key, defaultValue);
372 pref.setChecked(value);
385 private void synchronizedProperty()
387 final FragmentActivity activity = getActivity();
388 final boolean defaultValue = true;
389 if (activity != null)
391 activity.runOnUiThread(new Runnable() {
396 // Preferenceの画面に反映させる
397 setBooleanPreference(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, defaultValue);
398 setBooleanPreference(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, defaultValue);
399 setBooleanPreference(IPreferencePropertyAccessor.USE_PLAYBACK_MENU, IPreferencePropertyAccessor.USE_PLAYBACK_MENU, defaultValue);
400 setBooleanPreference(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, defaultValue);
401 setBooleanPreference(IPreferencePropertyAccessor.GR2_LCD_SLEEP, IPreferencePropertyAccessor.GR2_LCD_SLEEP, defaultValue);
402 setBooleanPreference(IPreferencePropertyAccessor.SHARE_AFTER_SAVE, IPreferencePropertyAccessor.SHARE_AFTER_SAVE, defaultValue);
403 setBooleanPreference(IPreferencePropertyAccessor.USE_GR2_SPECIAL_COMMAND, IPreferencePropertyAccessor.USE_GR2_SPECIAL_COMMAND, defaultValue);
404 setBooleanPreference(IPreferencePropertyAccessor.PENTAX_CAPTURE_AFTER_AF, IPreferencePropertyAccessor.PENTAX_CAPTURE_AFTER_AF, false);
417 public boolean onPreferenceClick(Preference preference)
421 String preferenceKey = preference.getKey();
422 if (preferenceKey.contains("wifi_settings"))
425 Log.v(TAG, " onPreferenceClick : " + preferenceKey);
428 context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));