当搜索记录为0条的时候,提示toast,关闭软键盘

This commit is contained in:
xingxing
2017-03-21 23:45:12 +08:00
parent b681327733
commit 5d43387369
5 changed files with 56 additions and 1 deletions

View File

@@ -56,6 +56,11 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
ActionModeHandler<Note> mActionModeHandler;
NoteList mNoteList;
Mode mCurrentMode;
OnSearchFinishListener mOnSearchFinishListener;
public void setOnSearchFinishListener(OnSearchFinishListener onSearchFinishListener) {
this.mOnSearchFinishListener = onSearchFinishListener;
}
public NoteFragment() {
}
@@ -146,6 +151,9 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
mNotes = notes;
Collections.sort(mNotes, new Note.UpdateTimeComparetor());
mNoteList.render(mNotes);
if (mNotes.size() == 0 && mOnSearchFinishListener != null) {
mOnSearchFinishListener.doSearchFinish();
}
}
@Override
@@ -304,4 +312,8 @@ public class NoteFragment extends Fragment implements NoteAdapter.NoteAdapterLis
}
}
public interface OnSearchFinishListener {
void doSearchFinish();
}
}

View File

@@ -4,11 +4,12 @@ import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import org.houxg.leamonax.R;
import org.houxg.leamonax.utils.DisplayUtils;
import org.houxg.leamonax.utils.ToastUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -46,6 +47,13 @@ public class SearchActivity extends BaseActivity {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
mNoteFragment = NoteFragment.newInstance();
mNoteFragment.setOnSearchFinishListener(new NoteFragment.OnSearchFinishListener() {
@Override
public void doSearchFinish() {
ToastUtils.show(SearchActivity.this, R.string.activity_search_note_not_found);
DisplayUtils.hideKeyboard(mSearchView);
}
});
transaction.add(R.id.container, mNoteFragment);
transaction.commit();

View File

@@ -1,6 +1,11 @@
package org.houxg.leamonax.utils;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import org.houxg.leamonax.Leamonax;
public class DisplayUtils {
@@ -13,4 +18,32 @@ public class DisplayUtils {
final float scale = Leamonax.getContext().getResources().getDisplayMetrics().density;
return (int) (px / scale + 0.5f);
}
public static void hideKeyboard(View view) {
if (view == null) {
return;
}
try {
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (!imm.isActive()) {
return;
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
} catch (Exception e) {
Log.e("DisplayUtils", e.getMessage());
}
}
public static void showKeyboard(View view) {
if (view == null) {
return;
}
view.requestFocus();
try {
InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
} catch (Exception e) {
Log.e("DisplayUtils", e.getMessage());
}
}
}

View File

@@ -113,4 +113,5 @@
<string name="notebook_choose_notebook_hint">选择该笔记本所在的上一级笔记本目录</string>
<string name="notebook_default_root_notebook_title">空目录(最顶层目录)</string>
<string name="delete_network_error">网络不可用,将在下次同步时删除</string>
<string name="activity_search_note_not_found">没有找到</string>
</resources>

View File

@@ -115,4 +115,5 @@
<string name="notebook_choose_notebook_hint">选择该笔记本所在的上一级笔记本目录 Choose current Notebook \'s parentNotebook directory</string>
<string name="notebook_default_root_notebook_title">Empty directory</string>
<string name="delete_network_error">Network is unavailable, these notes will be deleted in next sync</string>
<string name="activity_search_note_not_found">Not found</string>
</resources>