com.vodafone360.people.engine.activities
Class FetchSmsLogEvents

java.lang.Object
  extended by com.vodafone360.people.engine.activities.FetchSmsLogEvents
All Implemented Interfaces:
ActivitiesEngine.ISyncHelper

public class FetchSmsLogEvents
extends java.lang.Object
implements ActivitiesEngine.ISyncHelper

Fetches SMS/MMS log events from the Native message log. These are treated as Activities and displayed in Timeline UI.


Nested Class Summary
private static class FetchSmsLogEvents.InternalState
          Internal states for message log sync: Idle,, fetching SMS events, fetching MMS events.
 
Field Summary
private static int COLUMN_SMS_ADDRESS
           
private static int COLUMN_SMS_BODY
           
private static int COLUMN_SMS_DATE
           
private static int COLUMN_SMS_ID
           
private static int COLUMN_SMS_SUBJECT
           
private static int COLUMN_SMS_THREAD_ID
           
private static int COLUMN_SMS_TYPE
           
private static int MAX_DESC_LENGTH
           
private static int MAX_ITEMS_PER_PAGE
           
private static int MAX_ITEMS_TO_WRITE
           
private static int MAX_PAGES_TO_LOAD_AT_ONCE
          the number of timeline pages to be loaded by one ISyncHelper
private  Context mContext
           
private  ContentResolver mCr
           
private  DatabaseHelper mDb
           
private  ActivitiesEngine mEngine
           
private static int MESSAGE_TYPE_INBOX
           
private static int MESSAGE_TYPE_SENT
           
private  FetchSmsLogEvents.InternalState mInternalState
           
private  Cursor mMmsCursor
           
private  long mNewestMessage
          the current newest message time
private  long mOldestMessage
          the current oldest message time
private  int mPageCount
          the number of pages have been read
private  boolean mRefresh
          is true if newer events need to be loaded, false - if older
private  Cursor mSmsCursor
           
private  java.util.ArrayList<ActivitiesTable.TimelineSummaryItem> mSyncItemList
           
protected static Uri SMS_CONTENT_URI
           
private static java.lang.String[] SMS_PROJECTION
           
private static java.lang.String SMS_SORT_ORDER
           
 
Constructor Summary
FetchSmsLogEvents(Context context, ActivitiesEngine engine, DatabaseHelper db, boolean refresh)
          Constructor.
 
Method Summary
private  void addSmsData(int id)
          Create TimelineSummaryItem from Native message-log item.
 void cancel()
          Cancel message log sync.
private  void complete(ServiceStatus status)
          /** Completion of fetch from Native message log.
private  ActivityItem.Type nativeToNpTypeConvert(int type)
          Convert Native message type (Inbox, Sent) to corresponding ActivityItem type.
 void run()
          Drive internal state machine, either start call log sync, fetch next page of SMS items, next page of MMS items or complete call-log sync operation.
private  void saveTimeStampMms()
          This method updates the newest and oldest MMS timestamps in the database.
private  void saveTimeStampSms()
          This method updates the newest and oldest SMS timestamps in the database.
private  void startSyncMms()
          Start sync. of MMS message events.
private  void startSyncSms()
          Start sync of SMS message events.
private  void syncNextMmsPage()
          Sync. next page of MMS events (current page size is 2).
private  void syncNextSmsPage()
          Sync. next page of SMS events (current page size is 2).
private  void updateTimestamps()
          This method goes through the event list and updates the current newest and oldest message timestamps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SMS_CONTENT_URI

protected static final Uri SMS_CONTENT_URI

MAX_PAGES_TO_LOAD_AT_ONCE

private static final int MAX_PAGES_TO_LOAD_AT_ONCE
the number of timeline pages to be loaded by one ISyncHelper

See Also:
Constant Field Values

MAX_ITEMS_PER_PAGE

private static final int MAX_ITEMS_PER_PAGE
See Also:
Constant Field Values

MAX_ITEMS_TO_WRITE

private static final int MAX_ITEMS_TO_WRITE
See Also:
Constant Field Values

MAX_DESC_LENGTH

private static final int MAX_DESC_LENGTH
See Also:
Constant Field Values

SMS_SORT_ORDER

private static final java.lang.String SMS_SORT_ORDER
See Also:
Constant Field Values

SMS_PROJECTION

private static final java.lang.String[] SMS_PROJECTION

COLUMN_SMS_ID

private static final int COLUMN_SMS_ID
See Also:
Constant Field Values

COLUMN_SMS_DATE

private static final int COLUMN_SMS_DATE
See Also:
Constant Field Values

COLUMN_SMS_ADDRESS

private static final int COLUMN_SMS_ADDRESS
See Also:
Constant Field Values

COLUMN_SMS_SUBJECT

private static final int COLUMN_SMS_SUBJECT
See Also:
Constant Field Values

COLUMN_SMS_BODY

private static final int COLUMN_SMS_BODY
See Also:
Constant Field Values

COLUMN_SMS_TYPE

private static final int COLUMN_SMS_TYPE
See Also:
Constant Field Values

COLUMN_SMS_THREAD_ID

private static final int COLUMN_SMS_THREAD_ID
See Also:
Constant Field Values

MESSAGE_TYPE_INBOX

private static final int MESSAGE_TYPE_INBOX
See Also:
Constant Field Values

MESSAGE_TYPE_SENT

private static final int MESSAGE_TYPE_SENT
See Also:
Constant Field Values

mContext

private Context mContext

mEngine

private ActivitiesEngine mEngine

mDb

private DatabaseHelper mDb

mCr

private ContentResolver mCr

mInternalState

private FetchSmsLogEvents.InternalState mInternalState

mSmsCursor

private Cursor mSmsCursor

mMmsCursor

private Cursor mMmsCursor

mSyncItemList

private java.util.ArrayList<ActivitiesTable.TimelineSummaryItem> mSyncItemList

mRefresh

private boolean mRefresh
is true if newer events need to be loaded, false - if older


mPageCount

private int mPageCount
the number of pages have been read


mOldestMessage

private long mOldestMessage
the current oldest message time


mNewestMessage

private long mNewestMessage
the current newest message time

Constructor Detail

FetchSmsLogEvents

FetchSmsLogEvents(Context context,
                  ActivitiesEngine engine,
                  DatabaseHelper db,
                  boolean refresh)
Constructor.

Parameters:
context - Context - actually RemoteServe's Context.
engine - Handle to ActivitiesEngine.
db - Handle to DatabaseHelper.
refresh - - true if we need to fetch new sms, false if older.
Method Detail

run

public void run()
Drive internal state machine, either start call log sync, fetch next page of SMS items, next page of MMS items or complete call-log sync operation.

Specified by:
run in interface ActivitiesEngine.ISyncHelper

complete

private void complete(ServiceStatus status)
/** Completion of fetch from Native message log. Notify ActivitiesEngine that message-log sync. has completed. Close Cursors.

Parameters:
status - ServiceStatus containing result of sync.

startSyncSms

private void startSyncSms()
Start sync of SMS message events. Use Timeline last update time-stamp to ensure we only fetch 'new' events.


startSyncMms

private void startSyncMms()
Start sync. of MMS message events. Use Timeline last update time-stamp to ensure we only fetch 'new' events.


syncNextSmsPage

private void syncNextSmsPage()
Sync. next page of SMS events (current page size is 2).


updateTimestamps

private void updateTimestamps()
This method goes through the event list and updates the current newest and oldest message timestamps.


saveTimeStampMms

private void saveTimeStampMms()
This method updates the newest and oldest MMS timestamps in the database.


saveTimeStampSms

private void saveTimeStampSms()
This method updates the newest and oldest SMS timestamps in the database.


syncNextMmsPage

private void syncNextMmsPage()
Sync. next page of MMS events (current page size is 2).


addSmsData

private void addSmsData(int id)
Create TimelineSummaryItem from Native message-log item.

Parameters:
id - ID of item from Native log.

nativeToNpTypeConvert

private ActivityItem.Type nativeToNpTypeConvert(int type)
Convert Native message type (Inbox, Sent) to corresponding ActivityItem type.

Parameters:
type - Native message type.
Returns:
ActivityItem type.

cancel

public void cancel()
Cancel message log sync.

Specified by:
cancel in interface ActivitiesEngine.ISyncHelper


JavaDoc