Exemplo n.º 1
0
        @Override
        public void run() {

          // Execute 1/50th of a second of BBC micro!
          long now = android.os.SystemClock.uptimeMillis();
          handler.postAtTime(runInt50, now + 20);
          if (beebView.gl == null) {
            if (beebView.egl == null) { // no surface yet
              return;
            }
            beebView.initgl();
            bbcInitGl(beebView.width, beebView.height);
          }
          int trigger = bbcRun();

          // Handle trigger events
          if (controller.controllerInfo != null) {
            final List<TriggerAction> triggers = controller.controllerInfo.triggers;
            if (trigger != last_trigger && triggers != null) {
              Log.d("Trigger!", "PC hit trigger " + trigger);
              last_trigger = trigger;
              if (triggers.size() >= trigger) {
                onTriggerFired(controller.controllerInfo.triggers.get(trigger - 1));
              }
            }
          }

          // Automatic keyboard text
          if (keyboardTextWait > 0) {
            keyboardTextWait--;
          } else {
            if (keyboardTextEvents.size() > 0) {
              final KeyEvent event = keyboardTextEvents.remove(0);
              if (event.getAction() == KeyEvent.ACTION_DOWN) {
                onKeyDown(event.getKeyCode(), event);
              }
              if (event.getAction() == KeyEvent.ACTION_UP) {
                handler.postDelayed(
                    new Runnable() {
                      @Override
                      public void run() {
                        onKeyUp(event.getKeyCode(), event);
                        keyboardTextWait = 1;
                      }
                    },
                    10);
              }
            }
          }
        }
Exemplo n.º 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    use25fps = Build.DEVICE.equals("bravo");

    // Log.d("Build", "Its a " + Build.DEVICE);
    Analytics.trackPageView(getApplicationContext(), "/start");

    setContentView(R.layout.activity_beebdroid);

    setAdVisibility();

    DPI_MULT = getResources().getDisplayMetrics().density;
    DP_SCREEN_WIDTH = getResources().getDisplayMetrics().widthPixels;

    // Detect the Xperia Play, for which we do special magic
    if (Build.DEVICE.equalsIgnoreCase("R800i") || Build.DEVICE.equalsIgnoreCase("zeus")) {
      isXperiaPlay = true;
    }

    // Find UI bits and wire things up
    beebView = (BeebView) findViewById(R.id.beeb);
    keyboard = (Keyboard) findViewById(R.id.keyboard);
    keyboard.beebdroid = this;
    controller = (ControllerView) findViewById(R.id.controller);
    controller.beebdroid = this;

    // See if we're a previous instance of the same activity, or a totally fresh one
    Beebdroid prev = (Beebdroid) getLastNonConfigurationInstance();
    if (prev == null) {
      InstalledDisks.load(this);
      audiobuff = new byte[2000 * 2];
      audio =
          new AudioTrack(
              AudioManager.STREAM_MUSIC,
              31250,
              AudioFormat.CHANNEL_OUT_MONO,
              AudioFormat.ENCODING_PCM_16BIT,
              16384,
              AudioTrack.MODE_STREAM);
      model = new Model();
      model.loadRoms(this, Model.SupportedModels[1]);
      bbcInit(model.mem, model.roms, audiobuff, 1);
      currentController = Controllers.DEFAULT_CONTROLLER;
      if (UserPrefs.shouldShowSplashScreen(this)) {
        startActivity(new Intent(Beebdroid.this, AboutActivity.class));
      }
      processDiskViaIntent();
    } else {
      model = prev.model;
      audio = prev.audio;
      audiobuff = prev.audiobuff;
      diskInfo = prev.diskInfo;
      last_trigger = prev.last_trigger;
      keyboardTextWait = prev.keyboardTextWait;
      keyboardTextEvents = prev.keyboardTextEvents;
      keyboardShowing = prev.keyboardShowing;
      currentController = prev.currentController;
      bbcInit(model.mem, model.roms, audiobuff, 0);
    }
    setController(currentController);
    showKeyboard(keyboardShowing);

    // Wire up the white buttons
    final ImageView btnInput = (ImageView) findViewById(R.id.btnInput);
    if (btnInput != null) {
      btnInput.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              toggleKeyboard();
            }
          });
    }
    tvFps = (TextView) findViewById(R.id.fps);

    beebView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            bbcKeyEvent(BeebKeys.BBCKEY_CTRL, 0, 1);
            bbcKeyEvent(BeebKeys.BBCKEY_SPACE, 0, 1);
            handler.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    bbcKeyEvent(BeebKeys.BBCKEY_CTRL, 0, 0);
                    bbcKeyEvent(BeebKeys.BBCKEY_SPACE, 0, 0);
                  }
                },
                50);
            hintActioned("hint_space_to_start");
          }
        });

    UserPrefs.setGrandfatheredIn(this, true);
  }