diff --git a/res/layout/simplified_dialer.xml b/res/layout/simplified_dialer.xml index 533bf797c..7574a9166 100644 --- a/res/layout/simplified_dialer.xml +++ b/res/layout/simplified_dialer.xml @@ -1,6 +1,6 @@ @@ -20,6 +20,7 @@ diff --git a/res/values/digit_style.xml b/res/values/digit_style.xml index 400132100..d5f17e13a 100644 --- a/res/values/digit_style.xml +++ b/res/values/digit_style.xml @@ -9,4 +9,13 @@ 20sp 1 + + + + + + + + + \ No newline at end of file diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 88333772f..3eeda0e5e 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -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; diff --git a/src/org/linphone/UriPickerActivity.java b/src/org/linphone/UriPickerActivity.java index fa768a70f..37a91a03a 100644 --- a/src/org/linphone/UriPickerActivity.java +++ b/src/org/linphone/UriPickerActivity.java @@ -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); } diff --git a/src/org/linphone/ui/Digit.java b/src/org/linphone/ui/Digit.java index e3de49152..75e833845 100644 --- a/src/org/linphone/ui/Digit.java +++ b/src/org/linphone/ui/Digit.java @@ -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; - } + } diff --git a/src/org/linphone/ui/Numpad.java b/src/org/linphone/ui/Numpad.java index 5a0a19e1d..fe02e34c2 100644 --- a/src/org/linphone/ui/Numpad.java +++ b/src/org/linphone/ui/Numpad.java @@ -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 retrieveChildren(ViewGroup viewGroup) { - final Collection views = new ArrayList(); + private Collection retrieveChildren(ViewGroup viewGroup, Class clazz) { + final Collection views = new ArrayList(); 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)); } }