public static boolean moveUp(Spannable text,Layout layout){
  int start=getSelectionStart(text);
  int end=getSelectionEnd(text);
  if (start != end) {
    int min=Math.min(start,end);
    int max=Math.max(start,end);
    setSelection(text,min);
    if (min == 0 && max == text.length()) {
      return false;
    }
    return true;
  }
 else {
    int line=layout.getLineForOffset(end);
    if (line > 0) {
      int move;
      if (layout.getParagraphDirection(line) == layout.getParagraphDirection(line - 1)) {
        float h=layout.getPrimaryHorizontal(end);
        move=layout.getOffsetForHorizontal(line - 1,h);
      }
 else {
        move=layout.getLineStart(line - 1);
      }
      setSelection(text,move);
      return true;
    }
 else     if (end != 0) {
      setSelection(text,0);
      return true;
    }
  }
  return false;
}

public static boolean moveUp ( Spannable text , Layout layout ) { int start = getSelectionStart ( text ) ; int end = getSelectionEnd ( text ) ; if ( start != end ) { int min = Math . min ( start , end ) ; int max = Math . max ( start , end ) ; setSelection ( text , min ) ; if ( min == 0 && max == text . length ( ) ) { return false ; } return true ; } else { int line = layout . getLineForOffset ( end ) ; if ( line > 0 ) { int move ; if ( layout . getParagraphDirection ( line ) == layout . getParagraphDirection ( line - 1 ) ) { float h = layout . getPrimaryHorizontal ( end ) ; move = layout . getOffsetForHorizontal ( line - 1 , h ) ; } else { move = layout . getLineStart ( line - 1 ) ; } setSelection ( text , move ) ; return true ; } else if ( end != 0 ) { setSelection ( text , 0 ) ; return true ; } } return false ; }
move the cursor to the buffer offset physically above the current offset , to the beginning if it is on the top line but not at the start , or return false if the cursor is already on the top line .
