Home | History | Annotate | Download | only in providers
      1 /*
      2  * Copyright (C) 2013 Google Inc.
      3  * Licensed to The Android Open Source Project.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mail.providers;
     19 
     20 import android.database.DataSetObserver;
     21 
     22 import com.android.mail.ui.AccountController;
     23 import com.android.mail.ui.RecentFolderController;
     24 
     25 /**
     26  * Observes when the drawer is closed for the purpose of computing after the drawer is,
     27  * potentially, off-screen.
     28  */
     29 public abstract class DrawerClosedObserver extends DataSetObserver {
     30     private AccountController mController;
     31 
     32     /**
     33      * The no-argument constructor leaves the object unusable till
     34      * {@link #initialize(RecentFolderController)} is called.
     35      */
     36     public DrawerClosedObserver () {
     37     }
     38 
     39     /**
     40      * Initialize the {@link DrawerClosedObserver} object to receive calls when the drawer
     41      * is closed.
     42      *
     43      * @param controller
     44      */
     45     public void initialize(AccountController controller) {
     46         mController = controller;
     47         mController.registerDrawerClosedObserver(this);
     48     }
     49 
     50     /**
     51      * On drawer closed, execute necessary actions. In the case of {@link FolderListFragment}, this
     52      * includes changing the accounts and then redrawing.
     53      */
     54     public abstract void onDrawerClosed();
     55 
     56     @Override
     57     public final void onChanged() {
     58         if (mController != null) {
     59             onDrawerClosed();
     60         }
     61     }
     62 
     63     /**
     64      * Unregisters the {@link DrawerClosedObserver} and makes it unusable.
     65      */
     66     public void unregisterAndDestroy() {
     67         if (mController != null) {
     68             mController.unregisterDrawerClosedObserver(this);
     69         }
     70     }
     71 }