use of android.media.AudioManager in project Signal-Android by WhisperSystems.
the class SignalAudioManager method startOutgoingRinger.
public void startOutgoingRinger(OutgoingRinger.Type type) {
AudioManager audioManager = ServiceUtil.getAudioManager(context);
audioManager.setMicrophoneMute(false);
if (type == OutgoingRinger.Type.SONAR) {
audioManager.setSpeakerphoneOn(false);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
} else {
audioManager.setMode(AudioManager.MODE_IN_CALL);
}
outgoingRinger.start(type);
}
use of android.media.AudioManager in project Signal-Android by WhisperSystems.
the class SignalAudioManager method startIncomingRinger.
public void startIncomingRinger() {
AudioManager audioManager = ServiceUtil.getAudioManager(context);
boolean speaker = !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
} else {
audioManager.setMode(AudioManager.MODE_IN_CALL);
}
audioManager.setMicrophoneMute(false);
audioManager.setSpeakerphoneOn(speaker);
incomingRinger.start(speaker);
}
use of android.media.AudioManager in project actor-platform by actorapp.
the class CallFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.callId = getArguments().getLong("call_id");
this.call = messenger().getCall(callId);
if (call == null) {
this.peer = Peer.user(myUid());
} else {
this.peer = call.getPeer();
}
manager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
FrameLayout cont = (FrameLayout) inflater.inflate(R.layout.fragment_call, container, false);
v = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
CallBackgroundAvatarView backgroundAvatarView = (CallBackgroundAvatarView) cont.findViewById(R.id.background);
// animator = new CallAvatarLayerAnimator(cont.findViewById(R.id.layer),
// cont.findViewById(R.id.layer1),
// cont.findViewById(R.id.layer2),
// cont.findViewById(R.id.layer3),
// cont.findViewById(R.id.layer4)
// );
layer1 = cont.findViewById(R.id.layer1);
layer2 = cont.findViewById(R.id.layer2);
layer3 = cont.findViewById(R.id.layer3);
avatarLayers = new View[] { // cont.findViewById(R.id.layer),
layer1, layer2, layer3 };
for (int i = 0; i < avatarLayers.length; i++) {
View layer = avatarLayers[i];
((GradientDrawable) layer.getBackground()).setColor(Color.WHITE);
((GradientDrawable) layer.getBackground()).setAlpha(50);
}
endCallContainer = cont.findViewById(R.id.end_call_container);
answerContainer = cont.findViewById(R.id.answer_container);
ImageButton answer = (ImageButton) cont.findViewById(R.id.answer);
answer.setOnClickListener(v1 -> onAnswer());
ImageButton notAnswer = (ImageButton) cont.findViewById(R.id.notAnswer);
endCall = (ImageButton) cont.findViewById(R.id.end_call);
notAnswer.setOnClickListener(v1 -> doEndCall());
endCall.setOnClickListener(v1 -> doEndCall());
//
//Avatar/Name bind
//
avatarView = (AvatarView) cont.findViewById(R.id.avatar);
avatarView.init(Screen.dp(130), 50);
nameTV = (TextView) cont.findViewById(R.id.name);
nameTV.setTextColor(ActorSDK.sharedActor().style.getProfileTitleColor());
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM user = users().get(peer.getPeerId());
avatarView.bind(user);
backgroundAvatarView.bind(user);
bind(nameTV, user.getName());
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupVM g = groups().get(peer.getPeerId());
avatarView.bind(g);
backgroundAvatarView.bind(g);
bind(nameTV, g.getName());
}
nameTV.setSelected(true);
//
// Members list
//
membersList = (RecyclerListView) cont.findViewById(R.id.members_list);
if (call != null) {
CallMembersAdapter membersAdapter = new CallMembersAdapter(getActivity(), call.getMembers());
membersList.setAdapter(membersAdapter);
}
//
// Members list/ avatar switch
//
View.OnClickListener listener = v1 -> switchAvatarMembers();
avatarView.setOnClickListener(listener);
// cont.findViewById(R.id.background).setOnClickListener(listener);
membersList.setOnItemClickListener((parent, view, position, id) -> switchAvatarMembers());
statusTV = (TextView) cont.findViewById(R.id.status);
//
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.MODIFY_AUDIO_SETTINGS) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WAKE_LOCK) != PackageManager.PERMISSION_GRANTED) {
Log.d("Permissions", "call - no permission :c");
CallFragment.this.requestPermissions(new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA, Manifest.permission.VIBRATE, Manifest.permission.MODIFY_AUDIO_SETTINGS, Manifest.permission.WAKE_LOCK }, PERMISSIONS_REQUEST_FOR_CALL);
}
audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
speaker = (TintImageView) cont.findViewById(R.id.speaker);
speaker.setResource(R.drawable.ic_volume_up_white_24dp);
speakerTV = (TextView) cont.findViewById(R.id.speaker_tv);
cont.findViewById(R.id.speaker_btn).setOnClickListener(v1 -> toggleSpeaker(speaker, speakerTV));
checkSpeaker(speaker, speakerTV);
muteCall = (TintImageView) cont.findViewById(R.id.mute);
muteCallTv = (TextView) cont.findViewById(R.id.mute_tv);
muteCall.setResource(R.drawable.ic_mic_off_white_24dp);
cont.findViewById(R.id.mute_btn).setOnClickListener(v1 -> messenger().toggleCallMute(callId));
videoIcon = (TintImageView) cont.findViewById(R.id.video);
videoIcon.setResource(R.drawable.ic_videocam_white_24dp);
videoTv = (TextView) cont.findViewById(R.id.video_tv);
videoTv.setTextColor(getResources().getColor(R.color.picker_grey));
videoIcon.setTint(getResources().getColor(R.color.picker_grey));
cont.findViewById(R.id.video_btn).setOnClickListener(v1 -> messenger().toggleVideoEnabled(callId));
final TintImageView back = (TintImageView) cont.findViewById(R.id.back);
back.setResource(R.drawable.ic_message_white_24dp);
cont.findViewById(R.id.back_btn).setOnClickListener(v1 -> getActivity().startActivity(Intents.openDialog(peer, false, getActivity())));
final TintImageView add = (TintImageView) cont.findViewById(R.id.add);
add.setResource(R.drawable.ic_person_add_white_24dp);
TextView addTv = (TextView) cont.findViewById(R.id.add_user_tv);
addTv.setTextColor(getResources().getColor(R.color.picker_grey));
add.setTint(getResources().getColor(R.color.picker_grey));
if (peer.getPeerType() == PeerType.PRIVATE) {
eglContext = EglBase.create();
remoteVideoView = (SurfaceViewRenderer) cont.findViewById(R.id.remote_renderer);
localVideoView = new SurfaceViewRenderer(getActivity()) {
private boolean aspectFixed = false;
@Override
public void renderFrame(VideoRenderer.I420Frame frame) {
if (!aspectFixed) {
aspectFixed = true;
int maxWH = Screen.getWidth() / 3 - Screen.dp(20);
float scale = Math.min(maxWH / (float) frame.width, maxWH / (float) frame.height);
int destW = (int) (scale * frame.width);
int destH = (int) (scale * frame.height);
boolean turned = frame.rotationDegree % 90 % 2 == 0;
localVideoView.post(new Runnable() {
@Override
public void run() {
localVideoView.getLayoutParams().height = turned ? destW : destH;
localVideoView.getLayoutParams().width = turned ? destH : destW;
}
});
}
super.renderFrame(frame);
}
};
localVideoView.setVisibility(View.INVISIBLE);
localVideoView.setZOrderMediaOverlay(true);
localVideoView.setOnTouchListener((v1, event) -> {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
dX = localVideoView.getX() - event.getRawX();
dY = localVideoView.getY() - event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
localVideoView.animate().x(event.getRawX() + dX).y(event.getRawY() + dY).setDuration(0).start();
default:
return false;
}
return true;
});
int margin = Screen.dp(20);
int localVideoWidth = Screen.getWidth() / 3 - margin;
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(localVideoWidth, Math.round(localVideoWidth / 1.5f), Gravity.TOP | Gravity.LEFT);
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
params.setMargins(margin, margin + statusBarHeight, 0, 0);
cont.addView(localVideoView, params);
} else {
if (call != null) {
if (call.getIsVideoEnabled().get()) {
messenger().toggleVideoEnabled(callId);
}
}
}
return cont;
}
use of android.media.AudioManager in project android_frameworks_base by ParanoidAndroid.
the class MediaPlayPauseButton method isMusicActive.
private boolean isMusicActive(Context context) {
if (mCurrentState == MEDIA_STATE_UNKNOWN) {
mCurrentState = MEDIA_STATE_INACTIVE;
AudioManager am = getAudioManager(context);
if (am != null) {
mCurrentState = (am.isMusicActive() ? MEDIA_STATE_ACTIVE : MEDIA_STATE_INACTIVE);
}
return (mCurrentState == MEDIA_STATE_ACTIVE);
} else {
boolean active = (mCurrentState == MEDIA_STATE_ACTIVE);
mCurrentState = MEDIA_STATE_UNKNOWN;
return active;
}
}
use of android.media.AudioManager in project android_frameworks_base by ParanoidAndroid.
the class PhoneWindow method onKeyUpPanel.
/**
* Called when the panel key is released.
* @param featureId The feature ID of the relevant panel (defaults to FEATURE_OPTIONS_PANEL}.
* @param event The key event.
*/
public final void onKeyUpPanel(int featureId, KeyEvent event) {
// The panel key was released, so clear the chording key
if (mPanelChordingKey != 0) {
mPanelChordingKey = 0;
if (event.isCanceled() || (mDecor != null && mDecor.mActionMode != null)) {
return;
}
boolean playSoundEffect = false;
final PanelFeatureState st = getPanelState(featureId, true);
if (featureId == FEATURE_OPTIONS_PANEL && mActionBar != null && mActionBar.isOverflowReserved()) {
if (mActionBar.getVisibility() == View.VISIBLE) {
if (!mActionBar.isOverflowMenuShowing()) {
if (!isDestroyed() && preparePanel(st, event)) {
playSoundEffect = mActionBar.showOverflowMenu();
}
} else {
playSoundEffect = mActionBar.hideOverflowMenu();
}
}
} else {
if (st.isOpen || st.isHandled) {
// Play the sound effect if the user closed an open menu (and not if
// they just released a menu shortcut)
playSoundEffect = st.isOpen;
// Close menu
closePanel(st, true);
} else if (st.isPrepared) {
boolean show = true;
if (st.refreshMenuContent) {
// Something may have invalidated the menu since we prepared it.
// Re-prepare it to refresh.
st.isPrepared = false;
show = preparePanel(st, event);
}
if (show) {
// Write 'menu opened' to event log
EventLog.writeEvent(50001, 0);
// Show menu
openPanel(st, event);
playSoundEffect = true;
}
}
}
if (playSoundEffect) {
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) {
audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
} else {
Log.w(TAG, "Couldn't get audio manager");
}
}
}
}
Aggregations