예제 #1
0
파일: SearchViews.cs 프로젝트: adbk/spikes
		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;
		}
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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 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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        /// <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);
        }
예제 #10
0
		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) {
				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;
		}
예제 #11
0
        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);
        }
예제 #12
0
        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 }));
        }
예제 #13
0
 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);
 }