summaryrefslogtreecommitdiff
path: root/ISEDefaultNUI/MagnifierWindow.cs
blob: e8a0c0781c82d5d2499df75f006d3a361c646cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Collections.Generic;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;
using Tizen;

namespace ISEDefaultNUI
{
    public class MagnifierWindow
    {
        private static MagnifierWindow instance;
        private Timer timer;
        private List<ImageView> imageList;
        private List<TextLabel> labelList;
        private WindowAttribute.Position position;

        private MagnifierWindow()
        {
            timer = new Timer(ResourceManager.MagnifierShowDuration);
            timer.Tick += TimerTick;
            imageList = new List<ImageView>();
            labelList = new List<TextLabel>();
        }

        private bool TimerTick(object source, Timer.TickEventArgs e)
        {
            if (IsExists())
                Hide();

            return true;
        }

        public static MagnifierWindow Instance
        {
            get
            {
                if (instance == null)
                    instance = new MagnifierWindow();

                return instance;
            }
        }

        public void Show(View parent)
        {
            imageList.ForEach(image => parent.Add(image));
            labelList.ForEach(label => parent.Add(label));
            timer.Start();
        }

        public void Hide()
        {
            timer.Stop();

            labelList.ForEach(label =>
            {
                label.Unparent();
                label.Dispose();
            });

            imageList.ForEach(image =>
            {
                image.Unparent();
                image.Dispose();
            });

            labelList.Clear();
            imageList.Clear();
        }

        public void SetPosition(WindowAttribute.Position newPosition)
        {
            position = newPosition;
        }

        public WindowAttribute.Position GetPosition()
        {
            return position;
        }

        public void AddImage(ImageView imageView)
        {
            imageList.Add(imageView);
        }

        public void AddLabel(TextLabel textLabel)
        {
            labelList.Add(textLabel);
        }

        public bool IsExists()
        {
            if (imageList.Count != 0 || labelList.Count != 0)
                return true;

            return false;
        }

        public bool IsRunning()
        {
            return timer.IsRunning();
        }
    }
}