Exemple #1
0
 @Test
 public void testGetID() throws SQLException {
   int id = UserData.getId("lulz");
   assertTrue(id == -1);
   id = UserData.getId("");
   assertTrue(id == -1);
 }
  public synchronized void onNewFrame(UserTracker tracker) {
    if (mLastFrame != null) {
      mLastFrame.release();
      mLastFrame = null;
    }

    mLastFrame = mTracker.readFrame();

    // check if any new user detected
    for (UserData user : mLastFrame.getUsers()) {
      if (user.isNew()) {
        // start skeleton tracking
        mTracker.startSkeletonTracking(user.getId());
      }
    }

    VideoFrameRef depthFrame = mLastFrame.getDepthFrame();

    if (depthFrame != null) {
      ByteBuffer frameData = depthFrame.getData().order(ByteOrder.LITTLE_ENDIAN);
      ByteBuffer usersFrame = mLastFrame.getUserMap().getPixels().order(ByteOrder.LITTLE_ENDIAN);

      // make sure we have enough room
      if (mDepthPixels == null
          || mDepthPixels.length < depthFrame.getWidth() * depthFrame.getHeight()) {
        mDepthPixels = new int[depthFrame.getWidth() * depthFrame.getHeight()];
      }

      calcHist(frameData);
      frameData.rewind();

      int pos = 0;
      while (frameData.remaining() > 0) {
        short depth = frameData.getShort();
        short userId = usersFrame.getShort();
        short pixel = (short) mHistogram[depth];
        int color = 0xFFFFFFFF;
        if (userId > 0) {
          color = mColors[userId % mColors.length];
        }

        mDepthPixels[pos] = color & (0xFF000000 | (pixel << 16) | (pixel << 8) | pixel);
        pos++;
      }
    }

    repaint();
  }
  private void drawLimb(Graphics g, int x, int y, UserData user, JointType from, JointType to) {
    com.primesense.nite.SkeletonJoint fromJoint = user.getSkeleton().getJoint(from);
    com.primesense.nite.SkeletonJoint toJoint = user.getSkeleton().getJoint(to);

    if (fromJoint.getPositionConfidence() == 0.0 || toJoint.getPositionConfidence() == 0.0) {
      return;
    }

    com.primesense.nite.Point2D<Float> fromPos =
        mTracker.convertJointCoordinatesToDepth(fromJoint.getPosition());
    com.primesense.nite.Point2D<Float> toPos =
        mTracker.convertJointCoordinatesToDepth(toJoint.getPosition());

    // draw it in another color than the use color
    g.setColor(new Color(mColors[(user.getId() + 1) % mColors.length]));
    g.drawLine(
        x + fromPos.getX().intValue(),
        y + fromPos.getY().intValue(),
        x + toPos.getX().intValue(),
        y + toPos.getY().intValue());
  }
  /**
   * Add a single user to the list.
   *
   * @param user The user to add
   */
  private void addUser(UserData user) {
    userCnt++;

    LayoutInflater inflater = getLayoutInflater();
    View userView = inflater.inflate(R.layout.user_profile, list, false);

    TextView name = (TextView) userView.findViewById(R.id.user_name);
    name.setText(user.getUserName());

    TextView age = (TextView) userView.findViewById(R.id.user_age);
    age.setText(user.getAge());

    TextView city = (TextView) userView.findViewById(R.id.user_city);
    city.setText(user.getCity());

    TextView stateCountry = (TextView) userView.findViewById(R.id.user_state_country);
    stateCountry.setText(user.getState() + ", " + user.getCountry());

    Bitmap profilePic = user.getProfilePic();
    if (profilePic != null) {
      ImageView profile = (ImageView) userView.findViewById(R.id.user_profilepic);
      profile.setImageBitmap(profilePic);
    }

    String note = user.getNote();
    if (note != null && note.length() > 0) {
      Button noteButton = (Button) userView.findViewById(R.id.btn_note);
      noteButton.setVisibility(View.VISIBLE);
      noteButton.setOnClickListener(new NoteClicker(note));
    }

    userView.setOnClickListener(new ProfileClicker(user.getId()));
    userView.setTag(user);

    list.addView(userView);
  }