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

View file

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

View file

@ -88,7 +88,6 @@ 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.Vibrator; import android.os.Vibrator;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;

View file

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

View file

@ -34,7 +34,14 @@ import android.widget.Toast;
public class Digit extends Button implements AddressAware { public class Digit extends Button implements AddressAware {
private AddressText mAddress; private AddressText mAddress;
public void setAddressWidget(AddressText address) {
mAddress = address;
}
private boolean mPlayDtmf;
public void setPlayDtmf(boolean play) {
mPlayDtmf = play;
}
@Override @Override
protected void onTextChanged(CharSequence text, int start, int before, protected void onTextChanged(CharSequence text, int start, int before,
@ -75,7 +82,7 @@ public class Digit extends Button implements AddressAware {
private class DialKeyListener implements OnClickListener, OnTouchListener, OnLongClickListener { private class DialKeyListener implements OnClickListener, OnTouchListener, OnLongClickListener {
final CharSequence mKeyCode; final CharSequence mKeyCode;
boolean mIsDtmfStarted=false; boolean mIsDtmfStarted;
DialKeyListener() { DialKeyListener() {
mKeyCode = Digit.this.getText().subSequence(0, 1); mKeyCode = Digit.this.getText().subSequence(0, 1);
@ -89,15 +96,20 @@ public class Digit extends Button implements AddressAware {
} }
return true; return true;
} }
public void onClick(View v) { public void onClick(View v) {
if (mPlayDtmf) {
if (!linphoneServiceReady()) return; if (!linphoneServiceReady()) return;
LinphoneCore lc = LinphoneManager.getLc(); LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf(); lc.stopDtmf();
mIsDtmfStarted =false; mIsDtmfStarted =false;
if (lc.isIncall()) { if (lc.isIncall()) {
lc.sendDtmf(mKeyCode.charAt(0)); lc.sendDtmf(mKeyCode.charAt(0));
} else if (mAddress != null) { return;
}
}
if (mAddress != null) {
int lBegin = mAddress.getSelectionStart(); int lBegin = mAddress.getSelectionStart();
if (lBegin == -1) { if (lBegin == -1) {
lBegin = mAddress.length(); lBegin = mAddress.length();
@ -109,24 +121,29 @@ public class Digit extends Button implements AddressAware {
} }
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (!mPlayDtmf) return false;
if (!linphoneServiceReady()) return true; if (!linphoneServiceReady()) return true;
LinphoneCore lc = LinphoneManager.getLc(); 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)); LinphoneManager.getInstance().playDtmf(getContext().getContentResolver(), mKeyCode.charAt(0));
mIsDtmfStarted=true; mIsDtmfStarted=true;
} else { } else {
if (event.getAction() == MotionEvent.ACTION_UP) if (event.getAction() == MotionEvent.ACTION_UP) {
lc.stopDtmf(); lc.stopDtmf();
mIsDtmfStarted =false; mIsDtmfStarted=false;
}
} }
return false; return false;
} }
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
if (mPlayDtmf) {
if (!linphoneServiceReady()) return true; if (!linphoneServiceReady()) return true;
// Called if "0+" dtmf // Called if "0+" dtmf
LinphoneCore lc = LinphoneManager.getLc(); LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf(); lc.stopDtmf();
}
if (mAddress == null) return true; 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 org.linphone.R;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -36,29 +37,42 @@ import android.widget.LinearLayout;
*/ */
public class Numpad extends LinearLayout implements AddressAware { public class Numpad extends LinearLayout implements AddressAware {
private boolean mPlayDtmf;
public Numpad(Context context, AttributeSet attrs) { public Numpad(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.numpad, this); LayoutInflater.from(context).inflate(R.layout.numpad, this);
setLongClickable(true); 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) { public void setAddressWidget(AddressText address) {
for (AddressAware v : retrieveChildren(this)) { for (AddressAware v : retrieveChildren(this, AddressAware.class)) {
v.setAddressWidget(address); v.setAddressWidget(address);
} }
} }
private Collection<AddressAware> retrieveChildren(ViewGroup viewGroup) { private <T> Collection<T> retrieveChildren(ViewGroup viewGroup, Class<T> clazz) {
final Collection<AddressAware> views = new ArrayList<AddressAware>(); final Collection<T> views = new ArrayList<T>();
for (int i = 0; i < viewGroup.getChildCount(); i++) { for (int i = 0; i < viewGroup.getChildCount(); i++) {
View v = viewGroup.getChildAt(i); View v = viewGroup.getChildAt(i);
if (v instanceof ViewGroup) { if (v instanceof ViewGroup) {
views.addAll(retrieveChildren((ViewGroup) v)); views.addAll(retrieveChildren((ViewGroup) v, clazz));
} else { } else {
if (v instanceof AddressAware) if (clazz.isInstance(v))
views.add((AddressAware) v); views.add(clazz.cast(v));
} }
} }