19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.database;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
19825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown/**
20825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * A cross process cursor is an extension of a {@link Cursor} that also supports
21825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * usage from remote processes.
22825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * <p>
23825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * The contents of a cross process cursor are marshalled to the remote process by
24825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * filling {@link CursorWindow} objects using {@link #fillWindow}.  As an optimization,
25825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * the cursor can provide a pre-filled window to use via {@link #getWindow} thereby
26825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * obviating the need to copy the data to yet another cursor window.
27825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown */
28d2183654e03d589b120467f4e98da1b178ceeadbJeff Brownpublic interface CrossProcessCursor extends Cursor {
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
30825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * Returns a pre-filled window that contains the data within this cursor.
31825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * <p>
32825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * In particular, the window contains the row indicated by {@link Cursor#getPosition}.
33825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * The window's contents are automatically scrolled whenever the current
34825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * row moved outside the range covered by the window.
35825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * </p>
36825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     *
37825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * @return The pre-filled window, or null if none.
389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    CursorWindow getWindow();
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
42825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * Copies cursor data into the window.
43825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * <p>
44825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * Clears the window and fills it with data beginning at the requested
45825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * row position until all of the data in the cursor is exhausted
46825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * or the window runs out of space.
47825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * </p><p>
48825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * The filled window uses the same row indices as the original cursor.
49825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * For example, if you fill a window starting from row 5 from the cursor,
50825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * you can query the contents of row 5 from the window just by asking it
51825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * for row 5 because there is a direct correspondence between the row indices
52825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * used by the cursor and the window.
53825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * </p><p>
54825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * The current position of the cursor, as returned by {@link #getPosition},
55825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * is not changed by this method.
56825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * </p>
57825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     *
58825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * @param position The zero-based index of the first row to copy into the window.
59825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * @param window The window to fill.
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
61825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown    void fillWindow(int position, CursorWindow window);
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * This function is called every time the cursor is successfully scrolled
659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * to a new position, giving the subclass a chance to update any state it
66825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * may have.  If it returns false the move function will also do so and the
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * cursor will scroll to the beforeFirst position.
68825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * <p>
69825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * This function should be called by methods such as {@link #moveToPosition(int)},
70825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * so it will typically not be called from outside of the cursor class itself.
71825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * </p>
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
73825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * @param oldPosition The position that we're moving from.
74825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * @param newPosition The position that we're moving to.
75825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown     * @return True if the move is successful, false otherwise.
769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    boolean onMove(int oldPosition, int newPosition);
789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
79