Corrected speaker and mute buttons not correctly handling state.

This commit is contained in:
Guillaume Beraudo 2010-11-29 14:08:58 +01:00
parent 03568062a5
commit c2ced898a6
4 changed files with 30 additions and 22 deletions

View file

@ -25,13 +25,13 @@
android:layout_width="fill_parent"></EditText> android:layout_width="fill_parent"></EditText>
<org.linphone.component.ToggleImageButton <org.linphone.component.ToggleImageButton
android:id="@+id/mic_mute_button" android:layout_height="wrap_content" android:id="@+id/mic_mute_button" android:layout_height="wrap_content"
android:layout_width="wrap_content" toggled="@drawable/mic_muted" android:layout_width="wrap_content" android:layout_weight="0.5"
untoggled="@drawable/mic_active" android:layout_weight="0.5" checked="@drawable/mic_muted" unchecked="@drawable/mic_active"
android:layout_gravity="left|center_vertical" /> android:layout_gravity="left|center_vertical" />
<org.linphone.component.ToggleImageButton <org.linphone.component.ToggleImageButton
android:id="@+id/speaker_button" android:layout_height="wrap_content" android:id="@+id/speaker_button" android:layout_height="wrap_content"
android:layout_width="wrap_content" toggled="@drawable/speaker_32_on" android:layout_width="wrap_content" android:layout_weight="0.5"
untoggled="@drawable/speaker_32_off" android:layout_weight="0.5" checked="@drawable/speaker_32_on" unchecked="@drawable/speaker_32_off"
android:layout_gravity="right|center_vertical" /> android:layout_gravity="right|center_vertical" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>

View file

@ -26,11 +26,11 @@
></EditText> ></EditText>
<org.linphone.component.ToggleImageButton android:id="@+id/mic_mute_button" <org.linphone.component.ToggleImageButton android:id="@+id/mic_mute_button"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_width="wrap_content"
toggled="@drawable/mic_muted" untoggled="@drawable/mic_active" checked="@drawable/mic_muted" unchecked="@drawable/mic_active"
android:layout_gravity="left|center_vertical"/> android:layout_gravity="left|center_vertical"/>
<org.linphone.component.ToggleImageButton android:id="@+id/speaker_button" <org.linphone.component.ToggleImageButton android:id="@+id/speaker_button"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_width="wrap_content"
toggled="@drawable/speaker_32_on" untoggled="@drawable/speaker_32_off" checked="@drawable/speaker_32_on" unchecked="@drawable/speaker_32_off"
android:layout_gravity="right|center_vertical"/> android:layout_gravity="right|center_vertical"/>
</FrameLayout> </FrameLayout>

View file

@ -249,17 +249,14 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mInCallControlRow.setVisibility(View.VISIBLE); mInCallControlRow.setVisibility(View.VISIBLE);
mAddressLayout.setVisibility(View.GONE); mAddressLayout.setVisibility(View.GONE);
mInCallAddressLayout.setVisibility(View.VISIBLE); mInCallAddressLayout.setVisibility(View.VISIBLE);
mMute.setChecked(!lLinphoneCore.isMicMuted());
String DisplayName = lLinphoneCore.getRemoteAddress().getDisplayName(); String DisplayName = lLinphoneCore.getRemoteAddress().getDisplayName();
if (DisplayName!=null) { if (DisplayName!=null) {
mDisplayNameView.setText(DisplayName); mDisplayNameView.setText(DisplayName);
} else { } else {
mDisplayNameView.setText(lLinphoneCore.getRemoteAddress().getUserName()); mDisplayNameView.setText(lLinphoneCore.getRemoteAddress().getUserName());
} }
if ((Integer.parseInt(Build.VERSION.SDK) <=4 && mAudioManager.getMode() == AudioManager.MODE_NORMAL) configureMuteButtons();
|| Integer.parseInt(Build.VERSION.SDK) >4 &&mAudioManager.isSpeakerphoneOn()) {
mSpeaker.setChecked(true);
}
mWakeLock.acquire(); mWakeLock.acquire();
} }
} }
@ -271,9 +268,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
public void onCheckedChanged(ToggleImageButton button, boolean isChecked) { public void onCheckedChanged(ToggleImageButton button, boolean isChecked) {
LinphoneCore lc = LinphoneService.instance().getLinphoneCore(); LinphoneCore lc = LinphoneService.instance().getLinphoneCore();
if (isChecked) { if (isChecked) {
lc.muteMic(false);
} else {
lc.muteMic(true); lc.muteMic(true);
} else {
lc.muteMic(false);
} }
} }
}); });
@ -497,6 +494,8 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mDisplayNameView.setText(lc.getRemoteAddress().toString()); mDisplayNameView.setText(lc.getRemoteAddress().toString());
} }
} }
configureMuteButtons();
if (mSpeaker.isChecked()) { if (mSpeaker.isChecked()) {
routeAudioToSpeaker(); routeAudioToSpeaker();
} else { } else {
@ -504,6 +503,15 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
} }
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
} }
private void configureMuteButtons() {
mMute.setChecked(LinphoneService.instance().getLinphoneCore().isMicMuted());
if ((Integer.parseInt(Build.VERSION.SDK) <=4 && mAudioManager.getMode() == AudioManager.MODE_NORMAL)
|| Integer.parseInt(Build.VERSION.SDK) >4 &&mAudioManager.isSpeakerphoneOn()) {
mSpeaker.setChecked(true);
} else {
mSpeaker.setChecked(false);
}
}
private void exitCallMode() { private void exitCallMode() {
mCallControlRow.setVisibility(View.VISIBLE); mCallControlRow.setVisibility(View.VISIBLE);
mInCallControlRow.setVisibility(View.GONE); mInCallControlRow.setVisibility(View.GONE);
@ -512,13 +520,13 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mCall.setEnabled(true); mCall.setEnabled(true);
mHangup.setEnabled(false); mHangup.setEnabled(false);
setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE); setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
mMute.setChecked(true);
mSpeaker.setChecked(false);
mDecline.setEnabled(false); mDecline.setEnabled(false);
if (LinphoneService.instance().getLinphoneCore().isVideoEnabled()) { if (LinphoneService.instance().getLinphoneCore().isVideoEnabled()) {
finishActivity(VIDEO_VIEW_ACTIVITY); finishActivity(VIDEO_VIEW_ACTIVITY);
} }
if (mWakeLock.isHeld())mWakeLock.release(); if (mWakeLock.isHeld())mWakeLock.release();
mSpeaker.setChecked(false);
routeAudioToReceiver();
} }
private void routeAudioToSpeaker() { private void routeAudioToSpeaker() {
if (Integer.parseInt(Build.VERSION.SDK) <= 4 /*<donut*/) { if (Integer.parseInt(Build.VERSION.SDK) <= 4 /*<donut*/) {

View file

@ -29,8 +29,8 @@ import android.widget.ImageButton;
/** /**
* Image button storing a checked state to display alternating drawables. * Image button storing a checked state to display alternating drawables.
* The "toggled" drawable is displayed when button is down / checked. * The "checked" drawable is displayed when button is down / checked.
* The "untoggled" drawable is displayed when button is up / unchecked. * The "unchecked" drawable is displayed when button is up / unchecked.
* *
* @author Guillaume Beraudo * @author Guillaume Beraudo
* *
@ -38,14 +38,14 @@ import android.widget.ImageButton;
public class ToggleImageButton extends ImageButton implements OnClickListener { public class ToggleImageButton extends ImageButton implements OnClickListener {
private static final String namespace = null; private static final String namespace = null;
private boolean checked; private boolean checked;
private Drawable on; private Drawable stateChecked;
private Drawable off; private Drawable stateUnChecked;
private OnCheckedChangeListener onCheckedChangeListener; private OnCheckedChangeListener onCheckedChangeListener;
public ToggleImageButton(Context context, AttributeSet attrs) { public ToggleImageButton(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
on = getResources().getDrawable(attrs.getAttributeResourceValue(namespace, "toggled", -1)); stateChecked = getResources().getDrawable(attrs.getAttributeResourceValue(namespace, "checked", -1));
off = getResources().getDrawable(attrs.getAttributeResourceValue(namespace, "untoggled", -1)); stateUnChecked = getResources().getDrawable(attrs.getAttributeResourceValue(namespace, "unchecked", -1));
setBackgroundColor(Color.TRANSPARENT); setBackgroundColor(Color.TRANSPARENT);
setOnClickListener(this); setOnClickListener(this);
@ -65,7 +65,7 @@ public class ToggleImageButton extends ImageButton implements OnClickListener {
private void handleCheckChanged() { private void handleCheckChanged() {
setImageDrawable(checked?on:off); setImageDrawable(checked?stateChecked:stateUnChecked);
requestLayout(); requestLayout();
invalidate(); invalidate();
if (onCheckedChangeListener != null) onCheckedChangeListener.onCheckedChanged(this, checked); if (onCheckedChangeListener != null) onCheckedChangeListener.onCheckedChanged(this, checked);