Skip to content

Commit

Permalink
improved icon handling for search
Browse files Browse the repository at this point in the history
  • Loading branch information
mg4gh committed Apr 15, 2024
1 parent a7b01cb commit cbacc40
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class FSSearch extends FeatureService {
private final Pref<Boolean> prefShowSearchResult = getPref(R.string.FSSearch_qc_showSearchResult, false);
private final Pref<Boolean> prefShowSearchResultEnabled = new Pref<>(false);
private final Pref<String> prefSearchPos = getPref(R.string.FSSearch_pref_SearchPos2, "");
private final Pref<Boolean> prefPosBasedSearch = getPref(R.string.FSSearch_pref_PosBasedSearch, false);
final Pref<Boolean> prefPosBasedSearch = getPref(R.string.FSSearch_pref_PosBasedSearch, false);
private final Pref<Boolean> prefSearchResultDetails = getPref(R.string.FSSearch_pref_SearchDetails_key, false);
private final Pref<Boolean> prefReverseSearchOn = getPref(R.string.FSSearch_reverseSearchOn, false);
private final Pref<Boolean> prefLocationBasedSearchOn = getPref(R.string.FSSearch_locationBasedSearchOn, false);
Expand All @@ -78,7 +78,7 @@ public FSSearch(MGMapActivity mmActivity) {

searchView = new SearchView(mmActivity.getApplicationContext(), this);
searchView.init(mmActivity);
searchView.setPosBasedSearchIcon(prefPosBasedSearch.getValue());
searchView.setPosBasedSearchIcon(prefPosBasedSearch.getValue(), prefLocationBasedSearchOn.getValue());
RelativeLayout mainView = mmActivity.findViewById(R.id.mainView);
mainView.addView(searchView);
getControlView().variableVerticalOffsetViews.add(searchView);
Expand All @@ -102,10 +102,13 @@ public void afterTextChanged(Editable s) {
doSearch(searchText.getText().toString().trim(), -1);
}
});
searchText.setOnClickListener(v -> triggerTTHideKeyboard());
searchText.setOnClickListener(v -> {
showKeyboard();
triggerTTHideKeyboard();
});

prefPosBasedSearch.addObserver(e -> {
searchView.setPosBasedSearchIcon(prefPosBasedSearch.getValue());
searchView.setPosBasedSearchIcon(prefPosBasedSearch.getValue(), prefLocationBasedSearchOn.getValue());
if (prefSearchOn.getValue()){
doSearch(searchText.getText().toString().trim(), EditorInfo.IME_ACTION_SEARCH);
}
Expand Down Expand Up @@ -266,12 +269,16 @@ void showSearchPos(){
}
}

private void hideKeyboard(){
void hideKeyboard(){
KeyboardUtil.hideKeyboard(searchView.searchText);
searchView.keyboardIconView.setImageResource(R.drawable.keyboard1);
searchView.keyboardIconView.setOnClickListener(v->showKeyboard());
}

private void showKeyboard(){
void showKeyboard(){
KeyboardUtil.showKeyboard(searchView.searchText);
searchView.keyboardIconView.setImageResource(R.drawable.keyboard2);
searchView.keyboardIconView.setOnClickListener(v->hideKeyboard());
}

public void setSearchResult(PointModel pmSearchResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
Expand All @@ -47,6 +48,8 @@ public SearchView(Context context, FSSearch fsSearch) {
}

EditText searchText = null;
ImageView posBasedSearchIcon = null;
ImageView keyboardIconView = null;
ArrayList<TextView> searchResults = new ArrayList<>();
private static final int NUM_SEARCH_RESULTS = 5;

Expand All @@ -57,16 +60,41 @@ void init(MGMapActivity activity){
setOrientation(LinearLayout.VERTICAL);
setVisibility(INVISIBLE);

LinearLayout searchTextLine = new LinearLayout(context);
searchTextLine.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

searchTextLine.setOrientation(LinearLayout.HORIZONTAL);
this.addView(searchTextLine);

searchText = new EditText(context);
searchText.setId(R.id.search_edit_text);
searchText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
searchText.setHint("Search Text");
searchText.setHintTextColor(CC.getColor(R.color.CC_GRAY100_A150));
searchText.setSingleLine(true);
searchText.setSelectAllOnFocus(true);
this.addView(searchText);
{
posBasedSearchIcon = new ImageView(context);
posBasedSearchIcon.setImageResource(R.drawable.search_pos_dis);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ControlView.dp(40),ControlView.dp(32));
params.gravity = Gravity.CENTER_VERTICAL | Gravity.START;
posBasedSearchIcon.setLayoutParams(params);
posBasedSearchIcon.setOnClickListener(v -> fsSearch.prefPosBasedSearch.toggle());
searchTextLine.addView(posBasedSearchIcon);
}
{
searchText = new EditText(context);
searchText.setId(R.id.search_edit_text);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
params.weight = 10;
searchText.setLayoutParams(params);
searchText.setHint("Search Text");
searchText.setHintTextColor(CC.getColor(R.color.CC_GRAY100_A150));
searchText.setSingleLine(true);
searchText.setSelectAllOnFocus(true);
searchTextLine.addView(searchText);
}
{
keyboardIconView = new ImageView(context);
keyboardIconView.setImageResource(R.drawable.keyboard1);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ControlView.dp(40),ControlView.dp(32));
params.gravity = Gravity.CENTER_VERTICAL;
keyboardIconView.setLayoutParams(params);
searchTextLine.addView(keyboardIconView);
}

for (int i=0; i<NUM_SEARCH_RESULTS; i++){
TextView textView = new TextView(context);
Expand All @@ -82,12 +110,8 @@ void init(MGMapActivity activity){
resetSearchResults();
}

void setPosBasedSearchIcon(boolean posBasedSearch){
Drawable drawable = fsSearch.getDrawable( posBasedSearch?R.drawable.search_pos2:R.drawable.search_pos1 );
if (drawable != null){
drawable.setBounds(0,0, ControlView.dp(24),ControlView.dp(24));
searchText.setCompoundDrawables(drawable,null,null,null);
}
void setPosBasedSearchIcon(boolean posBasedSearch, boolean locationBasedSearchOn){
posBasedSearchIcon.setImageResource(locationBasedSearchOn?(posBasedSearch?R.drawable.search_pos2:R.drawable.search_pos1):R.drawable.search_pos_dis);
}

public SearchView(Context context, AttributeSet attributeSet) {
Expand Down
33 changes: 33 additions & 0 deletions mgmap/src/main/res/drawable/keyboard1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">


<path
android:strokeColor="#FFFFFFFF"
android:strokeWidth="1"
android:pathData="
M4,8 l0,1 l1,0 l0,-1 l-1.5,0
M7,8 l0,1 l1,0 l0,-1 l-1.5,0
M10,8 l0,1 l1,0 l0,-1 l-1.5,0
M13,8 l0,1 l1,0 l0,-1 l-1.5,0
M16,8 l0,1 l1,0 l0,-1 l-1.5,0
M19,8 l0,1 l1,0 l0,-1 l-1.5,0
M4,12 l0,1 l1,0 l0,-1 l-1.5,0
M7,12 l0,1 l1,0 l0,-1 l-1.5,0
M10,12 l0,1 l1,0 l0,-1 l-1.5,0
M13,12 l0,1 l1,0 l0,-1 l-1.5,0
M16,12 l0,1 l1,0 l0,-1 l-1.5,0
M19,12 l0,1 l1,0 l0,-1 l-1.5,0
M7.5,17 l0,1 l9,0 l0,-1 l-9.5,0
" />





</vector>
33 changes: 33 additions & 0 deletions mgmap/src/main/res/drawable/keyboard2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">


<path
android:strokeColor="#FFFF6000"
android:strokeWidth="1"
android:pathData="
M4,8 l0,1 l1,0 l0,-1 l-1.5,0
M7,8 l0,1 l1,0 l0,-1 l-1.5,0
M10,8 l0,1 l1,0 l0,-1 l-1.5,0
M13,8 l0,1 l1,0 l0,-1 l-1.5,0
M16,8 l0,1 l1,0 l0,-1 l-1.5,0
M19,8 l0,1 l1,0 l0,-1 l-1.5,0
M4,12 l0,1 l1,0 l0,-1 l-1.5,0
M7,12 l0,1 l1,0 l0,-1 l-1.5,0
M10,12 l0,1 l1,0 l0,-1 l-1.5,0
M13,12 l0,1 l1,0 l0,-1 l-1.5,0
M16,12 l0,1 l1,0 l0,-1 l-1.5,0
M19,12 l0,1 l1,0 l0,-1 l-1.5,0
M7.5,17 l0,1 l9,0 l0,-1 l-9.5,0
" />





</vector>

0 comments on commit cbacc40

Please sign in to comment.