1 /* 2 * Copyright (C) 2015 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 17 package com.android.documentsui.dirlist; 18 19 import android.database.MatrixCursor; 20 import android.provider.DocumentsContract.Document; 21 22 import com.android.documentsui.DirectoryResult; 23 import com.android.documentsui.RootCursorWrapper; 24 25 import java.util.Random; 26 27 public class TestModel extends Model { 28 29 static final String[] COLUMNS = new String[]{ 30 RootCursorWrapper.COLUMN_AUTHORITY, 31 Document.COLUMN_DOCUMENT_ID, 32 Document.COLUMN_FLAGS, 33 Document.COLUMN_DISPLAY_NAME, 34 Document.COLUMN_SIZE, 35 Document.COLUMN_MIME_TYPE 36 }; 37 38 private final String mAuthority; 39 40 public TestModel(String authority) { 41 super(); 42 mAuthority = authority; 43 } 44 45 void update(String... names) { 46 Random rand = new Random(); 47 48 MatrixCursor c = new MatrixCursor(COLUMNS); 49 for (int i = 0; i < names.length; i++) { 50 MatrixCursor.RowBuilder row = c.newRow(); 51 row.add(RootCursorWrapper.COLUMN_AUTHORITY, mAuthority); 52 row.add(Document.COLUMN_DOCUMENT_ID, Integer.toString(i)); 53 row.add(Document.COLUMN_FLAGS, Document.FLAG_SUPPORTS_DELETE); 54 // Generate random document names and sizes. This forces the model's internal sort code 55 // to actually do something. 56 row.add(Document.COLUMN_DISPLAY_NAME, names[i]); 57 row.add(Document.COLUMN_SIZE, rand.nextInt()); 58 } 59 60 DirectoryResult r = new DirectoryResult(); 61 r.cursor = c; 62 update(r); 63 } 64 65 String idForPosition(int p) { 66 return Integer.toString(p); 67 } 68 } 69