private void displayButtons() {

    boolean ButtonsPresentFlag = false;
    LinearLayout layout = (LinearLayout) findViewById(R.id.activeCodesButtonLayout);
    if (buttonList != null) {

      String codeString = getCodeString(ACTIVE_CODES_SET);
      if (codeString != null) {
        // displayLog("Code String not null");
        GetLocationFromServer getLocationFromServer = new GetLocationFromServer();
        getLocationFromServer.getLocation(codeString);

        for (ButtonObjectForReceive buttonObject : buttonList) {
          displayLog("iterating button list");
          buttonObject.getButton().setVisibility(View.GONE);
          long remainingTime =
              buttonObject.getUnixStartTime() + buttonObject.getDuration() - getUnixTime();
          if (buttonObject.getStatus() == 1) {

            if (remainingTime > 0) {

              displayLog("updating location for" + buttonObject.getButton().getText());
              layout.setVisibility(View.VISIBLE);
              ButtonsPresentFlag = true;

              buttonObject.getButton().setVisibility(View.VISIBLE);

              String name = buttonObject.getName();
              buttonObject.getButton().setText(name);

              double lat = buttonObject.getLatitude();
              double lng = buttonObject.getLongitude();

              double previousLat = buttonObject.getPreviousLatitude();
              double previousLng = buttonObject.getPreviousLongitude();
              //  displayLog("Setting new marker for " + buttonObject.getButton().getText() + "  at:
              // " + String.valueOf(lat) + "  ,  " + String.valueOf(lng));

              String title;

              displayLog("Gonna start showing marker");
              if (buttonObject.getStopFlag() == 1) {

                displayLog("Inside if");
                // Change the marker status to inactive to notify the user.
                if (buttonObject.isIdleToActive()) {
                  buttonObject.setIdleToActiveFlag(false);
                  if (buttonObject.getMarker() != null) {
                    buttonObject.getMarker().setTitle(buttonObject.getName() + ": Inactive");
                    buttonObject.getMarker().showInfoWindow();
                  }
                }
                title = buttonObject.getName() + ": Inactive";
                buttonObject.getButton().setBackgroundResource(R.drawable.user_button_white);
                buttonObject.getButton().setTextColor(0xFFCCCCCC);
              } else {
                displayLog("Inside else");
                // User is active
                if (buttonObject.isIdleToActive()) {
                  buttonObject.setIdleToActiveFlag(false);
                  if (buttonObject.getMarker() != null) {
                    buttonObject.getMarker().setTitle(buttonObject.getName() + ": Active");
                    buttonObject.getMarker().showInfoWindow();
                  }
                }
                title = buttonObject.getName() + ": Active";
                buttonObject.getButton().setBackgroundResource(R.drawable.user_button_white);
                buttonObject.getButton().setTextColor(0xFF428f89);
              }

              buttonObject.setMarker(setMarker(buttonObject.getMarker(), lat, lng, title));
              if (buttonObject.getFocusCount() == FOCUS_COUNT) {
                gotoLocation(lat, lng, mMap.getCameraPosition().zoom);
                if (buttonObject.getStopFlag() != 1) {
                  buttonObject.getButton().setBackgroundResource(R.drawable.user_button);
                  buttonObject.getButton().setTextColor(0xFF428f89);
                }
              }

              if (previousLat != 0) {
                drawLine(previousLat, previousLng, lat, lng, 0xff64B5F6, 20);
                drawLine(previousLat, previousLng, lat, lng, 0xff2196F3, 10);
              }

            } else if (((getUnixTime() - buttonObject.getUnixStartTime()) / (3600)) >= 24) {
              displayToast("Removing expired dead code " + buttonObject.getCode());
              displayLog("Removing dead code after 24 hours");
              removeCode(buttonObject.getCode());

            } else {
              removeMarker(buttonObject.getMarker());
            }
          }
        }
      }
    }
    if (ButtonsPresentFlag == false) {
      layout.setVisibility(View.GONE);
    }
  }
  private void initialiseButtonList() {

    displayLog("initialiseActiveCodes");
    LinearLayout layout = (LinearLayout) findViewById(R.id.activeCodesButtonLayout);
    layout.setBackgroundColor(Color.GRAY);
    layout.removeAllViews();
    mMap.clear();
    currentLocationMarker = null;
    String codeString = getCodeString(ACTIVE_CODES_SET);
    if (codeString != null) {

      // Create a list of button for active codes
      buttonList = new ArrayList<ButtonObjectForReceive>();
      final String[] codeStringArray = codeString.split("_");
      for (int i = 0; i < codeStringArray.length; i++) {
        // We need a list of buttons but buttons has more information to it. So we are using a class
        // that contains button, code, lat and lng.
        Button button = new Button(this);
        final String code = codeStringArray[i];
        final ButtonObjectForReceive buttonObjectForReceive =
            new ButtonObjectForReceive("User " + String.valueOf(i + 1), code, button);
        buttonObjectForReceive.setLineColor(colorArray[i % colorArray.length]);
        button.setId(i);
        button.setText("User " + String.valueOf(i + 1));
        LinearLayout.LayoutParams layoutParams =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
        layoutParams.weight = 1;
        layoutParams.setMargins(4, 2, 4, 2);
        // layoutParams
        button.setLayoutParams(layoutParams);

        //  button.setBackgroundColor(colorArray[i % colorArray.length]);
        buttonObjectForReceive
            .getButton()
            .setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    FOCUS_COUNT++;
                    buttonObjectForReceive.setFocusCount(FOCUS_COUNT);
                    buttonObjectForReceive.getMarker().showInfoWindow();
                    gotoLocation(
                        buttonObjectForReceive.getLatitude(),
                        buttonObjectForReceive.getLongitude(),
                        mMap.getCameraPosition().zoom);
                  }
                });

        buttonObjectForReceive.getButton().setLongClickable(true);
        buttonObjectForReceive
            .getButton()
            .setOnLongClickListener(
                new View.OnLongClickListener() {
                  @Override
                  public boolean onLongClick(View v) {

                    confirmationDialogBoxForCodeStringDelete(
                        buttonObjectForReceive.getName(),
                        buttonObjectForReceive.getCode(),
                        buttonObjectForReceive.getMarker());
                    // removeCode(code);
                    ;
                    return false;
                  }
                });

        layout.addView(buttonObjectForReceive.getButton());
        buttonList.add(i, buttonObjectForReceive);
      }
      displayToastPublished("Click on the username to see his location.");
      displayToastPublished("Click on the username to see his location.");
    }

    initialiseButtonCount = 10;
  }