@TargetApi(Build.VERSION_CODES.FROYO)
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.activity_channel, menu);

    searchItem = menu.findItem(R.id.menu_search);

    if (mViewPager == null) fullscreenButton = menu.findItem(R.id.menu_fullscreen);

    if (VERSION.SDK_INT >= 8) { // SearchManager supported by Froyo+.
      SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
      SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
      searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    } else {
      searchItem.setVisible(false);
    }

    mutedButton = menu.findItem(R.id.menu_mute_button);
    deafenedButton = menu.findItem(R.id.menu_deafen_button);

    if (mService != null && mService.getCurrentUser() != null) {
      updateMuteDeafenMenuItems(mService.isMuted(), mService.isDeafened());
    }

    return true;
  }
  @Override
  protected void onResume() {
    super.onResume();

    if (settings.getCallMode().equals(Settings.ARRAY_CALL_MODE_VOICE)) setProximityEnabled(true);

    if (mService != null && mService.getCurrentUser() != null)
      updateMuteDeafenMenuItems(mService.isMuted(), mService.isDeafened());

    // Clear chat notifications when activity is re-opened
    if (mService != null && settings.isChatNotifyEnabled()) {
      mService.setActivityVisible(true);
      mService.clearChatNotification();
    }
  }
  /* (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);
  }