mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-11-04 15:34:44 +01:00
Fixed searchview, which did not trigger SearchListActivity.
This commit is contained in:
@@ -4,7 +4,7 @@ Changes:
|
|||||||
- Removed Widget
|
- Removed Widget
|
||||||
|
|
||||||
Bugfix:
|
Bugfix:
|
||||||
-
|
- Fixed search functionality
|
||||||
|
|
||||||
Developer:
|
Developer:
|
||||||
- Fixed (some) test cases
|
- Fixed (some) test cases
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ package de.dennisguse.opentracks;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -50,6 +52,8 @@ import de.dennisguse.opentracks.util.TrackRecordingServiceConnectionUtils;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractListActivity extends AbstractActivity implements ConfirmDeleteCaller {
|
public abstract class AbstractListActivity extends AbstractActivity implements ConfirmDeleteCaller {
|
||||||
|
|
||||||
|
private static final String TAG = AbstractListActivity.class.getSimpleName();
|
||||||
|
|
||||||
protected static final int GPS_REQUEST_CODE = 6;
|
protected static final int GPS_REQUEST_CODE = 6;
|
||||||
private static final int DELETE_REQUEST_CODE = 3;
|
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) {
|
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);
|
SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
|
||||||
SearchView searchView = (SearchView) menuItem.getActionView();
|
if (searchManager != null) {
|
||||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
|
//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.setQueryRefinementEnabled(true);
|
||||||
|
searchView.setSubmitButtonEnabled(true);
|
||||||
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
|
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFocusChange(View v, boolean hasFocus) {
|
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 (trackController != null) {
|
||||||
if (hasFocus) {
|
if (hasFocus) {
|
||||||
trackController.hide();
|
trackController.hide();
|
||||||
|
|||||||
@@ -63,11 +63,11 @@ import de.dennisguse.opentracks.util.TrackIconUtils;
|
|||||||
import de.dennisguse.opentracks.util.TrackRecordingServiceConnectionUtils;
|
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
|
* @author Rodrigo Damazio
|
||||||
* <p>
|
* <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 {
|
public class SearchListActivity extends AbstractListActivity implements DeleteMarkerCaller, ConfirmDeleteDialogFragment.ConfirmDeleteCaller {
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
}
|
}
|
||||||
startActivity(intent);
|
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();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_delete:
|
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
|
* @param textQuery the query
|
||||||
*/
|
*/
|
||||||
@@ -414,7 +414,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
private Map<String, Object> prepareMarkerForDisplay(Waypoint waypoint) {
|
private Map<String, Object> prepareMarkerForDisplay(Waypoint waypoint) {
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
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;
|
String trackName = null;
|
||||||
long trackId = waypoint.getTrackId();
|
long trackId = waypoint.getTrackId();
|
||||||
if (trackId != -1L) {
|
if (trackId != -1L) {
|
||||||
|
|||||||
@@ -550,10 +550,9 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
trackRecordingServiceConnection.startAndBind();
|
trackRecordingServiceConnection.startAndBind();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the binding has happened, then invoke the callback to start a new
|
* If the binding has happened, then invoke the callback to start a new recording.
|
||||||
* recording. If the binding hasn't happened, then invoking the callback
|
* If the binding hasn't happened, then invoking the callback will have no effect.
|
||||||
* will have no effect. But when the binding occurs, the callback will get
|
* But when the binding occurs, the callback will get invoked.
|
||||||
* invoked.
|
|
||||||
*/
|
*/
|
||||||
bindChangedCallback.run();
|
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
|
* @param query the query to execute
|
||||||
* @return a set of results, sorted according to their score
|
* @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 {
|
public static class SearchQuery {
|
||||||
final String textQuery;
|
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 static class ScoredResult {
|
||||||
public final Track track;
|
public final Track track;
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:hint="@string/menu_search"
|
android:hint="@string/menu_search"
|
||||||
android:imeOptions="actionSearch"
|
|
||||||
android:includeInGlobalSearch="false"
|
android:includeInGlobalSearch="false"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:queryAfterZeroResults="true"
|
android:queryAfterZeroResults="true"
|
||||||
android:searchSettingsDescription="@string/search_global_description"
|
android:searchSettingsDescription="@string/search_global_description" />
|
||||||
android:voicePromptText="@string/search_voice_prompt"
|
|
||||||
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />
|
|
||||||
Reference in New Issue
Block a user