10f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah/*
20f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * Copyright (C) 2013 Google Inc.
30f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * Licensed to The Android Open Source Project.
40f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah *
50f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * Licensed under the Apache License, Version 2.0 (the "License");
60f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * you may not use this file except in compliance with the License.
70f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * You may obtain a copy of the License at
80f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah *
90f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah *      http://www.apache.org/licenses/LICENSE-2.0
100f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah *
110f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * Unless required by applicable law or agreed to in writing, software
120f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * distributed under the License is distributed on an "AS IS" BASIS,
130f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * See the License for the specific language governing permissions and
150f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * limitations under the License.
160f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah */
170f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
180f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shahpackage com.android.mail.providers;
190f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
200f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shahimport android.database.DataSetObserver;
210f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
220f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shahimport com.android.mail.ui.AccountController;
230f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shahimport com.android.mail.ui.RecentFolderController;
240f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
250f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah/**
260f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * Observes when the drawer is closed for the purpose of computing after the drawer is,
270f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah * potentially, off-screen.
280f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah */
290f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shahpublic abstract class DrawerClosedObserver extends DataSetObserver {
300f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    private AccountController mController;
310f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
320f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    /**
330f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * The no-argument constructor leaves the object unusable till
340f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * {@link #initialize(RecentFolderController)} is called.
350f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     */
360f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    public DrawerClosedObserver () {
370f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    }
380f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
390f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    /**
400f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * Initialize the {@link DrawerClosedObserver} object to receive calls when the drawer
410f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * is closed.
420f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     *
430f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * @param controller
440f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     */
450f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    public void initialize(AccountController controller) {
460f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah        mController = controller;
470f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah        mController.registerDrawerClosedObserver(this);
480f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    }
490f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
500f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    /**
510f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * On drawer closed, execute necessary actions. In the case of {@link FolderListFragment}, this
520f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * includes changing the accounts and then redrawing.
530f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     */
540f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    public abstract void onDrawerClosed();
550f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
560f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    @Override
570f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    public final void onChanged() {
580f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah        if (mController != null) {
590f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah            onDrawerClosed();
600f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah        }
610f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    }
620f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah
630f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    /**
640f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     * Unregisters the {@link DrawerClosedObserver} and makes it unusable.
650f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah     */
660f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    public void unregisterAndDestroy() {
670f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah        if (mController != null) {
680f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah            mController.unregisterDrawerClosedObserver(this);
690f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah        }
700f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah    }
710f73d905c5e935a5280f8eb647cc924c2854b7deRohan Shah}