MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / keyPressed

Method keyPressed

CodenameOne/src/com/codename1/ui/List.java:928–1000  ·  view source on GitHub ↗
(int keyCode)

Source from the content-addressed store, hash-verified

926
927 /// {@inheritDoc}
928 @Override
929 public void keyPressed(int keyCode) {
930 // scrolling events are in keyPressed to provide immediate feedback
931 if (!handlesInput()) {
932 return;
933 }
934
935 int gameAction = Display.getInstance().getGameAction(keyCode);
936 int keyFwd;
937 int keyBck;
938 if (getOrientation() != HORIZONTAL) {
939 keyFwd = Display.GAME_DOWN;
940 keyBck = Display.GAME_UP;
941 if (gameAction == Display.GAME_LEFT || gameAction == Display.GAME_RIGHT) {
942 setHandlesInput(false);
943 }
944 } else {
945 if (isRTL()) {
946 keyFwd = Display.GAME_LEFT;
947 keyBck = Display.GAME_RIGHT;
948 } else {
949 keyFwd = Display.GAME_RIGHT;
950 keyBck = Display.GAME_LEFT;
951 }
952 if (gameAction == Display.GAME_DOWN || gameAction == Display.GAME_UP) {
953 setHandlesInput(false);
954 }
955 }
956
957 int selectedIndex = model.getSelectedIndex();
958 if (gameAction == keyBck) {
959 selectedIndex--;
960 if (selectedIndex < 0) {
961 if (fixedSelection != FIXED_NONE && fixedSelection != FIXED_NONE_ONE_ELEMENT_MARGIN_FROM_EDGE) {
962 selectedIndex = size() - 1;
963 } else {
964 selectedIndex = 0;
965 setHandlesInput(false);
966 }
967 }
968 } else if (gameAction == keyFwd) {
969 selectedIndex++;
970 if (selectedIndex >= size()) {
971 if (fixedSelection != FIXED_NONE && fixedSelection != FIXED_NONE_ONE_ELEMENT_MARGIN_FROM_EDGE) {
972 selectedIndex = 0;
973 } else {
974 selectedIndex = size() - 1;
975 setHandlesInput(false);
976 }
977 }
978 }
979
980 if (selectedIndex != model.getSelectedIndex()) {
981 model.setSelectedIndex(selectedIndex);
982 int direction = (gameAction == keyFwd ? 1 : -1);
983 if ((isRTL()) && (getOrientation() == HORIZONTAL)) {
984 direction = -direction;
985 }

Callers

nothing calls this directly

Calls 15

getInstanceMethod · 0.95
getOrientationMethod · 0.95
setHandlesInputMethod · 0.95
sizeMethod · 0.95
selectElementMethod · 0.95
minMethod · 0.95
getModelMethod · 0.95
maxMethod · 0.95
getSelectedIndexMethod · 0.65
setSelectedIndexMethod · 0.65
getSizeMethod · 0.65

Tested by

no test coverage detected