Soft volume. Forced for galaxy S. Pref. access mgr.
This commit is contained in:
parent
f4a65ba623
commit
5fb71717cb
9 changed files with 118 additions and 48 deletions
|
@ -34,7 +34,6 @@ import org.linphone.ui.HangCallButton;
|
|||
import org.linphone.ui.MuteMicButton;
|
||||
import org.linphone.ui.SpeakerButton;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
|
@ -45,7 +44,6 @@ import android.os.Bundle;
|
|||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
|
@ -63,7 +61,7 @@ import android.widget.Toast;
|
|||
* </ul>
|
||||
*
|
||||
*/
|
||||
public class DialerActivity extends Activity implements LinphoneGuiListener, NewOutgoingCallUiListener {
|
||||
public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiListener, NewOutgoingCallUiListener {
|
||||
|
||||
private TextView mStatus;
|
||||
private View mHangup;
|
||||
|
@ -85,7 +83,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, New
|
|||
private SharedPreferences mPref;
|
||||
private boolean useIncallActivity;
|
||||
private boolean useVideoActivity;
|
||||
private SoftVolume softVolume;
|
||||
|
||||
private static final String CURRENT_ADDRESS = "org.linphone.current-address";
|
||||
private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
|
||||
|
@ -104,8 +101,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, New
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialer);
|
||||
|
||||
softVolume = new SoftVolume(this);
|
||||
|
||||
useIncallActivity = getResources().getBoolean(R.bool.use_incall_activity);
|
||||
useVideoActivity = getResources().getBoolean(R.bool.use_video_activity);
|
||||
// Don't use Linphone Manager in the onCreate as it takes time in LinphoneService to initialize it.
|
||||
|
@ -422,10 +417,4 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, New
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (softVolume.onKeyDown(keyCode, event)) return true;
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.TimerTask;
|
|||
|
||||
import org.linphone.ui.HangCallButton;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -33,7 +32,7 @@ import android.view.View;
|
|||
import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class IncallActivity extends Activity implements OnClickListener {
|
||||
public class IncallActivity extends SoftVolumeActivity implements OnClickListener {
|
||||
|
||||
public static final String CONTACT_KEY = "contact";
|
||||
private View numpadClose;
|
||||
|
|
|
@ -111,6 +111,7 @@ public class LinphoneActivity extends TabActivity {
|
|||
instance = this;
|
||||
setContentView(R.layout.main);
|
||||
|
||||
LinphonePreferenceManager.setContext(this);
|
||||
useFirstLoginActivity = getResources().getBoolean(R.bool.useFirstLoginActivity);
|
||||
useMenuSettings = getResources().getBoolean(R.bool.useMenuSettings);
|
||||
useMenuAbout = getResources().getBoolean(R.bool.useMenuAbout);
|
||||
|
|
|
@ -156,6 +156,8 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
}
|
||||
|
||||
public static final String TAG="Linphone";
|
||||
private static final int LINPHONE_VOLUME_STREAM = STREAM_VOICE_CALL;
|
||||
private static final int dbStep = 4;
|
||||
/** Called when the activity is first created. */
|
||||
private final String linphoneInitialConfigFile;
|
||||
private final String linphoneConfigFile;
|
||||
|
@ -331,9 +333,6 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
this, linphoneConfigFile, linphoneInitialConfigFile, null);
|
||||
|
||||
mLc.enableIpv6(mPref.getBoolean(getString(R.string.pref_ipv6_key), false));
|
||||
if (mPref.getBoolean(getString(R.string.pref_audio_soft_volume_key), false)) {
|
||||
adjustSoftwareVolume(0); // Set maximum
|
||||
}
|
||||
|
||||
mLc.setPlaybackGain(3);
|
||||
mLc.setRing(null);
|
||||
|
@ -696,6 +695,12 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
mAudioManager.setMode(MODE_NORMAL);
|
||||
}
|
||||
|
||||
if (state == State.Connected) {
|
||||
if (Hacks.needSoftvolume() || LinphonePreferenceManager.getInstance().useSoftvolume()) {
|
||||
adjustSoftwareVolume(0); // Synchronize
|
||||
}
|
||||
}
|
||||
|
||||
mCurrentCallState=state;
|
||||
serviceListener.onCallStateChanged(call, state, message);
|
||||
}
|
||||
|
@ -861,7 +866,14 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
}
|
||||
|
||||
public void adjustSoftwareVolume(int i) {
|
||||
mLc.adjustSoftwareVolume(i);
|
||||
int oldVolume = mAudioManager.getStreamVolume(LINPHONE_VOLUME_STREAM);
|
||||
int maxVolume = mAudioManager.getStreamMaxVolume(LINPHONE_VOLUME_STREAM);
|
||||
|
||||
int nextVolume = oldVolume +i;
|
||||
if (nextVolume > maxVolume) nextVolume = maxVolume;
|
||||
if (nextVolume < 0) nextVolume = 0;
|
||||
|
||||
mLc.adjustSoftwareVolume((nextVolume - maxVolume)* dbStep);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
54
src/org/linphone/LinphonePreferenceManager.java
Normal file
54
src/org/linphone/LinphonePreferenceManager.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
PreferenceManager.java
|
||||
Copyright (C) 2011 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
package org.linphone;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class LinphonePreferenceManager {
|
||||
|
||||
private static LinphonePreferenceManager instance;
|
||||
private static Context c;
|
||||
private static SharedPreferences p;
|
||||
|
||||
public LinphonePreferenceManager() {
|
||||
p = PreferenceManager.getDefaultSharedPreferences(c);
|
||||
}
|
||||
|
||||
private String getString(int key) {
|
||||
return c.getString(key);
|
||||
}
|
||||
|
||||
public static final synchronized LinphonePreferenceManager getInstance() {
|
||||
if (c == null) throw new RuntimeException("need a context");
|
||||
if (instance == null) instance = new LinphonePreferenceManager();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static final void setContext(Context context) {
|
||||
c = context.getApplicationContext();
|
||||
}
|
||||
|
||||
|
||||
public boolean useSoftvolume() {
|
||||
return p.getBoolean(
|
||||
getString(R.string.pref_audio_soft_volume_key), false);
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
import org.linphone.LinphoneManager.EcCalibrationListener;
|
||||
import org.linphone.core.Hacks;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.Version;
|
||||
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
||||
|
@ -96,7 +97,7 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
|
|||
|
||||
// No video
|
||||
if (Version.sdkStrictlyBelow(5) || !fastCpu || !LinphoneManager.getInstance().hasCamera()) {
|
||||
disableCheckbox(pref_video_enable_key);
|
||||
uncheckAndDisableCheckbox(pref_video_enable_key);
|
||||
}
|
||||
if (prefs().getBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,true)) {
|
||||
if (fastCpu) {
|
||||
|
@ -110,8 +111,10 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
|
|||
detectVideoCodec(R.string.pref_video_codec_h264_key, "H264");
|
||||
|
||||
if (!AndroidCameraRecordManager.getInstance().hasFrontCamera()) {
|
||||
disableAndHideCheckbox(R.string.pref_video_use_front_camera_key);
|
||||
uncheckDisableAndHideCheckbox(R.string.pref_video_use_front_camera_key);
|
||||
}
|
||||
|
||||
if (Hacks.needSoftvolume()) checkAndDisableCheckbox(R.string.pref_audio_soft_volume_key);
|
||||
}
|
||||
|
||||
|
||||
|
@ -194,19 +197,22 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
|
|||
});
|
||||
}
|
||||
|
||||
private void disableAndHideCheckbox(int key) {
|
||||
writeBoolean(key, false);
|
||||
CheckBoxPreference box = (CheckBoxPreference) findPreference(key);
|
||||
box.setEnabled(false);
|
||||
box.setChecked(false);
|
||||
box.setLayoutResource(R.layout.hidden);
|
||||
private void uncheckDisableAndHideCheckbox(int key) {
|
||||
manageCheckbox(key, false, false, true);
|
||||
}
|
||||
|
||||
private void disableCheckbox(int key) {
|
||||
writeBoolean(key, false);
|
||||
private void uncheckAndDisableCheckbox(int key) {
|
||||
manageCheckbox(key, false, false, false);
|
||||
}
|
||||
private void checkAndDisableCheckbox(int key) {
|
||||
manageCheckbox(key, true, false, false);
|
||||
}
|
||||
private void manageCheckbox(int key, boolean value, boolean enabled, boolean hidden) {
|
||||
CheckBoxPreference box = (CheckBoxPreference) findPreference(key);
|
||||
box.setEnabled(false);
|
||||
box.setChecked(false);
|
||||
box.setEnabled(enabled);
|
||||
box.setChecked(value);
|
||||
writeBoolean(key, value);
|
||||
if (hidden) box.setLayoutResource(R.layout.hidden);
|
||||
}
|
||||
|
||||
private Preference findPreference(int key) {
|
||||
|
|
|
@ -18,32 +18,39 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
package org.linphone;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.PreferenceManager;
|
||||
import org.linphone.core.Hacks;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
public class SoftVolume {
|
||||
/**
|
||||
* Activity which handles softvolume.
|
||||
* @author Guillaume Beraudo
|
||||
*
|
||||
*/
|
||||
public class SoftVolumeActivity extends Activity {
|
||||
|
||||
private Context c;
|
||||
private static boolean preventVolumeBarToDisplay = false;
|
||||
|
||||
public SoftVolume(Context context) {
|
||||
c = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (!PreferenceManager.getDefaultSharedPreferences(c).getBoolean(
|
||||
c.getString(R.string.pref_audio_soft_volume_key), false))
|
||||
if (keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
return false;
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||
LinphoneManager.getInstance().adjustSoftwareVolume(6);
|
||||
return true;
|
||||
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
LinphoneManager.getInstance().adjustSoftwareVolume(-6);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (!Hacks.needSoftvolume() && !LinphonePreferenceManager.getInstance().useSoftvolume())
|
||||
return false;
|
||||
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||
LinphoneManager.getInstance().adjustSoftwareVolume(1);
|
||||
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
LinphoneManager.getInstance().adjustSoftwareVolume(-1);
|
||||
}
|
||||
|
||||
return preventVolumeBarToDisplay;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@ import org.linphone.core.Version;
|
|||
import org.linphone.core.VideoSize;
|
||||
import org.linphone.core.video.AndroidCameraRecordManager;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Bundle;
|
||||
|
@ -43,7 +42,7 @@ import android.view.ViewGroup.LayoutParams;
|
|||
* @author Guillaume Beraudo
|
||||
*
|
||||
*/
|
||||
public class VideoCallActivity extends Activity {
|
||||
public class VideoCallActivity extends SoftVolumeActivity {
|
||||
private SurfaceView mVideoView;
|
||||
private SurfaceView mVideoCaptureView;
|
||||
private AndroidCameraRecordManager recordManager;
|
||||
|
@ -207,5 +206,4 @@ public class VideoCallActivity extends Activity {
|
|||
super.onPause();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -97,4 +97,8 @@ public final class Hacks {
|
|||
|
||||
Log.d(LinphoneManager.TAG, sb.toString());
|
||||
}
|
||||
|
||||
public static boolean needSoftvolume() {
|
||||
return isGalaxySOrTab();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue