Java Code Examples for android.database.Cursor.registerDataSetObserver()

The following are Jave code examples for showing how to use registerDataSetObserver() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: CSipSimple   File: GroupingListAdapter.java   Source Code and License Vote up 6 votes
public void changeCursor(Cursor cursor) {
    if (cursor == mCursor) {
        return;
    }

    if (mCursor != null) {
        mCursor.unregisterContentObserver(mChangeObserver);
        mCursor.unregisterDataSetObserver(mDataSetObserver);
        mCursor.close();
    }
    mCursor = cursor;
    resetCache();
    findGroups();

    if (cursor != null) {
        cursor.registerContentObserver(mChangeObserver);
        cursor.registerDataSetObserver(mDataSetObserver);
        mRowIdColumnIndex = cursor.getColumnIndexOrThrow("_id");
        notifyDataSetChanged();
    } else {
        // notify the observers about the lack of a data set
        notifyDataSetInvalidated();
    }

}
 
Example 2
Project: SuperSelector   File: RecyclerViewCursorAdapter.java   Source Code and License Vote up 6 votes
void init(Context context, Cursor c, int flags) {

        boolean cursorPresent = c != null;
        mCursor = c;
        mDataValid = cursorPresent;
        mContext = context;
        mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
        if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) {
            mChangeObserver = new ChangeObserver();
            mDataSetObserver = new MyDataSetObserver();
        } else {
            mChangeObserver = null;
            mDataSetObserver = null;
        }

        if (cursorPresent) {
            if (mChangeObserver != null) c.registerContentObserver(mChangeObserver);
            if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver);
        }
        setHasStableIds(true);
    }
 
Example 3
Project: FuelUp   File: RecyclerViewCursorAdapter.java   Source Code and License Vote up 6 votes
public void swapCursor(Cursor newCursor)
{
    if(newCursor == mCursor){
        return;
    }
    Cursor oldCursor = mCursor;
    if(oldCursor != null){
        if(mDataSetObserver != null){
            oldCursor.unregisterDataSetObserver(mDataSetObserver);
        }
    }
    mCursor = newCursor;
    if(newCursor != null){
        if(mDataSetObserver != null){
            newCursor.registerDataSetObserver(mDataSetObserver);
        }
        mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        mDataValid = true;
        notifyDataSetChanged();
    }
    else{
        mRowIDColumn = -1;
        mDataValid = false;
        notifyDataSetChanged();
    }
}
 
Example 4
Project: Ocr-android   File: BaseRecyclerCursorAdapter.java   Source Code and License Vote up 6 votes
private void init(Context context, Cursor c, int flags) {
    boolean cursorPresent = c != null;
    mCursor = c;
    mDataValid = cursorPresent;
    mContext = context;
    mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
    if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) {
        mChangeObserver = new ChangeObserver();
        mDataSetObserver = new MyDataSetObserver();
    } else {
        mChangeObserver = null;
        mDataSetObserver = null;
    }

    if (cursorPresent) {
        if (mChangeObserver != null) {
            c.registerContentObserver(mChangeObserver);
        }
        if (mDataSetObserver != null) {
            c.registerDataSetObserver(mDataSetObserver);
        }
    }
    setHasStableIds(true);
}
 
Example 5
Project: PeSanKita-android   File: CursorRecyclerViewAdapter.java   Source Code and License Vote up 5 votes
protected CursorRecyclerViewAdapter(Context context, Cursor cursor) {
  this.context = context;
  this.cursor = cursor;
  if (cursor != null) {
    valid = true;
    cursor.registerDataSetObserver(observer);
  }
}
 
Example 6
Project: SuperSelector   File: RecyclerViewCursorAdapter.java   Source Code and License Vote up 5 votes
/**
     * Swap in a new Cursor, returning the old Cursor.  Unlike
     * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
     * closed.
     *
     * @param newCursor The new cursor to be used.
     * @return Returns the previously set Cursor, or null if there wasa not one.
     * If the given new Cursor is the same instance is the previously set
     * Cursor, null is also returned.
     */
    public Cursor swapCursor(Cursor newCursor) {
        if (newCursor == mCursor) {
            return null;
        }
        Cursor oldCursor = mCursor;
        if (oldCursor != null) {
            if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
            if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
        }
        mCursor = newCursor;
        if (newCursor != null) {
            if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
            if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
            mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
            mDataValid = true;
            // notify the observers about the new cursor
            notifyDataSetChanged();
        } else {
            mRowIDColumn = -1;
            mDataValid = false;
            // notify the observers about the lack of a data set
            notifyDataSetChanged();
//            notifyDataSetInvalidated();
        }
        return oldCursor;
    }
 
Example 7
Project: letv   File: CursorAdapter.java   Source Code and License Vote up 5 votes
void init(Context context, Cursor c, int flags) {
    boolean cursorPresent = true;
    if ((flags & 1) == 1) {
        flags |= 2;
        this.mAutoRequery = true;
    } else {
        this.mAutoRequery = false;
    }
    if (c == null) {
        cursorPresent = false;
    }
    this.mCursor = c;
    this.mDataValid = cursorPresent;
    this.mContext = context;
    this.mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
    if ((flags & 2) == 2) {
        this.mChangeObserver = new ChangeObserver(this);
        this.mDataSetObserver = new MyDataSetObserver(this, null);
    } else {
        this.mChangeObserver = null;
        this.mDataSetObserver = null;
    }
    if (cursorPresent) {
        if (this.mChangeObserver != null) {
            c.registerContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            c.registerDataSetObserver(this.mDataSetObserver);
        }
    }
}
 
Example 8
Project: letv   File: CursorAdapter.java   Source Code and License Vote up 5 votes
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == this.mCursor) {
        return null;
    }
    Cursor oldCursor = this.mCursor;
    if (oldCursor != null) {
        if (this.mChangeObserver != null) {
            oldCursor.unregisterContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            oldCursor.unregisterDataSetObserver(this.mDataSetObserver);
        }
    }
    this.mCursor = newCursor;
    if (newCursor != null) {
        if (this.mChangeObserver != null) {
            newCursor.registerContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            newCursor.registerDataSetObserver(this.mDataSetObserver);
        }
        this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        this.mDataValid = true;
        notifyDataSetChanged();
        return oldCursor;
    }
    this.mRowIDColumn = -1;
    this.mDataValid = false;
    notifyDataSetInvalidated();
    return oldCursor;
}
 
Example 9
Project: letv   File: CursorAdapter.java   Source Code and License Vote up 5 votes
void init(Context context, Cursor c, int flags) {
    boolean cursorPresent = true;
    if ((flags & 1) == 1) {
        flags |= 2;
        this.mAutoRequery = true;
    } else {
        this.mAutoRequery = false;
    }
    if (c == null) {
        cursorPresent = false;
    }
    this.mCursor = c;
    this.mDataValid = cursorPresent;
    this.mContext = context;
    this.mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
    if ((flags & 2) == 2) {
        this.mChangeObserver = new ChangeObserver();
        this.mDataSetObserver = new MyDataSetObserver();
    } else {
        this.mChangeObserver = null;
        this.mDataSetObserver = null;
    }
    if (cursorPresent) {
        if (this.mChangeObserver != null) {
            c.registerContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            c.registerDataSetObserver(this.mDataSetObserver);
        }
    }
}
 
Example 10
Project: letv   File: CursorAdapter.java   Source Code and License Vote up 5 votes
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == this.mCursor) {
        return null;
    }
    Cursor oldCursor = this.mCursor;
    if (oldCursor != null) {
        if (this.mChangeObserver != null) {
            oldCursor.unregisterContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            oldCursor.unregisterDataSetObserver(this.mDataSetObserver);
        }
    }
    this.mCursor = newCursor;
    if (newCursor != null) {
        if (this.mChangeObserver != null) {
            newCursor.registerContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            newCursor.registerDataSetObserver(this.mDataSetObserver);
        }
        this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        this.mDataValid = true;
        notifyDataSetChanged();
        return oldCursor;
    }
    this.mRowIDColumn = -1;
    this.mDataValid = false;
    notifyDataSetInvalidated();
    return oldCursor;
}
 
Example 11
Project: boohee_v5.6   File: CursorAdapter.java   Source Code and License Vote up 5 votes
void init(Context context, Cursor c, int flags) {
    boolean cursorPresent = true;
    if ((flags & 1) == 1) {
        flags |= 2;
        this.mAutoRequery = true;
    } else {
        this.mAutoRequery = false;
    }
    if (c == null) {
        cursorPresent = false;
    }
    this.mCursor = c;
    this.mDataValid = cursorPresent;
    this.mContext = context;
    this.mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
    if ((flags & 2) == 2) {
        this.mChangeObserver = new ChangeObserver();
        this.mDataSetObserver = new MyDataSetObserver();
    } else {
        this.mChangeObserver = null;
        this.mDataSetObserver = null;
    }
    if (cursorPresent) {
        if (this.mChangeObserver != null) {
            c.registerContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            c.registerDataSetObserver(this.mDataSetObserver);
        }
    }
}
 
Example 12
Project: boohee_v5.6   File: CursorAdapter.java   Source Code and License Vote up 5 votes
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == this.mCursor) {
        return null;
    }
    Cursor oldCursor = this.mCursor;
    if (oldCursor != null) {
        if (this.mChangeObserver != null) {
            oldCursor.unregisterContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            oldCursor.unregisterDataSetObserver(this.mDataSetObserver);
        }
    }
    this.mCursor = newCursor;
    if (newCursor != null) {
        if (this.mChangeObserver != null) {
            newCursor.registerContentObserver(this.mChangeObserver);
        }
        if (this.mDataSetObserver != null) {
            newCursor.registerDataSetObserver(this.mDataSetObserver);
        }
        this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        this.mDataValid = true;
        notifyDataSetChanged();
        return oldCursor;
    }
    this.mRowIDColumn = -1;
    this.mDataValid = false;
    notifyDataSetInvalidated();
    return oldCursor;
}
 
Example 13
Project: Cable-Android   File: CursorRecyclerViewAdapter.java   Source Code and License Vote up 5 votes
protected CursorRecyclerViewAdapter(Context context, Cursor cursor) {
  this.context = context;
  this.cursor = cursor;
  if (cursor != null) {
    valid = true;
    cursor.registerDataSetObserver(observer);
  }
}
 
Example 14
Project: News24x7-news-from-every-part-of-the-world   File: CursorRecyclerViewAdapter.java   Source Code and License Vote up 5 votes
void init(Cursor c) {
    boolean cursorPresent = c != null;
    mCursor = c;
    mDataValid = cursorPresent;
    mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;

    mChangeObserver = new ChangeObserver();
    mDataSetObserver = new MyDataSetObserver();

    if (cursorPresent) {
        if (mChangeObserver != null) c.registerContentObserver(mChangeObserver);
        if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver);
    }
}
 
Example 15
Project: News24x7-news-from-every-part-of-the-world   File: CursorRecyclerViewAdapter.java   Source Code and License Vote up 5 votes
/**
 * Swap in a new Cursor, returning the old Cursor.  Unlike
 * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
 * closed.
 *
 * @param newCursor The new cursor to be used.
 * @return Returns the previously set Cursor, or null if there wasa not one.
 * If the given new Cursor is the same instance is the previously set
 * Cursor, null is also returned.
 */
public Cursor swapCursor(Cursor newCursor) {
    if (newCursor == mCursor) {
        return null;
    }
    Cursor oldCursor = mCursor;
    if (oldCursor != null) {
        if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
        if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
    }
    mCursor = newCursor;
    if (newCursor != null) {
        if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
        if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
        mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
        mDataValid = true;
        // notify the observers about the new cursor
        notifyDataSetChanged();
    } else {
        mRowIDColumn = -1;
        mDataValid = false;
        // notify the observers about the lack of a data set
        // notifyDataSetInvalidated();
        notifyItemRangeRemoved(0, oldCursor.getCount());
    }
    return oldCursor;
}
 
Example 16
Project: Ocr-android   File: BaseRecyclerCursorAdapter.java   Source Code and License Vote up 5 votes
/**
     * Swap in a new Cursor, returning the old Cursor.  Unlike
     * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em>
     * closed.
     *
     * @param newCursor The new cursor to be used.
     * @return Returns the previously set Cursor, or null if there wasa not one.
     * If the given new Cursor is the same instance is the previously set
     * Cursor, null is also returned.
     */
    public Cursor swapCursor(Cursor newCursor) {
        if (newCursor == mCursor) {
            return null;
        }
        Cursor oldCursor = mCursor;
        if (oldCursor != null) {
            if (mChangeObserver != null) {
                oldCursor.unregisterContentObserver(mChangeObserver);
            }
            if (mDataSetObserver != null) {
                oldCursor.unregisterDataSetObserver(mDataSetObserver);
            }
        }
        mCursor = newCursor;
        if (newCursor != null) {
            if (mChangeObserver != null) {
                newCursor.registerContentObserver(mChangeObserver);
            }
            if (mDataSetObserver != null) {
                newCursor.registerDataSetObserver(mDataSetObserver);
            }
            mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
            mDataValid = true;
            // notify the observers about the new cursor
            notifyDataSetChanged();
        } else {
            mRowIDColumn = -1;
            mDataValid = false;
            // notify the observers about the lack of a data set
            notifyDataSetChanged();
//            notifyDataSetInvalidated();
        }
        return oldCursor;
    }
 
Example 17
Project: q-mail   File: MergeCursor.java   Source Code and License Vote up 4 votes
@Override
public void registerDataSetObserver(DataSetObserver observer) {
    for (Cursor cursor : mCursors) {
        cursor.registerDataSetObserver(observer);
    }
}