Merge remote-tracking branch 'origin/master'

master
ongbo 5 years ago
commit e6288af322

@ -38,7 +38,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
api 'com.hankcs:hanlp:portable-1.7.2' api 'com.hankcs:hanlp:portable-1.7.2'
implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.android.material:material:1.0.0'
implementation 'com.alibaba:fastjson:1.2.62' implementation 'com.alibaba:fastjson:1.2.62'
implementation 'com.loopeer.library:cardstack:1.0.2' implementation 'com.loopeer.library:cardstack:1.0.2'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'

@ -12,16 +12,12 @@ import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.example.Util.ConditionCode; import com.example.Util.ConditionCode;
import com.example.Util.ReturnData; import com.example.Util.ReturnData;
import com.example.cmknowledgegraph.R; import com.example.cmknowledgegraph.R;
import com.loopeer.cardstack.CardStackView; import com.loopeer.cardstack.CardStackView;
import com.loopeer.cardstack.StackAdapter; import com.loopeer.cardstack.StackAdapter;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.List; import java.util.List;
public class CMKGStackAdapter extends StackAdapter<Integer> implements ConditionCode { public class CMKGStackAdapter extends StackAdapter<Integer> implements ConditionCode {
@ -118,8 +114,6 @@ public class CMKGStackAdapter extends StackAdapter<Integer> implements Condition
titleText.setText(returnData.getMsg()); titleText.setText(returnData.getMsg());
}else { }else {
//对应治疗方法,那么标题就要有多个 //对应治疗方法,那么标题就要有多个
titleText.setText(SearchEntryActivity.content.get(title_num)); titleText.setText(SearchEntryActivity.content.get(title_num));
title_num++; title_num++;
} }

@ -2,15 +2,21 @@ package com.example.SearchCenter;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.example.Util.ConditionCode; import com.example.Util.ConditionCode;
import com.example.Util.ReturnData; import com.example.Util.ReturnData;
import com.example.Util.cmkgWebServiceGet;
import com.example.Util.publicStringUtil;
import com.example.cmknowledgegraph.R; import com.example.cmknowledgegraph.R;
import com.loopeer.cardstack.AllMoveDownAnimatorAdapter; import com.loopeer.cardstack.AllMoveDownAnimatorAdapter;
import com.loopeer.cardstack.CardStackView; import com.loopeer.cardstack.CardStackView;
@ -19,6 +25,7 @@ import com.loopeer.cardstack.UpDownStackAnimatorAdapter;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -29,6 +36,8 @@ import java.util.Random;
public class SearchEntryActivity extends AppCompatActivity implements CardStackView.ItemExpendListener,ConditionCode{ public class SearchEntryActivity extends AppCompatActivity implements CardStackView.ItemExpendListener,ConditionCode{
public static ArrayList<String> content=new ArrayList<String>();//存储数据内容 public static ArrayList<String> content=new ArrayList<String>();//存储数据内容
public static String model_Text;
public static int[] index=new int[3];//在随机生成选定联想搜索产生的索引值
Integer[] color = { Integer[] color = {
R.color.holo_blue_bright, R.color.holo_blue_bright,
R.color.holo_orange_light, R.color.holo_orange_light,
@ -48,8 +57,6 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
private CMKGStackAdapter cmkgStackAdapter; private CMKGStackAdapter cmkgStackAdapter;
Integer[] new_color; Integer[] new_color;
String[] name = {"数据结构","计算机网络","编译原理","C语言","算法设计","FPGA编程"};
String[] scores = {"77","87","65","98","74","80"};
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -62,6 +69,8 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
public void onItemExpend(boolean expend) { public void onItemExpend(boolean expend) {
} }
void init(Bundle bundle) void init(Bundle bundle)
{ {
@ -71,40 +80,23 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
//获取response后将这个json数据解析 //获取response后将这个json数据解析
ReturnData response = (ReturnData) bundle.getSerializable("msg"); ReturnData response = (ReturnData) bundle.getSerializable("msg");
System.out.println("code=!!!!!!!!1"+response.getCode());
Log.i("response+++++",response+"返回值"); Log.i("response+++++",response+"返回值");
try { try {
int code = response.getCode(); int code = response.getCode();
Log.i("code:",""+code); Log.i("code:",""+code);
String message = response.getMsg(); String message = response.getMsg();
Log.i("msg:",""+message); 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){ if(code == DiseaseToSymptom){
/** /**
* //返回的是病症 * //返回的是病症
* listslist * listslist
*/ */
// 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<ContentData> list = new LinkedList<>();
list.add(new ContentData((String)response.getData())); list.add(new ContentData((String)response.getData()));
Log.i("response.getData",(String)response.getData());
lists.add(list); lists.add(list);
new_color=new Integer[1]; new_color=new Integer[1];
}else if(code==DiseaseToMedicines){ }else if(code==DiseaseToMedicines){
@ -114,41 +106,42 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
*/ */
Log.i("hah",""+(String)response.getData()); Log.i("hah",""+(String)response.getData());
JSONArray jsonArray = new JSONArray((String)response.getData()); JSONArray jsonArray = new JSONArray((String)response.getData());
List<ContentData> list=new LinkedList<>();
for(int i=0;i<jsonArray.length();i++){ for(int i=0;i<jsonArray.length();i++){
List<ContentData> list=new LinkedList<>();
list.add(new ContentData("我是您的用法哦~请您看看我嘞\n我无比的期待您的光临嘞\n我们没有连数据呢马上就有嘞")); list.add(new ContentData("我是您的用法哦~请您看看我嘞\n我无比的期待您的光临嘞\n我们没有连数据呢马上就有嘞"));
lists.add(list);
content.add((String) jsonArray.get(i)); content.add((String) jsonArray.get(i));
lists.add(list);
} }
new_color=new Integer[jsonArray.length()]; new_color=new Integer[jsonArray.length()];
}else if(code==MedicineToOperation) { }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<ContentData> list = new LinkedList<>();
list.add(new ContentData((String)response.getData())); list.add(new ContentData((String)response.getData()));
lists.add(list); lists.add(list);
new_color=new Integer[1]; new_color=new Integer[1];
}else{ }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<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); 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]; 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); CardStackView mCardStack = (CardStackView)findViewById(R.id.cardStackView);
CMKGStackAdapter adapter = new CMKGStackAdapter(this,response); CMKGStackAdapter adapter = new CMKGStackAdapter(this,response);
mCardStack.setAdapter(adapter); 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 AllMoveDownAnimatorAdapter(mCardStack));
mCardStack.setAnimatorAdapter(new UpDownAnimatorAdapter(mCardStack)); mCardStack.setAnimatorAdapter(new UpDownAnimatorAdapter(mCardStack));
mCardStack.setAnimatorAdapter(new UpDownStackAnimatorAdapter(mCardStack)); mCardStack.setAnimatorAdapter(new UpDownStackAnimatorAdapter(mCardStack));
@ -195,19 +182,15 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
* nhm nhmnhm * nhm nhmnhm
* nhmnhmnhm * nhmnhmnhm
*/ */
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){ if(response.getCode()==DiseaseToSymptom){
/** /**
* nm * nm
*/ */
TextView textView_1=findViewById(R.id.asscoiate_entry); texts[0]=response.getMsg()+"应该吃什么药";
textView_1.setText(response.getMsg()+"应该吃什么药"); model_Text=Model_Symptom;
textView_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}else if(response.getCode()==DiseaseToMedicines){ }else if(response.getCode()==DiseaseToMedicines){
/** /**
* nhmnhmnhm * nhmnhmnhm
@ -215,54 +198,55 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV
*/ */
Random r=new Random(); Random r=new Random();
for(int i=0;i<3;i++) { for(int i=0;i<3;i++) {
TextView textView = findViewById(R.id.asscoiate_entry); index[i] = r.nextInt(9) + 1;
int index = r.nextInt(10) + 1; texts[i]=content.get(index[i])+"能治什么病症";
textView.setText(content.get(index) + "能治什么病症");
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
} }
model_Text=Model_Function;
}else if(response.getCode()==MedicineToOperation){ }else if(response.getCode()==MedicineToOperation){
/** /**
* *
* nhm nhmnhm * nhm
*/
texts[0]=response.getMsg()+"能治什么病";
model_Text=Model_Function;
}else {
/**
*
* nhm
*/ */
texts[0]=response.getMsg()+"的用法";
model_Text=Model_Operation;
}
TextView textView_1=findViewById(R.id.asscoiate_entry); ArrayAdapter<String> view_adapter = new ArrayAdapter<String>(SearchEntryActivity.this,R.layout.list_view, texts);
TextView textView_2=findViewById(R.id.asscoiate_entry); ListView listView=findViewById(R.id.listview_group);
TextView textView_3=findViewById(R.id.asscoiate_entry); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
textView_1.setText(response.getMsg()+"能治什么病");
textView_2.setText(response.getMsg()+"的证候");
textView_3.setText(response.getMsg()+"的功能");
textView_1.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
new Thread(new Runnable() {
}
});
textView_2.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void run() {
ReturnData rd=null;
if(response.getCode()==DiseaseToMedicines) {
rd = cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname + content.get(index[position]) + model_Text, publicStringUtil.questionSearchURL);
} }
}); else{
textView_3.setOnClickListener(new View.OnClickListener() { rd= cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname+response.getMsg()+model_Text, publicStringUtil.questionSearchURL);
@Override
public void onClick(View view) {
} }
}); Message m = new Message();
}else if(response.getCode()==MedicineToSymptom){ Bundle bundle = new Bundle();
/** bundle.putSerializable("msg", rd);
* Intent intent = new Intent();
* nhmnhmnhm intent.setClass(SearchEntryActivity.this, SearchEntryActivity.class);
*/ intent.putExtras(bundle);
startActivity(intent);
} }
}).start();
} }
});
listView.setAdapter(view_adapter);
adapter.updateData(Arrays.asList(new_color),lists);
}
} }

@ -12,6 +12,16 @@ public interface ConditionCode {
public final int DiseaseToMedicines=200; public final int DiseaseToMedicines=200;
public final int MedicineToOperation=300; public final int MedicineToOperation=300;
public final int MedicineToSymptom=400; public final int MedicineToSymptom=400;
/***
*Model_Symptom
* Model_Medicines
* Model_Operation
* Model_Function
*/
public final String Model_Symptom="的症状";
public final String Model_Medicines="治疗方法";
public final String Model_Operation="用法";
public final String Model_Function="作用";
//登陆成功 //登陆成功
public final int loginsucess = 200; public final int loginsucess = 200;

@ -4,32 +4,43 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".SearchEntryActivity"> tools:context=".SearchEntryActivity">
<com.loopeer.cardstack.CardStackView <com.loopeer.cardstack.CardStackView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/cardStackView" android:id="@+id/cardStackView"
> android:layout_width="match_parent"
</com.loopeer.cardstack.CardStackView> android:layout_height="299dp"></com.loopeer.cardstack.CardStackView>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="12sp" android:textSize="24sp"
android:text="你可能感兴趣" android:text="你可能感兴趣"
android:paddingLeft="50dp" android:textStyle="bold"
android:paddingTop="100dp" android:paddingLeft="100dp"
android:paddingTop="150dp"
android:id="@+id/asscoiate_text" android:id="@+id/asscoiate_text"
/> />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="14sp" android:paddingLeft="20dp"
android:paddingLeft="50dp"
android:paddingTop="10dp"
android:id="@+id/asscoiate_entry" android:id="@+id/asscoiate_entry"
/> />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="40dp"
android:paddingLeft="20dp"
android:divider="@null"
android:id="@+id/listview_group"
android:textSize="16sp"
android:textColor="#ff000000"
android:shadowDx="4"
android:shadowDy="4"
android:shadowRadius="2"
/>
</LinearLayout> </LinearLayout>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="10dp"
android:textColor="#FF4500"
android:shadowDx="4"
android:shadowDy="4"
android:shadowRadius="2"
/>

@ -33,4 +33,8 @@
<!-- A really bright Holo shade of gray --> <!-- A really bright Holo shade of gray -->
<color name="holo_gray_bright">#33CCCCCC</color> <color name="holo_gray_bright">#33CCCCCC</color>
<color name="my_color_dark_pink">#FF1493</color>
<color name="my_color_green_light">#3CB371</color>
<color name="my_color_dark_yellow">#FFD700</color>
</resources> </resources>
Loading…
Cancel
Save