|
|
|
@ -2,15 +2,21 @@ package com.example.SearchCenter;
|
|
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Message;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
import com.example.Util.ConditionCode;
|
|
|
|
|
import com.example.Util.ReturnData;
|
|
|
|
|
import com.example.Util.cmkgWebServiceGet;
|
|
|
|
|
import com.example.Util.publicStringUtil;
|
|
|
|
|
import com.example.cmknowledgegraph.R;
|
|
|
|
|
import com.loopeer.cardstack.AllMoveDownAnimatorAdapter;
|
|
|
|
|
import com.loopeer.cardstack.CardStackView;
|
|
|
|
@ -19,6 +25,7 @@ import com.loopeer.cardstack.UpDownStackAnimatorAdapter;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
@ -29,6 +36,8 @@ import java.util.Random;
|
|
|
|
|
public class SearchEntryActivity extends AppCompatActivity implements CardStackView.ItemExpendListener,ConditionCode{
|
|
|
|
|
|
|
|
|
|
public static ArrayList<String> content=new ArrayList<String>();//存储数据内容
|
|
|
|
|
public static String model_Text;
|
|
|
|
|
public static int[] index=new int[3];//在随机生成选定联想搜索产生的索引值
|
|
|
|
|
Integer[] color = {
|
|
|
|
|
R.color.holo_blue_bright,
|
|
|
|
|
R.color.holo_orange_light,
|
|
|
|
@ -48,8 +57,6 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
private CMKGStackAdapter cmkgStackAdapter;
|
|
|
|
|
Integer[] new_color;
|
|
|
|
|
|
|
|
|
|
String[] name = {"数据结构","计算机网络","编译原理","C语言","算法设计","FPGA编程"};
|
|
|
|
|
String[] scores = {"77","87","65","98","74","80"};
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
@ -62,6 +69,8 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
public void onItemExpend(boolean expend) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void init(Bundle bundle)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -71,40 +80,23 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
|
|
|
|
|
//获取response后,将这个json数据解析
|
|
|
|
|
ReturnData response = (ReturnData) bundle.getSerializable("msg");
|
|
|
|
|
System.out.println("code=!!!!!!!!1"+response.getCode());
|
|
|
|
|
Log.i("response+++++",response+"返回值");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
int code = response.getCode();
|
|
|
|
|
Log.i("code:",""+code);
|
|
|
|
|
String message = response.getMsg();
|
|
|
|
|
Log.i("msg:",""+message);
|
|
|
|
|
|
|
|
|
|
// if(code== ConditionCode.DiseaseToMedicines || code == ConditionCode.MedicineToSymptom){
|
|
|
|
|
//// //病的治疗方法和药的作用,返回数组
|
|
|
|
|
//// JSONArray jsonArray = jsonObject.getJSONArray("data");
|
|
|
|
|
//// Log.i("length==",""+jsonArray.length());
|
|
|
|
|
//// for(int i=0;i<jsonArray.length();i++) Log.i("dataJsonArray=====",""+jsonArray.get(i));
|
|
|
|
|
//// }if(code == ConditionCode.DiseaseToSymptom || code ==ConditionCode.MedicineToOperation){
|
|
|
|
|
//// //病的症状或者药的用法,返回字符串
|
|
|
|
|
//// String jsonString = jsonObject.getString("data");
|
|
|
|
|
//// Log.i("dataString=====",jsonString);
|
|
|
|
|
////
|
|
|
|
|
//// }
|
|
|
|
|
|
|
|
|
|
if(code == DiseaseToSymptom){
|
|
|
|
|
/**
|
|
|
|
|
* //返回的是病症
|
|
|
|
|
* 标题就是病的名字,内容就是症状。lists就是病名,list就是病症
|
|
|
|
|
*/
|
|
|
|
|
// for(int i=0;i<content.size();i++){
|
|
|
|
|
// System.out.println("content="+content.get(i));
|
|
|
|
|
// List<ContentData> list=new LinkedList<>();
|
|
|
|
|
// list.add(new ContentData(content.get(i)));
|
|
|
|
|
// lists.add(list);
|
|
|
|
|
// }
|
|
|
|
|
List<ContentData> list = new LinkedList<>();
|
|
|
|
|
list.add(new ContentData((String)response.getData()));
|
|
|
|
|
Log.i("response.getData",(String)response.getData());
|
|
|
|
|
lists.add(list);
|
|
|
|
|
new_color=new Integer[1];
|
|
|
|
|
}else if(code==DiseaseToMedicines){
|
|
|
|
@ -114,41 +106,42 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
*/
|
|
|
|
|
Log.i("hah",""+(String)response.getData());
|
|
|
|
|
JSONArray jsonArray = new JSONArray((String)response.getData());
|
|
|
|
|
List<ContentData> list=new LinkedList<>();
|
|
|
|
|
for(int i=0;i<jsonArray.length();i++){
|
|
|
|
|
List<ContentData> list=new LinkedList<>();
|
|
|
|
|
list.add(new ContentData("我是您的用法哦~请您看看我嘞\n我无比的期待您的光临嘞\n我们没有连数据呢,马上就有嘞!"));
|
|
|
|
|
lists.add(list);
|
|
|
|
|
content.add((String) jsonArray.get(i));
|
|
|
|
|
lists.add(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_color=new Integer[jsonArray.length()];
|
|
|
|
|
}else if(code==MedicineToOperation) {
|
|
|
|
|
/**
|
|
|
|
|
* //返回的是药的用法
|
|
|
|
|
* //标题就是药品的名字,内容是用法
|
|
|
|
|
*/
|
|
|
|
|
// for(int i=0;i<content.size();i++){
|
|
|
|
|
// List<ContentData> list=new LinkedList<>();
|
|
|
|
|
// list.add(new ContentData(content.get(i)));
|
|
|
|
|
// lists.add(list);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
List<ContentData> list = new LinkedList<>();
|
|
|
|
|
list.add(new ContentData((String)response.getData()));
|
|
|
|
|
lists.add(list);
|
|
|
|
|
new_color=new Integer[1];
|
|
|
|
|
}else{
|
|
|
|
|
/**
|
|
|
|
|
* //返回的是药的主治症状
|
|
|
|
|
* 标题是药的名字,内容是主治症状
|
|
|
|
|
* //返回的是药的主治症状和对应的
|
|
|
|
|
* 标题是药的名字和“可以治疗的疾病”,内容是症状,和十种药物
|
|
|
|
|
*/
|
|
|
|
|
// for(int i = 0; i< content.size(); i++){
|
|
|
|
|
// List<ContentData> list=new LinkedList<>();
|
|
|
|
|
// list.add(new ContentData(content.get(i)));
|
|
|
|
|
// lists.add(list);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
List<ContentData> list = new LinkedList<>();
|
|
|
|
|
list.add(new ContentData((String)response.getData()));
|
|
|
|
|
String data=(String)response.getData();
|
|
|
|
|
JSONObject jo=new JSONObject(data);
|
|
|
|
|
String medicine_symptom=jo.getString("symptom");
|
|
|
|
|
list.add(new ContentData(medicine_symptom));
|
|
|
|
|
lists.add(list);
|
|
|
|
|
String disease_names=new String(jo.getString("name"));
|
|
|
|
|
JSONArray ja=new JSONArray(disease_names);
|
|
|
|
|
for(int i=0;i<ja.length();i++){
|
|
|
|
|
List<ContentData> list_1=new LinkedList<>();
|
|
|
|
|
list_1.add(new ContentData(content.get(i)));
|
|
|
|
|
lists.add(list);
|
|
|
|
|
}
|
|
|
|
|
new_color=new Integer[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -161,10 +154,6 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<new_color.length;i++){
|
|
|
|
|
new_color[i]=color[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CardStackView mCardStack = (CardStackView)findViewById(R.id.cardStackView);
|
|
|
|
|
CMKGStackAdapter adapter = new CMKGStackAdapter(this,response);
|
|
|
|
|
mCardStack.setAdapter(adapter);
|
|
|
|
@ -177,13 +166,11 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
* 病-症状:标题是名字,内容是症状
|
|
|
|
|
* 病-治疗药品:标题是药的名字,内容是药的用法(暂时不做)
|
|
|
|
|
* 药-用法:标题是药的名字,内容是药的用法
|
|
|
|
|
* 药-作用:标题是药的名字,内容是药的用法
|
|
|
|
|
* 药-作用:标题是药的名字和 “可以治疗的疾病”,内容是药的用法
|
|
|
|
|
*
|
|
|
|
|
* 每种不同的情况对应不同的状态码,用接口实现状态码
|
|
|
|
|
*/
|
|
|
|
|
adapter.updateData(Arrays.asList(new_color),lists);
|
|
|
|
|
|
|
|
|
|
// adapter.updateData(Arrays.asList(color),lists);
|
|
|
|
|
mCardStack.setAnimatorAdapter(new AllMoveDownAnimatorAdapter(mCardStack));
|
|
|
|
|
mCardStack.setAnimatorAdapter(new UpDownAnimatorAdapter(mCardStack));
|
|
|
|
|
mCardStack.setAnimatorAdapter(new UpDownStackAnimatorAdapter(mCardStack));
|
|
|
|
@ -195,19 +182,15 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
* 药——操作方法 联想搜索:nhm能治什么病 ,nhm的证候,nhm的功能
|
|
|
|
|
* 药——作用 联想搜索:nhm能治什么病,nhm的证候,nhm的功能
|
|
|
|
|
*/
|
|
|
|
|
TextView asscoiate_text=findViewById(R.id.asscoiate_text);
|
|
|
|
|
TextView asscoiate_text=findViewById(R.id.asscoiate_text);//显示文本“你可能感兴趣”
|
|
|
|
|
String[] texts=new String[3];//存放listView中的显示的数据
|
|
|
|
|
|
|
|
|
|
if(response.getCode()==DiseaseToSymptom){
|
|
|
|
|
/**
|
|
|
|
|
* 病——症状 nm能吃什么药
|
|
|
|
|
*/
|
|
|
|
|
TextView textView_1=findViewById(R.id.asscoiate_entry);
|
|
|
|
|
textView_1.setText(response.getMsg()+"应该吃什么药");
|
|
|
|
|
textView_1.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
texts[0]=response.getMsg()+"应该吃什么药";
|
|
|
|
|
model_Text=Model_Symptom;
|
|
|
|
|
}else if(response.getCode()==DiseaseToMedicines){
|
|
|
|
|
/**
|
|
|
|
|
* 病——药 nhm能指什么病,nhm能治什么病,nhm能治什么病
|
|
|
|
@ -215,54 +198,55 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
*/
|
|
|
|
|
Random r=new Random();
|
|
|
|
|
for(int i=0;i<3;i++) {
|
|
|
|
|
TextView textView = findViewById(R.id.asscoiate_entry);
|
|
|
|
|
int index = r.nextInt(10) + 1;
|
|
|
|
|
textView.setText(content.get(index) + "能治什么病症");
|
|
|
|
|
textView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
index[i] = r.nextInt(9) + 1;
|
|
|
|
|
texts[i]=content.get(index[i])+"能治什么病症";
|
|
|
|
|
}
|
|
|
|
|
model_Text=Model_Function;
|
|
|
|
|
}else if(response.getCode()==MedicineToOperation){
|
|
|
|
|
/**
|
|
|
|
|
* 药——操作方法
|
|
|
|
|
* nhm能治什么病 ,nhm的证候,nhm的功能
|
|
|
|
|
* nhm能治什么病
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
TextView textView_1=findViewById(R.id.asscoiate_entry);
|
|
|
|
|
TextView textView_2=findViewById(R.id.asscoiate_entry);
|
|
|
|
|
TextView textView_3=findViewById(R.id.asscoiate_entry);
|
|
|
|
|
textView_1.setText(response.getMsg()+"能治什么病");
|
|
|
|
|
textView_2.setText(response.getMsg()+"的证候");
|
|
|
|
|
textView_3.setText(response.getMsg()+"的功能");
|
|
|
|
|
textView_1.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
textView_2.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
textView_3.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}else if(response.getCode()==MedicineToSymptom){
|
|
|
|
|
texts[0]=response.getMsg()+"能治什么病";
|
|
|
|
|
model_Text=Model_Function;
|
|
|
|
|
}else {
|
|
|
|
|
/**
|
|
|
|
|
*药——作用
|
|
|
|
|
* nhm能治什么病,nhm的证候,nhm的功能
|
|
|
|
|
*药——作用,能治什么病
|
|
|
|
|
* nhm 操作方法
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
texts[0]=response.getMsg()+"的用法";
|
|
|
|
|
model_Text=Model_Operation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayAdapter<String> view_adapter = new ArrayAdapter<String>(SearchEntryActivity.this,R.layout.list_view, texts);
|
|
|
|
|
ListView listView=findViewById(R.id.listview_group);
|
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
ReturnData rd=null;
|
|
|
|
|
if(response.getCode()==DiseaseToMedicines) {
|
|
|
|
|
rd = cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname + content.get(index[position]) + model_Text, publicStringUtil.questionSearchURL);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
rd= cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname+response.getMsg()+model_Text, publicStringUtil.questionSearchURL);
|
|
|
|
|
}
|
|
|
|
|
Message m = new Message();
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
bundle.putSerializable("msg", rd);
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
|
intent.setClass(SearchEntryActivity.this, SearchEntryActivity.class);
|
|
|
|
|
intent.putExtras(bundle);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
listView.setAdapter(view_adapter);
|
|
|
|
|
adapter.updateData(Arrays.asList(new_color),lists);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|