1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.email.mail; 18 19 import com.android.email.MessagingListener; 20 import com.android.email.provider.EmailContent; 21 import com.android.email.GroupMessagingListener; 22 23 import android.content.Context; 24 25 import java.util.Collection; 26 27 /** 28 * This interface allows a store to define a completely different synchronizer algorithm, 29 * as necessary. 30 */ 31 public interface StoreSynchronizer { 32 33 /** 34 * An object of this class is returned by SynchronizeMessagesSynchronous to report 35 * the results of the sync run. 36 */ 37 public static class SyncResults { 38 /** 39 * The total # of messages in the folder 40 */ 41 public int mTotalMessages; 42 /** 43 * The # of new messages in the folder 44 */ 45 public int mNewMessages; 46 SyncResults(int totalMessages, int newMessages)47 public SyncResults(int totalMessages, int newMessages) { 48 mTotalMessages = totalMessages; 49 mNewMessages = newMessages; 50 } 51 } 52 53 /** 54 * The job of this method is to synchronize messages between a remote folder and the 55 * corresponding local folder. 56 * 57 * The following callbacks should be called during this operation: 58 * {@link MessagingListener#synchronizeMailboxNewMessage(Account, String, Message)} 59 * {@link MessagingListener#synchronizeMailboxRemovedMessage(Account, String, Message)} 60 * 61 * Callbacks (through listeners) *must* be synchronized on the listeners object, e.g. 62 * synchronized (listeners) { 63 * for(MessagingListener listener : listeners) { 64 * listener.synchronizeMailboxNewMessage(account, folder, message); 65 * } 66 * } 67 * 68 * @param account The account to synchronize 69 * @param folder The folder to synchronize 70 * @param listeners callbacks to make during sync operation 71 * @param context if needed for making system calls 72 * @return an object describing the sync results 73 */ SynchronizeMessagesSynchronous( EmailContent.Account account, EmailContent.Mailbox folder, GroupMessagingListener listeners, Context context)74 public SyncResults SynchronizeMessagesSynchronous( 75 EmailContent.Account account, EmailContent.Mailbox folder, 76 GroupMessagingListener listeners, Context context) throws MessagingException; 77 78 } 79