|
@@ -0,0 +1,84 @@
|
|
|
|
+package com.compdfkit.tools.search;
|
|
|
|
+
|
|
|
|
+import android.content.Context;
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
+import android.util.AttributeSet;
|
|
|
|
+import android.view.View;
|
|
|
|
+import android.widget.Button;
|
|
|
|
+import android.widget.EditText;
|
|
|
|
+import android.widget.ImageView;
|
|
|
|
+import android.widget.RelativeLayout;
|
|
|
|
+
|
|
|
|
+import com.compdfkit.tools.R;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+public class CSearchToolbar extends RelativeLayout implements View.OnClickListener {
|
|
|
|
+ private Button completeBt;
|
|
|
|
+ private EditText searchEdit;
|
|
|
|
+ private ImageView leftImage;
|
|
|
|
+ private ImageView rightImage;
|
|
|
|
+ private ImageView listImage;
|
|
|
|
+
|
|
|
|
+ private Context context;
|
|
|
|
+
|
|
|
|
+ OnSearchListener onSearchListener = null;
|
|
|
|
+ List<CSearchTextInfo> searchTextInfos = null;
|
|
|
|
+
|
|
|
|
+ public CSearchToolbar(Context context) {
|
|
|
|
+ super(context);
|
|
|
|
+ init(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CSearchToolbar(Context context, AttributeSet attrs) {
|
|
|
|
+ super(context, attrs);
|
|
|
|
+ init(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CSearchToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
+ super(context, attrs, defStyleAttr);
|
|
|
|
+ init(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CSearchToolbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
|
|
+ super(context, attrs, defStyleAttr, defStyleRes);
|
|
|
|
+ init(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void init(Context context) {
|
|
|
|
+ this.context = context;
|
|
|
|
+ inflate(context, R.layout.search_toolbar, this);
|
|
|
|
+ completeBt = findViewById(R.id.complete);
|
|
|
|
+ searchEdit = findViewById(R.id.search_word);
|
|
|
|
+ leftImage = findViewById(R.id.left);
|
|
|
|
+ rightImage = findViewById(R.id.right);
|
|
|
|
+ listImage = findViewById(R.id.list);
|
|
|
|
+ completeBt.setOnClickListener(this);
|
|
|
|
+ leftImage.setOnClickListener(this);
|
|
|
|
+ rightImage.setOnClickListener(this);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View view) {
|
|
|
|
+ int id = view.getId();
|
|
|
|
+ if (id == R.id.complete) {
|
|
|
|
+ if (null != onSearchListener && (!TextUtils.isEmpty(searchEdit.getText().toString()))) {
|
|
|
|
+ searchTextInfos = onSearchListener.onSearch(searchEdit.getText().toString());
|
|
|
|
+ }
|
|
|
|
+ } else if (id == R.id.left) {
|
|
|
|
+
|
|
|
|
+ } else if (id == R.id.right) {
|
|
|
|
+
|
|
|
|
+ } else if (id == R.id.list) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setSearchListener(OnSearchListener onSearchListener) {
|
|
|
|
+ this.onSearchListener = onSearchListener;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public interface OnSearchListener {
|
|
|
|
+ List<CSearchTextInfo> onSearch(String word);
|
|
|
|
+ }
|
|
|
|
+}
|