From da1c5fe6cec3437b14fabe93587e54c9cba8263a Mon Sep 17 00:00:00 2001 From: hanxueqing <1045352474@qq.com> Date: Sat, 4 Jan 2020 20:50:32 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' # Conflicts: # app/src/main/res/layout/activity_main.xml --- app/app.iml | 2 +- app/src/main/AndroidManifest.xml | 1 - .../PersonalCenter/SearchServiceGet.java | 20 ++- .../cmknowledgegraph/CMKGStackAdapter.java | 32 +++- .../cmknowledgegraph/ConditionCode.java | 6 + .../example/cmknowledgegraph/ContentData.java | 8 +- .../example/cmknowledgegraph/LessonData.java | 28 ---- .../example/cmknowledgegraph/ListAdapter.java | 29 +--- .../cmknowledgegraph/SearchContent.java | 3 +- .../SearchContentActivity.java | 52 ------- .../cmknowledgegraph/SearchEntryActivity.java | 63 ++++++-- app/src/main/res/layout/cmkg_item.xml | 1 + app/src/main/res/layout/cmkg_list_item.xml | 144 +++++++++--------- 13 files changed, 186 insertions(+), 203 deletions(-) delete mode 100644 app/src/main/java/com/example/cmknowledgegraph/LessonData.java delete mode 100644 app/src/main/java/com/example/cmknowledgegraph/SearchContentActivity.java diff --git a/app/app.iml b/app/app.iml index 214d55a..fca0cd4 100644 --- a/app/app.iml +++ b/app/app.iml @@ -117,9 +117,9 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1514070..b274090 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,6 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - diff --git a/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java b/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java index d8df8e7..9ef0e5d 100644 --- a/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java +++ b/app/src/main/java/com/example/PersonalCenter/SearchServiceGet.java @@ -1,10 +1,8 @@ package com.example.PersonalCenter; import android.util.Log; - import net.sf.json.JSONArray; import net.sf.json.JSONObject; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -20,14 +18,15 @@ public class SearchServiceGet { public static ArrayList content=new ArrayList();//存储数据内容 public static String name_back; public static boolean SearchSuccess=false; + public static int code; public static void executeSearchGet(String name){ HttpURLConnection connection = null; InputStream in = null; - String address="/rest/cmkg/question"; + String address="/rest/cmkg/question/hello"; - String Url = "http://localhost:8080"+address; + String Url = "http://114.116.199.154:5000"+address; String path = Url + "?name="+name; URL url = null; try { @@ -52,7 +51,7 @@ public class SearchServiceGet { //开始解析返回的数据 JSONObject jo=JSONObject.fromObject(response.toString()); - int code=jo.getInt("code"); + code=jo.getInt("code"); if(code!=0){ //查询成功,在开始解析数据 name_back=jo.getString("message");//查询的主语 //把data看作一个JSONObject,无论里面由多少元素,都转换为JSONArray,存在数组里 @@ -87,4 +86,15 @@ public class SearchServiceGet { // return ""; } + public static void exxcuteTest(String name){ + code=100; + name_back="糖尿病"; + content.add("jjfkdjfkjklfjdklsjfklasjflksjflsjfdlsjfdklsjfklsjfklsjfkldjsafl;das" + +"FJDKSLDJFKLDSKLFJDSKLAJFKLDSAJFKLDASJFKLDSAJFKLDSAJFKLDASJFKLDASJFKLDASJFKLDASJFL" + +"FNDFJDJFKLDSJFKLDSJFIOWUIORUEJGKLDKLGDKSLFJKDLSAJFKLD;SA"); + content.add("dddddddd反馈i惹我给i偶i哦好v考虑的设计规范房价的快速了解法拉盛覅柔儿一个可能" + +"fdighreioghi飞机迪斯科飞机俄欧分工i热i购房贷款了JFK逻辑非我"); + + } + } diff --git a/app/src/main/java/com/example/cmknowledgegraph/CMKGStackAdapter.java b/app/src/main/java/com/example/cmknowledgegraph/CMKGStackAdapter.java index 5157cf2..ea6cc71 100644 --- a/app/src/main/java/com/example/cmknowledgegraph/CMKGStackAdapter.java +++ b/app/src/main/java/com/example/cmknowledgegraph/CMKGStackAdapter.java @@ -12,18 +12,20 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.example.PersonalCenter.SearchServiceGet; import com.loopeer.cardstack.CardStackView; import com.loopeer.cardstack.StackAdapter; import java.util.List; -public class CMKGStackAdapter extends StackAdapter { +public class CMKGStackAdapter extends StackAdapter implements ConditionCode{ - List> lessonList; + List> contentList; /** * * 构造函数 */ + static int title_num=0;//标题的数目 public CMKGStackAdapter(Context context) { super(context); @@ -55,17 +57,17 @@ public class CMKGStackAdapter extends StackAdapter { * @param data * @param lessonList */ - public void updateData(List data, List> lessonList) { - this.lessonList = lessonList; + public void updateData(List data, List> lessonList) { + this.contentList = lessonList; updateData(data); - System.out.println("Updata!"); + System.out.println("Updata!*****************************"); } public void bindView(Integer data, int position, CardStackView.ViewHolder holder) { if(holder instanceof CardViewHolder) { CardViewHolder cardHolder = (CardViewHolder)holder; - cardHolder.onBind(data,position,lessonList); + cardHolder.onBind(data,position,contentList); } System.out.println("bindView"); } @@ -92,12 +94,28 @@ public class CMKGStackAdapter extends StackAdapter { System.out.println("CardViewHolder constructor"); } - public void onBind(Integer backgroundColorId,int position,List> dataList) + public void onBind(Integer backgroundColorId,int position,List> dataList) { /* 该方法是在bindView 调用时被调用的,因为可能有不同的布局,因而有不同的ViewHolder,将bindView实现的操作放在了ViewHolder中的onBind方法中,会使代码看来起更简洁,易懂。 */ + /** + * v 病-症状:标题是名字,内容是症状 + * * 病-治疗药品:标题是药的名字,内容是药的用法(暂时不做) + * * 药-用法:标题是药的名字,内容是药的用法 + * * 药-作用:标题是药的名字,内容是药的用法 + */ + if(SearchServiceGet.code==DiseaseToSymptom||SearchServiceGet.code==MedicineToOperation||SearchServiceGet.code==MedicineToSymptom){ + //对应病症,那么标题只有一个就是病的名字 + titleText.setText(SearchServiceGet.name_back); + }else { + //对应治疗方法,那么标题就要有多个 + titleText.setText(SearchServiceGet.content.get(title_num)); + title_num++; + } + cardTitle.getBackground().setColorFilter(ContextCompat.getColor(getContext(),backgroundColorId), PorterDuff.Mode.SRC_IN);//传入的int值,其实是一个颜色,在这里改变头部的颜色 + System.out.println("========================"+position); ListAdapter adapter = new ListAdapter(dataList.get(position)); scoreList.setLayoutManager(new LinearLayoutManager(getContext())); scoreList.setAdapter(adapter); diff --git a/app/src/main/java/com/example/cmknowledgegraph/ConditionCode.java b/app/src/main/java/com/example/cmknowledgegraph/ConditionCode.java index 0525e0b..6812158 100644 --- a/app/src/main/java/com/example/cmknowledgegraph/ConditionCode.java +++ b/app/src/main/java/com/example/cmknowledgegraph/ConditionCode.java @@ -2,6 +2,12 @@ package com.example.cmknowledgegraph; public interface ConditionCode { + /** + * DiseaseToSymptom 病 症状 + * DiseaseToMedeicines 病 治疗方法 + * MedicineToOperation 药 用法 + * MedicineToSympton 药 作用 + */ public final int DiseaseToSymptom=100; public final int DiseaseToMedicines=200; public final int MedicineToOperation=300; diff --git a/app/src/main/java/com/example/cmknowledgegraph/ContentData.java b/app/src/main/java/com/example/cmknowledgegraph/ContentData.java index be59c21..a93466c 100644 --- a/app/src/main/java/com/example/cmknowledgegraph/ContentData.java +++ b/app/src/main/java/com/example/cmknowledgegraph/ContentData.java @@ -2,11 +2,12 @@ package com.example.cmknowledgegraph; public class ContentData { - /** - * 这个类用于存储返回来的数据,更准确说是存储显示的数据 - */ private String contentdata; + public ContentData(String content) { + this.contentdata = content; + } + public String getContentdata() { return contentdata; } @@ -15,3 +16,4 @@ public class ContentData { this.contentdata = contentdata; } } + diff --git a/app/src/main/java/com/example/cmknowledgegraph/LessonData.java b/app/src/main/java/com/example/cmknowledgegraph/LessonData.java deleted file mode 100644 index 91af9ca..0000000 --- a/app/src/main/java/com/example/cmknowledgegraph/LessonData.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.example.cmknowledgegraph; - -public class LessonData { - String lessonName; - String lessonScore; - - public LessonData(String lessonName, String lessonScore) { - this.lessonName = lessonName; - this.lessonScore = lessonScore; - } - - public String getLessonName() { - return lessonName; - } - - public void setLessonName(String lessonName) { - this.lessonName = lessonName; - } - - public String getLessonScore() { - return lessonScore; - } - - public void setLessonScore(String lessonScore) { - this.lessonScore = lessonScore; - } -} - diff --git a/app/src/main/java/com/example/cmknowledgegraph/ListAdapter.java b/app/src/main/java/com/example/cmknowledgegraph/ListAdapter.java index 2b9e535..03e5b67 100644 --- a/app/src/main/java/com/example/cmknowledgegraph/ListAdapter.java +++ b/app/src/main/java/com/example/cmknowledgegraph/ListAdapter.java @@ -13,40 +13,27 @@ import java.util.List; * Created by LZL on 2017/7/16. */ -public class ListAdapter extends RecyclerView.Adapter { - List scores_list; +public class ListAdapter extends RecyclerView.Adapter implements ConditionCode{ + List content_list; - public ListAdapter(List list) + public ListAdapter(List list) { - scores_list = list; + content_list = list; } public static class ScoresViewHodler extends RecyclerView.ViewHolder { - TextView name; //课程名称 - TextView high_scores; //最高分 - TextView daily_scores; //平时成绩 - TextView type; //课程类型 - TextView credit; //学分 - TextView middle_scores; //期中成绩 - TextView final_scores; //期末成绩 + TextView search_content; //内容 public ScoresViewHodler(View view) { super(view); - name = (TextView)view.findViewById(R.id.scores_lesson_name); - high_scores = (TextView)view.findViewById(R.id.scores_lesson_score); - daily_scores = (TextView)view.findViewById(R.id.scores_lesson_pingshi); - type = (TextView)view.findViewById(R.id.scores_lesson_type); - credit = (TextView)view.findViewById(R.id.scores_lesson_xf); - middle_scores = (TextView)view.findViewById(R.id.scores_lesson_qzcj); - final_scores = (TextView)view.findViewById(R.id.scores_lesson_qmcj); + search_content=(TextView)view.findViewById(R.id.search_content); } } @Override public void onBindViewHolder(ScoresViewHodler holder, int position) { - holder.name.setText(scores_list.get(position).getLessonName()); - holder.high_scores.setText(scores_list.get(position).getLessonScore()); + holder.search_content.setText(content_list.get(position).getContentdata()); } @Override @@ -57,6 +44,6 @@ public class ListAdapter extends RecyclerView.Adapter> lists = new LinkedList<>(); - for(int i = 0;i<4;i++) - { - List list = new LinkedList<>(); - for(int j = 0;j<6;j++) - { - list.add(new LessonData(name[j],scores[j])); + List> lists=new LinkedList<>(); + + if(SearchServiceGet.code==DiseaseToSymptom){ + /** + * //返回的是病症 + * 标题就是病的名字,内容就是病症。lists就是病名,list就是病症 + */ + for(int i=0;i list=new LinkedList<>(); + list.add(new ContentData(SearchServiceGet.content.get(i))); + lists.add(list); + } + + }else if(SearchServiceGet.code==DiseaseToMedicines){ + /** + * //返回的是结解决的多种药品方法 + * 标题就是药品的名字,内容就是用法,暂时不做用法(用法先用数字代替) + */ + List list=new LinkedList<>(); + for(int i=0;i list=new LinkedList<>(); + list.add(new ContentData(SearchServiceGet.content.get(i))); + lists.add(list); + } + + }else{ + /** + * //返回的是药的主治症状 + * 标题是药的名字,内容是主治症状 + */ + for(int i = 0; i< SearchServiceGet.content.size(); i++){ + List list=new LinkedList<>(); + list.add(new ContentData(SearchServiceGet.content.get(i))); + lists.add(list); } - lists.add(list); + } + adapter.updateData(Arrays.asList(color),lists); mCardStack.setAnimatorAdapter(new AllMoveDownAnimatorAdapter(mCardStack)); mCardStack.setAnimatorAdapter(new UpDownAnimatorAdapter(mCardStack)); diff --git a/app/src/main/res/layout/cmkg_item.xml b/app/src/main/res/layout/cmkg_item.xml index efc4c7e..3a29fa2 100644 --- a/app/src/main/res/layout/cmkg_item.xml +++ b/app/src/main/res/layout/cmkg_item.xml @@ -25,6 +25,7 @@ android:textColor="#ffffff" android:id="@+id/card_title_text" /> + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +