|
|
|
@ -10,6 +10,7 @@ import android.widget.ArrayAdapter;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
@ -63,6 +64,7 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
setContentView(R.layout.activity_search_entry);
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
|
Log.i("bundle",bundle.toString());
|
|
|
|
|
init(bundle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -73,11 +75,7 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
|
|
|
|
|
void init(Bundle bundle)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<List<ContentData>> lists=new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取response后,将这个json数据解析
|
|
|
|
|
ReturnData response = (ReturnData) bundle.getSerializable("msg");
|
|
|
|
|
Log.i("response+++++",response+"返回值");
|
|
|
|
@ -88,14 +86,19 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
String message = response.getMsg();
|
|
|
|
|
Log.i("msg:",""+message);
|
|
|
|
|
|
|
|
|
|
if(code == DiseaseToSymptom){
|
|
|
|
|
if(code==501){
|
|
|
|
|
Toast.makeText(this, "抱歉没有找到呢", Toast.LENGTH_LONG).show();
|
|
|
|
|
System.out.println("显示错误啦啊");
|
|
|
|
|
}else if(code == DiseaseToSymptom){
|
|
|
|
|
/**
|
|
|
|
|
* //返回的是病症
|
|
|
|
|
* 标题就是病的名字,内容就是症状。lists就是病名,list就是病症
|
|
|
|
|
*/
|
|
|
|
|
if(content.size()!=0){
|
|
|
|
|
content.clear();
|
|
|
|
|
}
|
|
|
|
|
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){
|
|
|
|
@ -103,32 +106,39 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
* //返回的是结解决的多种药品方法
|
|
|
|
|
* 标题就是药品的名字,内容就是用法,暂时不做用法(用法先用数字代替)
|
|
|
|
|
*/
|
|
|
|
|
if(content.size()!=0){
|
|
|
|
|
content.clear();
|
|
|
|
|
}
|
|
|
|
|
Log.i("hah",""+(String)response.getData());
|
|
|
|
|
JSONArray jsonArray = new JSONArray((String)response.getData());
|
|
|
|
|
for(int i=0;i<jsonArray.length();i++){
|
|
|
|
|
List<ContentData> list=new LinkedList<>();
|
|
|
|
|
list.add(new ContentData("我是您的用法哦~请您看看我嘞\n我无比的期待您的光临嘞\n我们没有连数据呢,马上就有嘞!"));
|
|
|
|
|
content.add((String) jsonArray.get(i));
|
|
|
|
|
System.out.println("content.size="+content.size());
|
|
|
|
|
lists.add(list);
|
|
|
|
|
}
|
|
|
|
|
System.out.println("++++"+jsonArray.length());
|
|
|
|
|
new_color=new Integer[jsonArray.length()];
|
|
|
|
|
}else if(code==MedicineToOperation) {
|
|
|
|
|
/**
|
|
|
|
|
* //返回的是药的用法
|
|
|
|
|
* //标题就是药品的名字,内容是用法
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if(content.size()!=0){
|
|
|
|
|
content.clear();
|
|
|
|
|
}
|
|
|
|
|
List<ContentData> list = new LinkedList<>();
|
|
|
|
|
list.add(new ContentData((String)response.getData()));
|
|
|
|
|
lists.add(list);
|
|
|
|
|
new_color=new Integer[1];
|
|
|
|
|
}else{
|
|
|
|
|
}else if(code==MedicineToFunction){
|
|
|
|
|
/**
|
|
|
|
|
* //返回的是药的主治症状和对应的
|
|
|
|
|
* 标题是药的名字和“可以治疗的疾病”,内容是症状,和十种药物
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if(content.size()!=0){
|
|
|
|
|
content.clear();
|
|
|
|
|
}
|
|
|
|
|
List<ContentData> list = new LinkedList<>();
|
|
|
|
|
String str=(String)response.getData();
|
|
|
|
|
JSONObject jo=new JSONObject(str.toString());
|
|
|
|
@ -139,23 +149,21 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
JSONArray ja=new JSONArray(disease_names);
|
|
|
|
|
List<ContentData> list_1=new LinkedList<>();
|
|
|
|
|
for(int i=0;i<ja.length();i++){
|
|
|
|
|
// list_1=new LinkedList<>();
|
|
|
|
|
list_1.add(new ContentData(ja.get(i).toString()));
|
|
|
|
|
System.out.println("病症有这些!="+ja.get(i).toString());
|
|
|
|
|
content.add(ja.get(i).toString());
|
|
|
|
|
}
|
|
|
|
|
lists.add(list_1);
|
|
|
|
|
new_color=new Integer[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<new_color.length;i++){
|
|
|
|
|
new_color[i]=color[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(response.getCode()!=501)
|
|
|
|
|
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);
|
|
|
|
@ -185,9 +193,6 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
* 药——作用 联想搜索:nhm能治什么病,nhm的证候,nhm的功能
|
|
|
|
|
*/
|
|
|
|
|
TextView asscoiate_text=findViewById(R.id.asscoiate_text);//显示文本“你可能感兴趣”
|
|
|
|
|
// String[] texts=new String[3];//存放listView中的显示的数据,只针对
|
|
|
|
|
// String[] new_texts=new String[1];
|
|
|
|
|
// String[]
|
|
|
|
|
String[] texts;
|
|
|
|
|
|
|
|
|
|
if(response.getCode()==DiseaseToSymptom){
|
|
|
|
@ -203,11 +208,26 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
* 随机选三种药品
|
|
|
|
|
*/
|
|
|
|
|
Random r=new Random();
|
|
|
|
|
if(content.size()>3){
|
|
|
|
|
texts=new String[3];
|
|
|
|
|
for(int i=0;i<3;i++) {
|
|
|
|
|
index[i] = r.nextInt(9) + 1;
|
|
|
|
|
int a;
|
|
|
|
|
while(true){
|
|
|
|
|
a=r.nextInt(content.size());
|
|
|
|
|
if(getDuplicate(a,index))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
index[i] =a;
|
|
|
|
|
texts[i]=content.get(index[i])+"能治什么病症";
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
texts=new String[content.size()];
|
|
|
|
|
for(int i=0;i<content.size();i++){
|
|
|
|
|
index[i]=i;
|
|
|
|
|
texts[i]=content.get(i)+"能治什么病症";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model_Text=Model_Function;
|
|
|
|
|
}else if(response.getCode()==MedicineToOperation){
|
|
|
|
|
/**
|
|
|
|
@ -220,11 +240,32 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
}else {
|
|
|
|
|
/**
|
|
|
|
|
*药——作用,能治什么病
|
|
|
|
|
* nhm 操作方法
|
|
|
|
|
* nm 吃什么药
|
|
|
|
|
*/
|
|
|
|
|
texts=new String[1];
|
|
|
|
|
texts[0]=response.getMsg()+"的用法";
|
|
|
|
|
model_Text=Model_Operation;
|
|
|
|
|
Random r=new Random();
|
|
|
|
|
if(content.size()>3){
|
|
|
|
|
texts=new String[3];
|
|
|
|
|
for(int i=0;i<3;i++) {
|
|
|
|
|
int a;
|
|
|
|
|
while(true){
|
|
|
|
|
a=r.nextInt(9);
|
|
|
|
|
System.out.println("The last a="+a);
|
|
|
|
|
if(getDuplicate(a,index))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("The waibu a="+a);
|
|
|
|
|
index[i] = r.nextInt(content.size());
|
|
|
|
|
texts[i]=content.get(index[i])+"吃什么药";
|
|
|
|
|
System.out.println("text[i]="+texts[i]);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
texts=new String[content.size()];
|
|
|
|
|
for(int i=0;i<content.size();i++){
|
|
|
|
|
texts[i]=content.get(i)+"吃什么药";
|
|
|
|
|
System.out.println("text[i]!!!!="+texts[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
model_Text=Model_Medicines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayAdapter<String> view_adapter = new ArrayAdapter<String>(SearchEntryActivity.this,R.layout.list_view, texts);
|
|
|
|
@ -232,15 +273,20 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
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) {
|
|
|
|
|
System.out.println("list "+response.getCode());
|
|
|
|
|
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);
|
|
|
|
|
} else if(response.getCode()==MedicineToFunction){
|
|
|
|
|
System.out.println("list "+response.getCode());
|
|
|
|
|
if(content.size()>3)
|
|
|
|
|
rd = cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname + content.get(index[position]) + model_Text, publicStringUtil.questionSearchURL);
|
|
|
|
|
else
|
|
|
|
|
rd = cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname + content.get(position) + model_Text, publicStringUtil.questionSearchURL);
|
|
|
|
|
}
|
|
|
|
|
Message m = new Message();
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
@ -251,13 +297,19 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
listView.setAdapter(view_adapter);
|
|
|
|
|
for(int i:new_color)
|
|
|
|
|
System.out.println("i="+i);
|
|
|
|
|
if(response.getCode()!=501)
|
|
|
|
|
adapter.updateData(Arrays.asList(new_color),lists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean getDuplicate(int a,int[] index) {
|
|
|
|
|
for(int num:index){
|
|
|
|
|
if(a==num)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|