Esempio n. 1
0
int main(int argc, char **argv)
{
  struct stat sbuf;
  const char *fname = "test.jpg";
  FlowImage image("image");
  if (stat(fname, &sbuf))
    toast("stat error");
  printf("file has %d bytes.\n", sbuf.st_size);
  if (sbuf.st_size <= 0)
    toast("file has zero size.\n");
  image.set_data_size(sbuf.st_size);
  FILE *f = fopen(fname, "rb");
  int num_read = fread(image.data, 1, sbuf.st_size, f);
  if (num_read != sbuf.st_size)
    toast("couldn't read entire file\n");
  printf("read %d bytes\n", num_read);
  image.compression = "jpeg";
  image.colorspace = "rgb24";
  image.width = 200;
  image.height = 153;
  ImageCodec<FlowImage> codec(&image);
  uint8_t *raster;
  if (!(raster = codec.get_raster()))
    printf("couldn't get raster\n");
  else
  {
    printf("got raster of %d bytes\n", codec.get_raster_size());
    codec.write_file("out.ppm");
    codec.write_file("out.jpg", 5);
  }

  return 0;
}
Esempio n. 2
0
std::string md5hash(const std::string &text, U32 thing)
{
	char temp[MD5HEX_STR_SIZE];
	LLMD5 toast((const U8*)text.c_str(), thing);
	toast.hex_digest(temp);
	return std::string(temp);
}
/*
 * Show toast when completing quest
 */
void Engine::CompleteQuest(gpg::Quest quest)
{
  ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([quest]() {
    std::string str = std::string("Quest completed:");
    str += quest.Name();
    jui_helper::JUIToast toast(str.c_str());
    toast.Show();
  });
}
Esempio n. 4
0
bool BeatQuestScene::dealFriendHit(BeatNode* node)
{
    bool shouldDelete = false;
    switch (node->type) {
        case TestBeatType::COMBO:
            //TODO
            break;
        case TestBeatType::SWORD:
            if (_friendShieldCnt > 0) {
                _friendShieldCnt--;
                node->beatSpeed = -node->beatSpeed*1.2;
                shouldDelete = false;
                toast(true, "REFLECT", true);

            } else {
                _friendBlood -= _enemyAttack;
                toast(true, fmt::sprintf("-%d", _enemyAttack), false);
                shouldDelete = true;
                if (_friendBlood < 0) {
                    toast(true, "DEAD!!!", false);
                    newFriend();
                }
            }
            break;

        case TestBeatType::BLOOD:
            _friendBlood += node->value;
            toast(true, fmt::sprintf("+%d", node->value), true);

            shouldDelete = true;
            break;
        case TestBeatType::SHIELD:
            _friendShieldCnt++;
            toast(true, "SHIELD", true);
            shouldDelete = true;
            break;

        default:
            break;
    }
    return shouldDelete;
}
void Engine::OnAuthActionFinished(gpg::AuthOperation op,
                                  gpg::AuthStatus status) {
  ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, status]() {
    if (status == gpg::AuthStatus::VALID) {
      jui_helper::JUIToast toast("Signed In.");
      toast.Show();
    } else {
      jui_helper::JUIToast toast("Signed Out.");
      toast.Show();
    }

    if (button_sign_in_) {
      button_sign_in_->SetAttribute("Text", status == gpg::AuthStatus::VALID
                                            ? "Sign Out"
                                            : "Sign In");
    }

    if (status_text_) {
      status_text_->SetAttribute("Text", status == gpg::AuthStatus::VALID
                                         ? "Signed In"
                                         : "Signed Out");
    }
  });
}
/*
 * Claim quest milestone
 */
void Engine::ClaimMilestone(gpg::QuestMilestone milestone)
{
  EnableUI(false);
  service_->Quests().ClaimMilestone(milestone, [this,milestone](gpg::QuestManager::ClaimMilestoneResponse milestoneResponse){
    if( gpg::IsSuccess(milestoneResponse.status) )
    {
      LOGI("Claiming reward");
      auto begin = milestone.CompletionRewardData().begin();
      auto end = milestone.CompletionRewardData().end();
      std::string reward = "You got " + std::string(begin, end);
      ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([reward]() {
        jui_helper::JUIToast toast(reward.c_str());
        toast.Show();
      });
    }
    EnableUI(true);
  });
}
/*
 * Initialize main sample UI,
 * invoking jui_helper functions to create java UIs
 */
void Engine::InitUI() {
  const int32_t buttonWidth = 600;
    // Show toast with app label
  ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
    jui_helper::JUIToast toast(
        ndk_helper::JNIHelper::GetInstance()->GetAppLabel());
    toast.Show();
  });

  // The window initialization
  jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME);

  //
  // Setup Buttons
  //
  status_text_ = new jui_helper::JUITextView(
      service_->IsAuthorized() ? "Signed In." : "Signed Out.");

  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_ALIGN_PARENT_BOTTOM,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);

  // Sign in button.
  button_sign_in_ = new jui_helper::JUIButton(
      service_->IsAuthorized() ? "Sign Out" : "Sign In");
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                           jui_helper::LAYOUT_PARAMETER_TRUE);
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, status_text_);
  button_sign_in_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      if (service_->IsAuthorized()) {
        service_->SignOut();
      } else {
        service_->StartAuthorizationUI();
      }
    }
  });
  button_sign_in_->SetAttribute("MinimumWidth", buttonWidth);
  button_sign_in_->SetMargins(0, 50, 0, 0);

  button_quests_ = new jui_helper::JUIButton("Show quests");
  button_quests_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, button_sign_in_);
  button_quests_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                           jui_helper::LAYOUT_PARAMETER_TRUE);
  button_quests_->SetAttribute("MinimumWidth", buttonWidth);
  button_quests_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      ShowQuestUI();
    }
  });

  button_events_ = new jui_helper::JUIButton("Show event status");
  button_events_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE,
                          button_quests_);
  button_events_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                          jui_helper::LAYOUT_PARAMETER_TRUE);
  button_events_->SetAttribute("MinimumWidth", buttonWidth);
  button_events_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      ShowEventStatus();
    }
  });
  button_events_->SetMargins(0, 50, 0, 0);

  button_green_ = new jui_helper::JUIButton("Green event");
  button_green_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE,
                         button_events_);
  button_green_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                               jui_helper::LAYOUT_PARAMETER_TRUE);
  button_green_->SetAttribute("MinimumWidth", buttonWidth);
  button_green_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      std::string id = ndk_helper::JNIHelper::GetInstance()->GetStringResource("event_green");
      if( id == "" || id == "ReplaceMe")
      {
        LOGI("Invalid Event ID!, please check res/values/ids.xml");
        return;
      }
      service_->Events().Increment(id.c_str());
      ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
        jui_helper::JUIToast toast("Got Green event");
        toast.Show();
      });
    }
  });

  button_yellow_ = new jui_helper::JUIButton("Yellow event");
  button_yellow_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE,
                          button_green_);
  button_yellow_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                               jui_helper::LAYOUT_PARAMETER_TRUE);
  button_yellow_->SetAttribute("MinimumWidth", buttonWidth);
  button_yellow_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      std::string id = ndk_helper::JNIHelper::GetInstance()->GetStringResource("event_yellow");
      if( id == "" || id == "ReplaceMe")
      {
        LOGI("Invalid Event ID!, please check res/values/ids.xml");
        return;
      }
      service_->Events().Increment(id.c_str());
      ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
        jui_helper::JUIToast toast("Got Yellow event");
        toast.Show();
      });
    }
  });

  button_blue_ = new jui_helper::JUIButton("Blue event");
  button_blue_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE,
                        button_yellow_);
  button_blue_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                               jui_helper::LAYOUT_PARAMETER_TRUE);
  button_blue_->SetAttribute("MinimumWidth", buttonWidth);
  button_blue_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      std::string id = ndk_helper::JNIHelper::GetInstance()->GetStringResource("event_blue");
      if( id == "" || id == "ReplaceMe")
      {
        LOGI("Invalid Event ID!, please check res/values/ids.xml");
        return;
      }
      service_->Events().Increment(id.c_str());
      ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
        jui_helper::JUIToast toast("Got Blue event");
        toast.Show();
      });
    }
  });

  button_red_ = new jui_helper::JUIButton("Red event");
  button_red_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE,
                       button_blue_);
  button_red_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                               jui_helper::LAYOUT_PARAMETER_TRUE);
  button_red_->SetAttribute("MinimumWidth", buttonWidth);
  button_red_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      std::string id = ndk_helper::JNIHelper::GetInstance()->GetStringResource("event_red");
      if( id == "" || id == "ReplaceMe")
      {
        LOGI("Invalid Event ID!, please check res/values/ids.xml");
        return;
      }
      service_->Events().Increment(id.c_str());
      ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
        jui_helper::JUIToast toast("Got Red event");
        toast.Show();
      });
    }
  });

  //Add to screen
  jui_helper::JUIWindow::GetInstance()->AddView(button_red_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_blue_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_yellow_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_green_);

  jui_helper::JUIWindow::GetInstance()->AddView(button_events_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_quests_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_sign_in_);
  jui_helper::JUIWindow::GetInstance()->AddView(status_text_);

  textViewFPS_ = new jui_helper::JUITextView("0.0FPS");
  textViewFPS_->SetAttribute("Gravity", jui_helper::ATTRIBUTE_GRAVITY_LEFT);
  textViewFPS_->SetAttribute("TextColor", 0xffffffff);
  textViewFPS_->SetAttribute("TextSize", jui_helper::ATTRIBUTE_UNIT_SP, 18.f);
  textViewFPS_->SetAttribute("Padding", 10, 10, 10, 10);
  jui_helper::JUIWindow::GetInstance()->AddView(textViewFPS_);

  if (authorizing_)
    EnableUI(false);
  return;
}
void Engine::InitUI() {
  // Show toast with app label
  ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
    jui_helper::JUIToast toast(
      ndk_helper::JNIHelper::GetInstance()->GetAppLabel());
    toast.Show();
  });

  // The window is being shown, get it ready.
  jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME);

  //
  // Buttons
  //
  // Sign in button.
  button_sign_in_ = new jui_helper::JUIButton(
      StateManager::GetGameServices()->IsAuthorized() ? "Sign Out" : "Sign In");
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                           jui_helper::LAYOUT_PARAMETER_TRUE);
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                           jui_helper::LAYOUT_PARAMETER_TRUE);
  button_sign_in_->SetCallback(
      [this](jui_helper::JUIView *view, const int32_t message) {
        LOGI("button_sign_in_ click: %d", message);
        if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
          if (StateManager::GetGameServices()->IsAuthorized()) {
            StateManager::SignOut();
          } else {
            StateManager::BeginUserInitiatedSignIn();
          }
        }
      });
  jui_helper::JUIWindow::GetInstance()->AddView(button_sign_in_);

  // Achievement button
  jui_helper::JUIButton *button_achievement =
      new jui_helper::JUIButton("Unlock Achievement");
  button_achievement->AddRule(jui_helper::LAYOUT_PARAMETER_BELOW,
                              button_sign_in_);
  button_achievement->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                              jui_helper::LAYOUT_PARAMETER_TRUE);
  button_achievement->SetCallback(
      [this](jui_helper::JUIView *view, const int32_t message) {
        LOGI("Button click: %d", message);
        if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
          StateManager::UnlockAchievement(TEST_ACHIEVEMENT_ID);
        }
      });
  jui_helper::JUIWindow::GetInstance()->AddView(button_achievement);

  // Show Achievements button
  jui_helper::JUIButton *button_show_achievements_ui =
      new jui_helper::JUIButton("Show Achievements UI!");
  button_show_achievements_ui->AddRule(jui_helper::LAYOUT_PARAMETER_BELOW,
                                       button_achievement);
  button_show_achievements_ui->AddRule(
      jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
      jui_helper::LAYOUT_PARAMETER_TRUE);
  button_show_achievements_ui->SetCallback(
      [this](jui_helper::JUIView *view, const int32_t message) {
        LOGI("Button click: %d", message);
        if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
          StateManager::ShowAchievements();
        }
      });
  jui_helper::JUIWindow::GetInstance()->AddView(button_show_achievements_ui);

  // High score UI
  //
  // Setup SeekBar
  //
  jui_helper::JUISeekBar *seek_bar_high_score = new jui_helper::JUISeekBar();
  seek_bar_high_score->SetCallback(
      jui_helper::JUICALLBACK_SEEKBAR_PROGRESSCHANGED,
      [this](jui_helper::JUIView *view, const int32_t mes, const int32_t p1,
          const int32_t p2) {
        LOGI("Seek progress %d", p1);
        current_score_ = p1;
      });

  // Configure relative layout parameter
  seek_bar_high_score->AddRule(jui_helper::LAYOUT_PARAMETER_BELOW,
                               button_show_achievements_ui);
  seek_bar_high_score->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                               jui_helper::LAYOUT_PARAMETER_TRUE);
  seek_bar_high_score->SetLayoutParams(jui_helper::ATTRIBUTE_SIZE_MATCH_PARENT,
                                       jui_helper::ATTRIBUTE_SIZE_WRAP_CONTENT);
  jui_helper::JUIWindow::GetInstance()->AddView(seek_bar_high_score);

  // Achievement Button
  jui_helper::JUIButton *button_submit_high_score =
      new jui_helper::JUIButton("Submit High Score!!");
  button_submit_high_score->AddRule(jui_helper::LAYOUT_PARAMETER_BELOW,
                                    seek_bar_high_score);
  button_submit_high_score->AddRule(
      jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
      jui_helper::LAYOUT_PARAMETER_TRUE);
  button_submit_high_score->SetCallback(
      [this](jui_helper::JUIView *view, const int32_t message) {
        LOGI("Button click: %d", message);
        if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
          StateManager::SubmitHighScore(TEST_LEADERBOARD_ID, current_score_);
        }
      });
  jui_helper::JUIWindow::GetInstance()->AddView(button_submit_high_score);

  // Show Leaderboard UI
  jui_helper::JUIButton *button_show_leaderboard_ui =
      new jui_helper::JUIButton("Show Leaderboard UI!");
  button_show_leaderboard_ui->AddRule(jui_helper::LAYOUT_PARAMETER_BELOW,
                                      button_submit_high_score);
  button_show_leaderboard_ui->AddRule(
      jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
      jui_helper::LAYOUT_PARAMETER_TRUE);
  button_show_leaderboard_ui->SetCallback(
      [this](jui_helper::JUIView *view, const int32_t message) {
        LOGI("Button click: %d", message);
        if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
          StateManager::ShowLeaderboard(TEST_LEADERBOARD_ID);
        }
      });
  jui_helper::JUIWindow::GetInstance()->AddView(button_show_leaderboard_ui);

  status_text_ = new jui_helper::JUITextView(
      StateManager::IsAuthInProgress()
      ? "Signing In..."
      : StateManager::GetGameServices()->IsAuthorized()
        ? "Signed In."
        : "Signed Out.");

  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_ALIGN_PARENT_BOTTOM,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  jui_helper::JUIWindow::GetInstance()->AddView(status_text_);
  return;
}
/*
 * Initialize main sample UI,
 * invoking jui_helper functions to create java UIs
 */
void Engine::InitUI() {
  const int32_t buttonWidth = 600;
    // Show toast with app label
  ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
    jui_helper::JUIToast toast(
        ndk_helper::JNIHelper::GetInstance()->GetAppLabel());
    toast.Show();
  });

  // The window initialization
  jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME);

  //
  // Buttons
  //
  // Setting up game UI
  int32_t index = 0;
  jui_helper::JUILinearLayout *masterLayout = new jui_helper::JUILinearLayout();
  masterLayout->SetAttribute("Orientation",
                             jui_helper::LAYOUT_ORIENTATION_VERTICAL);
  masterLayout->SetAttribute("Gravity",
                             jui_helper::ATTRIBUTE_GRAVITY_CENTER_VERTICAL);
  masterLayout->SetLayoutParams(jui_helper::ATTRIBUTE_SIZE_MATCH_PARENT,
                                jui_helper::ATTRIBUTE_SIZE_WRAP_CONTENT);

  //Select stage
  jui_helper::JUILinearLayout *layout = new jui_helper::JUILinearLayout();
  layout->SetLayoutParams(jui_helper::ATTRIBUTE_SIZE_MATCH_PARENT,
                          jui_helper::ATTRIBUTE_SIZE_WRAP_CONTENT);
  layout->SetMargins(0, 50, 0, 50);
  layout->SetAttribute("Orientation",
                       jui_helper::LAYOUT_ORIENTATION_HORIZONTAL);
  layout->SetAttribute("Gravity", jui_helper::ATTRIBUTE_GRAVITY_CENTER);
  buttonLeft_ = new jui_helper::JUIButton("<<");
  buttonRight_ = new jui_helper::JUIButton(">>");
  labelWorld_ = new jui_helper::JUITextView("Stage 1");
  buttonLeft_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      //Change game world
      if (current_world_ > 0) {
        current_world_--;
        UpdateGameUI();
      }
    }
  });
  buttonRight_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      //Change game world
      if (current_world_ < NUM_GAME_WORLD - 1) {
        current_world_++;
        UpdateGameUI();
      }
    }
  });

  layout->AddView(buttonLeft_);
  layout->AddView(labelWorld_);
  layout->AddView(buttonRight_);
  masterLayout->AddView(layout);

  for (int32_t i = 0; i < 4; ++i) {
    button_games_[index + 0] = CreateButton(index + 0);
    button_games_[index + 1] = CreateButton(index + 1);
    button_games_[index + 2] = CreateButton(index + 2);

    //Center element
    button_games_[index + 1]
        ->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                  jui_helper::LAYOUT_PARAMETER_TRUE);
    button_games_[index + 1]->SetMargins(50, 50, 50, 50);

    jui_helper::JUILinearLayout *layout = new jui_helper::JUILinearLayout();
    layout->SetLayoutParams(jui_helper::ATTRIBUTE_SIZE_MATCH_PARENT,
                            jui_helper::ATTRIBUTE_SIZE_WRAP_CONTENT);
    layout->SetMargins(0, 50, 0, 50);
    layout->SetAttribute("Orientation",
                         jui_helper::LAYOUT_ORIENTATION_HORIZONTAL);
    layout->SetAttribute("Gravity", jui_helper::ATTRIBUTE_GRAVITY_CENTER);
    layout->AddView(button_games_[index + 0]);
    layout->AddView(button_games_[index + 1]);
    layout->AddView(button_games_[index + 2]);
    masterLayout->AddView(layout);

    index += 3;
  }
  jui_helper::JUIWindow::GetInstance()->AddView(masterLayout);

  status_text_ = new jui_helper::JUITextView(
      service_->IsAuthorized() ? "Signed In." : "Signed Out.");

  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_ALIGN_PARENT_BOTTOM,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  jui_helper::JUIWindow::GetInstance()->AddView(status_text_);

  // Sign in button.
  button_sign_in_ = new jui_helper::JUIButton(
      service_->IsAuthorized() ? "Sign Out" : "Sign In");
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, status_text_);
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                           jui_helper::LAYOUT_PARAMETER_TRUE);
  button_sign_in_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_sign_in_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      if (service_->IsAuthorized()) {
        service_->SignOut();
      } else {
        service_->StartAuthorizationUI();
      }
    }
  });
  button_sign_in_->SetAttribute("MinimumWidth", buttonWidth);
  button_sign_in_->SetMargins(0, 50, 0, 0);

  // Select button.
  button_select_ = new jui_helper::JUIButton("Select");
  button_select_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, button_sign_in_);
  button_select_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                          jui_helper::LAYOUT_PARAMETER_TRUE);
  button_select_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_select_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      EnableUI(false);
      ShowSnapshotSelectUI();
    }
  });
  button_select_->SetAttribute("MinimumWidth", buttonWidth);

  // Save button.
  button_save_ = new jui_helper::JUIButton("Save");
  button_save_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, button_select_);
  button_save_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  button_save_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_save_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      //Save snapshot
      SaveSnapshot();
    }
  });
  button_save_->SetAttribute("MinimumWidth", buttonWidth);

  // Load button.
  button_load_ = new jui_helper::JUIButton("Load");
  button_load_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, button_save_);
  button_load_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  button_load_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_load_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      EnableUI(false);
      LoadFromSnapshot();
    }
  });
  button_load_->SetAttribute("MinimumWidth", buttonWidth);

  jui_helper::JUIWindow::GetInstance()->AddView(button_sign_in_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_select_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_save_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_load_);

  textViewFPS_ = new jui_helper::JUITextView("0.0FPS");
  textViewFPS_->SetAttribute("Gravity", jui_helper::ATTRIBUTE_GRAVITY_LEFT);
  textViewFPS_->SetAttribute("TextColor", 0xffffffff);
  textViewFPS_->SetAttribute("TextSize", jui_helper::ATTRIBUTE_UNIT_SP, 18.f);
  textViewFPS_->SetAttribute("Padding", 10, 10, 10, 10);
  jui_helper::JUIWindow::GetInstance()->AddView(textViewFPS_);

  // Progress bar
  progressBar_ = new jui_helper::JUIProgressBar();
  progressBar_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  jui_helper::JUIWindow::GetInstance()->AddView(progressBar_);
  progressBar_->SetAttribute("Hidden", true);

  //Update game ui
  UpdateGameUI();

  if (authorizing_)
    EnableUI(false);
  return;
}