Example #1
0
 protected boolean onBeginListeningQuery(BeginListeningQuery query) {
   NullCheck.notNull(query, "query");
   final int index = selectedIndex();
   if (index < 0) return false;
   final int count = model.getItemCount();
   if (index >= count) return false;
   final Object current = model.getItem(index);
   final String text =
       appearance
           .getScreenAppearance(current, NONE_APPEARANCE_FLAGS)
           .substring(hotPointX, appearance.getObservableRightBound(current));
   //	Log.debug("listen", appearance.getScreenAppearance(current, NONE_APPEARANCE_FLAGS));
   //	Log.debug("listen", "" + hotPointX);
   if (text.isEmpty() && index + 1 >= count) return false;
   if (index + 1 < count) {
     final Object next = model.getItem(index + 1);
     query.answer(
         new BeginListeningQuery.Answer(
             text, new ListeningInfo(index + 1, appearance.getObservableLeftBound(next))));
   } else
     query.answer(
         new BeginListeningQuery.Answer(
             text, new ListeningInfo(index, appearance.getObservableRightBound(current))));
   return true;
 }
Example #2
0
 private boolean onAltLeft(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   if (item == null) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   if (line.isEmpty()) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final int leftBound = appearance.getObservableLeftBound(item);
   final int rightBound = appearance.getObservableRightBound(item);
   if (hotPointX <= leftBound) {
     environment.hint(Hints.BEGIN_OF_LINE);
     return true;
   }
   final String subline = line.substring(leftBound, rightBound);
   final WordIterator it = new WordIterator(subline, hotPointX - leftBound);
   if (!it.stepBackward()) {
     environment.hint(Hints.BEGIN_OF_LINE);
     return true;
   }
   hotPointX = it.pos() + leftBound;
   environment.say(it.announce());
   environment.onAreaNewHotPoint(this);
   return true;
 }
Example #3
0
 protected boolean onChar(KeyboardEvent event) {
   if (noContent()) return true;
   final int count = model.getItemCount();
   final char c = event.getChar();
   final String beginning;
   if (selected() != null) {
     if (hotPointX >= appearance.getObservableRightBound(selected())) return false;
     final String name = getObservableSubstr(selected());
     final int pos =
         Math.min(hotPointX - appearance.getObservableLeftBound(selected()), name.length());
     if (pos < 0) return false;
     beginning = name.substring(0, pos);
   } else beginning = "";
   Log.debug("list", "beginning:" + beginning);
   final String mustBegin = beginning + c;
   for (int i = 0; i < count; ++i) {
     Log.debug("list", "checking:" + i);
     final String name = getObservableSubstr(model.getItem(i));
     Log.debug("list", "name:" + name);
     if (!name.startsWith(mustBegin)) continue;
     hotPointY = getLineIndexByItemIndex(i);
     Log.debug("list", "hotPointY:" + hotPointY);
     ++hotPointX;
     appearance.announceItem(model.getItem(hotPointY), NONE_APPEARANCE_FLAGS);
     environment.onAreaNewHotPoint(this);
     return true;
   }
   return false;
 }
Example #4
0
 protected boolean onMoveHotPoint(MoveHotPointEvent event) {
   NullCheck.notNull(event, "event");
   final int x = event.getNewHotPointX();
   final int y = event.getNewHotPointY();
   final int newY;
   if (y >= getLineCount()) {
     if (event.precisely()) return false;
     newY = getLineCount() - 1;
   } else newY = y;
   if (getItemIndexOnLine(newY) >= 0) {
     // Line with item, not empty
     final Object item = model.getItem(getItemIndexOnLine(newY));
     final int leftBound = appearance.getObservableLeftBound(item);
     final int rightBound = appearance.getObservableRightBound(item);
     if (event.precisely() && (x < leftBound || x > rightBound)) return false;
     hotPointY = newY;
     hotPointX = x;
     if (hotPointX < leftBound) hotPointX = leftBound;
     if (hotPointX > rightBound) hotPointX = rightBound;
     environment.onAreaNewHotPoint(this);
     return true;
   }
   // On empty line
   hotPointY = newY;
   hotPointX = 0;
   environment.onAreaNewHotPoint(this);
   return true;
 }
Example #5
0
 protected String getObservableSubstr(Object item) {
   NullCheck.notNull(item, "item");
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   if (line.isEmpty()) return "";
   final int leftBound = Math.min(appearance.getObservableLeftBound(item), line.length());
   final int rightBound = Math.min(appearance.getObservableRightBound(item), line.length());
   if (leftBound >= rightBound) return "";
   return line.substring(leftBound, rightBound);
 }
Example #6
0
 private boolean onAltHome(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   NullCheck.notNull(item, "item");
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   hotPointX = appearance.getObservableLeftBound(item);
   announceChar(line, hotPointX, appearance.getObservableRightBound(item));
   environment.onAreaNewHotPoint(this);
   return true;
 }
Example #7
0
 private boolean onAltEnd(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   if (item == null) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   hotPointX = appearance.getObservableRightBound(item);
   environment.hint(Hints.END_OF_LINE);
   environment.onAreaNewHotPoint(this);
   return true;
 }
Example #8
0
 protected boolean onListeningFinishedEvent(ListeningFinishedEvent event) {
   NullCheck.notNull(event, "event");
   if (!(event.getExtraInfo() instanceof ListeningInfo)) return false;
   final ListeningInfo info = (ListeningInfo) event.getExtraInfo();
   final int count = model.getItemCount();
   if (info.itemIndex >= count) return false;
   final Object item = model.getItem(info.itemIndex);
   final int leftBound = appearance.getObservableLeftBound(item);
   final int rightBound = appearance.getObservableRightBound(item);
   if (info.pos < leftBound || info.pos > rightBound) return false;
   hotPointY = getLineIndexByItemIndex(info.itemIndex);
   hotPointX = info.pos;
   environment.onAreaNewHotPoint(this);
   return true;
 }
Example #9
0
 protected boolean onArrowRight(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   NullCheck.notNull(item, "item");
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   if (line.isEmpty()) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final int rightBound = appearance.getObservableRightBound(item);
   if (hotPointX >= rightBound) {
     environment.hint(Hints.END_OF_LINE);
     return true;
   }
   ++hotPointX;
   announceChar(line, hotPointX, rightBound);
   environment.onAreaNewHotPoint(this);
   return true;
 }