Mobile Example - Calculate minimum time required for the user to input string using the key pad
A mobile phone has 12 keys for input, (‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘0’, ‘*’ and ‘#’).
In standard text input mode each key can be used to input the letters of the alphabet and the space character. For example, to access the letter ‘b’ the user would press the ‘2’ key twice.
It takes a user a minimum of 100 ms to press a key. If a user has to use the same key to input consecutive characters there must be at least a 0.5 second pause for the phone to accept that the next key press represents a new character.
I want to write an application which accepts an开发者_运维技巧y string that can be entered using the key assignments in the grid using C#. The application should accept input from a user and calculate the minimum time required for the user to input that string using the key pad and the sequence of keys that would be required.
For example:
- What is the minimum time to enter the string ‘Hello World’ and what key sequence would be required?
- How can we design the application to allow the characters assigned to each key to be easily reconfigured?
- How would I provide access to the same functionality via a web page?
- If I calculated correctly 1.6sec, 4 3 5 5 6 # 9 6 7 5 3
There are many options, one which comes to mind:
var KeyMap = new Dictionary<char, List<char>> { { '1', new List<char>(), }, // at least on my phone 1 has no characters assigned { '2', new List<char> { 'a', 'b', 'c' } }, ... };
Basically each button on the phone is map to a list of assigned characters. You can then provide some UI to configure the dictionary (make sure no double mappings etc.)
Assuming you are using Visual Studio: Have a look around for ASP.NET MVC tutorials on the net. There are plenty around.
You should encapsulate the core of your application (button mapping and calculation of times and sequences) so that you can use it with any UI you like.
精彩评论