]> git.basschouten.com Git - openhab-addons.git/blob
3bb3b4d4bc99d92c38ef11df28c12278ed77f341
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 (contentType != null) {
85             if (contentType.equals("number")) {
86                 textInputType = TextInputType.NUMBER;
87             } else if (contentType.equals("phonenumber")) {
88                 textInputType = TextInputType.PHONE_NUMBER;
89             } else if (contentType.equals("url")) {
90                 textInputType = TextInputType.URL;
91             } else if (contentType.equals("email")) {
92                 textInputType = TextInputType.EMAIL;
93             }
94         }
95
96         return textInputType;
97     }
98
99     /**
100      * Sets the type of keyboard that should be displayed to the user.
101      *
102      * @param textInputType the keyboard type
103      */
104     public void setTextInputType(TextInputType textInputType) {
105         switch (textInputType) {
106             case NUMBER:
107                 contentType = "number";
108                 break;
109             case PHONE_NUMBER:
110                 contentType = "phonenumber";
111                 break;
112             case URL:
113                 contentType = "url";
114                 break;
115             case EMAIL:
116                 contentType = "number";
117                 break;
118             case DEFAULT:
119             default:
120                 contentType = "email";
121                 break;
122         }
123     }
124
125     public void setContentType(String contentType) {
126         this.contentType = contentType;
127     }
128
129     public boolean isPredictionEnabled() {
130         return predictionEnabled;
131     }
132
133     public void setPredictionEnabled(boolean predictionEnabled) {
134         this.predictionEnabled = predictionEnabled;
135     }
136
137     public boolean isCorrectionEnabled() {
138         return correctionEnabled;
139     }
140
141     public void setCorrectionEnabled(boolean correctionEnabled) {
142         this.correctionEnabled = correctionEnabled;
143     }
144
145     public boolean isAutoCapitalization() {
146         return autoCapitalization;
147     }
148
149     public void setAutoCapitalization(boolean autoCapitalization) {
150         this.autoCapitalization = autoCapitalization;
151     }
152
153     public boolean isHiddenText() {
154         return hiddenText;
155     }
156
157     public void setHiddenText(boolean hiddenText) {
158         this.hiddenText = hiddenText;
159     }
160
161     /** @return the raw data from the first screen device about the text input status. */
162     public JsonObject getRawData() {
163         return rawData;
164     }
165
166     /** @param data the raw data from the first screen device about the text input status. */
167     public void setRawData(JsonObject data) {
168         rawData = data;
169     }
170
171     public boolean isFocusChanged() {
172         return focusChanged;
173     }
174
175     public void setFocusChanged(boolean focusChanged) {
176         this.focusChanged = focusChanged;
177     }
178 }