Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2013 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 package com.android.mail.utils;
     17 
     18 import android.database.DataSetObservable;
     19 import android.support.v4.util.SparseArrayCompat;
     20 
     21 public class ObservableSparseArrayCompat<E> extends SparseArrayCompat<E> {
     22     private final DataSetObservable mDataSetObservable;
     23 
     24     public ObservableSparseArrayCompat() {
     25         super();
     26 
     27         mDataSetObservable = new DataSetObservable();
     28     }
     29 
     30     public ObservableSparseArrayCompat(final int initialCapacity) {
     31         super(initialCapacity);
     32 
     33         mDataSetObservable = new DataSetObservable();
     34     }
     35 
     36     public DataSetObservable getDataSetObservable() {
     37         return mDataSetObservable;
     38     }
     39 
     40     private void notifyChanged() {
     41         mDataSetObservable.notifyChanged();
     42     }
     43 
     44     @Override
     45     public void append(final int key, final E value) {
     46         super.append(key, value);
     47         notifyChanged();
     48     }
     49 
     50     @Override
     51     public void clear() {
     52         super.clear();
     53         notifyChanged();
     54     }
     55 
     56     @Override
     57     public void delete(final int key) {
     58         super.delete(key);
     59         notifyChanged();
     60     }
     61 
     62     @Override
     63     public void put(final int key, final E value) {
     64         super.put(key, value);
     65         notifyChanged();
     66     }
     67 
     68     @Override
     69     public void remove(final int key) {
     70         super.remove(key);
     71         notifyChanged();
     72     }
     73 
     74     @Override
     75     public void removeAt(final int index) {
     76         super.removeAt(index);
     77         notifyChanged();
     78     }
     79 
     80     @Override
     81     public void removeAtRange(final int index, final int size) {
     82         super.removeAtRange(index, size);
     83         notifyChanged();
     84     }
     85 
     86     @Override
     87     public void setValueAt(final int index, final E value) {
     88         super.setValueAt(index, value);
     89         notifyChanged();
     90     }
     91 }
     92