]> git.basschouten.com Git - openhab-addons.git/blob
eeb18f1b40dbb791f9412e2ae9e29737d03cabd5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 /* This file is based on:
14  *
15  * TextInputStatusInfo
16  * Connect SDK
17  *
18  * Copyright (c) 2014 LG Electronics.
19  * Created by Hyun Kook Khang on 19 Jan 2014
20  *
21  * Licensed under the Apache License, Version 2.0 (the "License");
22  * you may not use this file except in compliance with the License.
23  * You may obtain a copy of the License at
24  *
25  *     http://www.apache.org/licenses/LICENSE-2.0
26  *
27  * Unless required by applicable law or agreed to in writing, software
28  * distributed under the License is distributed on an "AS IS" BASIS,
29  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30  * See the License for the specific language governing permissions and
31  * limitations under the License.
32  */
33
34 package org.openhab.binding.lgwebos.internal.handler.core;
35
36 import com.google.gson.JsonObject;
37
38 /**
39  * Normalized reference object for information about a text input event.
40  *
41  * @author Hyun Kook Khang - Connect SDK initial contribution
42  * @author Sebastian Prehn - Adoption for openHAB
43  */
44 public class TextInputStatusInfo {
45     // @cond INTERNAL
46     public enum TextInputType {
47         DEFAULT,
48         URL,
49         NUMBER,
50         PHONE_NUMBER,
51         EMAIL
52     }
53
54     boolean focused = false;
55     String contentType = null;
56     boolean predictionEnabled = false;
57     boolean correctionEnabled = false;
58     boolean autoCapitalization = false;
59     boolean hiddenText = false;
60     boolean focusChanged = false;
61
62     JsonObject rawData;
63     // @endcond
64
65     public TextInputStatusInfo() {
66     }
67
68     public boolean isFocused() {
69         return focused;
70     }
71
72     public void setFocused(boolean focused) {
73         this.focused = focused;
74     }
75
76     /**
77      * Gets the type of keyboard that should be displayed to the user.
78      *
79      * @return the keyboard type
80      */
81     public TextInputType getTextInputType() {
82         TextInputType textInputType = TextInputType.DEFAULT;
83
84         if ("number".equals(contentType)) {
85             textInputType = TextInputType.NUMBER;
86         } else if ("phonenumber".equals(contentType)) {
87             textInputType = TextInputType.PHONE_NUMBER;
88         } else if ("url".equals(contentType)) {
89             textInputType = TextInputType.URL;
90         } else if ("email".equals(contentType)) {
91             textInputType = TextInputType.EMAIL;
92         }
93
94         return textInputType;
95     }
96
97     /**
98      * Sets the type of keyboard that should be displayed to the user.
99      *
100      * @param textInputType the keyboard type
101      */
102     public void setTextInputType(TextInputType textInputType) {
103         switch (textInputType) {
104             case NUMBER:
105                 contentType = "number";
106                 break;
107             case PHONE_NUMBER:
108                 contentType = "phonenumber";
109                 break;
110             case URL:
111                 contentType = "url";
112                 break;
113             case EMAIL:
114                 contentType = "number";
115                 break;
116             case DEFAULT:
117             default:
118                 contentType = "email";
119                 break;
120         }
121     }
122
123     public void setContentType(String contentType) {
124         this.contentType = contentType;
125     }
126
127     public boolean isPredictionEnabled() {
128         return predictionEnabled;
129     }
130
131     public void setPredictionEnabled(boolean predictionEnabled) {
132         this.predictionEnabled = predictionEnabled;
133     }
134
135     public boolean isCorrectionEnabled() {
136         return correctionEnabled;
137     }
138
139     public void setCorrectionEnabled(boolean correctionEnabled) {
140         this.correctionEnabled = correctionEnabled;
141     }
142
143     public boolean isAutoCapitalization() {
144         return autoCapitalization;
145     }
146
147     public void setAutoCapitalization(boolean autoCapitalization) {
148         this.autoCapitalization = autoCapitalization;
149     }
150
151     public boolean isHiddenText() {
152         return hiddenText;
153     }
154
155     public void setHiddenText(boolean hiddenText) {
156         this.hiddenText = hiddenText;
157     }
158
159     /** @return the raw data from the first screen device about the text input status. */
160     public JsonObject getRawData() {
161         return rawData;
162     }
163
164     /** @param data the raw data from the first screen device about the text input status. */
165     public void setRawData(JsonObject data) {
166         rawData = data;
167     }
168
169     public boolean isFocusChanged() {
170         return focusChanged;
171     }
172
173     public void setFocusChanged(boolean focusChanged) {
174         this.focusChanged = focusChanged;
175     }
176 }