Пример #1
0
  public void onDestroy() {
    super.onDestroy();

    try {
      m_instrumentService.unregisterCallback(m_callback);
      m_instrumentService.unloadSamples(m_sounds);
      unbindService(m_connection);
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }
Пример #2
0
  /**
   * Called on click of one of the buttons
   *
   * @param view The clicked button
   */
  public void buttonClick(View view) {
    if (view == null) return;

    // looped is stored in tag field
    boolean looped = view.getTag().equals("1");

    // play/stop depending on ToggleButton state, otherwise just play
    boolean play = true;
    if (view instanceof ToggleButton && !((ToggleButton) view).isChecked()) play = false;

    // either play or stop
    try {
      if (play) m_instrumentService.playSound(m_buttonToSound.get(view.getId()), looped);
      else m_instrumentService.stopSound(m_buttonToSound.get(view.getId()));
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  /** Do not reload sounds on screen rotation */
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.instrument_looper);

    try {
      // light up buttons for playing sounds
      for (Map.Entry<Integer, Integer> entry : m_buttonToSound.entrySet())
        if (m_instrumentService.isPlaying(entry.getValue()))
          ((ToggleButton) findViewById(entry.getKey())).setChecked(true);

      // re-associate progress bars
      m_instrumentService.unregisterCallback(m_callback);
      for (Map.Entry<Integer, Integer> entry : m_soundToProgressID.entrySet())
        m_soundToProgress.put(entry.getKey(), (ProgressBar) findViewById(entry.getValue()));
      m_instrumentService.registerCallback(m_callback);
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }