|
42 | 42 | public class SQLiteCursor extends AbstractWindowedCursor { |
43 | 43 | static final String TAG = "SQLiteCursor"; |
44 | 44 | static final int NO_COUNT = -1; |
45 | | - private static final int CURSOR_WINDOW_EXTRA = 512; |
46 | 45 | private static boolean CURSOR_WINDOW_NEEDS_RECREATED = false; |
47 | | - private static final int DEFAULT_CURSOR_WINDOW_SIZE = (int)(8 * Math.pow(1024, 2)); |
| 46 | + private static final int DEFAULT_CURSOR_WINDOW_SIZE = -1; |
48 | 47 | public static int PREFERRED_CURSOR_WINDOW_SIZE = DEFAULT_CURSOR_WINDOW_SIZE; |
49 | 48 |
|
50 | 49 | /** The name of the table to edit */ |
@@ -154,29 +153,38 @@ public static void resetCursorWindowSize() { |
154 | 153 | ** versions are required. |
155 | 154 | */ |
156 | 155 | private void awc_clearOrCreateWindow(String name) { |
157 | | - int cursorWindowAllocationSize = PREFERRED_CURSOR_WINDOW_SIZE + CURSOR_WINDOW_EXTRA; |
| 156 | + int cursorWindowAllocationSize = PREFERRED_CURSOR_WINDOW_SIZE; |
158 | 157 | if (CURSOR_WINDOW_NEEDS_RECREATED) { |
159 | 158 | awc_closeWindow(); |
160 | 159 | CURSOR_WINDOW_NEEDS_RECREATED = false; |
161 | 160 | } |
162 | 161 | CursorWindow win = getWindow(); |
163 | 162 | if ( win==null ) { |
164 | | - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
165 | | - win = new CursorWindow(name, cursorWindowAllocationSize); |
166 | | - } else { |
167 | | - try { |
168 | | - @SuppressLint("DiscouragedPrivateApi") |
169 | | - Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize"); |
170 | | - if (field != null) { |
171 | | - field.setAccessible(true); |
172 | | - field.set(null, cursorWindowAllocationSize); |
173 | | - Log.i(TAG, String.format("Set CursorWindow allocation size to %s", cursorWindowAllocationSize)); |
| 163 | + /* if the application has set a specific window size via setCursorWindowSize |
| 164 | + * then use it. Otherwise, use the system default size defined internally |
| 165 | + * by CursorWindow / com.android.internal.R.integer.config_cursorWindowSize |
| 166 | + */ |
| 167 | + if(cursorWindowAllocationSize > 0) { |
| 168 | + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { |
| 169 | + win = new CursorWindow(name, cursorWindowAllocationSize); |
| 170 | + } else { |
| 171 | + try { |
| 172 | + @SuppressLint("DiscouragedPrivateApi") |
| 173 | + Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize"); |
| 174 | + if (field != null) { |
| 175 | + field.setAccessible(true); |
| 176 | + field.set(null, cursorWindowAllocationSize); |
| 177 | + Log.i(TAG, String.format("Set CursorWindow allocation size to %s", cursorWindowAllocationSize)); |
| 178 | + } |
| 179 | + } catch (Exception ex) { |
| 180 | + Log.e(TAG, "Failed to override CursorWindow allocation size", ex); |
174 | 181 | } |
175 | | - } catch (Exception ex) { |
176 | | - Log.e(TAG, "Failed to override CursorWindow allocation size", ex); |
| 182 | + win = new CursorWindow(name); |
177 | 183 | } |
| 184 | + } else { |
178 | 185 | win = new CursorWindow(name); |
179 | 186 | } |
| 187 | + |
180 | 188 | setWindow(win); |
181 | 189 | }else{ |
182 | 190 | win.clear(); |
|
0 commit comments