コード例 #1
0
ファイル: Node.java プロジェクト: rajpalparyani/RajRepo
  public void setValueAt(long value, int index) {
    synchronized (this) {
      int oldSize = getValuesSize();
      for (int i = oldSize; i < index + 1; i++) {
        addValue(0);
      }

      int[] offset = new int[1];
      for (int i = 0; i < index; i++) {
        DataUtil.readOffset(valuesBuff, offset);
      }

      int startOffset = offset[0];
      DataUtil.readOffset(valuesBuff, offset);
      int endOffset = offset[0];

      checkValueBufferSize(value);
      int newValLength = DataUtil.getValueLength(value);
      int oldValLength = endOffset - startOffset;
      if (newValLength != oldValLength) {
        // need to move old values
        short delta = (short) (newValLength - oldValLength);
        int len = valuesBuffOffset - endOffset;
        System.arraycopy(valuesBuff, endOffset, valuesBuff, endOffset + delta, len);
        valuesBuffOffset = (short) (valuesBuffOffset + delta);
      }
      DataUtil.writeValue(valuesBuff, value, startOffset);
    }
  }
コード例 #2
0
ファイル: Node.java プロジェクト: rajpalparyani/RajRepo
  /* (non-Javadoc)
   * @see com.telenav.framework.data.INode#getValueAt(int)
   */
  public long getValueAt(int index) {
    if (index >= nValues) return 0;

    offsetValue[0] = 0;

    // int[] offset = new int[] { 0 };
    for (int i = 0; i < index; i++) {
      DataUtil.readOffset(valuesBuff, offsetValue);
    }
    return DataUtil.readValue(valuesBuff, offsetValue);
  }
コード例 #3
0
ファイル: Node.java プロジェクト: rajpalparyani/RajRepo
 /* (non-Javadoc)
  * @see com.telenav.framework.data.INode#addValue(long)
  */
 public void addValue(long value) {
   synchronized (this) {
     nValues++;
     checkValueBufferSize(value);
     valuesBuffOffset += DataUtil.writeValue(valuesBuff, value, valuesBuffOffset);
   }
 }
コード例 #4
0
ファイル: Node.java プロジェクト: rajpalparyani/RajRepo
 private void checkValueBufferSize(long value) {
   if (valuesBuff == null
       || valuesBuff.length < valuesBuffOffset + DataUtil.getValueLength(value)) {
     byte[] temp = new byte[valuesBuffOffset + 20];
     if (valuesBuff != null) {
       System.arraycopy(valuesBuff, 0, temp, 0, valuesBuffOffset);
     }
     valuesBuff = temp;
   }
 }
コード例 #5
0
ファイル: Node.java プロジェクト: rajpalparyani/RajRepo
 Node(byte[] binary, int startIndex) {
   if (binary.length >= startIndex + 4) {
     int headerCode = DataUtil.readInt(binary, startIndex);
     if (headerCode == HEADER_55) {
       fromByteArray55(binary, startIndex + 4, VERSION_55, null);
     } else if (headerCode == HEADER_551) {
       fromByteArray55(binary, startIndex + 4, VERSION_551, null);
     }
   }
 }
コード例 #6
0
ファイル: Node.java プロジェクト: rajpalparyani/RajRepo
  /* (non-Javadoc)
   * @see com.telenav.framework.data.INode#toBinary()
   */
  private byte[] toBinary55(int header, int ver) {
    int size = 0;
    if (ver == VERSION_55) {
      size = 1 + DataUtil.getValueLength(valuesBuffOffset) + valuesBuffOffset; // 1 byte for nValues
    } else if (ver == VERSION_551) {
      size =
          DataUtil.getValueLength(nValues)
              + DataUtil.getValueLength(valuesBuffOffset)
              + valuesBuffOffset;
    }

    //      int nMsgs = 0;

    /*
    if (nMsgs > 0)
    {
        if (msgsBuff == null)
        {
            msgsBuff = new byte[nMsgs][];
        }
        else if (msgsBuff.length < nMsgs)
        {
            byte[][] temp = new byte[nMsgs][];
            System.arraycopy(msgsBuff, 0, temp, 0, msgsBuff.length);
            msgsBuff = temp;
        }
    }
    */

    int len = 0;
    for (int i = 0; i < nMsgs; i++) {
      if (msgsBuff[i] != null) {
        len += (msgsBuff[i].length + DataUtil.getValueLength(msgsBuff[i].length));
      } else if (ver == VERSION_55) {
        len += DataUtil.getValueLength(0);
      } else if (ver == VERSION_551) {
        len += DataUtil.getValueLength(-1);
      }
    }

    size += (DataUtil.getValueLength(nMsgs) + len);

    len = 0;

    if (nChildren > 0) {
      if (childrenBuff == null) {
        childrenBuff = new byte[nChildren][];
      } else if (childrenBuff.length < nChildren) {
        byte[][] temp = new byte[nChildren][];
        System.arraycopy(childrenBuff, 0, temp, 0, childrenBuff.length);
        childrenBuff = temp;
      }
    }

    for (int i = 0; i < nChildren; i++) {
      if (children != null && children[i] != null) {
        childrenBuff[i] = children[i].toBinary55(-1, ver);
      }

      if (childrenBuff[i] != null) {
        len += (childrenBuff[i].length + DataUtil.getValueLength(childrenBuff[i].length));
      } else {
        len += (0 + DataUtil.getValueLength(0));
      }
    }

    size += (DataUtil.getValueLength(nChildren) + len);

    int binLen = 0;
    if (binData != null) {
      binLen = binData.length;
    }

    size += (DataUtil.getValueLength(binLen) + binLen);

    if (header == HEADER_55 || header == HEADER_551) size += 4;

    byte[] buff = new byte[size];

    int offset = 0;
    if (header == HEADER_55 || header == HEADER_551) {
      DataUtil.writeInt(buff, header, offset);
      offset += 4;
    }

    // do values

    if (ver == VERSION_55) {
      buff[offset++] = (byte) nValues;
    } else if (ver == VERSION_551) {
      offset += DataUtil.writeValue(buff, nValues, offset);
    }

    offset += DataUtil.writeValue(buff, valuesBuffOffset, offset);

    if (nValues > 0) {
      System.arraycopy(valuesBuff, 0, buff, offset, valuesBuffOffset);
      offset += valuesBuffOffset;
    }

    // do msgs
    offset += DataUtil.writeValue(buff, nMsgs, offset);
    for (int i = 0; i < nMsgs; i++) {
      if (msgsBuff[i] != null) {
        offset += DataUtil.writeValue(buff, msgsBuff[i].length, offset);
        System.arraycopy(msgsBuff[i], 0, buff, offset, msgsBuff[i].length);
        offset += msgsBuff[i].length;
      } else {
        if (ver == VERSION_55) {
          // 0 length indicate an empty string (relaxed protocol)
          offset += DataUtil.writeValue(buff, 0, offset);
        } else if (ver == VERSION_551) {
          // -1 length indicate a null string (to make it different from "" string)
          offset += DataUtil.writeValue(buff, -1, offset);
        }
      }
    }

    // do children
    offset += DataUtil.writeValue(buff, nChildren, offset);
    for (int i = 0; i < nChildren; i++) {
      if (childrenBuff[i] != null) {
        offset += DataUtil.writeValue(buff, childrenBuff[i].length, offset);
        System.arraycopy(childrenBuff[i], 0, buff, offset, childrenBuff[i].length);
        offset += childrenBuff[i].length;
      } else {
        offset += DataUtil.writeValue(buff, 0, offset);
      }
    }

    // do binData
    offset += DataUtil.writeValue(buff, binLen, offset);
    if (binData != null) {
      System.arraycopy(binData, 0, buff, offset, binData.length);
      offset += binData.length;
    }

    //      System.out.println(buff.length+" == "+offset);

    return buff;
  }
コード例 #7
0
ファイル: Node.java プロジェクト: rajpalparyani/RajRepo
  private void fromByteArray55(byte[] buff, int offsetInt, int ver, Node parent) {
    setVersion(ver);
    this.parent = parent;

    if (buff == null || buff.length == 0) return;

    int[] offset = new int[] {1};
    offset[0] = offsetInt;
    if (ver == VERSION_55) {
      this.nValues = buff[offset[0]++];
    } else if (ver == VERSION_551) {
      this.nValues = (short) DataUtil.readValue(buff, offset);
    }

    this.valuesBuffOffset = (short) DataUtil.readValue(buff, offset);

    //      System.out.println("TxNode55 - nValues: "+node.nValues);
    //      System.out.println("valuesBuffOffset: "+node.valuesBuffOffset);

    if (this.nValues > 0) {
      this.valuesBuff = new byte[this.valuesBuffOffset];
      System.arraycopy(buff, offset[0], this.valuesBuff, 0, this.valuesBuffOffset);
    }
    offset[0] += this.valuesBuffOffset;

    // do msgs
    this.nMsgs = (short) DataUtil.readValue(buff, offset);

    this.msgsBuff = new byte[this.nMsgs][];

    for (int i = 0; i < this.nMsgs; i++) {
      int msgLen = (int) DataUtil.readValue(buff, offset);
      if (msgLen != -1) {
        this.msgsBuff[i] = new byte[msgLen];
        System.arraycopy(buff, offset[0], this.msgsBuff[i], 0, msgLen);
        offset[0] += msgLen;
      }
    }

    // do children
    this.nChildren = (short) DataUtil.readValue(buff, offset);

    //      System.out.println("nChildren: "+nChildren);

    this.childrenBuff = new byte[this.nChildren][];

    for (int i = 0; i < this.nChildren; i++) {
      int childLen = (int) DataUtil.readValue(buff, offset);
      if (childLen > 0) {
        if (childLen + offset[0] > buff.length) {
          throw new IllegalArgumentException(
              "Bad data buffer for TxNode55: specified length is "
                  + childLen
                  + ", actually have just "
                  + (buff.length - offset[0])
                  + " bytes left.");
        }

        this.childrenBuff[i] = new byte[childLen];
        System.arraycopy(buff, offset[0], this.childrenBuff[i], 0, childLen);
        offset[0] += childLen;
      }
    }

    // do binData
    int binLen = (int) DataUtil.readValue(buff, offset);

    //      System.out.println("binLen: "+binLen);

    if (binLen > 0) {
      this.binData = new byte[binLen];
      if (offset[0] < 0 || offset[0] + binLen > buff.length) {
        throw new ArrayIndexOutOfBoundsException(
            "Bad index: "
                + "buff size="
                + buff.length
                + ", offset="
                + offset[0]
                + "/"
                + offsetInt
                + ", length="
                + binLen);
      }
      System.arraycopy(buff, offset[0], this.binData, 0, binLen);
    }
  }
コード例 #8
0
  public void updateSpeedLimit(boolean isSpeedLimitExceeded, int speedLimit) {
    Preference speedLimits =
        ((DaoManager) DaoManager.getInstance())
            .getPreferenceDao()
            .getPreference(Preference.ID_PREFERENCE_SPEED_LIMITS);
    isDisabled = speedLimits != null && speedLimits.getIntValue() == Preference.SPEED_LIMIT_OFF;

    int speedLimitFeature =
        FeaturesManager.getInstance().getStatus(FeaturesManager.FEATURE_CODE_NAV_SPEED_LIMIT);
    boolean isEnabled =
        speedLimitFeature == FeaturesManager.FE_ENABLED
            || speedLimitFeature == FeaturesManager.FE_PURCHASED;
    isDisabled = isDisabled || !isEnabled;
    int routeStyle =
        DaoManager.getInstance().getTripsDao().getIntValue(Preference.ID_PREFERENCE_ROUTETYPE);
    boolean isInPedestrian = routeStyle == Route.ROUTE_PEDESTRIAN ? true : false;
    isDisabled = isDisabled || isInPedestrian;
    if (isDisabled) {
      NavBottomStatusBarHelper.getInstance().setIsOverSpeedLimit(false);
      requestPaint();
      return;
    }

    Preference preference =
        ((DaoManager) DaoManager.getInstance())
            .getPreferenceDao()
            .getPreference(Preference.ID_PREFERENCE_DISTANCEUNIT);

    if (preference != null && preference.getIntValue() == Preference.UNIT_USCUSTOM) {
      // mph
      currentSpeedLimit = DataUtil.kmToMileInHighAccuracy(speedLimit);
      // currentUnit = "MPH";
      currentUnit =
          ResourceManager.getInstance()
              .getCurrentBundle()
              .getString(IStringNav.RES_SPEED_LIMIT, IStringNav.FAMILY_NAV);
    } else {
      // kph
      currentSpeedLimit = speedLimit;
      // currentUnit = "KPH";
      currentUnit =
          ResourceManager.getInstance()
              .getCurrentBundle()
              .getString(IStringNav.RES_SPEED_LIMIT, IStringNav.FAMILY_NAV);
    }

    if (speedLimit <= 0) {
      speedStr = "---";
      unitStr = currentUnit;
      NavBottomStatusBarHelper.getInstance().setIsOverSpeedLimit(false);
      requestPaint();
      return;
    }

    if (isSpeedLimitExceeded) {
      NavBottomStatusBarHelper.getInstance().setIsOverSpeedLimit(true);
    } else {
      NavBottomStatusBarHelper.getInstance().setIsOverSpeedLimit(false);
    }

    speedStr = currentSpeedLimit + "";
    unitStr = currentUnit;

    requestPaint();
  }