OSDN Git Service

PとSの制御コードを a01d からマージ。
[gokigen/PKRemote.git] / app / src / main / java / net / osdn / gokigen / pkremote / camera / vendor / panasonic / operation / CameraPowerOffPanasonic.java
1 package net.osdn.gokigen.pkremote.camera.vendor.panasonic.operation;
2
3 import android.content.Context;
4
5 import androidx.preference.Preference;
6
7 import net.osdn.gokigen.pkremote.R;
8 import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
9 import net.osdn.gokigen.pkremote.scene.ConfirmationDialog;
10 import net.osdn.gokigen.pkremote.scene.IChangeScene;
11
12 /**
13  *  Preferenceがクリックされた時に処理するクラス
14  *
15  */
16 public class CameraPowerOffPanasonic implements Preference.OnPreferenceClickListener, ConfirmationDialog.Callback
17 {
18
19     private final Context context;
20     private final IChangeScene changeScene;
21     private String preferenceKey = null;
22
23     /**
24      *   コンストラクタ
25      *
26      */
27     public CameraPowerOffPanasonic(Context context, IChangeScene changeScene)
28     {
29         this.context = context;
30         this.changeScene = changeScene;
31     }
32
33     /**
34      *   クラスの準備
35      *
36      */
37     public void prepare()
38     {
39         // 何もしない
40     }
41
42     /**
43      *
44      *
45      * @param preference クリックしたpreference
46      * @return false : ハンドルしない / true : ハンドルした
47      */
48     @Override
49     public boolean onPreferenceClick(Preference preference)
50     {
51         if (!preference.hasKey())
52         {
53             return (false);
54         }
55
56         preferenceKey = preference.getKey();
57         if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
58         {
59
60             // 確認ダイアログの生成と表示
61             ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
62             dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_exit_application, this);
63             return (true);
64         }
65         return (false);
66     }
67
68     /**
69      *
70      *
71      */
72     @Override
73     public void confirm()
74     {
75         if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
76         {
77             // カメラの電源をOFFにしたうえで、アプリケーションを終了する。
78             changeScene.exitApplication();
79         }
80     }
81 }
82