Fixed searchview, which did not trigger SearchListActivity.

This commit is contained in:
Dennis Guse
2019-09-10 21:30:49 +02:00
parent 0864bc8104
commit a326265dba
6 changed files with 26 additions and 20 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ Changes:
- Removed Widget
Bugfix:
-
- Fixed search functionality
Developer:
- Fixed (some) test cases
@@ -18,8 +18,10 @@ package de.dennisguse.opentracks;
import android.app.Activity;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.Menu;
@@ -50,6 +52,8 @@ import de.dennisguse.opentracks.util.TrackRecordingServiceConnectionUtils;
*/
public abstract class AbstractListActivity extends AbstractActivity implements ConfirmDeleteCaller {
private static final String TAG = AbstractListActivity.class.getSimpleName();
protected static final int GPS_REQUEST_CODE = 6;
private static final int DELETE_REQUEST_CODE = 3;
@@ -111,15 +115,21 @@ public abstract class AbstractListActivity extends AbstractActivity implements C
}
public static void configureSearchWidget(Activity activity, final MenuItem menuItem, final TrackController trackController) {
final SearchView searchView = (SearchView) menuItem.getActionView();
SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
if (searchManager != null) {
//NOTE: for some reason activity.getComponentName() did not trigger the SearchListActivity
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(activity, SearchListActivity.class)));
} else {
Log.w(TAG, "Could not retrieve SearchManager.");
}
searchView.setQueryRefinementEnabled(true);
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// Hide and show trackController when search widget has focus/no focus
// Hide and show trackController when searchable widget has focus/no focus
if (trackController != null) {
if (hasFocus) {
trackController.hide();
@@ -63,11 +63,11 @@ import de.dennisguse.opentracks.util.TrackIconUtils;
import de.dennisguse.opentracks.util.TrackRecordingServiceConnectionUtils;
/**
* An activity to display a list of search results.
* An activity to display a list of searchable results.
*
* @author Rodrigo Damazio
* <p>
* TODO: allow to refine search (present search in context menu)
* TODO: allow to refine searchable (present searchable in context menu)
*/
public class SearchListActivity extends AbstractListActivity implements DeleteMarkerCaller, ConfirmDeleteDialogFragment.ConfirmDeleteCaller {
@@ -333,7 +333,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
}
startActivity(intent);
// Close the search result since its content can change after edit.
// Close the searchable result since its content can change after edit.
finish();
return true;
case R.id.list_context_menu_delete:
@@ -367,7 +367,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
}
/**
* Do the search.
* Do the searchable.
*
* @param textQuery the query
*/
@@ -414,7 +414,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
private Map<String, Object> prepareMarkerForDisplay(Waypoint waypoint) {
Map<String, Object> resultMap = new HashMap<>();
//TODO: It may be more appropriate to obtain the track name as a join in the retrieval phase of the search.
//TODO: It may be more appropriate to obtain the track name as a join in the retrieval phase of the searchable.
String trackName = null;
long trackId = waypoint.getTrackId();
if (trackId != -1L) {
@@ -550,10 +550,9 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
trackRecordingServiceConnection.startAndBind();
/*
* If the binding has happened, then invoke the callback to start a new
* recording. If the binding hasn't happened, then invoking the callback
* will have no effect. But when the binding occurs, the callback will get
* invoked.
* If the binding has happened, then invoke the callback to start a new recording.
* If the binding hasn't happened, then invoking the callback will have no effect.
* But when the binding occurs, the callback will get invoked.
*/
bindChangedCallback.run();
}
@@ -142,7 +142,7 @@ public class SearchEngine {
}
/**
* Executes a search query and returns a set of sorted results.
* Executes a searchable query and returns a set of sorted results.
*
* @param query the query to execute
* @return a set of results, sorted according to their score
@@ -376,7 +376,7 @@ public class SearchEngine {
}
/**
* Description of a search query, along with all contextual data needed to execute it.
* Description of a searchable query, along with all contextual data needed to execute it.
*/
public static class SearchQuery {
final String textQuery;
@@ -393,7 +393,7 @@ public class SearchEngine {
}
/**
* Description of a search result which has been retrieved and scored.
* Description of a searchable result which has been retrieved and scored.
*/
public static class ScoredResult {
public final Track track;
@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/menu_search"
android:imeOptions="actionSearch"
android:includeInGlobalSearch="false"
android:label="@string/app_name"
android:queryAfterZeroResults="true"
android:searchSettingsDescription="@string/search_global_description"
android:voicePromptText="@string/search_voice_prompt"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />
android:searchSettingsDescription="@string/search_global_description" />