Back to project page Android-Apps.
The source code is released under:
Apache License
If you think the Android project Android-Apps listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.kniezrec.voiceremote2; // w w w . ja va2 s. c o m import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Set; import com.kniezrec.voiceremote2.R; import android.content.SharedPreferences; import android.content.res.Resources; public final class Mapper { public static Integer[] parseNumber(String nr) { Integer[] integers = null; try { Integer.valueOf(nr); char[] arr = nr.toCharArray(); integers = new Integer[arr.length]; for (int i = 0; i < arr.length; i++) { switch (arr[i]) { case '0': integers[i] = Integer.valueOf(Commands.BTN_0); break; case '1': integers[i] = Integer.valueOf(Commands.BTN_1); break; case '2': integers[i] = Integer.valueOf(Commands.BTN_2); break; case '3': integers[i] = Integer.valueOf(Commands.BTN_3); break; case '4': integers[i] = Integer.valueOf(Commands.BTN_4); break; case '5': integers[i] = Integer.valueOf(Commands.BTN_5); break; case '6': integers[i] = Integer.valueOf(Commands.BTN_6); break; case '7': integers[i] = Integer.valueOf(Commands.BTN_7); break; case '8': integers[i] = Integer.valueOf(Commands.BTN_8); break; case '9': integers[i] = Integer.valueOf(Commands.BTN_9); break; default: break; } } return integers; } catch (NumberFormatException e) { return null; } } public static Integer[][] checkActions(Set<String> set, String voice, SharedPreferences prefs) { ArrayList<Integer[]> parsed; if (set.contains(voice)) { parsed = new ArrayList<Integer[]>(); String tmp = prefs.getString(voice + NewAction.SUFFIX, ""); String[] _tmpArr = tmp.split(NewAction.SEP); int code; for (String s : _tmpArr) { if (s.startsWith(NewAction.CH_SEP)) { parsed.add(parseNumber(s.substring(3))); } else { code = Integer.parseInt(s); Integer[] _arr = new Integer[1]; switch (code) { case 1: _arr[0] = Integer.valueOf(Commands.BTN_UP); break; case 2: _arr[0] = Integer.valueOf(Commands.BTN_DOWN); break; case 3: _arr[0] = Integer.valueOf(Commands.BTN_LEFT); break; case 4: _arr[0] = Integer.valueOf(Commands.BTN_RIGHT); break; case 5: _arr[0] = Integer.valueOf(Commands.BTN_EXIT); break; case 6: _arr[0] = Integer.valueOf(Commands.BTN_ENTER); break; case 7: _arr[0] = Integer.valueOf(Commands.BTN_TIMEOUT_PAUSE); break; case 8: _arr[0] = Integer.valueOf(Commands.BTN_TOOLS); break; case 9: _arr[0] = Integer.valueOf(Commands.BTN_RETURN); break; case 10: _arr[0] = Integer.valueOf(Commands.BTN_CHANNEL_LIST); break; case 11: _arr[0] = Integer.valueOf(Commands.BTN_MENU); break; case 12: _arr[0] = Integer.valueOf(Commands.BTN_CHANNEL_UP); break; case 13: _arr[0] = Integer.valueOf(Commands.BTN_CHANNEL_DOWN); break; case 14: _arr[0] = Integer.valueOf(Commands.BTN_VOLUME_UP); break; case 15: _arr[0] = Integer.valueOf(Commands.BTN_VOLUME_DOWN); break; case 16: _arr[0] = Integer.valueOf(Commands.BTN_MUTE); break; case 17: _arr[0] = Integer.valueOf(Commands.BTN_INFO); break; case 18: _arr[0] = Integer.valueOf(Commands.BTN_TELETEXT); break; case 19: _arr[0] = Integer.valueOf(Commands.BTN_PAUSE); break; case 20: _arr[0] = Integer.valueOf(Commands.BTN_PLAY); break; case 21: _arr[0] = Integer.valueOf(Commands.BTN_STOP); break; case 22: _arr[0] = Integer.valueOf(Commands.BTN_INTERNET); break; case 23: _arr[0] = Integer.valueOf(Commands.BTN_SOURCE); break; case 24: _arr[0] = Integer.valueOf(Commands.BTN_POWER_OFF); break; case 25: _arr[0] = Integer.valueOf(Commands.BTN_S_HDMI1); break; default: break; } parsed.add(_arr); } } return parsed.toArray(new Integer[parsed.size()][]); } return null; } public static int checkSpecialInstruction(ArrayList<String> textMatchList, Commands cmds, SharedPreferences pref) { int reqId = Commands.NOT_FOUND; if (textMatchList == null || cmds == null) return reqId; String reqOne = textMatchList.get(0); for (String com : cmds.write) { if (reqOne.startsWith(com)) { textMatchList.add(com); return Commands.WRITE; } } for (String com : cmds.review) { if (com.equals(reqOne)) { return Commands.SHOW_ALL; } } for (String com : cmds.review_back) { if (com.equals(reqOne)) { return Commands.SHOW_ALL_BACK; } } for (String com : cmds.favouriteChannels) { if (com.equals(reqOne)) { return Commands.SHOW_ONLY_FAV; } } for (String com : cmds.stop) { if (com.equals(reqOne)) { return Commands.STOP; } } for (String com : cmds.toQuietList) { if (com.equals(reqOne)) { return Commands.TO_QUIET; } } for (String com : cmds.toLoudList) { if (com.equals(reqOne)) { return Commands.TO_LOUD; } } Map<String, ?> keys = pref.getAll(); Object value = keys.get(reqOne); if (value != null) { if (value instanceof Integer) { Integer val = Integer.parseInt(value.toString()); switch (val.intValue()) { case Commands.WRITE: return Commands.WRITE; case Commands.SHOW_ALL: return Commands.SHOW_ALL; case Commands.SHOW_ALL_BACK: return Commands.SHOW_ALL_BACK; case Commands.SHOW_ONLY_FAV: return Commands.SHOW_ONLY_FAV; case Commands.STOP: return Commands.STOP; case Commands.TO_QUIET: return Commands.TO_QUIET; case Commands.TO_LOUD: return Commands.TO_LOUD; default: return reqId; } } } return reqId; } public static Integer[] mapResult(String resOne, Commands cmds, SharedPreferences pref) { Integer[] codes; Integer tmp; for (String s : cmds.toRemove) { if (resOne.startsWith(s)) { resOne = resOne.replace(s, ""); resOne = resOne.trim(); codes = parseNumber(resOne); if (codes != null) { return codes; } for (HashMap<String, Integer> map : cmds.numeric) { tmp = map.get(resOne); if (tmp != null) { codes = new Integer[1]; codes[0] = tmp; return codes; } } break; } } codes = parseNumber(resOne); if (codes != null) { return codes; } for (HashMap<String, Integer> map : cmds.all) { tmp = map.get(resOne); if (tmp != null) { codes = new Integer[1]; codes[0] = tmp; return codes; } } Map<String, ?> keys = pref.getAll(); Object value = keys.get(resOne); if (value != null) { if (value instanceof Integer) { codes = new Integer[1]; codes[0] = (Integer) value; return codes; } else { String _val = new String(value.toString()); codes = parseNumber(_val.substring(0, _val.length() - 1)); return codes; } } return null; } public static String mapActionToName(String actionId, Resources res) { int action = Integer.parseInt(actionId); int step = 0; switch (action) { case Commands.SHOW_ONLY_FAV: step = 1; break; case Commands.SHOW_ALL: step = 2; break; case Commands.SHOW_ALL_BACK: step = 3; break; case Commands.WRITE: step = 4; break; case Commands.TO_QUIET: step = 5; break; case Commands.TO_LOUD: step = 6; break; case Commands.BTN_VOLUME_UP: step = 7; break; case Commands.BTN_VOLUME_DOWN: step = 8; break; case Commands.BTN_MUTE: step = 9; break; case Commands.BTN_CHANNEL_UP: step = 10; break; case Commands.BTN_CHANNEL_DOWN: step = 11; break; case Commands.BTN_INFO: step = 12; break; case Commands.BTN_ENTER: step = 13; break; case Commands.BTN_UP: step = 14; break; case Commands.BTN_DOWN: step = 15; break; case Commands.BTN_LEFT: step = 16; break; case Commands.BTN_RIGHT: step = 17; break; case Commands.BTN_EXIT: step = 18; break; case Commands.BTN_TELETEXT: step = 19; break; case Commands.BTN_PAUSE: step = 20; break; case Commands.BTN_PLAY: step = 21; break; case Commands.BTN_STOP: step = 22; break; case Commands.BTN_INTERNET: step = 23; break; case Commands.BTN_POWER_OFF: step = 24; break; case Commands.STOP: step = 25; break; case Commands.BTN_RETURN: step = 26; break; case Commands.BTN_CHANNEL_LIST: step = 27; break; case Commands.BTN_S_HDMI1: step = 28; break; default: break; } String[] list = res.getStringArray(R.array.buttons); return list[step]; } public static int mapOptionToAction(String id) { int _id = Integer.parseInt(id); switch (_id) { case 1: return Commands.SHOW_ONLY_FAV; case 2: return Commands.SHOW_ALL; case 3: return Commands.SHOW_ALL_BACK; case 4: return Commands.WRITE; case 5: return Commands.TO_QUIET; case 6: return Commands.TO_LOUD; case 7: return Commands.BTN_VOLUME_UP; case 8: return Commands.BTN_VOLUME_DOWN; case 9: return Commands.BTN_MUTE; case 10: return Commands.BTN_CHANNEL_UP; case 11: return Commands.BTN_CHANNEL_DOWN; case 12: return Commands.BTN_INFO; case 13: return Commands.BTN_ENTER; case 14: return Commands.BTN_UP; case 15: return Commands.BTN_DOWN; case 16: return Commands.BTN_LEFT; case 17: return Commands.BTN_RIGHT; case 18: return Commands.BTN_EXIT; case 19: return Commands.BTN_TELETEXT; case 20: return Commands.BTN_PAUSE; case 21: return Commands.BTN_PLAY; case 22: return Commands.BTN_STOP; case 23: return Commands.BTN_INTERNET; case 24: return Commands.BTN_POWER_OFF; case 25: return Commands.STOP; case 26: return Commands.BTN_RETURN; case 27: return Commands.BTN_CHANNEL_LIST; case 28: return Commands.BTN_S_HDMI1; default: return -1; } } public static String mapIntToName(String step, Resources res) { int _step = 0; try { _step = Integer.parseInt(step); } catch (NumberFormatException e) { return "Action"; } String[] list = res.getStringArray(R.array.buttons2); return list[_step]; } }