@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 public boolean onPrepareOptionsMenu(Menu menu) { // Only show favourites and access tokens (DB-related) if the connected server has a DB // representation (non-public). MenuItem fullscreenItem = menu.findItem(R.id.menu_fullscreen); MenuItem favouritesViewItem = menu.findItem(R.id.menu_view_favorites_button); MenuItem accessTokensItem = menu.findItem(R.id.menu_access_tokens_button); userRegisterItem = menu.findItem(R.id.menu_user_register); userCommentItem = menu.findItem(R.id.menu_user_comment); userInformationItem = menu.findItem(R.id.menu_user_information); if (mService != null && mService.getConnectedServer() != null) { favouritesViewItem.setVisible(!mService.isConnectedServerPublic()); accessTokensItem.setVisible(!mService.isConnectedServerPublic()); } fullscreenItem.setVisible(mViewPager == null); // Only show fullscreen option if in tablet mode // Show whether or not SCO is enabled AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); bluetoothItem = menu.findItem(R.id.menu_bluetooth); bluetoothItem.setChecked(audioManager.isBluetoothScoOn()); return super.onPrepareOptionsMenu(menu); }
/** Used to control the user settings shown when registered. */ private void updateUserControlMenuItems() { if (mService == null || mService.getCurrentUser() == null || userRegisterItem == null || userCommentItem == null || userInformationItem == null) return; boolean userRegistered = mService.getCurrentUser().isRegistered; userRegisterItem.setEnabled(!userRegistered); userCommentItem.setEnabled(userRegistered); userInformationItem.setEnabled(userRegistered); }
@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(); } }
private void showFavouritesDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.favorites); List<CharSequence> items = new ArrayList<CharSequence>(); final List<Favourite> activeFavourites = new ArrayList<Favourite>(mService.getFavourites()); for (Favourite favourite : mService.getFavourites()) { int channelId = favourite.getChannelId(); Channel channel = mService.getChannel(channelId); if (channel != null) { items.add(channel.name); } else { // TODO remove the favourite from DB here if channel is not found. activeFavourites.remove(favourite); } } if (items.size() > 0) { builder.setItems( items.toArray(new CharSequence[items.size()]), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Favourite favourite = activeFavourites.get(which); final Channel channel = mService.getChannel(favourite.getChannelId()); new AsyncTask<Channel, Void, Void>() { @Override protected Void doInBackground(Channel... params) { mService.joinChannel(params[0].id); return null; } }.execute(channel); } }); } else { builder.setMessage(R.string.noFavorites); } builder.setNegativeButton(android.R.string.cancel, null); builder.show(); }
/** * Handles activity initialization when the Service has connected. * * <p>Should be called when there is a reason to believe that the connection might have became * valid. The connection MUST be established but other validity criteria may still be unfilled * such as server synchronization being complete. * * <p>The method implements the logic required for making sure that the Connected service is in * such a state that it fills all the connection criteria for ChannelList. * * <p>The method also takes care of making sure that its initialization code is executed only once * so calling it several times doesn't cause problems. */ protected void onConnected() { // Tell the service that we are now visible. mService.setActivityVisible(true); // Update user control updateUserControlMenuItems(); // Restore push to talk state, if toggled. Otherwise make sure it's turned off. if (settings.isPushToTalk() && mService.isRecording()) { if (settings.isPushToTalkToggle() && settings.isPushToTalkButtonShown()) setPushToTalk(true); else mService.setPushToTalk(false); } if (settings.isPushToTalk() && mService.isRecording()) if (chatTarget != null) { listFragment.setChatTarget(chatTarget); chatFragment.setChatTarget(chatTarget); } // Showcase hints List<ShowcaseView> showcaseViews = new ArrayList<ShowcaseView>(); if (settings.isPushToTalk() && settings.isPushToTalkButtonShown()) { ConfigOptions pttConfig = new ConfigOptions(); pttConfig.shotType = ShowcaseView.TYPE_ONE_SHOT; pttConfig.showcaseId = Globals.SHOWCASE_PUSH_TO_TALK; showcaseViews.add( ShowcaseView.insertShowcaseView( pttView, this, R.string.hint_ptt, R.string.hint_ptt_summary, pttConfig)); } if (mViewPager != null) { ConfigOptions switcherConfig = new ConfigOptions(); switcherConfig.shotType = ShowcaseView.TYPE_ONE_SHOT; switcherConfig.showcaseId = Globals.SHOWCASE_SWITCHER; showcaseViews.add( ShowcaseView.insertShowcaseView( ShowcaseView.ITEM_ACTION_HOME, 0, this, R.string.hint_switching, R.string.hint_switching_summary, switcherConfig)); } ShowcaseViewQueue queue = new ShowcaseViewQueue(showcaseViews); queue.queueNext(); }
@Override public void onServiceConnected(ComponentName name, IBinder service) { LocalBinder localBinder = (LocalBinder) service; mObserver = new ChannelServiceObserver(); mService = localBinder.getService(); mService.registerObserver(mObserver); listFragment.notifyServiceBound(); chatFragment.notifyServiceBound(); onConnected(); }
/** * Handles activity initialization when the Service has connected. * * <p>Should be called when there is a reason to believe that the connection might have became * valid. The connection MUST be established but other validity criteria may still be unfilled * such as server synchronization being complete. * * <p>The method implements the logic required for making sure that the Connected service is in * such a state that it fills all the connection criteria for ChannelList. * * <p>The method also takes care of making sure that its initialization code is executed only once * so calling it several times doesn't cause problems. */ protected void onConnected() { // Tell the service that we are now visible. mService.setActivityVisible(true); // Update user control updateUserControlMenuItems(); // Restore push to talk state, if toggled. Otherwise make sure it's turned off. if (settings.isPushToTalk() && mService.isRecording()) { if (settings.isPushToTalkToggle() && settings.isPushToTalkButtonShown()) setPushToTalk(true); else mService.setPushToTalk(false); } if (settings.isPushToTalk() && mService.isRecording()) if (chatTarget != null) { listFragment.setChatTarget(chatTarget); chatFragment.setChatTarget(chatTarget); } }
public void setPushToTalk(final boolean talking) { mService.setPushToTalk(talking); int pushToTalkBackground = mViewPager != null ? R.color.push_to_talk_background : 0; // Use special 'second action bar' look for background of paged. if (pttView != null) pttView.setBackgroundResource(talking ? R.color.holo_blue_light : pushToTalkBackground); }
@Override protected void onDestroy() { // Unbind to service mService.unregisterObserver(mObserver); unbindService(conn); // Unregister bluetooth receiver unregisterReceiver(bluetoothReceiver); listFragment.notifyServiceUnbound(); chatFragment.notifyServiceUnbound(); super.onDestroy(); }
private void audioLoop() throws InterruptedException { final short[] out = new short[MumbleProtocol.FRAME_SIZE]; final List<AudioUser> mix = new LinkedList<AudioUser>(); int buffered = 0; boolean playing = false; while (shouldRun) { mix.clear(); // Get mix frames from the AudioUsers fillMixFrames(mix); // If there is output, play it now if not deafened. if (mix.size() > 0 && !MumbleService.getCurrentService().getCurrentUser().deafened) { // Mix all the frames into one array. mix(out, mix); at.write(out, 0, MumbleProtocol.FRAME_SIZE); // Make sure we are playing when there are enough samples // buffered. if (!playing) { buffered += out.length; if (buffered >= minBufferSize) { at.play(); playing = true; buffered = 0; Log.i(Globals.LOG_TAG, "AudioOutput: Enough data buffered. Starting audio."); } } // Continue with playback since we know that there is at least // one AudioUser in userPackets that wasn't removed as it had // frames for mixing. continue; } // Wait for more input. playing &= !pauseForInput(); if (!playing && buffered > 0) { Log.w(Globals.LOG_TAG, "AudioOutput: Stopped playing while buffered data present."); } } at.flush(); at.stop(); }
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); // Join channel selected in search suggestions if present if (intent != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_SEARCH)) { String resultType = (String) intent.getSerializableExtra(SearchManager.EXTRA_DATA_KEY); Uri data = intent.getData(); if (resultType.equals(ChannelSearchProvider.INTENT_DATA_CHANNEL)) { int channelId = Integer.parseInt(data.getLastPathSegment()); Channel channel = mService.getChannel(channelId); listFragment.scrollToChannel(channel); } else if (resultType.equals(ChannelSearchProvider.INTENT_DATA_USER)) { int session = Integer.parseInt(data.getLastPathSegment()); User user = mService.getUser(session); listFragment.scrollToUser(user); } if (searchItem != null) searchItem.collapseActionView(); } }
@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); // } } }
@Override public void deleteToken(String string) { mService.getDatabaseAdapter().deleteToken(mService.getConnectedServer().getId(), string); };
@Override public List<String> getTokens() { return mService.getDatabaseAdapter().fetchAllTokens(mService.getConnectedServer().getId()); }
/* (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); }