Example #1
0
  /**
   * @param str
   * @param scale
   * @param gapBetweenLetter
   * @return ArrayList of float[] {x1, y1, x2, y2}
   */
  public static ArrayList<float[]> getPath(String str, float scale, int gapBetweenLetter) {
    ArrayList<float[]> list = new ArrayList<float[]>();
    float offsetForWidth = 0;
    for (int i = 0; i < str.length(); i++) {
      int pos = str.charAt(i);
      int key = sPointList.indexOfKey(pos);
      if (key == -1) {
        continue;
      }
      float[] points = sPointList.get(pos);
      int pointCount = points.length / 4;

      for (int j = 0; j < pointCount; j++) {
        float[] line = new float[4];
        for (int k = 0; k < 4; k++) {
          float l = points[j * 4 + k];
          // x
          if (k % 2 == 0) {
            line[k] = (l + offsetForWidth) * scale;
          }
          // y
          else {
            line[k] = l * scale;
          }
        }
        list.add(line);
      }
      offsetForWidth += 57 + gapBetweenLetter;
    }
    return list;
  }
Example #2
0
  public int measureTextHeight(int resource_id) {
    if (bitmap_buffer.indexOfKey(resource_id) >= 0) {
      Quad temp = bitmap_buffer.get(resource_id);
      return temp.height;
    }

    return 0;
  }
Example #3
0
  // return the size of a section of text in screen coords
  public int measureTextWidth(int resource_id) {
    if (bitmap_buffer.indexOfKey(resource_id) >= 0) {
      Quad temp = bitmap_buffer.get(resource_id);
      return temp.width;
    }

    return 0;
  }
  public static Typeface getTypeface(Context context, int typeface) {
    synchronized (typefacesCache) {
      if (typefacesCache.indexOfKey(typeface) < 0) {
        typefacesCache.put(typeface, FactoryTypeface.createTypeface(context, typeface));
      }

      return typefacesCache.get(typeface);
    }
  }
 /**
  * Returns the next available user id, filling in any holes in the ids. TODO: May not be a good
  * idea to recycle ids, in case it results in confusion for data and battery stats collection, or
  * unexpected cross-talk.
  *
  * @return
  */
 private int getNextAvailableIdLocked() {
   synchronized (mPackagesLock) {
     int i = MIN_USER_ID;
     while (i < Integer.MAX_VALUE) {
       if (mUsers.indexOfKey(i) < 0 && !mRemovingUserIds.get(i)) {
         break;
       }
       i++;
     }
     return i;
   }
 }
Example #6
0
  public void drawText(
      int resource_value, double x, double y, EnumDrawFrom where, int color, double degree) {
    if (color == Color.TRANSPARENT) return;

    if (bitmap_buffer.indexOfKey(resource_value) >= 0) {
      // optimize the gets
      Quad temp = bitmap_buffer.get(resource_value);

      if (temp.degree != degree) temp.setRotationZ(degree);
      temp.setXYPos(x, y, where);

      // draw pretty!
      temp.color = color;
      temp.onDrawAmbient(Constants.my_ip_matrix, true);
    }
  }
Example #7
0
  public Key getKey(final int code) {
    if (code == Constants.CODE_UNSPECIFIED) {
      return null;
    }
    synchronized (mKeyCache) {
      final int index = mKeyCache.indexOfKey(code);
      if (index >= 0) {
        return mKeyCache.valueAt(index);
      }

      for (final Key key : getKeys()) {
        if (key.getCode() == code) {
          mKeyCache.put(code, key);
          return key;
        }
      }
      mKeyCache.put(code, null);
      return null;
    }
  }
 @Override
 public long getItemId(final int position) {
   return isSectionHeaderPosition(position)
       ? Integer.MAX_VALUE - mSections.indexOfKey(position)
       : mBaseAdapter.getItemId(sectionedPositionToPosition(position));
 }
Example #9
0
 public int indexOfKey(Object key) {
   return mArray.indexOfKey(key.hashCode());
 }
Example #10
0
 public boolean containsKey(Object key) {
   return mArray.indexOfKey(key.hashCode()) >= 0;
 }
  public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
    int selStart, selEnd;
    int pref = 0;

    if (view != null) {
      pref = TextKeyListener.getInstance().getPrefs(view.getContext());
    }

    {
      int a = Selection.getSelectionStart(content);
      int b = Selection.getSelectionEnd(content);

      selStart = Math.min(a, b);
      selEnd = Math.max(a, b);
    }

    int activeStart = content.getSpanStart(TextKeyListener.ACTIVE);
    int activeEnd = content.getSpanEnd(TextKeyListener.ACTIVE);

    // now for the multitap cases...

    // Try to increment the character we were working on before
    // if we have one and it's still the same key.

    int rec =
        (content.getSpanFlags(TextKeyListener.ACTIVE) & Spannable.SPAN_USER)
            >>> Spannable.SPAN_USER_SHIFT;

    if (activeStart == selStart
        && activeEnd == selEnd
        && selEnd - selStart == 1
        && rec >= 0
        && rec < sRecs.size()) {
      if (keyCode == KeyEvent.KEYCODE_STAR) {
        char current = content.charAt(selStart);

        if (Character.isLowerCase(current)) {
          content.replace(selStart, selEnd, String.valueOf(current).toUpperCase());
          removeTimeouts(content);
          new Timeout(content); // for its side effects

          return true;
        }
        if (Character.isUpperCase(current)) {
          content.replace(selStart, selEnd, String.valueOf(current).toLowerCase());
          removeTimeouts(content);
          new Timeout(content); // for its side effects

          return true;
        }
      }

      if (sRecs.indexOfKey(keyCode) == rec) {
        String val = sRecs.valueAt(rec);
        char ch = content.charAt(selStart);
        int ix = val.indexOf(ch);

        if (ix >= 0) {
          ix = (ix + 1) % (val.length());

          content.replace(selStart, selEnd, val, ix, ix + 1);
          removeTimeouts(content);
          new Timeout(content); // for its side effects

          return true;
        }
      }

      // Is this key one we know about at all?  If so, acknowledge
      // that the selection is our fault but the key has changed
      // or the text no longer matches, so move the selection over
      // so that it inserts instead of replaces.

      rec = sRecs.indexOfKey(keyCode);

      if (rec >= 0) {
        Selection.setSelection(content, selEnd, selEnd);
        selStart = selEnd;
      }
    } else {
      rec = sRecs.indexOfKey(keyCode);
    }

    if (rec >= 0) {
      // We have a valid key.  Replace the selection or insertion point
      // with the first character for that key, and remember what
      // record it came from for next time.

      String val = sRecs.valueAt(rec);

      int off = 0;
      if ((pref & TextKeyListener.AUTO_CAP) != 0
          && TextKeyListener.shouldCap(mCapitalize, content, selStart)) {
        for (int i = 0; i < val.length(); i++) {
          if (Character.isUpperCase(val.charAt(i))) {
            off = i;
            break;
          }
        }
      }

      if (selStart != selEnd) {
        Selection.setSelection(content, selEnd);
      }

      content.setSpan(OLD_SEL_START, selStart, selStart, Spannable.SPAN_MARK_MARK);

      content.replace(selStart, selEnd, val, off, off + 1);

      int oldStart = content.getSpanStart(OLD_SEL_START);
      selEnd = Selection.getSelectionEnd(content);

      if (selEnd != oldStart) {
        Selection.setSelection(content, oldStart, selEnd);

        content.setSpan(
            TextKeyListener.LAST_TYPED, oldStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        content.setSpan(
            TextKeyListener.ACTIVE,
            oldStart,
            selEnd,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE | (rec << Spannable.SPAN_USER_SHIFT));
      }

      removeTimeouts(content);
      new Timeout(content); // for its side effects

      // Set up the callback so we can remove the timeout if the
      // cursor moves.

      if (content.getSpanStart(this) < 0) {
        KeyListener[] methods = content.getSpans(0, content.length(), KeyListener.class);
        for (Object method : methods) {
          content.removeSpan(method);
        }
        content.setSpan(this, 0, content.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
      }

      return true;
    }

    return super.onKeyDown(view, content, keyCode, event);
  }
Example #12
0
 public final boolean hasUser(final User user) {
   return visibleUserNames.indexOfKey(user.session) < 0;
 }
Example #13
0
 /**
  * Checks if is record present.
  *
  * @param record the record
  * @return true, if is record present
  */
 public boolean isRecordPresent(final int record) {
   return mAdRecords.indexOfKey(record) >= 0;
 }