Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Binary file added demo/oskdemo.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions demo/oskdemo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
IT Crowd
Dune
Game of Thrones
Princess Bride
Mars Attacks!
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>OSK</groupId>
<artifactId>OSK</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
40 changes: 40 additions & 0 deletions src/main/java/osk/OnScreenKeyboardInstructionGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package osk;

import java.util.List;
import java.util.Scanner;
import utils.FileParser;
import utils.Translator;

/**
*
* @author Aaron Reinard
*
* Generate OnScreen keyboard instructions for media titles in provided in flat file
*
*/

public class OnScreenKeyboardInstructionGenerator {

public static void main(String[] args) throws Exception {

String file = null;
Scanner input = new Scanner(System.in);

try {
System.out.print("Please enter file: ");
file = input.next();
input.close();

List<String> titleList = FileParser.parseFlatFile(file);
List<String> keyboardInstructionList = Translator.getKeyboardInstructionStringList(titleList);
keyboardInstructionList.forEach(x -> System.out.println(x));

} catch (Exception e) {
throw new Exception(
"Unable to translate keyboard instructions for " + file + ". " + e.getMessage());
}
}



}
37 changes: 37 additions & 0 deletions src/main/java/screen/Coordinates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package screen;

/**
*
* @author Aaron Reinard
*
* Contains coordinates used for keyboard navigation instructions
*
*/
public class Coordinates {

private int x;
private int y;

public Coordinates(int x, int y) {
this.x = x;
this.y = y;

}

public int getX() {
return x;
}

public void setX(int value) {
this.x = value;
}

public int getY() {
return y;
}

public void setY(int value) {
this.y = value;
}

}
34 changes: 34 additions & 0 deletions src/main/java/screen/Key.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package screen;

/**
*
* @author Aaron Reinard
*
*/
public class Key {

private String value;
private Coordinates coordinates;

public Key(String character, Coordinates values) {
setValue(character);
setCoordinates(values);
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public Coordinates getCoordinates() {
return coordinates;
}

public void setCoordinates(Coordinates values) {
this.coordinates = values;
}

}
62 changes: 62 additions & 0 deletions src/main/java/screen/Keyboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package screen;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author Aaron Reinard
*
* Keyboard dictionary containing keyset and coordinates
*
*/

public class Keyboard {

private List<Key> keys = null;

public Keyboard() {
this.keys = setKeys();
}

public List<Key> getKeys() {
return keys;
}

public Key getKey(String value) {
Key result = null;
for (Key keyMap : getKeys()) {
if (keyMap.getValue().equalsIgnoreCase(value)) {
result = keyMap;
break;
}
}
return result;
}


private List<Key> setKeys() {

List<Key> keyList = new ArrayList<Key>();
List<String> lines = new ArrayList<String>();

lines.add("ABCDEF");
lines.add("GHIJKL");
lines.add("MNOPQR");
lines.add("STUVWX");
lines.add("YZ1234");
lines.add("567890");

int yInt = 0;
for (String line : lines) {
for (int xInt = 0; xInt < line.length(); xInt++) {
String value = String.valueOf(line.charAt(xInt));
Coordinates coordinates = new Coordinates(xInt, yInt);
keyList.add(new Key(value, coordinates));
}
yInt++;
}
return keyList;
}

}
43 changes: 43 additions & 0 deletions src/main/java/utils/FileParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class FileParser {

/**
*
* @param filePath inputFile
* @return list of strings parsed from flat file
* @throws IOException
*/
public static List<String> parseFlatFile(String filePath) throws IOException {
List<String> resultList = new ArrayList<String>();
try {
File input = new File(filePath);
InputStream inputStream = new FileInputStream(input);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
resultList = reader.lines().map(mapToString).collect(Collectors.toList());
reader.close();
} catch (Exception e) {
throw new IOException("unable to parse file " + filePath + "; " + e.getMessage());
}
return resultList;
}

private static Function<String, String> mapToString = (line) -> {
String items[] = line.split("\\r?\\n");
String item = items[0];
return item;

};

}
Loading