private boolean enterRoom(String roomName) {
    final Semaphore semaphore = new Semaphore(1);
    try {
      semaphore.acquire();
    } catch (Exception e) {
    }
    ;
    baseActivity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            fab.performClick();
            semaphore.release();
          }
        });
    /*
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View input_dialog = inflater.inflate(R.layout.input_dialog, null);
            textInputLayout = (TextInputLayout) input_dialog.findViewById(R.id.textInput);
            editText = textInputLayout.getEditText();
            editText.requestFocus();
        }
    });*/
    getInstrumentation().waitForIdleSync();
    getInstrumentation().sendStringSync(roomName);
    getInstrumentation().waitForIdleSync();

    assertNotNull("Text Input Layout  is not null", textInputLayout);
    assertNotNull("Edit Text is not null", editText);
    semaphore.release();

    try {
      Thread.sleep(1000);
    } catch (Exception e) {
    }
    ;
    Instrumentation.ActivityMonitor activityMonitor =
        getInstrumentation().addMonitor(QuestionRoomFragment.class.getName(), null, false);

    try {
      Thread.sleep(1000);
    } catch (Exception e) {
    }
    ;
    // QuestionRoomFragment questionFragment = (QuestionRoomFragment)
    // getInstrumentation().waitForMonitorWithTimeout(activityMonitor,2000);
    try {
      Thread.sleep(1000);
    } catch (Exception e) {
    }
    ;
    /*
    boolean result = (questionFragment != null);
    if(result)
        questionFragment.finish();*/
    return true;
  }
示例#2
0
  @Override
  public boolean onMenuItemClicked(MenuScene arg0, IMenuItem arg1, float arg2, float arg3) {
    switch (arg1.getID()) {
      case MENU_MAINMENU:
        if (activity.isSfx()) activity.menuClickSound.play();
        detachChildren();
        activity.setCurrentScene(new MainMenuScene());

        activity.runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                if (activity.interstitialAd.isLoaded()) {
                  activity.interstitialAd.show();
                } else {
                  activity.interstitialAd.loadAd(activity.adRequest);
                  if (activity.interstitialAd.isLoaded()) {
                    activity.interstitialAd.show();
                  }
                }
              }
            });

        return true;
      default:
        break;
    }
    return false;
  }
示例#3
0
  public GameoverScene() {
    super(BaseActivity.getSharedInstance().mCamera);
    activity = BaseActivity.getSharedInstance();

    setBackground(new Background(Color.WHITE));
    attachChild(activity.backgroundSprite);

    continueText =
        new Text(0, 0, activity.mFont, "Continue", activity.getVertexBufferObjectManager());
    continueText.setPosition(
        mCamera.getWidth() / 2 - continueText.getWidth() / 2,
        mCamera.getHeight() - continueText.getHeight() - 20);

    gameOverText =
        new Text(0, 0, activity.mFont, "Game Over", activity.getVertexBufferObjectManager());
    gameOverText.setPosition(
        mCamera.getWidth() / 2 - gameOverText.getWidth() / 2, mCamera.getHeight() / 6);

    scoreText =
        new Text(
            0,
            0,
            activity.mSmallFont,
            "Score: " + activity.score.getScore(),
            activity.getVertexBufferObjectManager());
    scoreText.setPosition(
        mCamera.getWidth() / 2 - scoreText.getWidth() / 2,
        mCamera.getHeight() / 2 - scoreText.getHeight() / 2 - gameOverText.getHeight());

    highscoreText =
        new Text(
            0,
            0,
            activity.mSmallFont,
            "Highscore: " + activity.highscore,
            activity.getVertexBufferObjectManager());
    highscoreText.setPosition(
        mCamera.getWidth() / 2 - highscoreText.getWidth() / 2,
        mCamera.getHeight() / 2
            - scoreText.getHeight() / 2
            - continueText.getHeight()
            + scoreText.getHeight()
            + activity.mCamera.getWidth() / 108f);

    IMenuItem startButton =
        new SpriteMenuItem(
            MENU_MAINMENU, activity.buttonRegion, activity.getVertexBufferObjectManager());
    startButton.setPosition(mCamera.getWidth() / 10, continueText.getY());
    startButton.setSize(mCamera.getWidth() - mCamera.getWidth() / 5, continueText.getHeight());

    Sprite panel =
        new Sprite(
            mCamera.getWidth() / 10 - mCamera.getWidth() / 20,
            gameOverText.getY() - 20,
            activity.panelRegion,
            activity.getVertexBufferObjectManager());
    panel.setSize(
        mCamera.getWidth() - mCamera.getWidth() / 10,
        mCamera.getHeight()
            - panel.getY()
            - (mCamera.getHeight() - highscoreText.getY())
            + highscoreText.getHeight()
            + 40);

    attachChild(panel);
    addMenuItem(startButton);
    attachChild(gameOverText);
    attachChild(highscoreText);
    attachChild(scoreText);
    attachChild(continueText);

    setOnMenuItemClickListener(this);

    if (activity.mGoogleApiClient == null || !activity.mGoogleApiClient.isConnected()) {
      activity.runOnUiThread(
          new Runnable() {
            @Override
            public void run() {
              Toast.makeText(
                      activity,
                      "Not connected to Google Play Services. Score not uploaded. Highscore gets uploaded automatically next time.",
                      Toast.LENGTH_LONG)
                  .show();
            }
          });
    }
  }