OSDN Git Service

ちょっとだけ、preferenceの準備。
[gokigen/FujiCam.git] / app / src / main / java / net / osdn / gokigen / cameratest / fuji / preference / FujiPreferenceFragment.java
1 package net.osdn.gokigen.cameratest.fuji.preference;
2
3 import android.content.Context;
4 import android.os.Bundle;
5
6 import androidx.annotation.NonNull;
7 import androidx.preference.ListPreference;
8 import androidx.preference.Preference;
9 import androidx.preference.PreferenceFragmentCompat;
10
11 import net.osdn.gokigen.cameratest.IApplicationControl;
12 import net.osdn.gokigen.cameratest.R;
13
14 public class FujiPreferenceFragment extends PreferenceFragmentCompat
15 {
16     private PowerOffController powerOffController = null;
17
18     /**
19      *
20      *
21      */
22     public static FujiPreferenceFragment newInstance(@NonNull Context context, @NonNull IApplicationControl control)
23     {
24         FujiPreferenceFragment instance = new FujiPreferenceFragment();
25         instance.prepare(context, control);
26
27         // パラメータはBundleにまとめておく
28         Bundle arguments = new Bundle();
29         //arguments.putString("title", title);
30         //arguments.putString("message", message);
31         instance.setArguments(arguments);
32
33         return (instance);
34     }
35
36     private void prepare(@NonNull Context context, @NonNull IApplicationControl control)
37     {
38         powerOffController = new PowerOffController(context, control);
39     }
40
41     @Override
42     public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
43     {
44         setPreferencesFromResource(R.xml.preferences_fuji_x, rootKey);
45
46         ListPreference connectionMethod = (ListPreference) findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
47         connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
48             @Override
49             public boolean onPreferenceChange(Preference preference, Object newValue) {
50                 preference.setSummary(newValue + " ");
51                 return (true);
52             }
53         });
54         connectionMethod.setSummary(connectionMethod.getValue() + " ");
55
56         findPreference("exit_application").setOnPreferenceClickListener(powerOffController);
57
58     }
59 }