1825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown/* 2825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * Copyright (C) 2011 The Android Open Source Project 3825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * 4825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * Licensed under the Apache License, Version 2.0 (the "License"); 5825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * you may not use this file except in compliance with the License. 6825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * You may obtain a copy of the License at 7825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * 8825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * http://www.apache.org/licenses/LICENSE-2.0 9825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * 10825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * Unless required by applicable law or agreed to in writing, software 11825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * distributed under the License is distributed on an "AS IS" BASIS, 12825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * See the License for the specific language governing permissions and 14825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * limitations under the License 15825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown */ 16825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 17825c5132bff21e72c1448241f4c6868563c8d624Jeff Brownpackage android.database; 18825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 19825c5132bff21e72c1448241f4c6868563c8d624Jeff Brownimport android.database.CrossProcessCursor; 20825c5132bff21e72c1448241f4c6868563c8d624Jeff Brownimport android.database.Cursor; 21825c5132bff21e72c1448241f4c6868563c8d624Jeff Brownimport android.database.CursorWindow; 22825c5132bff21e72c1448241f4c6868563c8d624Jeff Brownimport android.database.CursorWrapper; 23825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 24825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown/** 25825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * Cursor wrapper that implements {@link CrossProcessCursor}. 26825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * <p> 27603f97f3240ac3a18f617b30bcb8e2c7c27192fbJeff Brown * If the wrapped cursor implements {@link CrossProcessCursor}, then the wrapper 28603f97f3240ac3a18f617b30bcb8e2c7c27192fbJeff Brown * delegates {@link #fillWindow}, {@link #getWindow()} and {@link #onMove} to it. 29603f97f3240ac3a18f617b30bcb8e2c7c27192fbJeff Brown * Otherwise, the wrapper provides default implementations of these methods that 30603f97f3240ac3a18f617b30bcb8e2c7c27192fbJeff Brown * traverse the contents of the cursor similar to {@link AbstractCursor#fillWindow}. 31825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * </p><p> 32825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * This wrapper can be used to adapt an ordinary {@link Cursor} into a 33825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * {@link CrossProcessCursor}. 34825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * </p> 35825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown */ 36825c5132bff21e72c1448241f4c6868563c8d624Jeff Brownpublic class CrossProcessCursorWrapper extends CursorWrapper implements CrossProcessCursor { 37825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown /** 38825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * Creates a cross process cursor wrapper. 39825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown * @param cursor The underlying cursor to wrap. 40825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown */ 41825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown public CrossProcessCursorWrapper(Cursor cursor) { 42825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown super(cursor); 43825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown } 44825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 45825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown @Override 46825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown public void fillWindow(int position, CursorWindow window) { 47825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown if (mCursor instanceof CrossProcessCursor) { 48825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown final CrossProcessCursor crossProcessCursor = (CrossProcessCursor)mCursor; 49825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown crossProcessCursor.fillWindow(position, window); 50825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown return; 51825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown } 52825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 53825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown DatabaseUtils.cursorFillWindow(mCursor, position, window); 54825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown } 55825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 56825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown @Override 57825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown public CursorWindow getWindow() { 58825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown if (mCursor instanceof CrossProcessCursor) { 59825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown final CrossProcessCursor crossProcessCursor = (CrossProcessCursor)mCursor; 60825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown return crossProcessCursor.getWindow(); 61825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown } 62825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 63825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown return null; 64825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown } 65825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 66825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown @Override 67825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown public boolean onMove(int oldPosition, int newPosition) { 68825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown if (mCursor instanceof CrossProcessCursor) { 69825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown final CrossProcessCursor crossProcessCursor = (CrossProcessCursor)mCursor; 70825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown return crossProcessCursor.onMove(oldPosition, newPosition); 71825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown } 72825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown 73825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown return true; 74825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown } 75825c5132bff21e72c1448241f4c6868563c8d624Jeff Brown} 76