예제 #1
0
  void updateConnectionState() {
    final int oldState = serviceState;

    switch (state) {
      case MumbleConnectionHost.STATE_CONNECTING:
        serviceState = CONNECTION_STATE_CONNECTING;
        break;
      case MumbleConnectionHost.STATE_CONNECTED:
        settings.addObserver(this);
        serviceState = synced ? CONNECTION_STATE_CONNECTED : CONNECTION_STATE_SYNCHRONIZING;
        if (settings.isDeafened()) {
          setDeafened(true);
        } else if (settings.isMuted()) {
          setMuted(true);
        }
        updateFavourites();
        if (synced) {
          // Initialize audio input
          mAudioInput = new AudioInput(this, mProtocol.codec);
          if (settings.isVoiceActivity())
            mAudioInput.startRecording(); // Immediately begin record if using voice activity

          showNotification();
        }
        break;
      case MumbleConnectionHost.STATE_DISCONNECTED:
        settings.deleteObserver(this);
        serviceState = CONNECTION_STATE_DISCONNECTED;
        if (mAudioInput != null) {
          try {
            mAudioInput.stopRecordingAndBlock();
          } catch (InterruptedException e) {
            e.printStackTrace();
          } finally {
            mAudioInput.terminate();
            mAudioInput = null;
          }
        }
        hideNotification();
        break;
      default:
        Assert.fail();
    }

    if (oldState != serviceState) {
      broadcastState();
    }
  }
예제 #2
0
  @Override
  public int onStartCommand(final Intent intent, final int flags, final int startId) {
    /* Handle notification intents. */
    if (intent != null
        && intent.getExtras() != null
        && intent.getExtras().containsKey(MUMBLE_NOTIFICATION_ACTION_KEY)) {
      String keyString = intent.getExtras().getString(MUMBLE_NOTIFICATION_ACTION_KEY);

      if (keyString.equals(MUMBLE_NOTIFICATION_ACTION_MUTE)) {
        setMuted(!isMuted());
      }

      if (keyString.equals(MUMBLE_NOTIFICATION_ACTION_DEAFEN)) {
        setDeafened(!isDeafened());
      }

      return START_NOT_STICKY;
    }
    return handleCommand(intent);
  }
예제 #3
0
  /* (non-Javadoc)
   * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
   */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.menu_mute_button:
        if (!mService.isMuted()) {
          // Switching to muted
          updateMuteDeafenMenuItems(true, mService.isDeafened());
        } else {
          // Switching to unmuted
          updateMuteDeafenMenuItems(false, false);
        }
        mService.setMuted(!mService.isMuted());
        return true;
      case R.id.menu_deafen_button:
        updateMuteDeafenMenuItems(!mService.isDeafened(), !mService.isDeafened());
        mService.setDeafened(!mService.isDeafened());
        return true;
      case R.id.menu_fullscreen_chat:
        rightSplit.setVisibility(
            rightSplit.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
        leftSplit.setVisibility(View.VISIBLE);
        fullscreenButton.setIcon(R.drawable.ic_action_unfullscreen);
        return true;
      case R.id.menu_fullscreen_channel:
        leftSplit.setVisibility(
            leftSplit.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
        rightSplit.setVisibility(View.VISIBLE);
        fullscreenButton.setIcon(R.drawable.ic_action_unfullscreen);
        return true;
      case R.id.menu_fullscreen:
        if (leftSplit.getVisibility() == View.GONE || rightSplit.getVisibility() == View.GONE) {
          leftSplit.setVisibility(View.VISIBLE);
          rightSplit.setVisibility(View.VISIBLE);
          fullscreenButton.setIcon(R.drawable.ic_action_fullscreen);
        }
        return true;
      case R.id.menu_view_favorites_button:
        showFavouritesDialog();
        return true;
      case R.id.menu_user_register:
        new AsyncTask<Void, Void, Void>() {
          @Override
          protected Void doInBackground(Void... params) {
            mService.registerSelf();
            return null;
          }

          protected void onPostExecute(Void result) {
            Toast.makeText(ChannelActivity.this, R.string.registerSelfSuccess, Toast.LENGTH_SHORT)
                .show();
          };
        }.execute();
        return true;
      case R.id.menu_user_comment:
        // TODO
        Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show();
        return true;
      case R.id.menu_user_information:
        // TODO
        Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show();
        return true;
      case R.id.menu_clear_chat:
        mService.clearChat();
        chatFragment.clear();
        return true;
      case R.id.menu_search:
        return false;
      case R.id.menu_access_tokens_button:
        TokenDialogFragment dialogFragment = TokenDialogFragment.newInstance();
        dialogFragment.setShowsDialog(mViewPager == null);
        dialogFragment.show(getSupportFragmentManager(), "tokens");
        return true;
      case R.id.menu_bluetooth:
        item.setChecked(!item.isChecked());
        if (item.isChecked()) mService.enableBluetooth();
        else mService.disableBluetooth();
        break;
      case R.id.menu_amplifier:
        AmplifierDialogFragment amplifierDialogFragment = AmplifierDialogFragment.newInstance();
        amplifierDialogFragment.show(getSupportFragmentManager(), "amplifier");
        return true;
      case R.id.menu_preferences:
        Intent intent = new Intent(this, Preferences.class);
        startActivity(intent);
        return true;
      case R.id.menu_disconnect_item:
        disconnect();
        return true;
    }

    return super.onOptionsItemSelected(item);
  }