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

Search in note feature #650

Open
wants to merge 2 commits 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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

buildscript {
repositories {
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
google()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.SearchManager;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
Expand Down Expand Up @@ -48,6 +50,7 @@
import android.support.v4.util.Pair;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.SearchView;
import android.text.Editable;
import android.text.Selection;
import android.text.TextUtils;
Expand All @@ -59,6 +62,7 @@
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.*;
import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -1102,6 +1106,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.menu_note_info:
showNoteInfo();
break;
case R.id.menu_note_search:
searchInNote(item);
break;
default:
Log.w(Constants.TAG, "Invalid menu option selected");
}
Expand All @@ -1120,8 +1127,55 @@ private void showNoteInfo() {
startActivity(intent);

}
private void searchInNote(MenuItem item) {


noteTmp.setTitle(getNoteTitle());
noteTmp.setContent(getNoteContent());

android.support.v7.widget.SearchView search = (android.support.v7.widget.SearchView) item.getActionView();
search.requestFocus();
SearchManager searchManager = (SearchManager) mainActivity.getSystemService(Context.SEARCH_SERVICE);
search.setSearchableInfo(searchManager.getSearchableInfo(mainActivity.getComponentName()));
search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {

return false;
}

@Override
public boolean onQueryTextChange(String newText) {
if (!newText.isEmpty()) {
String NewNoteContent = search(newText);

private void navigateUp() {
noteTmp.setContent(NewNoteContent);
//View contentView = root.findViewById(R.id.detail_content);

//((EditText)contentView).setText(NewNoteContent);
}
noteTmp.setContent(newText);
return true;
}
});
}
private String search(String Searchkey)
{
String NoteContent= noteTmp.getContent();
Boolean check;
check= NoteContent.matches("(?i).*Searchkey.*");
if (check==true)
{
String newString = NoteContent.replaceAll(Searchkey, "<font color='red'>"+Searchkey+"</font>");
return newString;
}
else
{
return NoteContent;
}
}
private void navigateUp() {
afterSavedReturnsToList = true;
saveAndExit(this);
}
Expand Down
7 changes: 7 additions & 0 deletions omniNotes/src/main/res/menu/menu_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
android:title="@string/untrash"
android:visible="false"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_note_search"
android:icon="@drawable/ic_search_white_24dp"
android:orderInCategory="1200"
android:title="@string/search_in_note"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="collapseActionView|always" />
<item
android:id="@+id/menu_discard_changes"
android:orderInCategory="1000"
Expand Down
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,5 @@
<string name="note_reminder_symbol">رمز تذكير الملاحظة</string>
<string name="navigation_drawer_open">فتح قائمة الملاحة</string>
<string name="navigation_drawer_close">إغلاق قائمة الملاحة</string>
<string name="search_in_note">Search</string>
</resources>
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values-ca-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,5 @@
<string name="note_reminder_symbol">símbol de recordatori de nota</string>
<string name="navigation_drawer_open">Obre el tauler de navegació</string>
<string name="navigation_drawer_close">Tanca el tauler de navegació</string>
<string name="search_in_note">Search</string>
</resources>
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values-cs-rCZ/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,5 @@
<string name="note_reminder_symbol">symbol připomenutí poznámky</string>
<string name="navigation_drawer_open">Otevřít navigační lištu</string>
<string name="navigation_drawer_close">Zavřít navigační lištu</string>
<string name="search_in_note">Search</string>
</resources>
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,5 @@
<string name="note_reminder_symbol">Erinnerungssymbol</string>
<string name="navigation_drawer_open">Navigationsleiste öffnen</string>
<string name="navigation_drawer_close">Navigationsleiste schließen</string>
<string name="search_in_note">Search</string>
</resources>
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values-el-rGR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,5 @@
<string name="note_reminder_symbol">σύμβολο υπενθύμισης σημείωσης</string>
<string name="navigation_drawer_open">Άνοιγμα μενού πλοήγησης</string>
<string name="navigation_drawer_close">Κλείσιμο μενού πλοήγησης</string>
<string name="search_in_note">Search</string>
</resources>
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values-en-rUS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,5 @@
<string name="note_reminder_symbol">note reminder symbol</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="search_in_note">Search</string>
</resources>
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,5 @@
<string name="note_reminder_symbol">símbolo de recordatorio de nota</string>
<string name="navigation_drawer_open">Abrir cajón de navegación</string>
<string name="navigation_drawer_close">Cerrar cajón de navegación</string>
<string name="search_in_note">Search</string>
</resources>
1 change: 1 addition & 0 deletions omniNotes/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,6 @@
<string name="note_reminder_symbol">note reminder symbol</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="search_in_note">Search</string>

</resources>