diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java index cd6e59286b2c1af92adf1baf06f02f56e2e96842..53a6c6e7fa6d8ec0eab9881e30325df6ad39ef00 100644 --- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java +++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java @@ -145,7 +145,7 @@ public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Ca Intent intent = new Intent(this, SipService.class); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } - + if (mContactsFragment == null) { mContactsFragment = new ContactListFragment(); Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment); @@ -161,6 +161,13 @@ public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Ca // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f)); + final PagerTabStrip strip = PagerTabStrip.class.cast(mViewPager.findViewById(R.id.pts_main)); + strip.setDrawFullUnderline(false); + strip.setTabIndicatorColor(getResources().getColor(R.color.holo_blue_dark)); + strip.setBackgroundColor(getResources().getColor(R.color.darker_gray)); + strip.setNonPrimaryAlpha(0.5f); + strip.setTextSpacing(25); + strip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); mTitle = mDrawerTitle = getTitle(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); @@ -342,13 +349,7 @@ public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Ca getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit(); mSectionsPagerAdapter = new SectionsPagerAdapter(SFLPhoneHomeActivity.this, getFragmentManager()); - final PagerTabStrip strip = PagerTabStrip.class.cast(mViewPager.findViewById(R.id.pts_main)); - strip.setDrawFullUnderline(false); - strip.setTabIndicatorColor(getResources().getColor(R.color.holo_blue_dark)); - strip.setBackgroundColor(getResources().getColor(R.color.darker_gray)); - strip.setNonPrimaryAlpha(0.5f); - strip.setTextSpacing(25); - strip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); + // initialiseTabHost(null); mViewPager.setOffscreenPageLimit(2); diff --git a/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java b/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java index 166d926a4f04f783161d82fabd673ab74370c3b5..60cd68fe84129cd53673a6758438bcbe4c90c346 100644 --- a/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java +++ b/src/com/savoirfairelinux/sflphone/fragments/HomeFragment.java @@ -30,16 +30,23 @@ */ package com.savoirfairelinux.sflphone.fragments; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; +import java.util.Locale; import java.util.Observable; import java.util.Observer; +import java.util.TimeZone; import android.app.Activity; import android.app.Fragment; import android.content.Context; import android.os.Bundle; +import android.os.Handler; import android.os.RemoteException; +import android.os.SystemClock; +import android.text.format.DateFormat; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -62,10 +69,10 @@ public class HomeFragment extends Fragment { private static final String TAG = HomeFragment.class.getSimpleName(); private Callbacks mCallbacks = sDummyCallbacks; -// Button access_calls; + // Button access_calls; TextView nb_calls, nb_confs; CallListAdapter confs_adapter; - CallTimer timer; + CallTimer timer; private CallListAdapter calls_adapter; @@ -109,23 +116,48 @@ public class HomeFragment extends Fragment { } + 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; + + calls_adapter.notifyDataSetChanged(); + + mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000)); + } + }; + + private Handler mHandler = new Handler(); + @Override public void onResume() { super.onResume(); if (mCallbacks.getService() != null) { try { - timer = new CallTimer(); - + // timer = new CallTimer(); + updateLists(); - - if(!calls_adapter.isEmpty() || !confs_adapter.isEmpty()){ - timer.addObserver(calls_adapter); - timer.addObserver(confs_adapter); - new Thread(timer).start(); + 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(); + // } + // }; + // } - } catch (RemoteException e) { Log.e(TAG, e.toString()); @@ -134,7 +166,6 @@ public class HomeFragment extends Fragment { } - public void updateLists() throws RemoteException { HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); @@ -145,7 +176,7 @@ public class HomeFragment extends Fragment { private void updateConferenceList(HashMap<String, Conference> confs) { nb_confs.setText("" + confs.size()); - confs_adapter.update(new ArrayList<Conference>(confs.values())); + confs_adapter.updateDataset(new ArrayList<Conference>(confs.values())); } private void updateCallList(HashMap<String, SipCall> calls) { @@ -158,7 +189,7 @@ public class HomeFragment extends Fragment { conferences.add(confOne); } - calls_adapter.update(conferences); + calls_adapter.updateDataset(conferences); } @@ -179,7 +210,7 @@ public class HomeFragment extends Fragment { @Override public void onActivityCreated(Bundle savedInstanceState) { - + super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real @@ -216,15 +247,14 @@ public class HomeFragment extends Fragment { return inflatedView; } - - OnItemClickListener callClickListener= new OnItemClickListener() { + + OnItemClickListener callClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) { - mCallbacks.selectedCall((Conference)v.getTag()); + mCallbacks.selectedCall((Conference) v.getTag()); } }; - public class CallListAdapter extends BaseAdapter implements Observer { @@ -247,7 +277,7 @@ public class HomeFragment extends Fragment { } - public void update(ArrayList<Conference> list) { + public void updateDataset(ArrayList<Conference> list) { calls.clear(); calls.addAll(list); notifyDataSetChanged(); @@ -276,6 +306,10 @@ public class HomeFragment 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"; ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp); @@ -289,7 +323,8 @@ public class HomeFragment extends Fragment { @Override public void update(Observable observable, Object data) { - Log.i(TAG,"Updating views..."); + Log.i(TAG, "Updating views..."); + notifyDataSetChanged(); } } diff --git a/src/com/savoirfairelinux/sflphone/model/SipCall.java b/src/com/savoirfairelinux/sflphone/model/SipCall.java index ff32e3228ccd9f81fdfc1b07df81e8dff0671f2f..ec2fddb0a23f5d42baca534900248108d7e1beb7 100644 --- a/src/com/savoirfairelinux/sflphone/model/SipCall.java +++ b/src/com/savoirfairelinux/sflphone/model/SipCall.java @@ -69,6 +69,7 @@ public class SipCall implements Parcelable { mCallType = in.readInt(); mCallState = in.readInt(); mMediaState = in.readInt(); + timestamp_start = in.readLong(); } @@ -123,6 +124,7 @@ public class SipCall implements Parcelable { out.writeInt(mCallType); out.writeInt(mCallState); out.writeInt(mMediaState); + out.writeLong(timestamp_start); } public static final Parcelable.Creator<SipCall> CREATOR = new Parcelable.Creator<SipCall>() { diff --git a/src/com/savoirfairelinux/sflphone/receivers/IncomingReceiver.java b/src/com/savoirfairelinux/sflphone/receivers/IncomingReceiver.java index 2ae0200f91f8f2c5b6b5c0d6193e5cce72cc5a74..64769b884886c5525d8d78fd9a538d6c30e6792d 100644 --- a/src/com/savoirfairelinux/sflphone/receivers/IncomingReceiver.java +++ b/src/com/savoirfairelinux/sflphone/receivers/IncomingReceiver.java @@ -1,6 +1,7 @@ package com.savoirfairelinux.sflphone.receivers; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; @@ -11,13 +12,16 @@ import android.os.Bundle; import android.os.RemoteException; import android.util.Log; +import com.savoirfairelinux.sflphone.account.CallDetailsHandler; import com.savoirfairelinux.sflphone.model.CallContact; import com.savoirfairelinux.sflphone.model.Conference; import com.savoirfairelinux.sflphone.model.SipCall; import com.savoirfairelinux.sflphone.service.CallManagerCallBack; import com.savoirfairelinux.sflphone.service.ConfigurationManagerCallback; +import com.savoirfairelinux.sflphone.service.ServiceConstants; import com.savoirfairelinux.sflphone.service.ISipService.Stub; import com.savoirfairelinux.sflphone.service.SipService; +import com.savoirfairelinux.sflphone.service.StringMap; public class IncomingReceiver extends BroadcastReceiver { @@ -61,6 +65,8 @@ public class IncomingReceiver extends BroadcastReceiver { try { SipCall newCall = callBuilder.build(); toSend.putExtra("newcall", newCall); + HashMap<String, String> details = (HashMap<String, String>) mBinder.getCallDetails(b.getString("CallID")); + newCall.setTimestamp_start(Long.parseLong(details.get(ServiceConstants.call.TIMESTAMP_START))); callback.getCurrent_calls().put(newCall.getCallId(), newCall); callback.sendBroadcast(toSend); } catch (Exception e) { @@ -122,7 +128,7 @@ public class IncomingReceiver extends BroadcastReceiver { } } - + callback.sendBroadcast(intent); } else if (newState.equals("BUSY")) { diff --git a/src/com/savoirfairelinux/sflphone/service/SipService.java b/src/com/savoirfairelinux/sflphone/service/SipService.java index 3211a33a8a7db0cd25603b7f1c6e1e5c80198c03..91a0d342e17c4adc01c9873aa5581aacc0dd565b 100644 --- a/src/com/savoirfairelinux/sflphone/service/SipService.java +++ b/src/com/savoirfairelinux/sflphone/service/SipService.java @@ -360,6 +360,7 @@ public class SipService extends Service { callManagerJNI.placeCall(call.getAccountID(), call.getCallId(), call.getContact().getPhones().get(0).getNumber()); HashMap<String, String> details = CallDetailsHandler.convertSwigToNative(callManagerJNI.getCallDetails(call.getCallId())); + // watchout timestamp stored by sflphone is in seconds call.setTimestamp_start(Long.parseLong(details.get(ServiceConstants.call.TIMESTAMP_START))); getCurrent_calls().put(call.getCallId(), call);