diff --git a/src/com/savoirfairelinux/sflphone/client/CallActivity.java b/src/com/savoirfairelinux/sflphone/client/CallActivity.java index bb26765b33da3611d0eb57ad64cf78cdba08704d..98b6b2efdc0598682d5da73f15dee5f554539a86 100644 --- a/src/com/savoirfairelinux/sflphone/client/CallActivity.java +++ b/src/com/savoirfairelinux/sflphone/client/CallActivity.java @@ -44,8 +44,10 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; +import android.os.SystemClock; import android.support.v4.widget.SlidingPaneLayout; import android.util.Log; import android.view.View; @@ -150,14 +152,31 @@ public class CallActivity extends Activity implements CallInterface, CallFragmen intentFilter.addAction(CallManagerCallBack.CONF_CHANGED); intentFilter.addAction(CallManagerCallBack.RECORD_STATE_CHANGED); registerReceiver(receiver, intentFilter); + super.onResume(); } + private Handler mHandler = new Handler(); + private Runnable mUpdateTimeTask = new Runnable() { + public void run() { + final long start = SystemClock.uptimeMillis(); + long millis = SystemClock.uptimeMillis() - start; + int seconds = (int) (millis / 1000); + int minutes = seconds / 60; + seconds = seconds % 60; + + mCurrentCallFragment.updateTime(); + mCallsFragment.update(); + + mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000)); + } + }; + /* activity no more in foreground */ @Override protected void onPause() { super.onPause(); - + mHandler.removeCallbacks(mUpdateTimeTask); } @Override @@ -189,6 +208,7 @@ public class CallActivity extends Activity implements CallInterface, CallFragmen service = ISipService.Stub.asInterface(binder); mCurrentCallFragment = new CallFragment(); + Uri u = getIntent().getData(); if (u != null) { CallContact c = CallContact.ContactBuilder.buildUnknownContact(u.getSchemeSpecificPart()); @@ -271,8 +291,7 @@ public class CallActivity extends Activity implements CallInterface, CallFragmen if (callMap.size() > 0) { ArrayList<SipCall> calls = new ArrayList<SipCall>(callMap.values()); HashMap<String, String> details = (HashMap<String, String>) service.getCallDetails(calls.get(0).getCallId()); - - + } } catch (RemoteException e) { @@ -483,4 +502,9 @@ public class CallActivity extends Activity implements CallInterface, CallFragmen } + @Override + public void startTimer() { + mHandler.postDelayed(mUpdateTimeTask, 0); + } + } diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java index 6f01aea47c92caa63bd69a16fcffa50ce3af8ea7..c625fe8ff89b132847dd960fd0f6d9f52bc8542e 100644 --- a/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java +++ b/src/com/savoirfairelinux/sflphone/fragments/CallFragment.java @@ -143,6 +143,10 @@ public class CallFragment extends Fragment implements Callback { @Override public void replaceCurrentCallDisplayed() { } + + @Override + public void startTimer() { + } }; /** @@ -172,6 +176,8 @@ public class CallFragment extends Fragment implements Callback { public void onSendMessage(SipCall call, String msg); public void replaceCurrentCallDisplayed(); + + public void startTimer(); } @Override @@ -186,6 +192,7 @@ public class CallFragment extends Fragment implements Callback { mCallbacks = (Callbacks) activity; myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me"); + } @@ -262,7 +269,7 @@ public class CallFragment extends Fragment implements Callback { private void initNormalStateDisplay() { Log.i(TAG, "Start normal display"); - callStatusTxt.setText("0 min"); + mCallbacks.startTimer(); getBubbleFor(myself, model.width / 2, model.height / 2); @@ -343,7 +350,7 @@ public class CallFragment extends Fragment implements Callback { private void initIncomingCallDisplay() { Log.i(TAG, "Start incoming display"); - callStatusTxt.setText("Incoming call"); + mCallbacks.startTimer(); getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2); @@ -372,7 +379,7 @@ public class CallFragment extends Fragment implements Callback { private void initOutGoingCallDisplay() { Log.i(TAG, "Start outgoing display"); - callStatusTxt.setText("Calling..."); + mCallbacks.startTimer(); getBubbleFor(myself, model.width / 2, (float) (model.height / 2)); @@ -500,7 +507,6 @@ public class CallFragment extends Fragment implements Callback { Log.e(TAG, e.toString()); } } - if (conf.getParticipants().get(0).isOngoing()) { initNormalStateDisplay(); } @@ -535,4 +541,10 @@ public class CallFragment extends Fragment implements Callback { return view; } + + public void updateTime() { + long duration = System.currentTimeMillis() / 1000 - (this.conf.getParticipants().get(0).getTimestamp_start()); + callStatusTxt.setText(String.format("%d:%02d:%02d", duration/3600, (duration%3600)/60, (duration%60))); + + } } diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java index 7e671a7c8024b49c5b5e451793d94a55e8a1fb99..5d011db6611ec0da143f6f617d2cdd6838b7fc55 100644 --- a/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java +++ b/src/com/savoirfairelinux/sflphone/fragments/CallListFragment.java @@ -488,14 +488,16 @@ public class CallListFragment extends Fragment { Conference call = calls.get(position); if (call.getParticipants().size() == 1) { ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName()); + + long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start()); + + ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration/3600, (duration%3600)/60, (duration%60))); } else { String tmp = "Conference with " + call.getParticipants().size() + " participants"; - // for (SipCall c : call.getParticipants()) { - // tmp += c.getContact().getmDisplayName() + " "; - // } + ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp); } - // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size()); + ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState()); convertView.setOnDragListener(dragListener); diff --git a/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java b/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java index 60cd68fe84129cd53673a6758438bcbe4c90c346..33228ae0e0246b8b8e5741097bd63657cacfcecd 100644 --- a/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java +++ b/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java @@ -125,7 +125,7 @@ public class HomeFragment extends Fragment { seconds = seconds % 60; calls_adapter.notifyDataSetChanged(); - + confs_adapter.notifyDataSetChanged(); mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000)); } }; @@ -137,26 +137,9 @@ public class HomeFragment extends Fragment { super.onResume(); if (mCallbacks.getService() != null) { try { - - // timer = new CallTimer(); - updateLists(); - if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) { - - mHandler.postDelayed(mUpdateTimeTask, 0); - - // - // timer.addObserver(calls_adapter); - // timer.addObserver(confs_adapter); - // TimerTask test = new TimerTask() { - // - // @Override - // public void run() { - // timer.run(); - // } - // }; - // + mHandler.postDelayed(mUpdateTimeTask, 0); } } catch (RemoteException e) { @@ -203,9 +186,13 @@ public class HomeFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - + } + + @Override + public void onPause(){ + super.onPause(); + mHandler.removeCallbacks(mUpdateTimeTask); } @Override