Пример #1
0
  public static Barrage parse(String jsonStr) {
    Barrage barrage = null;

    try {
      JSONObject object = JSON.parseObject(jsonStr);
      barrage = new Barrage();
      barrage.setContent(object.getString("barrage"));
      barrage.setPostTime(object.getString("posttime"));
      barrage.setVideoTime(object.getIntValue("videotime"));
      String colorStr = object.getString("color");
      barrage.setColor(colorStr);
    } catch (Exception e) {
      e.printStackTrace();
      Log.e(TAG, "get exception when parse, cause: " + e.getMessage());
    }

    return barrage;
  }
Пример #2
0
  /** @param colorStr rrrgggbbb */
  public void setColor(String colorStr) {
    colorStr = danmakuColors[new Random().nextInt(danmakuColors.length)];

    int b = 255;
    int g = 255;
    int r = 255;
    String colorBit = "";
    if (colorStr.length() == 9) {
      colorBit = colorStr.substring(0, 3);
      if (colorBit.equals("000")) {
        r = 0;
      } else {
        try {
          r = Integer.parseInt(colorBit);
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }
      }
      colorBit = colorStr.substring(3, 6);
      if (colorBit.equals("000")) {
        g = 0;
      } else {
        try {
          g = Integer.parseInt(colorBit);
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }
      }
      colorBit = colorStr.substring(6);
      if (colorBit.equals("000")) {
        b = 0;
      } else {
        try {
          b = Integer.parseInt(colorBit);
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }
      }
    } else if (colorStr.length() == 6) {
      r = 0;
      colorBit = colorStr.substring(0, 3);
      if (colorBit.equals("000")) {
        g = 0;
      } else {
        try {
          g = Integer.parseInt(colorBit);
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }
      }
      colorBit = colorStr.substring(3);
      if (colorBit.equals("000")) {
        b = 0;
      } else {
        try {
          b = Integer.parseInt(colorBit);
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }
      }
    } else if (colorStr.length() == 3) {
      r = g = 0;
      colorBit = colorStr;
      if (colorBit.equals("000")) {
        b = 0;
      } else {
        try {
          b = Integer.parseInt(colorBit);
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }
      }
    }

    int color = Color.rgb(r, g, b);
    setColor(color);
  }