Exemplo n.º 1
0
		public override Android.Database.ICursor Query (Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder)
		{
			if (LOGV) Log.Verbose(TAG, "query(uri=" + uri + ", proj=" + projection.ToString() + ")");
	        SQLiteDatabase db = mOpenHelper.ReadableDatabase;
	
	        int match = sUriMatcher.Match(uri);
	        switch (match) {
	            default: {
	                // Most cases are handled with simple SelectionBuilder
	                SelectionBuilder builder = BuildExpandedSelection(uri, match);
	                return builder.Where(selection, selectionArgs).Query(db, projection, sortOrder);
	            }
	            case SEARCH_SUGGEST: {
	                SelectionBuilder builder = new SelectionBuilder();
	
	                // Adjust incoming query to become SQL text match
	                selectionArgs[0] = selectionArgs[0] + "%";
	                builder.Table(ScheduleDatabase.Tables.SEARCH_SUGGEST);
	                builder.Where(selection, selectionArgs);
	                builder.Map(SearchManager.SuggestColumnQuery,
	                        SearchManager.SuggestColumnText1);
	
	                projection = new String[] { BaseColumns.Id, SearchManager.SuggestColumnText1,
	                        SearchManager.SuggestColumnQuery };
	
	                String limit = uri.GetQueryParameter(SearchManager.SuggestParameterLimit);
	                return builder.Query(db, projection, null, null, ScheduleContract.SearchSuggest.DEFAULT_SORT, limit);
	            }
	        }
		}
Exemplo n.º 2
0
        public override ParcelFileDescriptor OpenFile(Android.Net.Uri uri, string mode)
        {
            switch ((UriMatches)UriMatcher.Match(uri))
            {
                case UriMatches.GetIcon:
                    var iconId = (PwIcon)Enum.Parse(typeof(PwIcon), uri.GetQueryParameter(IconIdParameter));
                    var customIconUuid = new PwUuid(MemUtil.HexStringToByteArray(uri.GetQueryParameter(CustomIconUuidParameter)));

                    var iconDrawable = _db.DrawableFactory.GetIconDrawable(App.Context.Resources, _db.KpDatabase, iconId, customIconUuid) as BitmapDrawable;
                    if (iconDrawable != null)
                    {
                        var pipe = ParcelFileDescriptor.CreatePipe();
                        var outStream = new OutputStreamInvoker(new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]));

                        ThreadPool.QueueUserWorkItem(state =>
                            {
                                iconDrawable.Bitmap.Compress(Bitmap.CompressFormat.Png, 100, outStream);
                                outStream.Close();
                            });

                        return pipe[0];
                    }

                    // Couldn't get an icon for some reason.
                    return null;
                default:
                    throw new ArgumentException("Unknown Uri: " + uri, "uri");
            }
        }