I modified the code to use a layout rather than the menu because ActionBarShelock just display it as a regular menu. But the commands doesn't seem to work anymore after changing it.
This is how my InCallControls looks like.
public class InCallControls extends FrameLayout implements Callback {
private static final String THIS_FILE = "InCallControls";
IOnCallActionTrigger onTriggerListener;
private MediaState lastMediaState;
private SipCallSession currentCall;
private MenuBuilder btnMenuBuilder;
private boolean supportMultipleCalls = false;
CheckBox chkLoudSpeaker, chkMute, chkBluetooth;
ImageView imgAddCall, imgMediaSetting;
LinearLayout lytLoudSpeaker, lytMute, lytBluetooth;
private static String TAG = "TAG";
public InCallControls(Context context) {
this(context, null, 0);
}
public InCallControls(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public InCallControls(final Context context, AttributeSet attrs, int style) {
super(context, attrs, style);
LayoutInflater.from(context).inflate(R.layout.in_call_controls_menu_v2, this, true);
if(!isInEditMode()) {
supportMultipleCalls = SipConfigManager.getPreferenceBooleanValue(getContext(), SipConfigManager.SUPPORT_MULTIPLE_CALLS, false);
}
chkLoudSpeaker = findViewById(R.id.chkInCallControlsMenuLoudSpeaker);
chkMute = findViewById(R.id.chkInCallControlsMenuMute);
chkBluetooth = findViewById(R.id.chkInCallControlsMenuBluetooth);
imgAddCall = findViewById(R.id.imgInCallControlsMenuAddCall);
imgMediaSetting = findViewById(R.id.imgInCallControlsMenuMediaSettings);
lytLoudSpeaker = findViewById(R.id.lytInCallControlsLoudSpeaker);
lytMute = findViewById(R.id.lytIncallControlsMute);
lytBluetooth = findViewById(R.id.lytInCallControlsBluetooth);
lytLoudSpeaker.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
chkLoudSpeaker.setChecked(!chkLoudSpeaker.isChecked());
Toast.makeText(context, "loudSpeak checked: "+chkLoudSpeaker.isChecked(), Toast.LENGTH_SHORT).show();
Log.d(TAG, "loudSpeak checked: "+chkLoudSpeaker.isChecked());
if (chkLoudSpeaker.isChecked()){
dispatchTriggerEvent(IOnCallActionTrigger.SPEAKER_ON);
}else{
dispatchTriggerEvent(IOnCallActionTrigger.SPEAKER_OFF);
}
}
});
lytMute.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
chkMute.setChecked(!chkMute.isChecked());
Toast.makeText(context, "mute checked: "+chkMute.isChecked(), Toast.LENGTH_SHORT).show();
Log.d(TAG, "mute: "+chkMute.isChecked());
if (chkMute.isChecked()) {
dispatchTriggerEvent(IOnCallActionTrigger.MUTE_ON);
} else {
dispatchTriggerEvent(IOnCallActionTrigger.MUTE_OFF);
}
}
});
lytBluetooth.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
chkBluetooth.setChecked(!chkBluetooth.isChecked());
Toast.makeText(context, "bluetooth checked: "+chkBluetooth.isChecked(), Toast.LENGTH_SHORT).show();
if (chkBluetooth.isChecked()) {
dispatchTriggerEvent(IOnCallActionTrigger.BLUETOOTH_ON);
} else {
dispatchTriggerEvent(IOnCallActionTrigger.BLUETOOTH_OFF);
}
}
});
imgAddCall.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dispatchTriggerEvent(IOnCallActionTrigger.ADD_CALL);
}
});
imgMediaSetting.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dispatchTriggerEvent(IOnCallActionTrigger.MEDIA_SETTINGS);
}
});
//this.addView(menuView, layoutParams);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
// Finalize object style
setEnabledMediaButtons(false);
}
private boolean callOngoing = false;
public void setEnabledMediaButtons(boolean isInCall) {
callOngoing = isInCall;
setMediaState(lastMediaState);
}
public void setCallState(SipCallSession callInfo) {
currentCall = callInfo;
if(currentCall == null) {
setVisibility(GONE);
return;
}
int state = currentCall.getCallState();
Log.d(THIS_FILE, "Mode is : "+state);
switch (state) {
case SipCallSession.InvState.INCOMING:
setVisibility(GONE);
break;
case SipCallSession.InvState.CALLING:
case SipCallSession.InvState.CONNECTING:
setVisibility(VISIBLE);
setEnabledMediaButtons(true);
break;
case SipCallSession.InvState.CONFIRMED:
setVisibility(VISIBLE);
setEnabledMediaButtons(true);
break;
case SipCallSession.InvState.NULL:
case SipCallSession.InvState.DISCONNECTED:
setVisibility(GONE);
break;
case SipCallSession.InvState.EARLY:
default:
if (currentCall.isIncoming()) {
setVisibility(GONE);
} else {
setVisibility(VISIBLE);
setEnabledMediaButtons(true);
}
break;
}
}
/**
* Registers a callback to be invoked when the user triggers an event.
*
* @param listener
* the OnTriggerListener to attach to this view
*/
public void setOnTriggerListener(IOnCallActionTrigger listener) {
onTriggerListener = listener;
}
private void dispatchTriggerEvent(int whichHandle) {
if (onTriggerListener != null) {
onTriggerListener.onTrigger(whichHandle, currentCall);
}
}
public void setMediaState(MediaState mediaState) {
lastMediaState = mediaState;
// Update menu
// BT
boolean enabled, checked;
if(lastMediaState == null) {
enabled = callOngoing;
checked = false;
}else {
enabled = callOngoing && lastMediaState.canBluetoothSco;
checked = lastMediaState.isBluetoothScoOn;
}
chkBluetooth.setVisibility(enabled ? VISIBLE : INVISIBLE);
chkBluetooth.setChecked(checked);
// Mic
if(lastMediaState == null) {
enabled = callOngoing;
checked = false;
}else {
enabled = callOngoing && lastMediaState.canMicrophoneMute;
checked = lastMediaState.isMicrophoneMute;
}
chkMute.setVisibility(enabled ? VISIBLE : INVISIBLE );
chkMute.setChecked(checked);
// Speaker
Log.d(THIS_FILE, ">> Speaker " + lastMediaState);
if(lastMediaState == null) {
enabled = callOngoing;
checked = false;
}else {
Log.d(THIS_FILE, ">> Speaker " + lastMediaState.isSpeakerphoneOn);
enabled = callOngoing && lastMediaState.canSpeakerphoneOn;
checked = lastMediaState.isSpeakerphoneOn;
}
chkLoudSpeaker.setVisibility(enabled ? VISIBLE : INVISIBLE );
chkLoudSpeaker.setChecked(checked);
// Add call
if(supportMultipleCalls && callOngoing){
imgAddCall.setVisibility(VISIBLE);
}else {
imgAddCall.setVisibility(INVISIBLE);
}
}
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
int id = item.getItemId();
if (item.isCheckable()) {
item.setChecked(!item.isChecked());
}
if (id == R.id.bluetoothButton) {
if (item.isChecked()) {
dispatchTriggerEvent(IOnCallActionTrigger.BLUETOOTH_ON);
} else {
dispatchTriggerEvent(IOnCallActionTrigger.BLUETOOTH_OFF);
}
return true;
} else if (id == R.id.speakerButton) {
if (item.isChecked()) {
dispatchTriggerEvent(IOnCallActionTrigger.SPEAKER_ON);
} else {
dispatchTriggerEvent(IOnCallActionTrigger.SPEAKER_OFF);
}
return true;
} else if (id == R.id.muteButton) {
if (item.isChecked()) {
dispatchTriggerEvent(IOnCallActionTrigger.MUTE_ON);
} else {
dispatchTriggerEvent(IOnCallActionTrigger.MUTE_OFF);
}
return true;
} else if (id == R.id.addCallButton) {
dispatchTriggerEvent(IOnCallActionTrigger.ADD_CALL);
return true;
} else if (id == R.id.mediaSettingsButton) {
dispatchTriggerEvent(IOnCallActionTrigger.MEDIA_SETTINGS);
return true;
}
return false;
}
@Override
public void onMenuModeChange(MenuBuilder menu) {
// Nothing to do.
}
}
I modified the code to use a layout rather than the menu because ActionBarShelock just display it as a regular menu. But the commands doesn't seem to work anymore after changing it.
This is how my InCallControls looks like.
I need help on how to fix it.