]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/HueRingDialog.java
improvement in the color selection UI
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / HueRingDialog.java
1 /*
2  * Copyright © 2019 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.ui;
19
20 import android.app.Dialog;
21 import android.content.Context;
22 import android.os.Bundle;
23
24 import net.ktnx.mobileledger.R;
25 import net.ktnx.mobileledger.utils.Colors;
26
27 import androidx.annotation.NonNull;
28
29 public class HueRingDialog extends Dialog {
30     private final int currentHue;
31     private int initialHue;
32     private HueRing hueRing;
33     private HueSelectedListener listener;
34
35     public HueRingDialog(@NonNull Context context, int initialHue, int currentHue) {
36         super(context);
37         this.initialHue = initialHue;
38         this.currentHue = currentHue;
39     }
40     @Override
41     protected void onCreate(Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43         setContentView(R.layout.hue_dialog);
44         hueRing = findViewById(R.id.ring);
45         hueRing.setInitialHue(initialHue);
46         hueRing.setHue(currentHue);
47
48         findViewById(R.id.btn_ok).setOnClickListener(v -> {
49             if (listener != null) listener.onHueSelected(hueRing.getHueDegrees());
50
51             dismiss();
52         });
53
54         findViewById(R.id.btn_default)
55                 .setOnClickListener(v -> hueRing.setHue(Colors.DEFAULT_HUE_DEG));
56     }
57     public void setColorSelectedListener(HueSelectedListener listener) {
58         this.listener = listener;
59     }
60     public interface HueSelectedListener {
61         void onHueSelected(int hue);
62     }
63 }