1
package uk.digitalsquid.droidpad.xml;
3
import java.io.IOException;
4
import java.io.InputStream;
6
import javax.xml.parsers.ParserConfigurationException;
7
import javax.xml.parsers.SAXParser;
8
import javax.xml.parsers.SAXParserFactory;
10
import org.xml.sax.Attributes;
11
import org.xml.sax.ContentHandler;
12
import org.xml.sax.InputSource;
13
import org.xml.sax.SAXException;
15
import uk.digitalsquid.droidpad.LogTag;
16
import uk.digitalsquid.droidpad.buttons.Button;
17
import uk.digitalsquid.droidpad.buttons.Layout;
18
import uk.digitalsquid.droidpad.buttons.ModeSpec;
19
import uk.digitalsquid.droidpad.buttons.Slider;
20
import uk.digitalsquid.droidpad.buttons.ToggleButton;
21
import uk.digitalsquid.droidpad.buttons.TouchPanel;
22
import uk.digitalsquid.droidpad.buttons.Slider.SliderType;
23
import uk.digitalsquid.droidpad.buttons.TouchPanel.PanelType;
24
import android.sax.Element;
25
import android.sax.ElementListener;
26
import android.sax.RootElement;
27
import android.sax.TextElementListener;
30
public class LayoutDecoder implements LogTag {
31
private LayoutDecoder() {}
1
/* This file is part of DroidPad.
3
* DroidPad is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* DroidPad is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with DroidPad. If not, see <http://www.gnu.org/licenses/>.
17
package uk.digitalsquid.droidpad.layout;
19
import java.io.IOException;
20
import java.io.Reader;
22
import javax.xml.parsers.ParserConfigurationException;
23
import javax.xml.parsers.SAXParser;
24
import javax.xml.parsers.SAXParserFactory;
26
import org.xml.sax.Attributes;
27
import org.xml.sax.ContentHandler;
28
import org.xml.sax.InputSource;
29
import org.xml.sax.SAXException;
31
import uk.digitalsquid.droidpad.LogTag;
32
import uk.digitalsquid.droidpad.buttons.Button;
33
import uk.digitalsquid.droidpad.buttons.Layout;
34
import uk.digitalsquid.droidpad.buttons.ModeSpec;
35
import uk.digitalsquid.droidpad.buttons.Orientation;
36
import uk.digitalsquid.droidpad.buttons.Slider;
37
import uk.digitalsquid.droidpad.buttons.ToggleButton;
38
import uk.digitalsquid.droidpad.buttons.TouchPanel;
39
import android.sax.Element;
40
import android.sax.ElementListener;
41
import android.sax.RootElement;
42
import android.sax.TextElementListener;
45
public class XmlDecoder implements LogTag {
46
private XmlDecoder() {}
33
48
private static final SAXParserFactory factory = SAXParserFactory.newInstance();
35
public static final ModeSpec decodeLayout(InputStream stream) throws IOException {
50
public static final ModeSpec decodeLayout(Reader stream) throws IOException {
37
52
return internalDecodeLayout(stream);
38
53
} catch (ParserConfigurationException e) {
175
190
String typeName = attr.getValue("type");
176
191
if(typeName == null) typeName = "both";
177
if(typeName.equalsIgnoreCase("x")) type = SliderType.X;
178
if(typeName.equalsIgnoreCase("y")) type = SliderType.Y;
179
if(typeName.equalsIgnoreCase("horizontal")) type = SliderType.X;
180
if(typeName.equalsIgnoreCase("vertical")) type = SliderType.Y;
192
if(typeName.equalsIgnoreCase("x")) type = Orientation.X;
193
if(typeName.equalsIgnoreCase("y")) type = Orientation.Y;
194
if(typeName.equalsIgnoreCase("horizontal")) type = Orientation.X;
195
if(typeName.equalsIgnoreCase("vertical")) type = Orientation.Y;
182
if(typeName.equalsIgnoreCase("xy")) type = SliderType.Both;
183
if(typeName.equalsIgnoreCase("both")) type = SliderType.Both;
184
if(typeName.equalsIgnoreCase("dual")) type = SliderType.Both;
197
if(typeName.equalsIgnoreCase("xy")) type = Orientation.Both;
198
if(typeName.equalsIgnoreCase("both")) type = Orientation.Both;
199
if(typeName.equalsIgnoreCase("dual")) type = Orientation.Both;
206
221
String typeName = attr.getValue("type");
207
222
if(typeName == null) typeName = "both";
208
if(typeName.equalsIgnoreCase("x")) type = PanelType.X;
209
if(typeName.equalsIgnoreCase("y")) type = PanelType.Y;
210
if(typeName.equalsIgnoreCase("horizontal")) type = PanelType.X;
211
if(typeName.equalsIgnoreCase("vertical")) type = PanelType.Y;
223
if(typeName.equalsIgnoreCase("x")) type = Orientation.X;
224
if(typeName.equalsIgnoreCase("y")) type = Orientation.Y;
225
if(typeName.equalsIgnoreCase("horizontal")) type = Orientation.X;
226
if(typeName.equalsIgnoreCase("vertical")) type = Orientation.Y;
213
if(typeName.equalsIgnoreCase("xy")) type = PanelType.Both;
214
if(typeName.equalsIgnoreCase("both")) type = PanelType.Both;
215
if(typeName.equalsIgnoreCase("dual")) type = PanelType.Both;
228
if(typeName.equalsIgnoreCase("xy")) type = Orientation.Both;
229
if(typeName.equalsIgnoreCase("both")) type = Orientation.Both;
230
if(typeName.equalsIgnoreCase("dual")) type = Orientation.Both;