/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2013 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU General Public License, as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any
 * later version. Please see the file LICENSE-GPL for details.
 *
 * Web Page: http://mielke.cc/brltty/
 *
 * This software is maintained by Dave Mielke <dave@mielke.cc>.
 */

package org.a11y.brltty.android;

import java.util.Map;
import java.util.HashMap;

import android.view.accessibility.AccessibilityNodeInfo;

import android.graphics.Rect;

public class ScreenWindow {
  public class TextEntry {
    private int cursorOffset = 0;

    public final int getCursorOffset () {
      return cursorOffset;
    }

    public final void setCursorOffset (int offset) {
      cursorOffset = offset;
    }

    public TextEntry () {
    }
  }

  private final int windowIdentifier;

  private final Map<Rect, TextEntry> textEntries = new HashMap<Rect, TextEntry>();

  public final int getWindowIdentifier () {
    return windowIdentifier;
  }

  public TextEntry getTextEntry (AccessibilityNodeInfo node, boolean canCreate) {
    Rect key = new Rect();
    node.getBoundsInScreen(key);
    TextEntry textEntry = textEntries.get(key);

    if (textEntry == null) {
      if (canCreate) {
        textEntry = new TextEntry();
        textEntries.put(key, textEntry);
      }
    }

    return textEntry;
  }

  public ScreenWindow (int identifier) {
    windowIdentifier = identifier;
  }
}

@@ -777,39 +777,8 @@
 o;%0A%0A
-import android.graphics.Rect;%0A%0A
 publ
@@ -1120,28 +1120,31 @@
 e final Map%3C
-Rect
+Integer
 , TextEntry%3E
@@ -1170,20 +1170,23 @@
 HashMap%3C
-Rect
+Integer
 , TextEn
@@ -1358,20 +1358,23 @@
 ) %7B%0A    
-Rect
+Integer
  key = n
@@ -1380,46 +1380,31 @@
 new 
-Rect();%0A    node.getBoundsInScreen(key
+Integer(node.hashCode()
 );%0A 
@@ -1416,25 +1416,21 @@
 xtEntry 
-textEntry
+value
  = textE
@@ -1455,25 +1455,21 @@
     if (
-textEntry
+value
  == null
@@ -1503,25 +1503,21 @@
         
-textEntry
+value
  = new T
@@ -1557,25 +1557,21 @@
 ut(key, 
-textEntry
+value
 );%0A     
@@ -1595,17 +1595,13 @@
 urn 
-textEntry
+value
 ;%0A  

Use a more accurate way to associate an accessibility node with a text editor. (dm)