OSDN Git Service

ちょっとだけ、preferenceの準備。
[gokigen/FujiCam.git] / app / src / main / java / net / osdn / gokigen / cameratest / fuji / preference / PowerOffController.java
1 package net.osdn.gokigen.cameratest.fuji.preference;
2
3 import android.content.Context;
4
5 import androidx.annotation.NonNull;
6 import androidx.preference.Preference;
7
8 import net.osdn.gokigen.cameratest.ConfirmationDialog;
9 import net.osdn.gokigen.cameratest.IApplicationControl;
10 import net.osdn.gokigen.cameratest.R;
11
12 public class PowerOffController implements Preference.OnPreferenceClickListener, ConfirmationDialog.Callback
13 {
14     private final Context context;
15     private final IApplicationControl appControl;
16     private String preferenceKey = null;
17
18     PowerOffController(@NonNull Context context, @NonNull IApplicationControl control)
19     {
20         this.context = context;
21         this.appControl = control;
22     }
23
24     @Override
25     public boolean onPreferenceClick(Preference preference)
26     {
27         if (!preference.hasKey())
28         {
29             return (false);
30         }
31
32         preferenceKey = preference.getKey();
33         if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
34         {
35
36             // 確認ダイアログの生成と表示
37             ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
38             dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, this);
39             return (true);
40         }
41         return (false);
42     }
43
44     /**
45      *
46      *
47      */
48     @Override
49     public void confirm()
50     {
51         try
52         {
53             if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
54             {
55                 // カメラの電源をOFFにしたうえで、アプリケーションを終了する。
56                 appControl.exitApplication();
57
58             }
59         }
60         catch (Exception e)
61         {
62             e.printStackTrace();
63         }
64     }
65 }