aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-01-12 19:05:49 +0100
committerBananeweizen <bananeweizen@gmx.de>2014-01-12 19:05:49 +0100
commitdf177f0e15f4a8fa3dd378648477200596306be9 (patch)
treeef194d722a1270875fd8be55e03bbce80aaf8fb6
parent05ccbe7f00e3ab378cc83fc7aed1a62f7aae6ad6 (diff)
downloadcgeo-df177f0e15f4a8fa3dd378648477200596306be9.zip
cgeo-df177f0e15f4a8fa3dd378648477200596306be9.tar.gz
cgeo-df177f0e15f4a8fa3dd378648477200596306be9.tar.bz2
new: search suggestions for caches and trackables while typing
-rw-r--r--main/AndroidManifest.xml49
-rw-r--r--main/res/xml/searchable.xml1
-rw-r--r--main/src/cgeo/geocaching/DataStore.java72
-rw-r--r--main/src/cgeo/geocaching/Intents.java4
-rw-r--r--main/src/cgeo/geocaching/SearchActivity.java16
-rw-r--r--main/src/cgeo/geocaching/search/SuggestionProvider.java57
6 files changed, 177 insertions, 22 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml
index bd3c899..d83f2b3 100644
--- a/main/AndroidManifest.xml
+++ b/main/AndroidManifest.xml
@@ -111,8 +111,8 @@
android:name=".twitter.TwitterAuthorizationActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/auth_twitter"
- android:windowSoftInputMode="stateHidden"
- android:launchMode="singleTask" >
+ android:launchMode="singleTask"
+ android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -142,11 +142,11 @@
android:label="@string/search_address_result"
android:windowSoftInputMode="stateHidden" >
</activity>
- <activity
+ <activity
android:name=".settings.SettingsActivity"
+ android:configChanges="keyboardHidden|orientation"
android:label="@string/settings_titlebar"
- android:theme="@style/settings"
- android:configChanges="keyboardHidden|orientation" >
+ android:theme="@style/settings" >
</activity>
<activity
android:name=".CacheListActivity"
@@ -308,6 +308,7 @@
android:name="cgeo.geocaching.TrackableActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name" >
+
<!-- TravelBug URL via coord.info redirection -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -331,7 +332,7 @@
android:pathPrefix="/TB"
android:scheme="http" />
</intent-filter>
-
+
<!-- TravelBug URL tracking page -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -355,7 +356,7 @@
android:pathPrefix="/track/details.aspx"
android:scheme="http" />
</intent-filter>
-
+
<!-- GeoKrety URLs -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -379,8 +380,9 @@
android:pathPrefix="/konkret.php"
android:scheme="http" />
</intent-filter>
-
- <!-- Geokrety QR code URLs, not yet implemented
+
+ <!--
+ Geokrety QR code URLs, not yet implemented
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -421,10 +423,6 @@
android:label="@string/map_file_select_title" >
</activity>
- <provider
- android:name=".apps.LocusDataStorageProvider"
- android:authorities="cgeo.geocaching.apps.locusdatastorageprovider" />
-
<activity
android:name="WaypointPopup"
android:configChanges="keyboardHidden|orientation"
@@ -450,8 +448,8 @@
android:name=".connector.oc.OCDEAuthorizationActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
- android:windowSoftInputMode="stateHidden"
- android:launchMode="singleTask">
+ android:launchMode="singleTask"
+ android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -468,8 +466,8 @@
android:name=".connector.oc.OCPLAuthorizationActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
- android:windowSoftInputMode="stateHidden"
- android:launchMode="singleTask">
+ android:launchMode="singleTask"
+ android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@@ -486,10 +484,21 @@
android:name=".CreateShortcutActivity"
android:label="@string/cgeo_shortcut" >
<intent-filter>
- <action android:name="android.intent.action.CREATE_SHORTCUT"/>
- <category android:name="android.intent.category.DEFAULT"/>
+ <action android:name="android.intent.action.CREATE_SHORTCUT" />
+
+ <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
+ <!-- provide enhanced meta data for caches (and waypoints) when invoking Locus from c:geo -->
+ <provider
+ android:name=".apps.LocusDataStorageProvider"
+ android:authorities="cgeo.geocaching.apps.locusdatastorageprovider" />
+
+ <!-- search suggestions for the search bar at the top -->
+ <provider
+ android:name=".search.SuggestionProvider"
+ android:authorities="cgeo.geocaching.search.SuggestionProvider" />
</application>
-</manifest>
+
+</manifest> \ No newline at end of file
diff --git a/main/res/xml/searchable.xml b/main/res/xml/searchable.xml
index 13e34c5..a3844cf 100644
--- a/main/res/xml/searchable.xml
+++ b/main/res/xml/searchable.xml
@@ -6,6 +6,7 @@
android:inputType="textNoSuggestions"
android:label="@string/app_name"
android:searchSettingsDescription="@string/search_bar_desc"
+ android:searchSuggestAuthority="cgeo.geocaching.search.SuggestionProvider"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
</searchable> \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java
index 9d8a640..60dcd0d 100644
--- a/main/src/cgeo/geocaching/DataStore.java
+++ b/main/src/cgeo/geocaching/DataStore.java
@@ -25,17 +25,20 @@ import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
+import android.app.SearchManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.DatabaseUtils;
+import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteDoneException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;
+import android.provider.BaseColumns;
import java.io.File;
import java.io.FilenameFilter;
@@ -818,7 +821,7 @@ public class DataStore {
/**
* Remove obsolete cache directories in c:geo private storage.
- *
+ *
* @param db
* the read-write database to use
*/
@@ -3129,4 +3132,71 @@ public class DataStore {
return missingFromSearch;
}
+ public static Cursor findSuggestions(final String searchTerm) {
+ // require 3 characters, otherwise there are to many results
+ if (StringUtils.length(searchTerm) < 3) {
+ return null;
+ }
+ init();
+ final MatrixCursor resultCursor = new MatrixCursor(new String[] {
+ BaseColumns._ID,
+ SearchManager.SUGGEST_COLUMN_TEXT_1,
+ SearchManager.SUGGEST_COLUMN_TEXT_2,
+ SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
+ SearchManager.SUGGEST_COLUMN_QUERY
+ });
+ try {
+ final String selectionArg = "%" + searchTerm + "%";
+ findCaches(resultCursor, selectionArg);
+ findTrackables(resultCursor, selectionArg);
+ } catch (final Exception e) {
+ Log.e("DataStore.loadBatchOfStoredGeocodes", e);
+ }
+ return resultCursor;
+ }
+
+ private static void findCaches(final MatrixCursor resultCursor, final String selectionArg) {
+ Cursor cursor = database.query(
+ dbTableCaches,
+ new String[] { "geocode", "name" },
+ "geocode IS NOT NULL AND geocode != '' AND (geocode LIKE ? OR name LIKE ?)",
+ new String[] { selectionArg, selectionArg },
+ null,
+ null,
+ "name");
+ while (cursor.moveToNext()) {
+ final String geocode = cursor.getString(0);
+ resultCursor.addRow(new String[] {
+ String.valueOf(resultCursor.getCount()),
+ cursor.getString(1),
+ geocode,
+ Intents.ACTION_GEOCACHE,
+ geocode
+ });
+ }
+ cursor.close();
+ }
+
+ private static void findTrackables(final MatrixCursor resultCursor, final String selectionArg) {
+ Cursor cursor = database.query(
+ dbTableTrackables,
+ new String[] { "tbcode", "title" },
+ "tbcode IS NOT NULL AND tbcode != '' AND (tbcode LIKE ? OR title LIKE ?)",
+ new String[] { selectionArg, selectionArg },
+ null,
+ null,
+ "title");
+ while (cursor.moveToNext()) {
+ final String tbcode = cursor.getString(0);
+ resultCursor.addRow(new String[] {
+ String.valueOf(resultCursor.getCount()),
+ cursor.getString(1),
+ tbcode,
+ Intents.ACTION_TRACKABLE,
+ tbcode
+ });
+ }
+ cursor.close();
+ }
+
}
diff --git a/main/src/cgeo/geocaching/Intents.java b/main/src/cgeo/geocaching/Intents.java
index d9d9829..5c969a1 100644
--- a/main/src/cgeo/geocaching/Intents.java
+++ b/main/src/cgeo/geocaching/Intents.java
@@ -29,4 +29,8 @@ public class Intents {
public static final String EXTRA_WAYPOINT_ID = PREFIX + "waypoint_id";
public static final String EXTRA_CACHELIST = PREFIX + "cache_list";
public static final String EXTRA_POCKET_GUID = PREFIX + "pocket_guid";
+
+ private static final String PREFIX_ACTION = "cgeo.geocaching.intent.action.";
+ public static final String ACTION_GEOCACHE = PREFIX_ACTION + "GEOCACHE";
+ public static final String ACTION_TRACKABLE = PREFIX_ACTION + "TRACKABLE";
}
diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java
index 0648073..a078fd2 100644
--- a/main/src/cgeo/geocaching/SearchActivity.java
+++ b/main/src/cgeo/geocaching/SearchActivity.java
@@ -60,9 +60,23 @@ public class SearchActivity extends AbstractActivity {
@Override
public final void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ final Intent intent = getIntent();
+
+ // search suggestion for a cache
+ if (Intents.ACTION_GEOCACHE.equals(intent.getAction())) {
+ CacheDetailActivity.startActivity(this, intent.getStringExtra(SearchManager.QUERY));
+ finish();
+ return;
+ }
+
+ // search suggestion for a trackable
+ if (Intents.ACTION_TRACKABLE.equals(intent.getAction())) {
+ TrackableActivity.startActivity(this, null, intent.getStringExtra(SearchManager.QUERY), null);
+ finish();
+ return;
+ }
// search query
- final Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
hideKeyboard();
final String query = intent.getStringExtra(SearchManager.QUERY);
diff --git a/main/src/cgeo/geocaching/search/SuggestionProvider.java b/main/src/cgeo/geocaching/search/SuggestionProvider.java
new file mode 100644
index 0000000..c0a7728
--- /dev/null
+++ b/main/src/cgeo/geocaching/search/SuggestionProvider.java
@@ -0,0 +1,57 @@
+package cgeo.geocaching.search;
+
+import cgeo.geocaching.DataStore;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.app.SearchManager;
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+
+public class SuggestionProvider extends ContentProvider {
+
+ private static Cursor lastCursor;
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public String getType(final Uri arg0) {
+ return SearchManager.SUGGEST_MIME_TYPE;
+ }
+
+ @Override
+ public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) {
+ final String searchTerm = uri.getLastPathSegment();
+ // can be empty when deleting the query
+ if (StringUtils.equals(searchTerm, SearchManager.SUGGEST_URI_PATH_QUERY)) {
+ return lastCursor;
+ }
+ return getSuggestions(searchTerm);
+ }
+
+ private static Cursor getSuggestions(final String searchTerm) {
+ lastCursor = DataStore.findSuggestions(searchTerm);
+ return lastCursor;
+ }
+
+ @Override
+ public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Uri insert(final Uri uri, final ContentValues values) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int update(final Uri uri, final ContentValues values, final String selection, final String[] selectionArgs) {
+ throw new UnsupportedOperationException();
+ }
+
+}