|
@@ -2,7 +2,9 @@ package com.compdfkit.tools.viewer.pdfsearch;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.os.AsyncTask;
|
|
|
+import android.text.Editable;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.view.View;
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
@@ -44,6 +46,8 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
|
|
|
private boolean enableSearchResultList = true;
|
|
|
OnSearchListener onSearchListener = null;
|
|
|
+ private ImageView ivNext;
|
|
|
+ private ImageView ivPrevious;
|
|
|
|
|
|
public void setOnExitSearchListener(OnSearchListener listener) {
|
|
|
onSearchListener = listener;
|
|
@@ -68,8 +72,8 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
CViewUtils.applyViewBackground(this);
|
|
|
AppCompatImageView tvComplete = findViewById(R.id.iv_search_back);
|
|
|
etSearchKeywords = findViewById(R.id.et_search_keywords);
|
|
|
- ImageView ivNext = findViewById(R.id.iv_search_next);
|
|
|
- ImageView ivPrevious = findViewById(R.id.iv_search_previous);
|
|
|
+ ivNext = findViewById(R.id.iv_search_next);
|
|
|
+ ivPrevious = findViewById(R.id.iv_search_previous);
|
|
|
ivSearchResultList = findViewById(R.id.iv_search_list);
|
|
|
tvComplete.setOnClickListener(this);
|
|
|
ivNext.setOnClickListener(this);
|
|
@@ -77,21 +81,17 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
ivSearchResultList.setOnClickListener(this);
|
|
|
|
|
|
etSearchKeywords.setOnEditorActionListener((v, actionId, event) -> {
|
|
|
- if (actionId == EditorInfo.IME_ACTION_SEARCH){
|
|
|
- startSearch(etSearchKeywords.getText().toString(), 1,false, list -> {
|
|
|
+ if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
|
|
+ startSearch(etSearchKeywords.getText().toString(), 1, false, list -> {
|
|
|
searchTextInfos = list;
|
|
|
boolean hasResult = list.size() > 0;
|
|
|
- ivPrevious.setVisibility(hasResult ? VISIBLE : INVISIBLE);
|
|
|
- ivNext.setVisibility(hasResult ? VISIBLE : INVISIBLE);
|
|
|
- if (enableSearchResultList){
|
|
|
- ivSearchResultList.setVisibility(hasResult ? VISIBLE : INVISIBLE);
|
|
|
- }
|
|
|
+ showActions(hasResult);
|
|
|
if (hasResult) {
|
|
|
CSearchTextInfo searchTextInfo = searchTextInfos.get(0);
|
|
|
pdfView.getCPdfReaderView().getTextSearcher().searchBegin(searchTextInfo.page, searchTextInfo.textRangeIndex);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
resetSearch();
|
|
|
- CToastUtil.showLongToast(context,R.string.tools_sorry_no_contents);
|
|
|
+ CToastUtil.showLongToast(context, R.string.tools_sorry_no_contents);
|
|
|
}
|
|
|
});
|
|
|
etSearchKeywords.clearFocus();
|
|
@@ -100,6 +100,22 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
}
|
|
|
return false;
|
|
|
});
|
|
|
+ etSearchKeywords.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+ showActions(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void cancelTask() {
|
|
@@ -116,7 +132,15 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void startSearch(String keywords, int searchCount,boolean showLoading, OnSearchResultListener searchResultListener) {
|
|
|
+ private void showActions(boolean show) {
|
|
|
+ ivPrevious.setVisibility(show ? VISIBLE : INVISIBLE);
|
|
|
+ ivNext.setVisibility(show ? VISIBLE : INVISIBLE);
|
|
|
+ if (enableSearchResultList) {
|
|
|
+ ivSearchResultList.setVisibility(show ? VISIBLE : INVISIBLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startSearch(String keywords, int searchCount, boolean showLoading, OnSearchResultListener searchResultListener) {
|
|
|
if (TextUtils.isEmpty(keywords)) {
|
|
|
resetSearch();
|
|
|
cancelTask();
|
|
@@ -196,7 +220,7 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
previous();
|
|
|
} else if (id == R.id.iv_search_list) {
|
|
|
hideKeyboard();
|
|
|
- startSearch(etSearchKeywords.getText().toString(), Integer.MAX_VALUE,true, list -> {
|
|
|
+ startSearch(etSearchKeywords.getText().toString(), Integer.MAX_VALUE, true, list -> {
|
|
|
if (null == list || list.size() <= 0) {
|
|
|
Toast.makeText(getContext(), getContext().getString(R.string.tools_sorry_no_contents), Toast.LENGTH_SHORT).show();
|
|
|
return;
|
|
@@ -218,18 +242,18 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void enableSearchResultList(boolean enable){
|
|
|
+ public void enableSearchResultList(boolean enable) {
|
|
|
enableSearchResultList = enable;
|
|
|
}
|
|
|
|
|
|
- public void showKeyboard(){
|
|
|
+ public void showKeyboard() {
|
|
|
if (etSearchKeywords != null) {
|
|
|
CViewUtils.showKeyboard(etSearchKeywords);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void hideKeyboard(){
|
|
|
- if (etSearchKeywords != null){
|
|
|
+ public void hideKeyboard() {
|
|
|
+ if (etSearchKeywords != null) {
|
|
|
CViewUtils.hideKeyboard(etSearchKeywords);
|
|
|
}
|
|
|
}
|
|
@@ -252,6 +276,7 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
|
|
|
public interface OnSearchListener {
|
|
|
void onStartSearch(boolean showLoading);
|
|
|
+
|
|
|
void onEndSearch();
|
|
|
}
|
|
|
}
|