From 39c06043976ec7ae21464f1ce8756409181f5d67 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Thu, 18 Mar 2010 18:13:56 +0100 Subject: [PATCH] add clear history to call history tab --- AndroidManifest.xml | 1 + res/layout-land/dialer.xml | 30 ++--- res/layout/about.xml | 4 +- res/layout/dialer.xml | 110 ++++++++++-------- res/menu/history_activity_menu.xml | 6 + res/values/strings.xml | 4 +- src/org/linphone/AboutActivity.java | 11 ++ src/org/linphone/DialerActivity.java | 77 +++++++++--- src/org/linphone/HistoryActivity.java | 29 +++++ .../linphone/core/LinphoneAddressImpl.java | 3 +- src/org/linphone/core/LinphoneCore.java | 11 +- src/org/linphone/core/LinphoneCoreImpl.java | 8 ++ 12 files changed, 204 insertions(+), 90 deletions(-) create mode 100644 res/menu/history_activity_menu.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3af217811..b556f3c10 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -58,5 +58,6 @@ + \ No newline at end of file diff --git a/res/layout-land/dialer.xml b/res/layout-land/dialer.xml index 2b98dc7d4..e6fc58984 100644 --- a/res/layout-land/dialer.xml +++ b/res/layout-land/dialer.xml @@ -25,26 +25,16 @@ android:layout_width="fill_parent"> - - + + + + + + + - - - - - + android:layout_width="fill_parent" android:id="@+id/CallControlRow" android:layout_weight="1"> @@ -63,6 +53,6 @@ - + diff --git a/res/layout/about.xml b/res/layout/about.xml index bdb5351a5..511bab776 100644 --- a/res/layout/about.xml +++ b/res/layout/about.xml @@ -2,6 +2,6 @@ - - + + diff --git a/res/layout/dialer.xml b/res/layout/dialer.xml index f270162bb..611eb59ad 100644 --- a/res/layout/dialer.xml +++ b/res/layout/dialer.xml @@ -11,93 +11,105 @@ android:hint="sip:" android:layout_width="fill_parent" android:lines="1" android:layout_weight="0.2"> + android:layout_width="fill_parent" android:text="<-" + android:layout_weight="0.8" android:textSize="20sp" + android:textStyle="bold"> - + + + - + android:layout_height="fill_parent" android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_width="fill_parent" android:layout_height="fill_parent" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_height="fill_parent" android:text="*" android:id="@+id/ButtonStar" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:layout_height="fill_parent" android:text="0+" android:id="@+id/Button00" + android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> + android:text="#" android:textStyle="bold" android:textSize="20sp" + android:layout_weight="1"> - - - - - - - - + + + + + + + + + + + + - - + + - - diff --git a/res/menu/history_activity_menu.xml b/res/menu/history_activity_menu.xml new file mode 100644 index 000000000..f1d6161a1 --- /dev/null +++ b/res/menu/history_activity_menu.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 6a5fe0d9a..e1afb6c69 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,6 +1,6 @@ - Linphone 3.1.2 SIP (rfc 3261) Compatible Internet phone \n http://www.linphone.org + Linphone %s SIP (rfc 3261) Compatible Internet phone \n http://www.linphone.org About Audio Exit @@ -26,4 +26,6 @@ Cannot initiate a new call because a call is already engaged History Cannot build destination address from [%s] +Clear + diff --git a/src/org/linphone/AboutActivity.java b/src/org/linphone/AboutActivity.java index e860ed064..130135d01 100644 --- a/src/org/linphone/AboutActivity.java +++ b/src/org/linphone/AboutActivity.java @@ -19,13 +19,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package org.linphone; import android.app.Activity; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; +import android.util.Log; +import android.widget.TextView; public class AboutActivity extends Activity { + TextView aboutText; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about); + aboutText = (TextView) findViewById(R.id.AboutText); + try { + aboutText.setText(String.format(getString(R.string.about_text), getPackageManager().getPackageInfo(getPackageName(), 0).versionName)); + } catch (NameNotFoundException e) { + Log.e(LinphoneService.TAG, "cannot get version name", e); + } } } diff --git a/src/org/linphone/DialerActivity.java b/src/org/linphone/DialerActivity.java index 5537ba0d3..ae100d3e3 100644 --- a/src/org/linphone/DialerActivity.java +++ b/src/org/linphone/DialerActivity.java @@ -31,13 +31,16 @@ import android.content.Context; import android.media.AudioManager; import android.os.Build; import android.os.Bundle; +import android.os.PowerManager; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.widget.Button; import android.widget.CompoundButton; import android.widget.ImageButton; import android.widget.LinearLayout; +import android.widget.TableRow; import android.widget.TextView; import android.widget.Toast; import android.widget.ToggleButton; @@ -71,7 +74,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { private ToggleButton mSpeaker; private LinearLayout mCallControlRow; - private LinearLayout mInCallControlRow; + private TableRow mInCallControlRow; private LinearLayout mAddressLayout; private LinearLayout mInCallAddressLayout; @@ -79,6 +82,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { private String mDisplayName; private AudioManager mAudioManager; + private PowerManager.WakeLock mWakeLock; /** * @@ -99,6 +103,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { super.onCreate(savedInstanceState); setContentView(R.layout.dialer); mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE)); + PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"Linphone"); + try { @@ -119,6 +126,13 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { } } }); + mErase.setOnLongClickListener(new OnLongClickListener() { + public boolean onLongClick(View arg0) { + mAddress.getEditableText().clear(); + return true; + } + + }); mCall = (ImageButton) findViewById(R.id.Call); mCall.setOnClickListener(new OnClickListener() { @@ -170,19 +184,30 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { mAddressView = anAddress; } public void onClick(View v) { - mAddressView.append(mKeyCode); - mDisplayName=""; + LinphoneCore lc = LinphoneService.instance().getLinphoneCore(); + if (lc.isIncall()) { + lc.sendDtmf(mKeyCode.charAt(0)); + } else { + int lBegin = mAddressView.getSelectionStart(); + if (lBegin == -1) { + lBegin = mAddressView.getEditableText().length(); + } + if (lBegin >=0) { + mAddressView.getEditableText().insert(lBegin,mKeyCode); + } + mDisplayName=""; + } } }; mCallControlRow = (LinearLayout) findViewById(R.id.CallControlRow); - mInCallControlRow = (LinearLayout) findViewById(R.id.IncallControlRow); + mInCallControlRow = (TableRow) findViewById(R.id.IncallControlRow); mAddressLayout = (LinearLayout) findViewById(R.id.Addresslayout); mInCallAddressLayout = (LinearLayout) findViewById(R.id.IncallAddressLayout); mInCallControlRow.setVisibility(View.GONE); mInCallAddressLayout.setVisibility(View.GONE); - + mDecline.setEnabled(false); if (LinphoneService.isready()) { if (LinphoneService.instance().getLinphoneCore().isIncall()) { mCall.setEnabled(false); @@ -192,7 +217,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { mAddressLayout.setVisibility(View.GONE); mInCallAddressLayout.setVisibility(View.VISIBLE); } - } + } mMute = (ToggleButton)findViewById(R.id.mic_mute_button); @@ -230,6 +255,19 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { if (mZero != null) { mZero.setOnClickListener(new DialKeyListener(mAddress,'0')); + mZero.setOnLongClickListener(new OnLongClickListener() { + public boolean onLongClick(View arg0) { + int lBegin = mAddress.getSelectionStart(); + if (lBegin == -1) { + lBegin = mAddress.getEditableText().length(); + } + if (lBegin >=0) { + mAddress.getEditableText().insert(lBegin,"+"); + } + return true; + } + + }); mOne = (Button) findViewById(R.id.Button01) ; mOne.setOnClickListener(new DialKeyListener(mAddress,'1')); mTwo = (Button) findViewById(R.id.Button02); @@ -298,20 +336,18 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { break; } case GSTATE_CALL_OUT_INVITE: { - } - case GSTATE_CALL_IN_INVITE: { enterIncalMode(lc); routeAudioToSpeaker(); break; } - case GSTATE_CALL_IN_CONNECTED: + case GSTATE_CALL_IN_INVITE: { + mDecline.setEnabled(true); + routeAudioToSpeaker(); + break; + } + case GSTATE_CALL_IN_CONNECTED: case GSTATE_CALL_OUT_CONNECTED: { - if (mSpeaker.isChecked()) { - routeAudioToSpeaker(); - } else { - routeAudioToReceiver(); - } - setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); + enterIncalMode(lc); break; } case GSTATE_CALL_ERROR: { @@ -337,6 +373,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { } private void enterIncalMode(LinphoneCore lc) { + mWakeLock.acquire(); mCallControlRow.setVisibility(View.GONE); mInCallControlRow.setVisibility(View.VISIBLE); mAddressLayout.setVisibility(View.GONE); @@ -349,6 +386,12 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { } else { mDisplayNameView.setText(lc.getRemoteAddress().getUserName()); } + if (mSpeaker.isChecked()) { + routeAudioToSpeaker(); + } else { + routeAudioToReceiver(); + } + setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); } private void exitCallMode() { mCallControlRow.setVisibility(View.VISIBLE); @@ -358,6 +401,10 @@ public class DialerActivity extends Activity implements LinphoneCoreListener { mCall.setEnabled(true); mHangup.setEnabled(false); setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE); + mMute.setChecked(true); + mSpeaker.setChecked(false); + mDecline.setEnabled(false); + mWakeLock.release(); } private void routeAudioToSpeaker() { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) { diff --git a/src/org/linphone/HistoryActivity.java b/src/org/linphone/HistoryActivity.java index 49c5a3510..04eddaa06 100644 --- a/src/org/linphone/HistoryActivity.java +++ b/src/org/linphone/HistoryActivity.java @@ -30,8 +30,13 @@ import org.linphone.core.LinphoneCallLog.CallDirection; import android.app.ListActivity; import android.content.Context; +import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; @@ -70,6 +75,30 @@ public class HistoryActivity extends ListActivity { setListAdapter(new CallHistoryAdapter(this)); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the currently selected menu XML resource. + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.history_activity_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_clear_history: + LinphoneService.instance().getLinphoneCore().clearCallLogs(); + setListAdapter(new CallHistoryAdapter(this)); + + break; + default: + Log.e(LinphoneService.TAG, "Unknown menu item ["+item+"]"); + break; + } + + return false; + } + class CallHistoryAdapter extends BaseAdapter { final List mLogs; diff --git a/src/org/linphone/core/LinphoneAddressImpl.java b/src/org/linphone/core/LinphoneAddressImpl.java index 50036ac7d..ed879338c 100644 --- a/src/org/linphone/core/LinphoneAddressImpl.java +++ b/src/org/linphone/core/LinphoneAddressImpl.java @@ -30,6 +30,7 @@ public class LinphoneAddressImpl implements LinphoneAddress { private native String getDomain(long ptr); private native String toUri(long ptr); private native String setDisplayName(long ptr,String name); + private native String toString(long ptr); protected LinphoneAddressImpl(String username,String domain,String displayName) { @@ -53,7 +54,7 @@ public class LinphoneAddressImpl implements LinphoneAddress { } public String toString() { - return toUri(); + return toString(nativePtr); } public String toUri() { return toUri(nativePtr); diff --git a/src/org/linphone/core/LinphoneCore.java b/src/org/linphone/core/LinphoneCore.java index 4245c5518..6ab7e2348 100644 --- a/src/org/linphone/core/LinphoneCore.java +++ b/src/org/linphone/core/LinphoneCore.java @@ -160,6 +160,13 @@ public interface LinphoneCore { * @throws If no LinphonrAddress can be built from destination */ public LinphoneAddress interpretUrl(String destination) throws LinphoneCoreException; - - + /** + * Initiate a dtmf signal if in call + * @param number + */ + public void sendDtmf(char number); + /** + * + */ + public void clearCallLogs(); } diff --git a/src/org/linphone/core/LinphoneCoreImpl.java b/src/org/linphone/core/LinphoneCoreImpl.java index 173d5846c..ed938a841 100644 --- a/src/org/linphone/core/LinphoneCoreImpl.java +++ b/src/org/linphone/core/LinphoneCoreImpl.java @@ -54,6 +54,8 @@ class LinphoneCoreImpl implements LinphoneCore { private native void muteMic(long nativePtr,boolean isMuted); private native long interpretUrl(long nativePtr,String destination); private native void inviteAddress(long nativePtr,long to); + private native void sendDtmf(long nativePtr,char dtmf); + private native void clearCallLogs(long nativePtr); LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException { @@ -182,4 +184,10 @@ class LinphoneCoreImpl implements LinphoneCore { public void invite(LinphoneAddress to) { inviteAddress(nativePtr,((LinphoneAddressImpl)to).nativePtr); } + public void sendDtmf(char number) { + sendDtmf(nativePtr,number); + } + public void clearCallLogs() { + clearCallLogs(nativePtr); + } }