update volume management to Handle ICS behavior

This commit is contained in:
Jehan Monnier 2012-07-04 14:50:54 +02:00
parent 89093384a4
commit 9b0f8be225
7 changed files with 22 additions and 18 deletions

View file

@ -160,8 +160,6 @@
<CheckBoxPreference android:key="@string/pref_debug_key" <CheckBoxPreference android:key="@string/pref_debug_key"
android:title="@string/pref_debug" android:enabled="true"></CheckBoxPreference> android:title="@string/pref_debug" android:enabled="true"></CheckBoxPreference>
<CheckBoxPreference android:key="@string/pref_audio_soft_volume_key"
android:title="@string/pref_audio_soft_volume_title" />
<PreferenceScreen android:title="@string/pref_network_title"> <PreferenceScreen android:title="@string/pref_network_title">
<CheckBoxPreference android:key="@string/pref_ipv6_key" <CheckBoxPreference android:key="@string/pref_ipv6_key"

View file

@ -564,7 +564,7 @@ public class DialerActivity extends Activity implements LinphoneGuiListener {
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (LinphoneUtils.onKeyVolumeSoftAdjust(keyCode)) return true; if (LinphoneUtils.onKeyVolumeAdjust(keyCode)) return true;
boolean isInCall = LinphoneManager.getLc().isIncall(); boolean isInCall = LinphoneManager.getLc().isIncall();
isInCall = isInCall || LinphoneManager.getLc().getCallsNb() > 0; isInCall = isInCall || LinphoneManager.getLc().getCallsNb() > 0;
if (keyCode == KeyEvent.KEYCODE_BACK && isInCall) { if (keyCode == KeyEvent.KEYCODE_BACK && isInCall) {

View file

@ -812,7 +812,7 @@ public class IncallActivity extends AbstractCalleesActivity implements
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (LinphoneUtils.onKeyVolumeSoftAdjust(keyCode)) return true; if (LinphoneUtils.onKeyVolumeAdjust(keyCode)) return true;
if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) return true; if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) return true;
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }

View file

@ -93,6 +93,7 @@ import android.media.AudioManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.os.Vibrator; import android.os.Vibrator;
@ -990,7 +991,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
if (state == State.Connected) { if (state == State.Connected) {
if (Hacks.needSoftvolume() || sLPref.useSoftvolume()) { if (Hacks.needSoftvolume() || sLPref.useSoftvolume()) {
adjustSoftwareVolume(0); // Synchronize adjustVolume(0); // Synchronize
} }
} }
@ -1225,15 +1226,19 @@ public final class LinphoneManager implements LinphoneCoreListener {
return r.getString(R.string.unknown_incoming_call_name); return r.getString(R.string.unknown_incoming_call_name);
} }
public void adjustSoftwareVolume(int i) { public void adjustVolume(int i) {
int oldVolume = mAudioManager.getStreamVolume(LINPHONE_VOLUME_STREAM); if (Build.VERSION.SDK_INT<15) {
int maxVolume = mAudioManager.getStreamMaxVolume(LINPHONE_VOLUME_STREAM); int oldVolume = mAudioManager.getStreamVolume(LINPHONE_VOLUME_STREAM);
int maxVolume = mAudioManager.getStreamMaxVolume(LINPHONE_VOLUME_STREAM);
int nextVolume = oldVolume +i; int nextVolume = oldVolume +i;
if (nextVolume > maxVolume) nextVolume = maxVolume; if (nextVolume > maxVolume) nextVolume = maxVolume;
if (nextVolume < 0) nextVolume = 0; if (nextVolume < 0) nextVolume = 0;
mLc.adjustSoftwareVolume((nextVolume - maxVolume)* dbStep); mLc.adjustSoftwareVolume((nextVolume - maxVolume)* dbStep);
} else
// starting from ICS, volume must be adjusted by the application, at least for STREAM_VOICE_CALL volume stream
mAudioManager.adjustStreamVolume(LINPHONE_VOLUME_STREAM, i<0?AudioManager.ADJUST_LOWER:AudioManager.ADJUST_RAISE, 0);
} }
public static Boolean isProximitySensorNearby(final SensorEvent event) { public static Boolean isProximitySensorNearby(final SensorEvent event) {

View file

@ -47,6 +47,7 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -74,9 +75,9 @@ public final class LinphoneUtils {
return true; return true;
} }
public static boolean onKeyVolumeSoftAdjust(int keyCode) { public static boolean onKeyVolumeAdjust(int keyCode) {
if (!((keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) if (!((keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
&& Hacks.needSoftvolume())) { && (Hacks.needSoftvolume())|| Build.VERSION.SDK_INT>=15)) {
return false; // continue return false; // continue
} }
@ -84,9 +85,9 @@ public final class LinphoneUtils {
Log.i("Couldn't change softvolume has service is not running"); Log.i("Couldn't change softvolume has service is not running");
return true; return true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
LinphoneManager.getInstance().adjustSoftwareVolume(1); LinphoneManager.getInstance().adjustVolume(1);
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
LinphoneManager.getInstance().adjustSoftwareVolume(-1); LinphoneManager.getInstance().adjustVolume(-1);
} }
return preventVolumeBarToDisplay; return preventVolumeBarToDisplay;
} }

View file

@ -374,7 +374,7 @@ public class VideoCallActivity extends Activity implements
} }
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (LinphoneUtils.onKeyVolumeSoftAdjust(keyCode)) if (LinphoneUtils.onKeyVolumeAdjust(keyCode))
return true; return true;
if (Version.isXLargeScreen(this) && LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) { if (Version.isXLargeScreen(this) && LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
return true; return true;

@ -1 +1 @@
Subproject commit 9f02a12f4641989a225ee77bf6f403cd1c57d9e6 Subproject commit 9496394c88dbdf6e6dd120b5657a2846b603d612