Add InputFilter to TextField, TextEditor
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / BackgroundColorTest5 / BackgroundColorTest5Page.xaml.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using Tizen.NUI;
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Components;
20 using System.Linq;
21
22 namespace NUITizenGallery
23 {
24     public partial class BackgroundColorTest5Page : View
25     {
26         private int setColorCount = 1;
27         public BackgroundColorTest5Page()
28         {
29             InitializeComponent();
30             var resources_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
31             loading.ImageArray = Enumerable.Range(0, 12).Select(x => $"{resources_path}images/progress_{x}.png").ToArray();
32             loading.Stop();
33             button1.Clicked += OnButton1Clicked;
34         }
35
36         private void SetColor(Color color)
37         {
38             button1.BackgroundColor = color;
39             label.BackgroundColor = color;
40             textField.BackgroundColor = color;
41             progress.BufferColor = color;
42             slider.BgTrackColor = color;
43             loadingView.BackgroundColor = color;
44         }
45
46         private void OnButton1Clicked(object sender, ClickedEventArgs e)
47         {
48             if (setColorCount % 2 == 0)
49             {
50                 SetColor(Color.Yellow);
51             }
52             else
53             {
54                 SetColor(Color.Red);
55             }
56             loading.Play();
57             setColorCount++;
58         }
59
60         protected override void Dispose(DisposeTypes type)
61         {
62             if (Disposed)
63             {
64                 return;
65             }
66
67             if (type == DisposeTypes.Explicit)
68             {
69                 button1.Clicked -= OnButton1Clicked;
70                 RemoveAllChildren(true);
71             }
72
73             base.Dispose(type);
74         }
75
76         private void RemoveAllChildren(bool dispose = false)
77         {
78             RecursiveRemoveChildren(this, dispose);
79         }
80
81         private void RecursiveRemoveChildren(View parent, bool dispose)
82         {
83             if (parent == null)
84             {
85                 return;
86             }
87
88             int maxChild = (int)parent.ChildCount;
89             for (int i = maxChild - 1; i >= 0; --i)
90             {
91                 View child = parent.GetChildAt((uint)i);
92                 if (child == null)
93                 {
94                     continue;
95                 }
96                 RecursiveRemoveChildren(child, dispose);
97                 parent.Remove(child);
98                 if (dispose)
99                 {
100                     child.Dispose();
101                 }
102             }
103         }
104
105     }
106 }