Uri picker dialer don't play dtmf but concatenate to address.

This commit is contained in:
Guillaume Beraudo 2011-10-12 16:01:38 +02:00
parent 2a54fc632f
commit 31a660a6a1
6 changed files with 70 additions and 29 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:linphone="http://schemas.android.com/apk/res/linphone"
xmlns:linphone="http://schemas.android.com/apk/res/org.linphone"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
@ -20,6 +20,7 @@
</LinearLayout>
<org.linphone.ui.Numpad android:id="@+id/Dialer"
linphone:play_dtmf="dont"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="4" />

View file

@ -9,4 +9,13 @@
<item name="android:textSize">20sp</item>
<item name="android:layout_weight">1</item>
</style>
<declare-styleable name="Numpad">
<attr name="play_dtmf">
<enum name="dont" value="0" />
<enum name="play" value="1" />
</attr>
</declare-styleable>
</resources>

View file

@ -88,7 +88,6 @@ import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.PowerManager;
import android.os.Vibrator;
import android.os.PowerManager.WakeLock;
@ -242,7 +241,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
AndroidVideoApi5JniWrapper.setAndroidSdkVersion(Version.sdk());
return instance;
}
public static synchronized final LinphoneManager getInstance() {
if (instance != null) return instance;

View file

@ -20,7 +20,9 @@ package org.linphone;
import org.linphone.mediastream.Version;
import org.linphone.ui.AddressAware;
import org.linphone.ui.AddressText;
import org.linphone.ui.Numpad;
import android.app.Activity;
import android.app.TabActivity;
@ -130,6 +132,7 @@ public class UriPickerActivity extends TabActivity implements ContactPicked {
// findViewById(R.id.AddCallCancelButton).setOnClickListener(this);
((AddressAware)findViewById(R.id.Dialer)).setAddressWidget(mAddress);
super.onCreate(savedInstanceState);
}

View file

@ -34,8 +34,15 @@ import android.widget.Toast;
public class Digit extends Button implements AddressAware {
private AddressText mAddress;
public void setAddressWidget(AddressText address) {
mAddress = address;
}
private boolean mPlayDtmf;
public void setPlayDtmf(boolean play) {
mPlayDtmf = play;
}
@Override
protected void onTextChanged(CharSequence text, int start, int before,
int after) {
@ -75,7 +82,7 @@ public class Digit extends Button implements AddressAware {
private class DialKeyListener implements OnClickListener, OnTouchListener, OnLongClickListener {
final CharSequence mKeyCode;
boolean mIsDtmfStarted=false;
boolean mIsDtmfStarted;
DialKeyListener() {
mKeyCode = Digit.this.getText().subSequence(0, 1);
@ -89,15 +96,20 @@ public class Digit extends Button implements AddressAware {
}
return true;
}
public void onClick(View v) {
if (!linphoneServiceReady()) return;
LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf();
mIsDtmfStarted =false;
if (lc.isIncall()) {
lc.sendDtmf(mKeyCode.charAt(0));
} else if (mAddress != null) {
public void onClick(View v) {
if (mPlayDtmf) {
if (!linphoneServiceReady()) return;
LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf();
mIsDtmfStarted =false;
if (lc.isIncall()) {
lc.sendDtmf(mKeyCode.charAt(0));
return;
}
}
if (mAddress != null) {
int lBegin = mAddress.getSelectionStart();
if (lBegin == -1) {
lBegin = mAddress.length();
@ -109,24 +121,29 @@ public class Digit extends Button implements AddressAware {
}
public boolean onTouch(View v, MotionEvent event) {
if (!mPlayDtmf) return false;
if (!linphoneServiceReady()) return true;
LinphoneCore lc = LinphoneManager.getLc();
if (event.getAction() == MotionEvent.ACTION_DOWN && mIsDtmfStarted ==false) {
if (event.getAction() == MotionEvent.ACTION_DOWN && !mIsDtmfStarted) {
LinphoneManager.getInstance().playDtmf(getContext().getContentResolver(), mKeyCode.charAt(0));
mIsDtmfStarted=true;
} else {
if (event.getAction() == MotionEvent.ACTION_UP)
if (event.getAction() == MotionEvent.ACTION_UP) {
lc.stopDtmf();
mIsDtmfStarted =false;
mIsDtmfStarted=false;
}
}
return false;
}
public boolean onLongClick(View v) {
if (!linphoneServiceReady()) return true;
// Called if "0+" dtmf
LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf();
if (mPlayDtmf) {
if (!linphoneServiceReady()) return true;
// Called if "0+" dtmf
LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf();
}
if (mAddress == null) return true;
@ -141,7 +158,5 @@ public class Digit extends Button implements AddressAware {
}
};
public void setAddressWidget(AddressText address) {
mAddress = address;
}
}

View file

@ -24,6 +24,7 @@ import java.util.Collection;
import org.linphone.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@ -36,29 +37,42 @@ import android.widget.LinearLayout;
*/
public class Numpad extends LinearLayout implements AddressAware {
private boolean mPlayDtmf;
public Numpad(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.numpad, this);
setLongClickable(true);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Numpad);
mPlayDtmf = 1 == a.getInt(org.linphone.R.styleable.Numpad_play_dtmf, 1);
a.recycle();
}
@Override
protected void onFinishInflate() {
for (Digit v : retrieveChildren(this, Digit.class)) {
v.setPlayDtmf(mPlayDtmf);
}
super.onFinishInflate();
}
public void setAddressWidget(AddressText address) {
for (AddressAware v : retrieveChildren(this)) {
for (AddressAware v : retrieveChildren(this, AddressAware.class)) {
v.setAddressWidget(address);
}
}
private Collection<AddressAware> retrieveChildren(ViewGroup viewGroup) {
final Collection<AddressAware> views = new ArrayList<AddressAware>();
private <T> Collection<T> retrieveChildren(ViewGroup viewGroup, Class<T> clazz) {
final Collection<T> views = new ArrayList<T>();
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View v = viewGroup.getChildAt(i);
if (v instanceof ViewGroup) {
views.addAll(retrieveChildren((ViewGroup) v));
views.addAll(retrieveChildren((ViewGroup) v, clazz));
} else {
if (v instanceof AddressAware)
views.add((AddressAware) v);
if (clazz.isInstance(v))
views.add(clazz.cast(v));
}
}