|
@@ -14,10 +14,10 @@ import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.compdfkit.tools.R;
|
|
|
+import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
|
+import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
|
|
|
import com.compdfkit.tools.viewer.pdfsearch.bean.CSearchTextInfo;
|
|
|
import com.compdfkit.tools.viewer.pdfsearch.data.CPDFSearchKeywordsDatas;
|
|
|
-import com.compdfkit.tools.common.views.pdfview.CPDFViewCtrl;
|
|
|
-import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
|
|
|
import com.compdfkit.ui.textsearch.ITextSearcher;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -25,26 +25,24 @@ import java.util.concurrent.locks.Lock;
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
|
public class CSearchToolbar extends RelativeLayout implements View.OnClickListener {
|
|
|
- private TextView completeBt;
|
|
|
- private EditText searchEdit;
|
|
|
- private ImageView leftImage;
|
|
|
- private ImageView rightImage;
|
|
|
- private ImageView listImage;
|
|
|
+
|
|
|
+ private EditText etSearchKeywords;
|
|
|
|
|
|
private CPDFViewCtrl pdfView;
|
|
|
|
|
|
OnExitSearchListener onExitSearchListener = null;
|
|
|
|
|
|
OnSearchResultListener onSearchResultListener = null;
|
|
|
+
|
|
|
List<CSearchTextInfo> searchTextInfos = null;
|
|
|
|
|
|
Lock lock = new ReentrantLock();
|
|
|
+
|
|
|
private AsyncTask<Void, Void, List<CSearchTextInfo>> searchTask;
|
|
|
|
|
|
public CSearchToolbar(Context context, AttributeSet attrs) {
|
|
|
super(context, attrs);
|
|
|
init(context);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public CSearchToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
@@ -52,25 +50,25 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
init(context);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public void initWithPDFView(CPDFViewCtrl pdfView) {
|
|
|
this.pdfView = pdfView;
|
|
|
}
|
|
|
|
|
|
private void init(Context context) {
|
|
|
- inflate(context, R.layout.tools_search_toolbar, this);
|
|
|
+ inflate(context, R.layout.tools_search_keywords_toolbar, this);
|
|
|
CViewUtils.applyViewBackground(this);
|
|
|
- completeBt = findViewById(R.id.complete);
|
|
|
- searchEdit = findViewById(R.id.search_word);
|
|
|
- leftImage = findViewById(R.id.iv_search_next);
|
|
|
- rightImage = findViewById(R.id.iv_search_previous);
|
|
|
- listImage = findViewById(R.id.iv_search_list);
|
|
|
- completeBt.setOnClickListener(this);
|
|
|
- leftImage.setOnClickListener(this);
|
|
|
- rightImage.setOnClickListener(this);
|
|
|
- listImage.setOnClickListener(this);
|
|
|
-
|
|
|
- searchEdit.addTextChangedListener(new TextWatcher() {
|
|
|
+ TextView tvComplete = findViewById(R.id.tv_search_complete);
|
|
|
+ etSearchKeywords = findViewById(R.id.et_search_keywords);
|
|
|
+ ImageView ivNext = findViewById(R.id.iv_search_next);
|
|
|
+ ImageView ivPrevious = findViewById(R.id.iv_search_previous);
|
|
|
+ ImageView ivSearchResultList = findViewById(R.id.iv_search_list);
|
|
|
+
|
|
|
+ tvComplete.setOnClickListener(this);
|
|
|
+ ivNext.setOnClickListener(this);
|
|
|
+ ivPrevious.setOnClickListener(this);
|
|
|
+ ivSearchResultList.setOnClickListener(this);
|
|
|
+
|
|
|
+ etSearchKeywords.addTextChangedListener(new TextWatcher() {
|
|
|
@Override
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
@@ -83,12 +81,12 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
|
|
|
@Override
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
- startSearch(searchEdit.getText().toString(), list -> {
|
|
|
+ startSearch(etSearchKeywords.getText().toString(), list -> {
|
|
|
searchTextInfos = list;
|
|
|
if (list.size() > 0) {
|
|
|
CSearchTextInfo searchTextInfo = searchTextInfos.get(0);
|
|
|
pdfView.getCPdfReaderView().getTextSearcher().searchBegin(searchTextInfo.page, searchTextInfo.textRangeIndex);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
Toast.makeText(context, getContext().getString(R.string.tools_sorry_no_contents), Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
});
|
|
@@ -97,8 +95,8 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
}
|
|
|
|
|
|
private void cancelTask() {
|
|
|
+ lock.lock();
|
|
|
try {
|
|
|
- lock.lock();
|
|
|
if (searchTextInfos != null) {
|
|
|
searchTextInfos.clear();
|
|
|
}
|
|
@@ -139,42 +137,41 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
searchTask.execute();
|
|
|
}
|
|
|
|
|
|
- private void previous(){
|
|
|
+ private void previous() {
|
|
|
pdfView.getCPdfReaderView().getTextSearcher().searchBackward();
|
|
|
}
|
|
|
|
|
|
- private void next(){
|
|
|
+ private void next() {
|
|
|
pdfView.getCPdfReaderView().getTextSearcher().searchForward();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
int id = view.getId();
|
|
|
- if (id == R.id.complete) {
|
|
|
+ if (id == R.id.tv_search_complete) {
|
|
|
cancelTask();
|
|
|
if (null != onExitSearchListener) {
|
|
|
onExitSearchListener.exitSearch();
|
|
|
}
|
|
|
- searchEdit.setText("");
|
|
|
+ etSearchKeywords.setText("");
|
|
|
} else if (id == R.id.iv_search_next) {
|
|
|
next();
|
|
|
} else if (id == R.id.iv_search_previous) {
|
|
|
previous();
|
|
|
} else if (id == R.id.iv_search_list) {
|
|
|
- startSearch(searchEdit.getText().toString(), list -> {
|
|
|
- if (null == list || list.size() <=0){
|
|
|
+ startSearch(etSearchKeywords.getText().toString(), list -> {
|
|
|
+ if (null == list || list.size() <= 0) {
|
|
|
Toast.makeText(getContext(), getContext().getString(R.string.tools_sorry_no_contents), Toast.LENGTH_SHORT).show();
|
|
|
return;
|
|
|
}
|
|
|
if (onSearchResultListener != null) {
|
|
|
onSearchResultListener.result(list);
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void resetSearch(){
|
|
|
+ private void resetSearch() {
|
|
|
if (pdfView != null) {
|
|
|
ITextSearcher searcher = pdfView.getCPdfReaderView().getTextSearcher();
|
|
|
if (searcher != null) {
|
|
@@ -182,14 +179,13 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
pdfView.getCPdfReaderView().invalidateAllChildren();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public void setExitSearchListener(OnExitSearchListener onExitSearchListener) {
|
|
|
this.onExitSearchListener = onExitSearchListener;
|
|
|
}
|
|
|
|
|
|
- public void onSearchQueryResults(OnSearchResultListener searchResultListener){
|
|
|
+ public void onSearchQueryResults(OnSearchResultListener searchResultListener) {
|
|
|
this.onSearchResultListener = searchResultListener;
|
|
|
}
|
|
|
|
|
@@ -200,5 +196,4 @@ public class CSearchToolbar extends RelativeLayout implements View.OnClickListen
|
|
|
public interface OnExitSearchListener {
|
|
|
void exitSearch();
|
|
|
}
|
|
|
-
|
|
|
}
|