public ICursor FetchAllNotes() { var repo = new RemoteRepository(); var result = repo.GetAllEntries(); string[] columns = new string[] { "_id", "title", "body" }; MatrixCursor matrixCursor = new MatrixCursor(columns); foreach (var r in result) { var set = new ArraySet(); set.Add(r.id); set.Add(r.title.ToString()); set.Add(r.body.ToString()); matrixCursor.AddRow(set); } /*var set = new ArraySet(); * set.Add("1"); * set.Add("ZXC"); * set.Add("QWE"); * * matrixCursor.AddRow(set); * matrixCursor.AddRow(set);*/ return(matrixCursor); //return this.db.Query(DatabaseTable, new[] { KeyRowId, KeyTitle, KeyBody }, null, null, null, null, null); }
public override void DeliverResult(Java.Lang.Object data) { if (IsReset) { if (data != null) { ReleaseResources(data); } } MatrixCursor currList = Android.Runtime.Extensions.JavaCast <MatrixCursor>(data); MatrixCursor oldList = NowShowingList; NowShowingList = currList; NowShowingList.MoveToPosition(-1); if (IsStarted) { base.DeliverResult(data); } if (oldList != null && oldList != currList) { ReleaseResources(data); } }
public override ICursor QueryDocument(string documentId, string[] projection) { var result = new MatrixCursor(ResolveDocumentProjection(projection)); IncludeFile(result, documentId, null, null); return(result); }
public override ICursor QuerySearchDocuments(string rootId, string query, string[] projection) { // Create a cursor with the requested projection, or the default projection. var result = new MatrixCursor(ResolveDocumentProjection(projection)); var parent = GetFileForDocumentId(rootId); if (query.Contains(System.IO.Path.DirectorySeparatorChar)) { using (var file = new File(query)) { var parentDocId = GetDocIdForFile(file.ParentFile); return(QueryChildDocuments(parentDocId, projection, (string)null)); } } var queryLower = query.ToLower(); // This example implementation searches file names for the query and doesn't rank search // results, so we can stop as soon as we find a sufficient number of matches. Other // implementations might use other data about files, rather than the file name, to // produce a match; it might also require a network call to query a remote server. // Iterate through all files in the file structure under the root until we reach the // desired number of matches. // Start by adding the parent to the list of files to be processed var pending = new List <File> { parent }; // Do while we still have unexamined files, and fewer than the max search results while (pending.Any() && result.Count < MaxSearchResults) { // Take a file from the list of unprocessed files var file = pending[0]; pending.RemoveAt(0); if (file.IsDirectory) { if (!file.CanRead() || SystemDirectoryPaths.Contains(file.Path)) { continue; } // If it's a directory, add all its children to the unprocessed list var files = file.ListFiles(); if (files?.Length > 0) { pending.AddRange(files); } } else { // If it's a file and it matches, add it to the result cursor. if (file.Name.ToLower().Contains(queryLower)) { IncludeFile(result, null, file, GetDocIdForFile(file.ParentFile)); } } } return(result); }
public override bool OnCreateOptionsMenu (IMenu menu) { //Used to put dark icons on light action bar bool isLight = SampleList.THEME == Resource.Style.Sherlock___Theme_Light; //Create the search view SearchView searchView = new SearchView (SupportActionBar.ThemedContext); searchView.QueryHint = "Search for countries…"; searchView.SetOnQueryTextListener (this); searchView.SetOnSuggestionListener (this); if (mSuggestionsAdapter == null) { MatrixCursor cursor = new MatrixCursor (COLUMNS); Converter<string, Java.Lang.Object> func = s => new Java.Lang.String (s); cursor.AddRow (Array.ConvertAll<string,Java.Lang.Object> (new string[] { "1", "'Murica" }, func)); cursor.AddRow (Array.ConvertAll<string,Java.Lang.Object> (new string[] { "2", "Canada" }, func)); cursor.AddRow (Array.ConvertAll<string,Java.Lang.Object> (new string[] { "3", "Denmark" }, func)); mSuggestionsAdapter = new SuggestionsAdapter (SupportActionBar.ThemedContext, cursor); } searchView.SuggestionsAdapter = mSuggestionsAdapter; menu.Add ("Search") .SetIcon (isLight ? Resource.Drawable.ic_search_inverse : Resource.Drawable.abs__ic_search) .SetActionView (searchView) .SetShowAsAction (MenuItem.ShowAsActionIfRoom | MenuItem.ShowAsActionCollapseActionView); return true; }
public override bool OnCreateOptionsMenu(IMenu menu) { //Used to put dark icons on light action bar bool isLight = SampleList.THEME == Resource.Style.Sherlock___Theme_Light; //Create the search view SearchView searchView = new SearchView(SupportActionBar.ThemedContext); searchView.QueryHint = "Search for countries…"; searchView.SetOnQueryTextListener(this); searchView.SetOnSuggestionListener(this); if (mSuggestionsAdapter == null) { MatrixCursor cursor = new MatrixCursor(COLUMNS); Converter <string, Java.Lang.Object> func = s => new Java.Lang.String(s); cursor.AddRow(Array.ConvertAll <string, Java.Lang.Object> (new string[] { "1", "'Murica" }, func)); cursor.AddRow(Array.ConvertAll <string, Java.Lang.Object> (new string[] { "2", "Canada" }, func)); cursor.AddRow(Array.ConvertAll <string, Java.Lang.Object> (new string[] { "3", "Denmark" }, func)); mSuggestionsAdapter = new SuggestionsAdapter(SupportActionBar.ThemedContext, cursor); } searchView.SuggestionsAdapter = mSuggestionsAdapter; menu.Add("Search") .SetIcon(isLight ? Resource.Drawable.ic_search_inverse : Resource.Drawable.abs__ic_search) .SetActionView(searchView) .SetShowAsAction(MenuItem.ShowAsActionIfRoom | MenuItem.ShowAsActionCollapseActionView); return(true); }
public override ICursor QueryDocument(string documentId, string[] projection) { System.Diagnostics.Debug.WriteLine($"QUERY DOCUMENT {documentId} - {projection}"); var result = new MatrixCursor(projection ?? DEFAULT_DOCUMENT_PROJECTION); return(result); }
public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { var query = uri.LastPathSegment.ToLowerInvariant(); IList <Address> addresses = null; try { addresses = geocoder.GetFromLocationName(query, SuggestionCount, LowerLeftLat, LowerLeftLon, UpperRightLat, UpperRightLon); } catch (Exception e) { Xamarin.Insights.Report(e); Android.Util.Log.Warn("SuggestionsFetcher", e.ToString()); addresses = new Address[0]; } var cursor = new MatrixCursor(new string[] { BaseColumns.Id, SearchManager.SuggestColumnText1, SearchManager.SuggestColumnText2, SearchManager.SuggestColumnIntentExtraData }, addresses.Count); long id = 0; foreach (var address in addresses) { int dummy; if (int.TryParse(address.Thoroughfare, out dummy)) { continue; } var options1 = new string[] { address.FeatureName, address.Thoroughfare }; var options2 = new string[] { address.Locality, address.AdminArea }; var line1 = string.Join(", ", options1.Where(s => !string.IsNullOrEmpty(s)).Distinct()); var line2 = string.Join(", ", options2.Where(s => !string.IsNullOrEmpty(s))); if (string.IsNullOrEmpty(line1) || string.IsNullOrEmpty(line2)) { continue; } cursor.AddRow(new Java.Lang.Object[] { id++, line1, line2, address.Latitude + "|" + address.Longitude }); } return(cursor); }
public override ICursor QueryRecentDocuments(string rootId, string[] projection) { Log.Verbose(TAG, "queryRecentDocuments"); // This example implementation walks a local file structure to find the most recently // modified files. Other implementations might include making a network call to query a // server. // Create a cursor with the requested projection, or the default projection. var result = new MatrixCursor(ResolveDocumentProjection(projection)); File parent = GetFileForDocId(rootId); // Create a list to store the most recent documents, which orders by last modified. var lastModifiedFiles = new List <File> (); // Iterate through all files and directories in the file structure under the root. If // the file is more recent than the least recently modified, add it to the queue, // limiting the number of results. var pending = new List <File> (); // Start by adding the parent to the list of files to be processed pending.Add(parent); // Do while we still have unexamined files while (pending.Any()) { // Take a file from the front of the list of unprocessed files File file = pending [0]; pending.RemoveAt(0); if (file.IsDirectory) { // If it's a directory, add all its children to the unprocessed list pending.AddRange(file.ListFiles().AsEnumerable()); } else { // If it's a file, add it to the ordered list. lastModifiedFiles.Add(file); } } // Sort our list by last modified. lastModifiedFiles.Sort(new Comparison <File> (delegate(File i, File j) { return(i.LastModified().CompareTo(j.LastModified())); })); // Add the most recent files to the cursor, not exceeding the max number of results. for (int i = 0; i < Math.Min(MAX_LAST_MODIFIED + 1, lastModifiedFiles.Count); i++) { File file = lastModifiedFiles[0]; lastModifiedFiles.RemoveAt(0); IncludeFile(result, null, file); } return(result); }
private MatrixCursor PreferenceToCursor <T>(T value) where T : Java.Lang.Object { MatrixCursor matrixCursor = new MatrixCursor(PREFERENCE_COLUMNS, 1); MatrixCursor.RowBuilder builder = matrixCursor.NewRow(); builder.Add(value); return(matrixCursor); }
protected override void OnReset() { OnStopLoading(); if (ComingSoonList != null) { ReleaseResources(ComingSoonList); ComingSoonList = null; } }
public override ICursor QueryDocument(string documentId, string[] projection) { Log.Verbose(TAG, "queryDocument"); // Create a cursor with the requested projection, or the default projection. var result = new MatrixCursor(ResolveDocumentProjection(projection)); IncludeFile(result, documentId, null); return(result); }
protected override void OnReset() { OnStopLoading(); if (NowShowingList != null) { ReleaseResources(NowShowingList); NowShowingList = null; } }
public override Android.Database.ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { var c = new MatrixCursor(new String[] { "_id", SearchManager.SuggestColumnText1, "lat", "lng" }); c.AddRow(new Java.Lang.Object[] { 123, "description", "lat", "lng" }); c.AddRow(new Java.Lang.Object[] { 1243, "description 2", "lat", "lng" }); c.AddRow(new Java.Lang.Object[] { 1235, "description", "lat", "lng" }); c.AddRow(new Java.Lang.Object[] { 12436, "description 2", "lat", "lng" }); return(c); }
public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { MatrixCursor cursor = null; PrefModel model = GetPrefModelByUri(uri); try { switch (sUriMatcher.Match(uri)) { case PREF_BOOLEAN: if (GetDPreference(model.Name).HasKey(model.Key)) { cursor = PreferenceToCursor(new Java.Lang.Boolean((GetDPreference(model.Name).GetPrefBoolean(model.Key, false)))); } break; case PREF_STRING: if (GetDPreference(model.Name).HasKey(model.Key)) { cursor = PreferenceToCursor(new Java.Lang.String((GetDPreference(model.Name).GetPrefString(model.Key, "")))); } break; case PREF_INT: if (GetDPreference(model.Name).HasKey(model.Key)) { cursor = PreferenceToCursor((Java.Lang.Integer)(GetDPreference(model.Name).GetPrefInt(model.Key, -1))); } break; case PREF_LONG: if (GetDPreference(model.Name).HasKey(model.Key)) { cursor = PreferenceToCursor((Java.Lang.Long)(GetDPreference(model.Name).GetPrefLong(model.Key, -1))); } break; case PREF_DATETIME: if (GetDPreference(model.Name).HasKey(model.Key)) { cursor = PreferenceToCursor((Java.Lang.Long)(GetDPreference(model.Name).GetPrefLong(model.Key, -1))); } break; } return(cursor); } catch (Exception exQuery) { for (int i = 0; i < 10; i++) { Debug.WriteLine($"PreferenceProvider Query Exception: {exQuery.Message} ON pref: {sUriMatcher.Match(uri)}\nKey: {model.Key}"); } throw exQuery; } }
public static Android.Database.MatrixCursor Create(List <Goal> goals) { string[] columnNames = { "Id", "MemberId", "ClubId", "Type", "GoalValue" }; MatrixCursor cursor = new MatrixCursor(columnNames); foreach (var item in goals) { cursor.AddRow(new Java.Lang.Object[] { item.Id, item.ClubId, item.ClubId, item.Type, item.GoalValue }); } return(cursor); }
private void UpdateSearchSuggestions() { var matrix = new MatrixCursor(new string[] { BaseColumns.Id, "hint" }); int i = 0; foreach (var hint in ViewModel.CurrentHintSet.Where(s => s != MainPageSearchView.Query)) { matrix.AddRow(new Object[] { i, hint }); } _searchSuggestionAdapter.ChangeCursor(matrix); }
/** * Add a representation of a file to a cursor. * * @param result the cursor to modify * @param docId the document ID representing the desired file (may be null if given file) * @param file the File object representing the desired file (may be null if given docID) */ void IncludeFile(MatrixCursor result, string docId, File file) { if (docId == null) { docId = GetDocIdForFile(file); } else { file = GetFileForDocId(docId); } DocumentContractFlags flags = (DocumentContractFlags)0; if (file.IsDirectory) { // Request the folder to lay out as a grid rather than a list. This also allows a larger // thumbnail to be displayed for each image. // flags |= Document.FLAG_DIR_PREFERS_GRID; // Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory. if (file.IsDirectory && file.CanWrite()) { flags |= DocumentContractFlags.DirSupportsCreate; } } else if (file.CanWrite()) { // If the file is writable set FLAG_SUPPORTS_WRITE and // FLAG_SUPPORTS_DELETE flags |= DocumentContractFlags.SupportsWrite; flags |= DocumentContractFlags.SupportsDelete; } string displayName = file.Name; string mimeType = GetTypeForFile(file); if (mimeType.StartsWith("image/")) { // Allow the image to be represented by a thumbnail rather than an icon flags |= DocumentContractFlags.SupportsThumbnail; } MatrixCursor.RowBuilder row = result.NewRow(); row.Add(DocumentsContract.Document.ColumnDocumentId, docId); row.Add(DocumentsContract.Document.ColumnDisplayName, displayName); row.Add(DocumentsContract.Document.ColumnSize, file.Length()); row.Add(DocumentsContract.Document.ColumnMimeType, mimeType); row.Add(DocumentsContract.Document.ColumnLastModified, file.LastModified()); row.Add(DocumentsContract.Document.ColumnFlags, (int)flags); // Add a custom icon row.Add(DocumentsContract.Document.ColumnIcon, Resource.Drawable.icon); }
/// <summary> /// Returns a <see cref="MatrixCursor"/>, for the collection. /// </summary> /// <param name="collection">The colletion that will be used to create the Cursor.</param> /// <param name="text">The text to display.</param> /// <param name="serialize">A way to serialize the object and retrieve it from the third column => [2] as a string.</param> /// <returns>A new matrixcursor.</returns> public static MatrixCursor ToMatrixCursor <T>(this IEnumerable <T> collection, Func <T, string> text, Func <T, string> serialize = null) { MatrixCursor cursor = new MatrixCursor(new string[] { "_id", "text", "item" }); int id = 0; foreach (var item in collection) { cursor.AddRow(new Java.Lang.Object[] { id.ToString(), text?.Invoke(item), serialize?.Invoke(item) }); id++; } return(cursor); }
public override ICursor QueryChildDocuments(string parentDocumentId, string[] projection, string sortOrder) { Log.Verbose(TAG, "queryChildDocuments, parentDocumentId: " + parentDocumentId + " sortOrder: " + sortOrder); var result = new MatrixCursor(ResolveDocumentProjection(projection)); File parent = GetFileForDocId(parentDocumentId); foreach (File file in parent.ListFiles()) { IncludeFile(result, null, file); } return(result); }
public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { var query = uri.LastPathSegment.ToLowerInvariant (); IList<Address> addresses = null; try { addresses = geocoder.GetFromLocationName (query, SuggestionCount, LowerLeftLat, LowerLeftLon, UpperRightLat, UpperRightLon); } catch (Exception e) { AnalyticsHelper.LogException ("SuggestionsFetcher", e); Android.Util.Log.Warn ("SuggestionsFetcher", e.ToString ()); addresses = new Address[0]; } var cursor = new MatrixCursor (new string[] { BaseColumns.Id, SearchManager.SuggestColumnText1, SearchManager.SuggestColumnText2, SearchManager.SuggestColumnIntentExtraData }, addresses.Count); long id = 0; foreach (var address in addresses) { int dummy; if (int.TryParse (address.Thoroughfare, out dummy)) continue; var options1 = new string[] { address.FeatureName, address.Thoroughfare }; var options2 = new string[] { address.Locality, address.AdminArea }; var line1 = string.Join (", ", options1.Where (s => !string.IsNullOrEmpty (s)).Distinct ()); var line2 = string.Join (", ", options2.Where (s => !string.IsNullOrEmpty (s))); if (string.IsNullOrEmpty (line1) || string.IsNullOrEmpty (line2)) continue; cursor.AddRow (new Java.Lang.Object[] { id++, line1, line2, address.Latitude.ToSafeString () + "|" + address.Longitude.ToSafeString () }); } return cursor; }
void populatFromAutoComplete(List <StoppingPlace> fromList) { MatrixCursor cursor = new MatrixCursor(COLUMNS); Converter <string, Java.Lang.Object> func = s => new Java.Lang.String(s); _stopServerList = fromList; foreach (var stoppingPlace in fromList) { cursor.AddRow(Array.ConvertAll <string, Java.Lang.Object> (new string[] { stoppingPlace.Id, stoppingPlace.Name }, func)); } mSuggestionsAdapter.SwapCursor(cursor); }
/// <summary> /// The matrix cursor. /// </summary> /// <param name="projection"> /// The projection. /// </param> /// <param name="intProjection"> /// The int projection. /// </param> /// <param name="entries"> /// The entries. /// </param> /// <returns> /// The Android.Database.MatrixCursor. /// </returns> private static MatrixCursor MatrixCursor( string[] projection, ApezProjection[] intProjection, ZipFileEntry[] entries) { var mc = new MatrixCursor(projection, entries.Length); foreach (ZipFileEntry zer in entries) { MatrixCursor.RowBuilder rb = mc.NewRow(); for (int i = 0; i < intProjection.Length; i++) { switch (intProjection[i]) { case ApezProjection.File: rb.Add(i); break; case ApezProjection.FileName: rb.Add(zer.FilenameInZip); break; case ApezProjection.ZipFile: rb.Add(zer.ZipFileName); break; case ApezProjection.Modification: rb.Add(ZipFile.DateTimeToDosTime(zer.ModifyTime)); break; case ApezProjection.Crc: rb.Add(zer.Crc32); break; case ApezProjection.CompressedLength: rb.Add(zer.CompressedSize); break; case ApezProjection.UncompressedLength: rb.Add(zer.FileSize); break; case ApezProjection.CompressionType: rb.Add((int)zer.Method); break; } } } return(mc); }
public MatrixCursor GetNowShowingMovieList() { string[] columns = new string[] { "ID", "Title" }; MatrixCursor cursor = new MatrixCursor(columns); SearchContainerWithDates <SearchMovie> results = client.GetMovieNowPlayingListAsync().Result; foreach (SearchMovie result in results.Results) { MatrixCursor.RowBuilder builder = cursor.NewRow(); builder.Add(result.Id); builder.Add(result.Title); } return(cursor); }
public override ICursor QueryChildDocuments(string parentDocumentId, string[] projection, string sortOrder) { System.Diagnostics.Debug.WriteLine($"QUERY CHILD DOCUMENTS {parentDocumentId} - {projection} - {sortOrder}"); var result = new MatrixCursor(projection ?? DEFAULT_DOCUMENT_PROJECTION); var row = result.NewRow(); row.Add(DocumentsContract.Document.ColumnDocumentId, "root/testfile"); row.Add(DocumentsContract.Document.ColumnMimeType, "application/octet-stream"); row.Add(DocumentsContract.Document.ColumnDisplayName, "Test file"); row.Add(DocumentsContract.Document.ColumnLastModified, null); row.Add(DocumentsContract.Document.ColumnFlags, (int)DocumentContractFlags.SupportsMove); row.Add(DocumentsContract.Document.ColumnSize, null); return(result); }
public override ICursor QueryRoots(string[] projection) { Log.Verbose(TAG, "queryRoots"); // Create a cursor with either the requested fields, or the default projection. This // cursor is returned to the Android system picker UI and used to display all roots from // this provider. var result = new MatrixCursor(ResolveRootProjection(projection)); // If user is not logged in, return an empty root cursor. This removes our provider from // the list entirely. if (!IsUserLoggedIn()) { return(result); } // It's possible to have multiple roots (e.g. for multiple accounts in the same app) - // just add multiple cursor rows. // Construct one row for a root called "MyCloud". MatrixCursor.RowBuilder row = result.NewRow(); row.Add(DocumentsContract.Root.ColumnRootId, ROOT); row.Add(DocumentsContract.Root.ColumnSummary, Context.GetString(Resource.String.root_summary)); // FLAG_SUPPORTS_CREATE means at least one directory under the root supports creating // documents. FLAG_SUPPORTS_RECENTS means your application's most recently used // documents will show up in the "Recents" category. FLAG_SUPPORTS_SEARCH allows users // to search all documents the application shares. row.Add(DocumentsContract.Root.ColumnFlags, (int)DocumentRootFlags.SupportsCreate | (int)DocumentRootFlags.SupportsRecents | (int)DocumentRootFlags.SupportsSearch); // COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider). row.Add(DocumentsContract.Root.ColumnTitle, Context.GetString(Resource.String.app_name)); // This document id must be unique within this provider and consistent across time. The // system picker UI may save it and refer to it later. row.Add(DocumentsContract.Root.ColumnDocumentId, GetDocIdForFile(mBaseDir)); // The child MIME types are used to filter the roots and only present to the user roots // that contain the desired type somewhere in their file hierarchy. row.Add(DocumentsContract.Root.ColumnMimeTypes, GetChildMimeTypes(mBaseDir)); row.Add(DocumentsContract.Root.ColumnAvailableBytes, mBaseDir.FreeSpace); row.Add(DocumentsContract.Root.ColumnIcon, Resource.Drawable.icon); return(result); }
public override Object LoadInBackground() { ICursor albums = base.LoadInBackground() as ICursor; MatrixCursor allAlbum = new MatrixCursor(PROJECTION); long count = 0; if (albums.Count > 0) { while (albums.MoveToNext()) { count += albums.GetLong(3); } } allAlbum.AddRow(new Object[] { Album.ALBUM_ID_ALL, Album.ALBUM_NAME_ALL, MEDIA_ID_DUMMY, $"{count}" }); return(new MergeCursor(new ICursor[] { allAlbum, albums })); }
public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { /* * Intent serviceIntent = new Intent(this, Vertix.SearchService.JavaType); * ServiceConnection serviceConnection = new ServiceConnection(); * BindService(serviceIntent, serviceConnection, Bind.AutoCreate); */ MatrixCursor cursor = new MatrixCursor(new string[] { Android.Provider.BaseColumns.Id, SearchManager.SuggestColumnText1, SearchManager.SuggestColumnIntentData }, 0); if (!string.IsNullOrWhiteSpace(selectionArgs[0])) { cursor.AddRow(new Java.Lang.Object[] { "0", "hello", "0/hello" }); cursor.AddRow(new Java.Lang.Object[] { "1", "world", "1/world" }); } return(cursor); }
public override ICursor QueryRoots(string[] projection) { System.Diagnostics.Debug.WriteLine($"QUERY ROOTS {projection}"); var result = new MatrixCursor(projection ?? DEFAULT_ROOT_PROJECTION); var row = result.NewRow(); row.Add(DocumentsContract.Root.ColumnRootId, "root"); //row.Add(DocumentsContract.Root.ColumnSummary, "AutoActive archives"); row.Add(DocumentsContract.Root.ColumnFlags, (int)DocumentRootFlags.LocalOnly); row.Add(DocumentsContract.Root.ColumnIcon, Resource.Drawable.Icon); row.Add(DocumentsContract.Root.ColumnTitle, "AutoActive"); row.Add(DocumentsContract.Root.ColumnDocumentId, GetDocIDForFile(archivesRoot)); //row.Add(DocumentsContract.Root.ColumnMimeTypes, "application/octet-stream\n*/*"); //row.Add(DocumentsContract.Root.ColumnAvailableBytes, archivesRoot.FreeSpace); return(result); }
public override ICursor QueryRoots(string[] projection) { // Create a cursor with either the requested fields, or the default projection. This // cursor is returned to the Android system picker UI and used to display all roots from // this provider. var result = new MatrixCursor(ResolveRootProjection(projection)); // It's possible to have multiple roots (e.g. for multiple accounts in the same app) - // just add multiple cursor rows. Construct one row for a root. var row = result.NewRow(); row.Add(DocumentsContract.Root.ColumnRootId, Root); // Если не задано, то показывается размер. //row.Add(DocumentsContract.Root.ColumnSummary, Context.GetString(Resource.String.root_summary)); // FLAG_SUPPORTS_CREATE means at least one directory under the root supports creating // documents. FLAG_SUPPORTS_RECENTS means your application's most recently used // documents will show up in the "Recents" category. FLAG_SUPPORTS_SEARCH allows users // to search all documents the application shares. row.Add(DocumentsContract.Root.ColumnFlags, (int)DocumentRootFlags.SupportsCreate | (int)DocumentRootFlags.SupportsRecents | (int)DocumentRootFlags.SupportsSearch); // COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider). row.Add(DocumentsContract.Root.ColumnTitle, System.IO.Path.DirectorySeparatorChar.ToString()); // This document id must be unique within this provider and consistent across time. The // system picker UI may save it and refer to it later. row.Add(DocumentsContract.Root.ColumnDocumentId, GetDocIdForFile(_baseFolder)); // The child MIME types are used to filter the roots and only present to the user roots // that contain the desired type somewhere in their file hierarchy. //row.Add(DocumentsContract.Root.ColumnMimeTypes, // "image/*\ntext/*\napplication/vnd.openxmlformats-officedocument.wordprocessingml.document\n"); row.Add(DocumentsContract.Root.ColumnAvailableBytes, _baseFolder?.FreeSpace ?? 0); row.Add(DocumentsContract.Root.ColumnIcon, Resource.Mipmap.ic_launcher); return(result); }
public override ICursor QueryChildDocuments(string parentDocumentId, string[] projection, string sortOrder) { var result = new MatrixCursor(ResolveDocumentProjection(projection)); var parent = GetFileForDocumentId(parentDocumentId); var files = parent.ListFiles(); if (files == null || files.Length == 0) { return(result); } var parentDocId = GetDocIdForFile(parent); foreach (var file in files) { IncludeFile(result, null, file, parentDocId); } return(result); }
public override ICursor QuerySearchDocuments(string rootId, string query, string[] projection) { // Create a cursor with the requested projection, or the default projection. var result = new MatrixCursor(ResolveDocumentProjection(projection)); File parent = GetFileForDocId(rootId); // This example implementation searches file names for the query and doesn't rank search // results, so we can stop as soon as we find a sufficient number of matches. Other // implementations might use other data about files, rather than the file name, to // produce a match; it might also require a network call to query a remote server. // Iterate through all files in the file structure under the root until we reach the // desired number of matches. var pending = new List <File>(); // Start by adding the parent to the list of files to be processed pending.Add(parent); // Do while we still have unexamined files, and fewer than the max search results while (pending.Any() && result.Count < MAX_SEARCH_RESULTS) { // Take a file from the list of unprocessed files File file = pending [0]; pending.RemoveAt(0); if (file.IsDirectory) { // If it's a directory, add all its children to the unprocessed list pending.AddRange(file.ListFiles().AsEnumerable()); } else { // If it's a file and it matches, add it to the result cursor. if (file.Name.ToLower().Contains(query)) { IncludeFile(result, null, file); } } } return(result); }
public override ICursor QueryRoots (string[] projection) { Log.Verbose (TAG, "queryRoots"); // Create a cursor with either the requested fields, or the default projection. This // cursor is returned to the Android system picker UI and used to display all roots from // this provider. var result = new MatrixCursor (ResolveRootProjection (projection)); // If user is not logged in, return an empty root cursor. This removes our provider from // the list entirely. if (!IsUserLoggedIn ()) { return result; } // It's possible to have multiple roots (e.g. for multiple accounts in the same app) - // just add multiple cursor rows. // Construct one row for a root called "MyCloud". MatrixCursor.RowBuilder row = result.NewRow (); row.Add (DocumentsContract.Root.ColumnRootId, ROOT); row.Add (DocumentsContract.Root.ColumnSummary, Context.GetString (Resource.String.root_summary)); // FLAG_SUPPORTS_CREATE means at least one directory under the root supports creating // documents. FLAG_SUPPORTS_RECENTS means your application's most recently used // documents will show up in the "Recents" category. FLAG_SUPPORTS_SEARCH allows users // to search all documents the application shares. row.Add (DocumentsContract.Root.ColumnFlags, (int)DocumentRootFlags.SupportsCreate | (int)DocumentRootFlags.SupportsRecents | (int)DocumentRootFlags.SupportsSearch); // COLUMN_TITLE is the root title (e.g. what will be displayed to identify your provider). row.Add (DocumentsContract.Root.ColumnTitle, Context.GetString (Resource.String.app_name)); // This document id must be unique within this provider and consistent across time. The // system picker UI may save it and refer to it later. row.Add (DocumentsContract.Root.ColumnDocumentId, GetDocIdForFile (mBaseDir)); // The child MIME types are used to filter the roots and only present to the user roots // that contain the desired type somewhere in their file hierarchy. row.Add (DocumentsContract.Root.ColumnMimeTypes, GetChildMimeTypes (mBaseDir)); row.Add (DocumentsContract.Root.ColumnAvailableBytes, mBaseDir.FreeSpace); row.Add (DocumentsContract.Root.ColumnIcon, Resource.Drawable.icon); return result; }
/** * Add a representation of a file to a cursor. * * @param result the cursor to modify * @param docId the document ID representing the desired file (may be null if given file) * @param file the File object representing the desired file (may be null if given docID) */ void IncludeFile (MatrixCursor result, string docId, File file) { if (docId == null) { docId = GetDocIdForFile (file); } else { file = GetFileForDocId (docId); } DocumentContractFlags flags = (DocumentContractFlags)0; if (file.IsDirectory) { // Request the folder to lay out as a grid rather than a list. This also allows a larger // thumbnail to be displayed for each image. // flags |= Document.FLAG_DIR_PREFERS_GRID; // Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory. if (file.IsDirectory && file.CanWrite ()) { flags |= DocumentContractFlags.DirSupportsCreate; } } else if (file.CanWrite ()) { // If the file is writable set FLAG_SUPPORTS_WRITE and // FLAG_SUPPORTS_DELETE flags |= DocumentContractFlags.SupportsWrite; flags |= DocumentContractFlags.SupportsDelete; } string displayName = file.Name; string mimeType = GetTypeForFile (file); if (mimeType.StartsWith ("image/")) { // Allow the image to be represented by a thumbnail rather than an icon flags |= DocumentContractFlags.SupportsThumbnail; } MatrixCursor.RowBuilder row = result.NewRow (); row.Add (DocumentsContract.Document.ColumnDocumentId, docId); row.Add (DocumentsContract.Document.ColumnDisplayName, displayName); row.Add (DocumentsContract.Document.ColumnSize, file.Length ()); row.Add (DocumentsContract.Document.ColumnMimeType, mimeType); row.Add (DocumentsContract.Document.ColumnLastModified, file.LastModified ()); row.Add (DocumentsContract.Document.ColumnFlags, (int)flags); // Add a custom icon row.Add (DocumentsContract.Document.ColumnIcon, Resource.Drawable.icon); }
public override ICursor QueryChildDocuments (string parentDocumentId, string[] projection, string sortOrder) { Log.Verbose (TAG, "queryChildDocuments, parentDocumentId: " + parentDocumentId + " sortOrder: " + sortOrder); var result = new MatrixCursor (ResolveDocumentProjection (projection)); File parent = GetFileForDocId (parentDocumentId); foreach (File file in parent.ListFiles ()) { IncludeFile (result, null, file); } return result; }
public override ICursor QueryDocument (string documentId, string[] projection) { Log.Verbose (TAG, "queryDocument"); // Create a cursor with the requested projection, or the default projection. var result = new MatrixCursor (ResolveDocumentProjection (projection)); IncludeFile (result, documentId, null); return result; }
public override ICursor QuerySearchDocuments (string rootId, string query, string[] projection) { // Create a cursor with the requested projection, or the default projection. var result = new MatrixCursor (ResolveDocumentProjection (projection)); File parent = GetFileForDocId (rootId); // This example implementation searches file names for the query and doesn't rank search // results, so we can stop as soon as we find a sufficient number of matches. Other // implementations might use other data about files, rather than the file name, to // produce a match; it might also require a network call to query a remote server. // Iterate through all files in the file structure under the root until we reach the // desired number of matches. var pending = new List<File>(); // Start by adding the parent to the list of files to be processed pending.Add (parent); // Do while we still have unexamined files, and fewer than the max search results while (pending.Any () && result.Count < MAX_SEARCH_RESULTS) { // Take a file from the list of unprocessed files File file = pending [0]; pending.RemoveAt (0); if (file.IsDirectory) { // If it's a directory, add all its children to the unprocessed list pending.AddRange (file.ListFiles ().AsEnumerable ()); } else { // If it's a file and it matches, add it to the result cursor. if (file.Name.ToLower().Contains (query)) { IncludeFile (result, null, file); } } } return result; }
public override ICursor QueryRecentDocuments (string rootId, string[] projection) { Log.Verbose (TAG, "queryRecentDocuments"); // This example implementation walks a local file structure to find the most recently // modified files. Other implementations might include making a network call to query a // server. // Create a cursor with the requested projection, or the default projection. var result = new MatrixCursor (ResolveDocumentProjection (projection)); File parent = GetFileForDocId (rootId); // Create a list to store the most recent documents, which orders by last modified. var lastModifiedFiles = new List<File> (); // Iterate through all files and directories in the file structure under the root. If // the file is more recent than the least recently modified, add it to the queue, // limiting the number of results. var pending = new List<File> (); // Start by adding the parent to the list of files to be processed pending.Add (parent); // Do while we still have unexamined files while (pending.Any ()) { // Take a file from the front of the list of unprocessed files File file = pending [0]; pending.RemoveAt (0); if (file.IsDirectory) { // If it's a directory, add all its children to the unprocessed list pending.AddRange (file.ListFiles ().AsEnumerable ()); } else { // If it's a file, add it to the ordered list. lastModifiedFiles.Add (file); } } // Sort our list by last modified. lastModifiedFiles.Sort (new Comparison<File> (delegate (File i, File j) { return (i.LastModified().CompareTo (j.LastModified ())); })); // Add the most recent files to the cursor, not exceeding the max number of results. for (int i = 0; i < Math.Min (MAX_LAST_MODIFIED + 1, lastModifiedFiles.Count); i++) { File file = lastModifiedFiles[0]; lastModifiedFiles.RemoveAt (0); IncludeFile (result, null, file); } return result; }
private void UpdateSearchSuggestions() { var matrix = new MatrixCursor(new string[] {BaseColumns.Id,"hint"}); int i = 0; foreach (var hint in ViewModel.CurrentHintSet.Where(s => s != MainPageSearchView.Query)) { matrix.AddRow(new Object[] {i,hint}); } _searchSuggestionAdapter.ChangeCursor(matrix); }
/// <summary> /// The matrix cursor. /// </summary> /// <param name="projection"> /// The projection. /// </param> /// <param name="intProjection"> /// The int projection. /// </param> /// <param name="entries"> /// The entries. /// </param> /// <returns> /// The Android.Database.MatrixCursor. /// </returns> private static MatrixCursor MatrixCursor( string[] projection, ApezProjection[] intProjection, ZipFileEntry[] entries) { var mc = new MatrixCursor(projection, entries.Length); foreach (ZipFileEntry zer in entries) { MatrixCursor.RowBuilder rb = mc.NewRow(); for (int i = 0; i < intProjection.Length; i++) { switch (intProjection[i]) { case ApezProjection.File: rb.Add(i); break; case ApezProjection.FileName: rb.Add(zer.FilenameInZip); break; case ApezProjection.ZipFile: rb.Add(zer.ZipFileName); break; case ApezProjection.Modification: rb.Add(ZipFile.DateTimeToDosTime(zer.ModifyTime)); break; case ApezProjection.Crc: rb.Add(zer.Crc32); break; case ApezProjection.CompressedLength: rb.Add(zer.CompressedSize); break; case ApezProjection.UncompressedLength: rb.Add(zer.FileSize); break; case ApezProjection.CompressionType: rb.Add((int)zer.Method); break; } } } return mc; }