Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented search in note feature #749

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@
import android.provider.MediaStore;
import android.text.Editable;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.BackgroundColorSpan;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -103,6 +106,7 @@
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -187,7 +191,7 @@

public class DetailFragment extends BaseFragment implements OnReminderPickedListener, OnTouchListener,
OnAttachingFileListener, TextWatcher, CheckListChangedListener, OnNoteSaved,
OnGeoUtilResultListener {
OnGeoUtilResultListener, OnClickListener {

private static final int TAKE_PHOTO = 1;
private static final int TAKE_VIDEO = 2;
Expand All @@ -201,6 +205,10 @@ public class DetailFragment extends BaseFragment implements OnReminderPickedList
ViewGroup root;
@BindView(R.id.detail_title)
EditText title;
@BindView(R.id.detail_search)
EditText search;
@BindView(R.id.button_search)
Button searchButton;
@BindView(R.id.detail_content)
EditText content;
@BindView(R.id.detail_attachments_above)
Expand Down Expand Up @@ -351,6 +359,7 @@ public void onResume () {
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_detail, container, false);
ButterKnife.bind(this, view);
searchButton.setOnClickListener(this);
return view;
}

Expand Down Expand Up @@ -1357,6 +1366,7 @@ private void takeVideo () {
startActivityForResult(takeVideoIntent, TAKE_VIDEO);
}

@SuppressLint("SourceLockedOrientationActivity")
private void takeSketch (Attachment attachment) {

File f = StorageHelper.createNewAttachmentFile(mainActivity, MIME_TYPE_SKETCH_EXT);
Expand Down Expand Up @@ -2164,6 +2174,27 @@ public void onEventMainThread (PushbulletReplyEvent pushbulletReplyEvent) {
content.setText(text);
}

@Override
public void onClick(View view) {
String searchText = search.getText().toString();
setHighlightedText(content, searchText);
}

private void setHighlightedText(EditText et, String textToHighlight) {
String originalText = et.getText().toString();
int ofe = originalText.indexOf(textToHighlight);
Spannable wordToSpan = new SpannableString(et.getText());
for (int ofs = 0; ofs < originalText.length() && ofe != -1; ofs = ofe + 1) {
ofe = originalText.indexOf(textToHighlight, ofs);
if (ofe == -1)
break;
else {
wordToSpan.setSpan(new BackgroundColorSpan(0xFFFFFF00), ofe, ofe + textToHighlight.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
et.setText(wordToSpan, TextView.BufferType.SPANNABLE);
}
}
}

private static class OnGeoUtilResultListenerImpl implements OnGeoUtilResultListener {

private final WeakReference<MainActivity> mainActivityWeakReference;
Expand Down
43 changes: 39 additions & 4 deletions omniNotes/src/main/res/layout/fragment_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@
android:inputType="textCapSentences"
android:linksClickable="false"
android:paddingBottom="6dp"
paddingStart="6dp"
android:paddingLeft="6dp"
android:paddingStart="6dp"
paddingEnd="16dp"
android:paddingRight="16dp"
android:paddingEnd="16dp"
android:paddingTop="6dp"
android:textAppearance="@style/Text.Big"
Expand All @@ -85,6 +81,45 @@
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:layout_marginBottom="6dp"
android:background="@drawable/bg_card"
android:paddingStart="8dp"
android:paddingEnd="0dp"
android:paddingBottom="2dp">

<com.neopixl.pixlui.components.edittext.EditText
android:id="@+id/detail_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@null"
android:hint="@string/search"
android:inputType="textCapSentences"
android:linksClickable="false"
android:paddingBottom="6dp"
android:paddingStart="6dp"
android:paddingEnd="6dp"
android:paddingTop="6dp"
android:textAppearance="@style/Text.Big"
android:textColorHint="@color/text_color_lighter"
android:textColor="@color/text_color"
android:textCursorDrawable="@null"
pixlui:typeface="Roboto-Regular.ttf"/>

<Button
android:id="@+id/button_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/search"
pixlui:typeface="Roboto-Regular.ttf"/>

</LinearLayout>

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/detail_content_card"
android:layout_width="match_parent"
Expand Down