Пример #1
0
  @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();
    }
  }
Пример #2
0
  @Override
  protected void onPause() {
    super.onPause();

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

    if (mService != null) {
      mService.setActivityVisible(false);

      // Turn off push to talk when rotating so it doesn't get stuck on, except if it's in toggled
      // state.
      // if(settings.isPushToTalk() && !mTalkToggleBox.isChecked()) {
      //	mService.setRecording(false);
      // }
    }
  }
Пример #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    settings = Settings.getInstance(this);
    settings.addObserver(this);

    // Use theme from settings
    int theme = 0;
    if (settings.getTheme().equals(Settings.ARRAY_THEME_LIGHTDARK)) {
      theme = R.style.Theme_Sherlock_Light_DarkActionBar;
    } else if (settings.getTheme().equals(Settings.ARRAY_THEME_DARK)) {
      theme = R.style.Theme_Sherlock;
    }
    setTheme(theme);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_channel);

    // Bind to service
    Intent serviceIntent = new Intent(this, MumbleService.class);
    bindService(serviceIntent, conn, 0);

    // Register bluetooth SCO monitor
    registerReceiver(
        bluetoothReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));

    // Handle differences in CallMode

    String callMode = settings.getCallMode();
    setVolumeControlStream(
        Settings.ARRAY_CALL_MODE_SPEAKER.equals(callMode)
            ? AudioManager.STREAM_MUSIC
            : AudioManager.STREAM_VOICE_CALL);

    // Set up proximity sensor
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    proximityLock = powerManager.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, Globals.LOG_TAG);

    // Set up PTT button.

    mTalkButton = (Button) findViewById(R.id.pushtotalk);
    pttView = findViewById(R.id.pushtotalk_view);
    mTalkButton.setOnTouchListener(
        new OnTouchListener() {

          private static final int TOGGLE_INTERVAL =
              250; // 250ms is the interval needed to toggle push to talk.
          private long lastTouch = 0;

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (mService == null) {
              return false;
            }

            if (event.getAction() == MotionEvent.ACTION_DOWN && !settings.isPushToTalkToggle()) {
              setPushToTalk(true);
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
              if (settings.isPushToTalkToggle()) setPushToTalk(!mService.isRecording());
              else {
                if (System.currentTimeMillis() - lastTouch <= TOGGLE_INTERVAL) {
                  // Do nothing. We leave the push to talk on, as it has toggled.
                } else {
                  setPushToTalk(false);
                  lastTouch = System.currentTimeMillis();
                }
              }
            }

            return true; // We return true so that the selector that changes the background does not
            // fire.
          }
        });

    updatePTTConfiguration();

    mViewPager = (ViewPager) findViewById(R.id.pager);
    FragmentManager fragmentManager = getSupportFragmentManager();

    listFragment = (ChannelListFragment) fragmentManager.findFragmentByTag(LIST_FRAGMENT_TAG);
    chatFragment = (ChannelChatFragment) fragmentManager.findFragmentByTag(CHAT_FRAGMENT_TAG);

    FragmentTransaction remove = fragmentManager.beginTransaction();
    if (listFragment == null) listFragment = new ChannelListFragment();
    else remove.remove(listFragment);

    if (chatFragment == null) chatFragment = new ChannelChatFragment();
    else remove.remove(chatFragment);

    if (!remove.isEmpty()) {
      remove.commit();
      fragmentManager.executePendingTransactions();
    }

    if (mViewPager != null) {
      // Set up the ViewPager with the sections adapter.
      mViewPager.setOnPageChangeListener(
          new OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
              // Hide keyboard if moving to channel list.
              if (arg0 == 0) {
                InputMethodManager imm =
                    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mViewPager.getApplicationWindowToken(), 0);
              }
              // Update indicator
              channelsIndicator.setVisibility(arg0 == 0 ? View.VISIBLE : View.INVISIBLE);
              chatIndicator.setVisibility(arg0 == 1 ? View.VISIBLE : View.INVISIBLE);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {}

            @Override
            public void onPageScrollStateChanged(int arg0) {}
          });

      // Set up tabs
      getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

      View channelTabView = getLayoutInflater().inflate(R.layout.channel_tab_view, null);
      channelsIndicator = channelTabView.findViewById(R.id.tab_channels_indicator);
      chatIndicator = channelTabView.findViewById(R.id.tab_chat_indicator);

      ImageButton channelsButton = (ImageButton) channelTabView.findViewById(R.id.tab_channels);
      ImageButton chatButton = (ImageButton) channelTabView.findViewById(R.id.tab_chat);
      channelsButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              mViewPager.setCurrentItem(0, true);
            }
          });
      chatButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              mViewPager.setCurrentItem(1, true);
            }
          });

      getSupportActionBar().setCustomView(channelTabView);
      // Setup a pager that will return a fragment for each of the two primary sections of the app.
      mSectionsPagerAdapter =
          new PlumbleSectionsPagerAdapter(
              this, getSupportFragmentManager(), listFragment, chatFragment);
      mViewPager.setAdapter(mSectionsPagerAdapter);

    } else {
      // Create tablet UI
      leftSplit = findViewById(R.id.left_split);
      rightSplit = findViewById(R.id.right_split);
      fragmentManager
          .beginTransaction()
          .add(R.id.chat_fragment, chatFragment, CHAT_FRAGMENT_TAG)
          .add(R.id.list_fragment, listFragment, LIST_FRAGMENT_TAG)
          .commit();
    }

    if (savedInstanceState != null) {
      chatTarget = (User) savedInstanceState.getParcelable(SAVED_STATE_CHAT_TARGET);
    }
  }