void Engine::EnableUI()

in NearbyConnectionsCpp/app/src/main/cpp/NearbyNativeActivity.cpp [307:342]


void Engine::EnableUI(bool enable) {
  LOGI("Updating UI:%d", enable);
  ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, enable]() {
    ui_buttons_[BUTTON_ADVERTISE]->SetAttribute(
        "Enabled",
        enable && !(nbc_state_ & nearby_connection_state::ADVERTISING));
    ui_buttons_[BUTTON_DISCOVER]->SetAttribute(
        "Enabled",
        enable && !(nbc_state_ & nearby_connection_state::DISCOVERING));
    ui_buttons_[BUTTON_PLAY_GAME]->SetAttribute(
        "Enabled", enable && (nbc_state_ & nearby_connection_state::CONNECTED));
    /*
     * For experimental purpose, Stop button is always enabled
     */
    ui_buttons_[BUTTON_STOP]->SetAttribute("Enabled", true);

    std::string str;
    str += "Nearby Connection Status: Connected Clients = ";
    str += std::to_string(CountConnections());
    str += "; ";
    if (nbc_state_ & nearby_connection_state::IDLE) {
      str += "Currently Idle; ";
    }
    if (nbc_state_ & nearby_connection_state::ADVERTISING) {
      str += "In Advertising; ";
    }
    if (nbc_state_ & nearby_connection_state::DISCOVERING) {
      str += "In Discovering; ";
    }
    if (nbc_state_ & nearby_connection_state::FAILED) {
      str += "FAILED; ";
    }
    str = str.substr(0, str.size() - 2);
    status_text_->SetAttribute("Text", const_cast<const char *>(str.c_str()));
  });
}