11 package com.freerdp.freerdpcore.services;
13 import android.app.SearchManager;
14 import android.content.ContentProvider;
15 import android.content.ContentValues;
16 import android.database.Cursor;
17 import android.database.MatrixCursor;
18 import android.net.Uri;
20 import com.freerdp.freerdpcore.R;
21 import com.freerdp.freerdpcore.application.GlobalApp;
22 import com.freerdp.freerdpcore.domain.BookmarkBase;
23 import com.freerdp.freerdpcore.domain.ConnectionReference;
24 import com.freerdp.freerdpcore.domain.ManualBookmark;
26 import java.util.ArrayList;
31 public static final Uri CONTENT_URI =
32 Uri.parse(
"content://com.freerdp.afreerdp.services.freerdpsuggestionprovider");
34 @Override
public int delete(Uri uri, String selection, String[] selectionArgs)
40 @Override
public String getType(Uri uri)
42 return "vnd.android.cursor.item/vnd.freerdp.remote";
45 @Override
public Uri insert(Uri uri, ContentValues values)
51 @Override
public boolean onCreate()
57 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
61 String query = (selectionArgs !=
null && selectionArgs.length > 0) ? selectionArgs[0] :
"";
64 ArrayList<BookmarkBase> history =
65 GlobalApp.getQuickConnectHistoryGateway().findHistory(query);
68 ArrayList<BookmarkBase> manualBookmarks;
69 if (query.length() > 0)
70 manualBookmarks =
GlobalApp.getManualBookmarkGateway().findByLabelOrHostnameLike(query);
72 manualBookmarks =
GlobalApp.getManualBookmarkGateway().findAll();
74 return createResultCursor(history, manualBookmarks);
78 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs)
84 private void addBookmarksToCursor(ArrayList<BookmarkBase> bookmarks, MatrixCursor resultCursor)
86 Object[] row =
new Object[5];
89 row[0] = bookmark.getId();
90 row[1] = bookmark.getLabel();
93 row[4] =
"android.resource://" + getContext().getPackageName() +
"/" +
94 R.drawable.icon_star_on;
95 resultCursor.addRow(row);
99 private void addHistoryToCursor(ArrayList<BookmarkBase> history, MatrixCursor resultCursor)
101 Object[] row =
new Object[5];
105 row[1] = bookmark.getLabel();
106 row[2] = bookmark.getLabel();
108 row[4] =
"android.resource://" + getContext().getPackageName() +
"/" +
109 R.drawable.icon_star_off;
110 resultCursor.addRow(row);
114 private Cursor createResultCursor(ArrayList<BookmarkBase> history,
115 ArrayList<BookmarkBase> manualBookmarks)
119 int totalCount = history.size() + manualBookmarks.size();
120 String[] columns = { android.provider.BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
121 SearchManager.SUGGEST_COLUMN_TEXT_2,
122 SearchManager.SUGGEST_COLUMN_INTENT_DATA,
123 SearchManager.SUGGEST_COLUMN_ICON_2 };
124 MatrixCursor matrixCursor =
new MatrixCursor(columns, totalCount);
129 addHistoryToCursor(history, matrixCursor);
130 addBookmarksToCursor(manualBookmarks, matrixCursor);