├── .gitignore
├── .idea
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── clutch
│ │ └── student
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── clutch
│ │ │ └── student
│ │ │ ├── Adapter
│ │ │ ├── CourseAdapter.java
│ │ │ ├── CourseSecAdapter.java
│ │ │ ├── ScoreAdapter.java
│ │ │ ├── StudentAdapter.java
│ │ │ └── ViewPagerAdapter.java
│ │ │ ├── AddCourseActivity.java
│ │ │ ├── Dao
│ │ │ ├── CourseDao.java
│ │ │ ├── MyDatabaseHelper.java
│ │ │ ├── ScoreDao.java
│ │ │ ├── StudentDao.java
│ │ │ └── UserDao.java
│ │ │ ├── EditCheck.java
│ │ │ ├── Entity
│ │ │ ├── Course.java
│ │ │ ├── CourseSec.java
│ │ │ ├── Score.java
│ │ │ ├── Student.java
│ │ │ ├── Student_info.java
│ │ │ └── User.java
│ │ │ ├── Fragment
│ │ │ ├── FirstFragment.java
│ │ │ ├── ManagerFirstFragment.java
│ │ │ ├── ManagerSecondFragment.java
│ │ │ ├── ManagerThirdFragment.java
│ │ │ ├── SecondFragment.java
│ │ │ └── ThirdFragment.java
│ │ │ ├── LoginActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── ModifyPasswdActivity.java
│ │ │ ├── MyApplication.java
│ │ │ └── StudentChangeActivity.java
│ └── res
│ │ ├── drawable-hdpi
│ │ ├── ic_call.png
│ │ ├── ic_chat.png
│ │ └── ic_contact.png
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── age.png
│ │ ├── background.jpg
│ │ ├── bottom_navigation_color_selector.xml
│ │ ├── chemistry.png
│ │ ├── chinese.png
│ │ ├── english.png
│ │ ├── geography.png
│ │ ├── health.png
│ │ ├── history.png
│ │ ├── ic_launcher_background.xml
│ │ ├── id.png
│ │ ├── math.png
│ │ ├── name.png
│ │ ├── origin.png
│ │ ├── phone.png
│ │ ├── physic.png
│ │ ├── sex.png
│ │ └── sport.png
│ │ ├── layout
│ │ ├── activity_add_course.xml
│ │ ├── activity_login.xml
│ │ ├── activity_main.xml
│ │ ├── activity_modify_passwd.xml
│ │ ├── activity_student_change.xml
│ │ ├── course_item.xml
│ │ ├── fragment_first.xml
│ │ ├── fragment_manager_first.xml
│ │ ├── fragment_manager_second.xml
│ │ ├── fragment_manager_third.xml
│ │ ├── fragment_second.xml
│ │ ├── fragment_third.xml
│ │ └── student_item.xml
│ │ ├── menu
│ │ ├── main.xml
│ │ └── menu_bottom_navigation.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── clutch
│ └── student
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Android API 26 Platform
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android 学生选课系统
2 | ## 概述
3 | 此程序是功能为学生选课系统的Android App,功能涵盖了:
4 | 学生和管理员以账号密码的形式登录系统,进入系统分别对应各自的功能。
5 | 学生查看课表,课程成绩,进行选课,修改个人信息。
6 | 管理员添加删除课程,修改学生成绩,添加学生信息。
7 | ## 数据库
8 | 
9 | 共四个表:学生信息表 student ,课程信息表 course ,成绩表 score ,登录表 log。
10 | score表中course_id和student_id为联合主键,分别与对应course表和student表中的course_id和id组成外键。
11 | ## 程序功能
12 | ### 登录
13 | 实现在数据库中存入了一些数据,其中,登陆表log中管理员所对应的账号为0,密码为000000。只有此账号能登入管理员对应的界面。学生以学号为账号,初始密码默认为123456,可登入学生对应界面。
14 | 
15 | ### 学生界面
16 | 以账号10001,密码123456登入系统,进入此学生界面。
17 | 主界面可滑动,三个滑动界面对应三个功能,查看课表,选课,修改个人信息。
18 | 
19 | ### 管理员界面
20 | 
21 | ### 程序特色
22 | 界面采用 BottomNavigationView + ViewPager + Fragment 实现功能界面的左右滑动,用RecylerView 组件展示课程信息,其中在界面中刷新数据成为技术难点。程序中自己在要更新的界面写了更新方法,在提交界面点击按钮提交信息后,调用该方法,重新查询数据显示到相应的界面中。
23 | 程序中的主要思路为界面与数据操控逻辑分离,显示信息时将调用Dao 中对应的类查询到所需信息传入 Adapter 包中对应的适配器中,设置好适配器后,将适配器用于对应组件中,在传入对应界面实现显示。
24 | 输入信息时将采集到的信息传入 Dao 包中的对应的类,进行数据库操作,将操作是否成功以 boolean 类型返回到相应适配器,再传入对应界面给出相应提示,并实现数据刷新
25 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.clutch.student"
7 | minSdkVersion 15
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | testImplementation 'junit:junit:4.12'
25 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
26 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
27 | implementation 'com.android.support:recyclerview-v7:26.1.0'
28 | compile 'com.android.support:design:26.1.0'
29 | compile 'com.facebook.stetho:stetho:1.5.0'
30 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
31 | }
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/clutch/student/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.clutch.student", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
17 |
18 |
19 | android:label="修改个人信息"
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | android:label="修改课程信息"
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Adapter/CourseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Adapter;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/17.
5 | */
6 |
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 | import com.clutch.student.Entity.Course;
15 | import java.util.List;
16 | import com.clutch.student.Dao.CourseDao;
17 | import com.clutch.student.R;
18 |
19 | /**
20 | *课程类适配器,将课程信息展示在CourseFragment上
21 | * 管理员查看所有课程信息
22 | */
23 | public class CourseAdapter extends RecyclerView.Adapter{
24 |
25 | private List mCourseList;
26 |
27 | static class ViewHolder extends RecyclerView.ViewHolder {
28 | View CourseView;
29 | ImageView CourseImage;
30 | TextView CourseName;
31 |
32 | public ViewHolder(View view) {
33 | super(view);
34 | CourseView = view;
35 | CourseImage = (ImageView) view.findViewById(R.id.Course_image);
36 | CourseName = (TextView) view.findViewById(R.id.Course_name);
37 | }
38 | }
39 |
40 | public CourseAdapter(List courseList) {
41 | mCourseList=courseList;
42 | }
43 |
44 | @Override
45 | /**
46 | * 点击对应部分显示toast
47 | */
48 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
49 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.course_item, parent, false);
50 | final ViewHolder holder = new ViewHolder(view);
51 | holder.CourseView.setOnClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View v) {
54 | int position = holder.getAdapterPosition();
55 | Course course = mCourseList.get(position);
56 | Toast.makeText(v.getContext(), "you clicked view " + course.getName(), Toast.LENGTH_SHORT).show();
57 | }
58 | });
59 | holder.CourseImage.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View v) {
62 | int position = holder.getAdapterPosition();
63 | Course course = mCourseList.get(position);
64 | Toast.makeText(v.getContext(), "you clicked image " + course.getName(), Toast.LENGTH_SHORT).show();
65 | }
66 | });
67 | return holder;
68 | }
69 |
70 | @Override
71 | /**
72 | * 将课程信息显示在textView上
73 | */
74 | public void onBindViewHolder(ViewHolder holder, int position) {
75 | Course course = mCourseList.get(position);
76 | holder.CourseImage.setImageResource(course.getImageId());
77 | holder.CourseName.setText("课程号:"+course.getId()+" "+course.getName()+"\n学分:"+course.getCredit());
78 | }
79 |
80 | @Override
81 | public int getItemCount() {
82 | return mCourseList.size();
83 | }
84 |
85 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Adapter/CourseSecAdapter.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Adapter;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/22.
5 | */
6 |
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 | import com.clutch.student.Entity.CourseSec;
14 | import java.util.List;
15 | import com.clutch.student.R;
16 |
17 | /**
18 | *课程类适配器,将课程信息展示在CourseSecFragment上
19 | * 管理员查看所有课程信息
20 | */
21 | public class CourseSecAdapter extends RecyclerView.Adapter{
22 |
23 | private List mCourseSecList;
24 |
25 |
26 | static class ViewHolder extends RecyclerView.ViewHolder {
27 | View CourseSecView;
28 | ImageView CourseSecImage;
29 | TextView CourseSecName;
30 |
31 | public ViewHolder(View view) {
32 | super(view);
33 | CourseSecView = view;
34 | CourseSecImage = (ImageView) view.findViewById(R.id.Course_image);
35 | CourseSecName = (TextView) view.findViewById(R.id.Course_name);
36 | }
37 | }
38 |
39 | public CourseSecAdapter(List CourseSecList) {
40 | mCourseSecList=CourseSecList;
41 | }
42 | public void changeAdapter(List CourseSecList){
43 | mCourseSecList=CourseSecList;
44 | }
45 |
46 | @Override
47 | /**
48 | * 点击对应部分显示toast
49 | */
50 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
51 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.course_item, parent, false);
52 | final ViewHolder holder = new ViewHolder(view);
53 | holder.CourseSecView.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | int position = holder.getAdapterPosition();
57 | CourseSec CourseSec = mCourseSecList.get(position);
58 | }
59 | });
60 | holder.CourseSecImage.setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View v) {
63 | int position = holder.getAdapterPosition();
64 | CourseSec CourseSec = mCourseSecList.get(position);
65 | }
66 | });
67 | return holder;
68 | }
69 |
70 | @Override
71 | /**
72 | * 将课程信息显示在textView上
73 | */
74 | public void onBindViewHolder(ViewHolder holder, int position) {
75 | CourseSec CourseSec = mCourseSecList.get(position);
76 | holder.CourseSecImage.setImageResource(CourseSec.getImageId());
77 | holder.CourseSecName.setText("学号: "+CourseSec.getCourse_id()+" "+CourseSec.getCourse_name()+"\n学分:"+CourseSec.getCredit()+"\n成绩:"+CourseSec.getGrade());
78 | }
79 |
80 | @Override
81 | public int getItemCount() {
82 | return mCourseSecList.size();
83 | }
84 |
85 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Adapter/ScoreAdapter.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Adapter;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/26.
5 | * 显示学生未选课的信息,显示到SecondFragment中
6 | */
7 | import android.content.Context;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import com.clutch.student.Dao.ScoreDao;
17 | import com.clutch.student.Entity.Course;
18 | import java.util.List;
19 |
20 | import com.clutch.student.Fragment.FirstFragment;
21 | import com.clutch.student.Fragment.SecondFragment;
22 | import com.clutch.student.MainActivity;
23 | import com.clutch.student.MyApplication;
24 | import com.clutch.student.R;
25 |
26 | public class ScoreAdapter extends RecyclerView.Adapter{
27 | Context context = MyApplication.getInstance();
28 |
29 | private List mCourseList;
30 | private ScoreDao score = new ScoreDao(context);
31 | static class ViewHolder extends RecyclerView.ViewHolder {
32 | View CourseView;
33 | ImageView CourseImage;
34 | TextView CourseName;
35 |
36 | public ViewHolder(View view) {
37 | super(view);
38 | CourseView = view;
39 | CourseImage = (ImageView) view.findViewById(R.id.Course_image);
40 | CourseName = (TextView) view.findViewById(R.id.Course_name);
41 | }
42 | }
43 | public ScoreAdapter(List courseList) {
44 | mCourseList=courseList;
45 | }
46 | public ScoreAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
47 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.course_item, parent, false);
48 | final ScoreAdapter.ViewHolder holder = new ScoreAdapter.ViewHolder(view);
49 | holder.CourseView.setOnClickListener(new View.OnClickListener() {
50 | @Override
51 | public void onClick(View v) {
52 | int position = holder.getAdapterPosition();
53 | Course course = mCourseList.get(position);
54 | score.chooseCourse(MainActivity.getStudentId(),course.getId());
55 | Toast.makeText(v.getContext(), "选课成功!" , Toast.LENGTH_SHORT).show();
56 | SecondFragment.updata();
57 | FirstFragment.update();
58 |
59 | }
60 | });
61 | holder.CourseImage.setOnClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | int position = holder.getAdapterPosition();
65 | Course course = mCourseList.get(position);
66 | score.chooseCourse(MainActivity.getStudentId(),course.getId());
67 | Toast.makeText(v.getContext(), "选课成功! " , Toast.LENGTH_SHORT).show();
68 | SecondFragment.updata();
69 | FirstFragment.update();
70 |
71 | }
72 | });
73 | return holder;
74 | }
75 |
76 |
77 | /**
78 | * 将课程信息显示在textView上
79 | */
80 | public void onBindViewHolder(ScoreAdapter.ViewHolder holder, int position) {
81 | Course course = mCourseList.get(position);
82 | holder.CourseImage.setImageResource(course.getImageId());
83 | holder.CourseName.setText("课程号:"+course.getId()+" "+course.getName()+"\n学分:"+course.getCredit());
84 | }
85 |
86 | @Override
87 | public int getItemCount() {
88 | return mCourseList.size();
89 | }
90 |
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Adapter/StudentAdapter.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Adapter;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/19.
5 | */
6 |
7 |
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ImageView;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import com.clutch.student.Entity.Student;
17 | import com.clutch.student.Entity.Student_info;
18 | import com.clutch.student.R;
19 |
20 | import java.util.List;
21 |
22 | /**
23 | * 学生信息类适配器,将查找到的信息展示在ThirdFragment上
24 | * Student_info类,属性为图片Id,和一个字符串代表student中的各个属性,即每获取一个student对象将其转化成5个该对象,添加到List中。
25 | */
26 | public class StudentAdapter extends RecyclerView.Adapter{
27 |
28 | private List mStudentList;
29 |
30 | static class ViewHolder extends RecyclerView.ViewHolder {
31 | View StudentView;
32 | ImageView StudentImage;
33 | TextView StudentText;
34 |
35 | public ViewHolder(View view) {
36 | super(view);
37 | StudentView = view;
38 | StudentImage = (ImageView) view.findViewById(R.id.Student_image);
39 | StudentText = (TextView) view.findViewById(R.id.Student_text);
40 | }
41 | }
42 |
43 | public StudentAdapter(List StudentList) {
44 | mStudentList=StudentList;
45 | }
46 |
47 | @Override
48 | /**
49 | * 点击对应部分显示toast
50 | */
51 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
52 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.student_item, parent, false);
53 | final ViewHolder holder = new ViewHolder(view);
54 | holder.StudentView.setOnClickListener(new View.OnClickListener() {
55 | @Override
56 | public void onClick(View v) {
57 | int position = holder.getAdapterPosition();
58 | Student_info Student = mStudentList.get(position);
59 | }
60 | });
61 | holder.StudentImage.setOnClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | int position = holder.getAdapterPosition();
65 | Student_info Student = mStudentList.get(position);
66 | }
67 | });
68 | return holder;
69 | }
70 |
71 | @Override
72 | /**
73 | * 将课程信息显示在textView上
74 | */
75 | public void onBindViewHolder(ViewHolder holder, int position) {
76 | Student_info Student = mStudentList.get(position);
77 | holder.StudentImage.setImageResource(Student.getImage());
78 | holder.StudentText.setText(Student.getInfo());
79 | }
80 |
81 | @Override
82 | public int getItemCount() {
83 | return mStudentList.size();
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Adapter/ViewPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Adapter;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/17.
5 | */
6 |
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentPagerAdapter;
10 | import android.support.v4.app.FragmentTransaction;
11 | import android.view.ViewGroup;
12 |
13 | import com.clutch.student.Fragment.FirstFragment;
14 | import com.clutch.student.Fragment.SecondFragment;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 |
20 |
21 |
22 | public class ViewPagerAdapter extends FragmentPagerAdapter {
23 | private List mFragmentList = new ArrayList<>();
24 | private FragmentManager fm;
25 | public int getItemPosition(Object object) {
26 |
27 | if (object instanceof FirstFragment) {
28 | ((FirstFragment)object).update();
29 | }else if(object instanceof SecondFragment){
30 | ((SecondFragment)object).updata();
31 | }
32 | return super.getItemPosition(object);
33 | }
34 |
35 | public void setFragments(List fragments) {
36 | if (this.mFragmentList != null) {
37 | FragmentTransaction ft = fm.beginTransaction();
38 | for (Fragment f : this.mFragmentList) {
39 | ft.remove(f);
40 | }
41 | ft.commit();
42 | ft = null;
43 | fm.executePendingTransactions();
44 | }
45 | this.mFragmentList = fragments;
46 | notifyDataSetChanged();
47 | }
48 | public ViewPagerAdapter(FragmentManager manager) {
49 | super(manager);
50 | this.fm = manager;
51 | }
52 | @Override
53 | public Fragment getItem(int position) {
54 | return mFragmentList.get(position);
55 | }
56 |
57 | @Override
58 | public int getCount() {
59 | return mFragmentList.size();
60 | }
61 |
62 | public void addFragment(Fragment fragment) {
63 | mFragmentList.add(fragment);
64 | }
65 |
66 |
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/AddCourseActivity.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.DialogInterface;
5 | import android.content.Intent;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 |
12 | import com.clutch.student.Dao.CourseDao;
13 | import com.clutch.student.Entity.Course;
14 |
15 | public class AddCourseActivity extends AppCompatActivity {
16 | private EditText idText;
17 | private EditText nameText;
18 | private EditText creditText;
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_add_course);
23 | idText = (EditText)findViewById(R.id.studentId);
24 | nameText = (EditText)findViewById(R.id.courseId);
25 | creditText = (EditText)findViewById(R.id.credit);
26 | Button add = (Button)findViewById(R.id.add);
27 | Button delete = (Button)findViewById(R.id.delete);
28 | Button cancel = (Button)findViewById(R.id.cancel_a);
29 | add.setOnClickListener(new View.OnClickListener(){
30 | public void onClick(View v){
31 | String word;
32 | if(!EditCheck.CheckInt(idText.getText().toString(),"课程号",10000,99999)){
33 | showNormalDialog(EditCheck.getWarning());
34 | }
35 | else if(!EditCheck.CheckString(nameText.getText().toString(),"课程名",10)){
36 | showNormalDialog(EditCheck.getWarning());
37 | }
38 | else if(!EditCheck.CheckInt(creditText.getText().toString(),"学分",1,10)){
39 | showNormalDialog(EditCheck.getWarning());
40 | }
41 | else if(addDatebase()){
42 | word = "添加课程成功!";
43 | showNormalDialog(word);
44 | idText.setText("");
45 | nameText.setText("");
46 | creditText.setText("");
47 | // finish();
48 | }else{
49 | word = "添加课程失败,请重试!";
50 | showNormalDialog(word);
51 | }
52 | }
53 | });
54 | delete.setOnClickListener(new View.OnClickListener(){
55 | public void onClick(View v){
56 | String word ;
57 | if(idText.getText().toString().equals("")){
58 | word = "课程号不能为空!";
59 | showNormalDialog(word);
60 | }
61 | else if(deleteDatabase()){
62 | word = "删除课程成功!";
63 | showNormalDialog(word);
64 | idText.setText("");
65 | nameText.setText("");
66 | creditText.setText("");
67 | // finish();
68 | }else{
69 | word = "删除课程失败,请重试!";
70 | showNormalDialog(word);
71 | }
72 | }
73 | });
74 | cancel.setOnClickListener(new View.OnClickListener(){
75 | public void onClick(View v){
76 | finish();
77 | }
78 | });
79 |
80 | }
81 | private void showNormalDialog(String word){
82 |
83 | final AlertDialog.Builder normalDialog =
84 | new AlertDialog.Builder(AddCourseActivity.this);
85 | normalDialog.setTitle("提示");
86 | normalDialog.setMessage(word);
87 | normalDialog.setPositiveButton("确定",
88 | new DialogInterface.OnClickListener() {
89 | @Override
90 | public void onClick(DialogInterface dialog, int which) {
91 | normalDialog.setCancelable(true);
92 | //...To-do
93 | }
94 | });
95 |
96 | // 显示
97 | normalDialog.show();
98 | }
99 |
100 | /**
101 | * 向数据库添加课程信息
102 | */
103 | public boolean addDatebase(){
104 | CourseDao courseDao = new CourseDao(MyApplication.getInstance());
105 | int courseId = Integer.parseInt(idText.getText().toString());
106 | String courseName = nameText.getText().toString();
107 | int credit = Integer.parseInt(creditText.getText().toString());
108 | Course course = new Course(courseId,courseName,credit,R.drawable.health);
109 | if(courseDao.addCourse(course)){
110 | return true;
111 | }else{
112 | return false;
113 | }
114 | }
115 |
116 | /**
117 | * 在数据库删除课程信息
118 | */
119 | public boolean deleteDatabase(){
120 | CourseDao courseDao = new CourseDao(MyApplication.getInstance());
121 | int courseId = Integer.parseInt(idText.getText().toString());
122 | if(courseDao.deleteCourse(courseId)){
123 | return true;
124 | }else{
125 | return false;
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Dao/CourseDao.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Dao;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteConstraintException;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.util.Log;
9 | import android.widget.Toast;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import com.clutch.student.R;
13 | import com.clutch.student.Entity.Course;
14 | /**
15 | * Created by clutchyu on 2018/3/17.
16 | * 对course表进行数据库操作
17 | */
18 |
19 | public class CourseDao {
20 | private static final String TAG = "CourseDao";
21 |
22 | // 列定义
23 | private final String[] ORDER_COLUMNS = new String[] {"course_id","course_name","credit"};
24 |
25 | private Context context;
26 | private MyDatabaseHelper dbHelper;
27 |
28 | public CourseDao(Context context) {
29 | this.context = context;
30 | dbHelper = new MyDatabaseHelper(context);
31 | }
32 |
33 | /**
34 | * 判断表中是否有数据
35 | */
36 | public boolean isDataExist(){
37 | int count = 0;
38 |
39 | SQLiteDatabase db = null;
40 | Cursor cursor = null;
41 |
42 | try {
43 | db = dbHelper.getReadableDatabase();
44 | // select count(Id) from Orders
45 | cursor = db.query("course", new String[]{"COUNT(Id)"}, null, null, null, null, null);
46 |
47 | if (cursor.moveToFirst()) {
48 | count = cursor.getInt(0);
49 | }
50 | if (count > 0) return true;
51 | }
52 | catch (Exception e) {
53 | Log.e(TAG, "", e);
54 | }
55 | finally {
56 | if (cursor != null) {
57 | cursor.close();
58 | }
59 | if (db != null) {
60 | db.close();
61 | }
62 | }
63 | return false;
64 | }
65 | /**
66 | * 查询课程信息
67 | */
68 | public List getCourse(){
69 | SQLiteDatabase db = null;
70 | Cursor cursor = null;
71 | String sql = "select * from course";
72 | try {
73 | db = dbHelper.getReadableDatabase();
74 | cursor = db.rawQuery(sql,null);
75 | //cursor = db.rawQuery("select * from course",null);
76 | /* cursor = db.query(dbHelper.TABLE_NAME,
77 | ORDER_COLUMNS,
78 | "course_name = ?",
79 | new String[] {"math"},
80 | null, null, null);*/
81 | if (cursor.getCount() > 0) {
82 | List courseList = new ArrayList(cursor.getCount());
83 | while (cursor.moveToNext()) {
84 | Course course = parseCourse(cursor);
85 | courseList.add(course);
86 | }
87 | return courseList;
88 | }
89 | }
90 | catch (Exception e) {
91 | Log.e(TAG, "", e);
92 | }
93 | finally {
94 | if (cursor != null) {
95 | cursor.close();
96 | }
97 | if (db != null) {
98 | db.close();
99 | }
100 | }
101 |
102 | return null;
103 | }
104 | /**
105 | * 添加课程
106 | */
107 | public boolean addCourse(Course course) {
108 | SQLiteDatabase db = null;
109 | try {
110 | db = dbHelper.getWritableDatabase();
111 | db.beginTransaction();
112 | ContentValues values = new ContentValues();
113 | values.put("course_id",course.getId());
114 | values.put("course_name",course.getName());
115 | values.put("credit",course.getCredit());
116 | db.insertOrThrow("course",null,values);
117 | db.setTransactionSuccessful();
118 | return true;
119 | }catch (SQLiteConstraintException e){
120 | //Toast.makeText(context, "主键重复", Toast.LENGTH_SHORT).show();
121 | return false;
122 | }catch (Exception e){
123 | Log.e(TAG, "", e);
124 | }finally {
125 | if (db != null) {
126 | db.endTransaction();
127 | db.close();
128 | }
129 | }
130 | return false;
131 |
132 | }
133 | /**
134 | * 删除课程,以课程id
135 | */
136 | public boolean deleteCourse(int courseId) {
137 | SQLiteDatabase db = null;
138 | try {
139 | db = dbHelper.getWritableDatabase();
140 | db.beginTransaction();
141 | db.delete("course","course_id = ?",new String[]{String.valueOf(courseId)});
142 | db.setTransactionSuccessful();
143 | return true;
144 | }catch (SQLiteConstraintException e){
145 | //Toast.makeText(context, "主键重复", Toast.LENGTH_SHORT).show();
146 | return false;
147 | }catch (Exception e){
148 | Log.e(TAG, "", e);
149 | }finally {
150 | if (db != null) {
151 | db.endTransaction();
152 | db.close();
153 | }
154 | }
155 | return false;
156 | }
157 | /**
158 | * 将找到的数据转化为Course类
159 | */
160 | private Course parseCourse(Cursor cursor){
161 | Course course = new Course();
162 | int id = cursor.getInt(cursor.getColumnIndex("course_id"));
163 | course.setId(id);
164 | course.setName(cursor.getString(cursor.getColumnIndex("course_name")));
165 | course.setCredit(cursor.getInt(cursor.getColumnIndex("credit")));
166 | switch (id){
167 | case 10001:
168 | course.setImageId(R.drawable.math);
169 | break;
170 | case 10002:
171 | course.setImageId(R.drawable.chinese);
172 | break;
173 | case 10003:
174 | course.setImageId(R.drawable.english);
175 | break;
176 | case 10004:
177 | course.setImageId(R.drawable.physic);
178 | break;
179 | case 10005:
180 | course.setImageId(R.drawable.sport);
181 | break;
182 | default:
183 | course.setImageId(R.drawable.health);
184 | }
185 |
186 | return course;
187 | }
188 |
189 |
190 | }
191 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Dao/MyDatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Dao;
2 | import android.content.Context;
3 | import android.database.sqlite.SQLiteDatabase;
4 | import android.database.sqlite.SQLiteOpenHelper;
5 | /**
6 | * Created by clutchyu on 2018/3/17.
7 | * 创建表,运行MainActivity时首先创建该对象dbHelper
8 | */
9 |
10 | public class MyDatabaseHelper extends SQLiteOpenHelper {
11 | private static final int DB_VERSION = 1;
12 | private static final String DB_NAME = "StudentSystem.db";
13 | public static final String CREATE_STUDENT = "create table student(" +
14 | "id int primary key," +
15 | "name text not null," +
16 | "sex text not null," +
17 | "age int not null,"+
18 | "phone text not null)";
19 | public static final String CREATE_COURSE = "create table course(" +
20 | "course_id int primary key," +
21 | "course_name text unique," +
22 | "credit int not null)" ;
23 | public static final String CREATE_SCORE = "create table score(" +
24 | "student_id int not null," +
25 | "course_id int not null," +
26 | "grade int," +
27 | "constraint score_PK primary key(student_id,course_id)," +
28 | "constraint fk_SID foreign key(student_id) references student(id)on delete cascade," +
29 | "constraint fk_CID foreign key(course_id) references course(course_id)on delete cascade)";
30 | public static final String CREATE_LOG = "create table log(" +
31 | "student_id int primary key," +
32 | "password text not null," +
33 | "constraint fk_ID foreign key(student_id) references student(id) on delete cascade)";
34 |
35 |
36 |
37 | private Context mContext;
38 |
39 | //构造方法:第一个参数Context,第二个参数数据库名,第三个参数cursor允许我们在查询数据的时候返回一个自定义的光标位置,一般传入的都是null,第四个参数表示目前库的版本号(用于对库进行升级)
40 | public MyDatabaseHelper(Context context){
41 | super(context, DB_NAME, null, DB_VERSION);
42 | mContext = context;
43 | }
44 |
45 | @Override
46 | public void onCreate(SQLiteDatabase db) {
47 | //调用SQLiteDatabase中的execSQL()执行建表语句。
48 | db.execSQL(CREATE_STUDENT);
49 | db.execSQL(CREATE_COURSE);
50 | db.execSQL(CREATE_SCORE);
51 | db.execSQL(CREATE_LOG);
52 | init(db);
53 | }
54 |
55 | @Override
56 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
57 | }
58 |
59 | /**
60 | * 插入初始化数据
61 | */
62 | public void init(SQLiteDatabase db){
63 | String sql[] = {"insert into student values (10001,'小李','男',20,'123456789')",
64 | "insert into student values (10002,'小王','男',20,'123456789')",
65 | "insert into student values (10003,'小张','女',20,'123456789')",
66 | "insert into student values (10004,'小周','男',20,'123456789')",
67 | "insert into student values (10005,'小吾','女',20,'123456789')",
68 | "insert into student values (10006,'小贾','男',20,'123456789')",
69 | "insert into student values (00000,'管理员','男',0,'0000000')",
70 | "insert into course values (10001,'数学',5)",
71 | "insert into course values (10002,'语文',5)",
72 | "insert into course values (10003,'英语',5)",
73 | "insert into course values (10004,'物理',5)",
74 | "insert into course values (10005,'体育',5)",
75 | "insert into course values (10006,'数据库',5)",
76 | "insert into course values (10007,'系统结构',6)",
77 | "insert into course values (10008,'组成原理',5)",
78 | "insert into course values (10009,'程序设计',6)",
79 | "insert into course values (100010,'网络',5)",
80 | "insert into score values (10001,10001,95)",
81 | "insert into score values (10001,10002,95)",
82 | "insert into score values (10001,10003,95)",
83 | "insert into score values (10002,10001,95)",
84 | "insert into score values (10002,10006,95)",
85 | "insert into score values (10005,10007,95)",
86 | "insert into log values (10001,'123456')",
87 | "insert into log values (10002,'123456')",
88 | "insert into log values (10003,'123456')",
89 | "insert into log values (10004,'123456')",
90 | "insert into log values (10005,'123456')",
91 | "insert into log values (10006,'123456')",
92 | "insert into log values (00000,'000000')",
93 | };
94 | for(int i= 0;i 0) return true;
50 | }
51 | catch (Exception e) {
52 | Log.e(TAG, "", e);
53 | }
54 | finally {
55 | if (cursor != null) {
56 | cursor.close();
57 | }
58 | if (db != null) {
59 | db.close();
60 | }
61 | }
62 | return false;
63 | }
64 | /**
65 | * 录入选课信息及成绩
66 | */
67 | public boolean setScore(Score score){
68 | SQLiteDatabase db = null;
69 | try {
70 | db = dbHelper.getWritableDatabase();
71 | db.beginTransaction();
72 | ContentValues values = new ContentValues();
73 | values.put("student_id",score.getStudentId());
74 | values.put("course_id",score.getCourseId());
75 | values.put("grade",score.getGrade()); //此项数据可能为空
76 | db.insertOrThrow("student",null,values);
77 | db.setTransactionSuccessful();
78 | return true;
79 | }catch (SQLiteConstraintException e){
80 | //Toast.makeText(context, "主键重复", Toast.LENGTH_SHORT).show();
81 | return false;
82 | }catch (Exception e){
83 | Log.e(TAG, "", e);
84 | }finally {
85 | if (db != null) {
86 | db.endTransaction();
87 | db.close();
88 | }
89 | }
90 | return false;
91 | }
92 | /**
93 | * 查询选课情况及课程分数,根据学生Id
94 | */
95 | public List getScore(int student_id){
96 | SQLiteDatabase db = null;
97 | Cursor cursor = null;
98 | String sql = "select c.course_id,c.course_name,credit,grade " +
99 | "from course as c,score as s " +
100 | "where s.student_id= ? and s.course_id=c.course_id";
101 | try{
102 | db = dbHelper.getWritableDatabase();
103 | cursor = db.rawQuery(sql,new String[]{String.valueOf(student_id)});
104 | if (cursor.getCount() > 0) {
105 | List scoreList = new ArrayList(cursor.getCount());
106 | while (cursor.moveToNext()) {
107 | CourseSec course = parseCourseSec(cursor);
108 | scoreList.add(course);
109 | }
110 |
111 | return scoreList;
112 | }
113 |
114 |
115 | }catch (Exception e) {
116 | Log.e(TAG, "", e);
117 | }
118 | finally {
119 | if (cursor != null) {
120 | cursor.close();
121 | }
122 | if (db != null) {
123 | db.close();
124 | }
125 | }
126 |
127 | return null;
128 |
129 | }
130 | /**
131 | * 查询学生已选课程,Course类
132 | */
133 | public List getCourse(int id)
134 | {
135 | SQLiteDatabase db = null;
136 | Cursor cursor = null;
137 | String sql = "select c.course_id,c.course_name,credit " +
138 | "from course as c,score as s " +
139 | "where s.student_id= ? and s.course_id=c.course_id"; //出去socre表中已选的课程
140 | try {
141 | db = dbHelper.getReadableDatabase();
142 | cursor = db.rawQuery(sql,new String[]{String.valueOf(id)});
143 | if (cursor.getCount() > 0) {
144 | List courseList = new ArrayList(cursor.getCount());
145 | while (cursor.moveToNext()) {
146 | Course course = parseCourse(cursor);
147 | courseList.add(course);
148 | }
149 | return courseList;
150 | }
151 | }
152 | catch (Exception e) {
153 | Log.e(TAG, "", e);
154 | }
155 | finally {
156 | if (cursor != null) {
157 | cursor.close();
158 | }
159 | if (db != null) {
160 | db.close();
161 | }
162 | }
163 |
164 | return null;
165 | }
166 | /**
167 | * 查询学生未选课程信息
168 | */
169 | public List getUnCourse(int id){
170 | SQLiteDatabase db = null;
171 | Cursor cursor = null;
172 | String sql = "select * from course where course_id not in" +
173 | "(select course_id from score where student_id = ?)"; //除去socre表中已选的课程
174 | try {
175 | db = dbHelper.getReadableDatabase();
176 | cursor = db.rawQuery(sql,new String[]{String.valueOf(id)});
177 | if (cursor.getCount() > 0) {
178 | List courseList = new ArrayList(cursor.getCount());
179 | while (cursor.moveToNext()) {
180 | Course course = parseCourse(cursor);
181 | courseList.add(course);
182 | }
183 | return courseList;
184 | }
185 | }
186 | catch (Exception e) {
187 | Log.e(TAG, "", e);
188 | }
189 | finally {
190 | if (cursor != null) {
191 | cursor.close();
192 | }
193 | if (db != null) {
194 | db.close();
195 | }
196 | }
197 |
198 | return null;
199 | }
200 | /**
201 | * 学生选课
202 | */
203 | public boolean chooseCourse(int student_id,int course_id){
204 | SQLiteDatabase db = null;
205 | try {
206 | db = dbHelper.getWritableDatabase();
207 | db.beginTransaction();
208 | ContentValues values = new ContentValues();
209 | values.put("student_id",student_id);
210 | values.put("course_id",course_id);
211 | db.insertOrThrow("score",null,values);
212 | db.setTransactionSuccessful();
213 | return true;
214 | }catch (SQLiteConstraintException e){
215 | //Toast.makeText(context, "主键重复", Toast.LENGTH_SHORT).show();
216 | return false;
217 | }catch (Exception e){
218 | Log.e(TAG, "", e);
219 | }finally {
220 | if (db != null) {
221 | db.endTransaction();
222 | db.close();
223 | }
224 | }
225 | return false;
226 | }
227 | /**
228 | * 录入学生成绩,需要先判断学生是否选了该门课程,没选提示错误
229 | * 进行update操作即便是表中数据不符合要更新的条件,无法进行更行,也不会产生异常
230 | * 先对要进行更新的学生id和课程id进行查询,看表中是否有对应的项,如果有则进行update操作,没有则返回false
231 | */
232 | public boolean writeScore(Score score){
233 | SQLiteDatabase db = null;
234 | String sql = "update score set grade = ? where student_id = ? and course_id = ?";
235 | try {
236 | db = dbHelper.getWritableDatabase();
237 | db.beginTransaction();
238 | if(checkCourse(score.getStudentId(),score.getCourseId())){
239 | db.execSQL(sql,new Object[]{score.getGrade(),score.getStudentId(),score.getCourseId()});
240 | db.setTransactionSuccessful();
241 | return true;
242 | }else{
243 | return false;
244 | }
245 | }catch (SQLiteConstraintException e){
246 | return false;
247 | }catch (Exception e) {
248 | Log.e(TAG, "", e);
249 |
250 | }
251 | finally {
252 | if (db != null) {
253 | db.endTransaction();
254 | db.close();
255 | }
256 | }
257 | return false;
258 | }
259 | /**
260 | * 根据学生id,和课程Id,去Score中查询是否有对应项,有返回true,无返回false
261 | */
262 | private boolean checkCourse(int student_id,int course_id){
263 | SQLiteDatabase db = dbHelper.getReadableDatabase();
264 | Cursor cursor = null;
265 | String sql = "select * from score where student_id = ? and course_id = ?";
266 | cursor = db.rawQuery(sql,new String[]{String.valueOf(student_id),String.valueOf(course_id)});
267 | if(cursor.getCount()>0){
268 | return true;
269 | }else{
270 | return false;
271 | }
272 |
273 |
274 | }
275 | /**
276 | * 将查询到的数据转换为CourseSec类对象
277 | * @param cursor
278 | * @return
279 | */
280 | private CourseSec parseCourseSec(Cursor cursor) {
281 | CourseSec course = new CourseSec();
282 | int id = cursor.getInt(cursor.getColumnIndex("course_id"));
283 | course.setCourse_id(cursor.getInt(cursor.getColumnIndex("course_id")));
284 | course.setCourse_name(cursor.getString(cursor.getColumnIndex("course_name")));
285 | course.setCredit(cursor.getInt(cursor.getColumnIndex("credit")));
286 | course.setGrade(cursor.getInt(cursor.getColumnIndex("grade")));
287 | switch (id){
288 | case 10001:
289 | course.setImageId(R.drawable.math);
290 | break;
291 | case 10002:
292 | course.setImageId(R.drawable.chinese);
293 | break;
294 | case 10003:
295 | course.setImageId(R.drawable.english);
296 | break;
297 | case 10004:
298 | course.setImageId(R.drawable.physic);
299 | break;
300 | case 10005:
301 | course.setImageId(R.drawable.sport);
302 | break;
303 | default:
304 | course.setImageId(R.drawable.health);
305 | }
306 | return course;
307 | }
308 | /**
309 | * 将找到的数据转化为Course类
310 | */
311 | private Course parseCourse(Cursor cursor){
312 | Course course = new Course();
313 | int id = cursor.getInt(cursor.getColumnIndex("course_id"));
314 | course.setId(id);
315 | course.setName(cursor.getString(cursor.getColumnIndex("course_name")));
316 | course.setCredit(cursor.getInt(cursor.getColumnIndex("credit")));
317 | switch (id){
318 | case 10001:
319 | course.setImageId(R.drawable.math);
320 | break;
321 | case 10002:
322 | course.setImageId(R.drawable.chinese);
323 | break;
324 | case 10003:
325 | course.setImageId(R.drawable.english);
326 | break;
327 | case 10004:
328 | course.setImageId(R.drawable.physic);
329 | break;
330 | case 10005:
331 | course.setImageId(R.drawable.sport);
332 | break;
333 | default:
334 | course.setImageId(R.drawable.health);
335 | }
336 |
337 | return course;
338 | }
339 | }
340 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Dao/StudentDao.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Dao;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteConstraintException;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.util.Log;
9 |
10 | import com.clutch.student.Entity.Student_info;
11 | import com.clutch.student.Entity.Student;
12 | import com.clutch.student.R;
13 |
14 | import java.sql.SQLData;
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | /**
19 | * Created by clutchyu on 2018/3/19.
20 | * 对student表进行数据库操作
21 | */
22 |
23 | public class StudentDao {
24 | private static final String TAG = "StudentDao";
25 |
26 | // 列定义
27 | private final String[] ORDER_COLUMNS = new String[] {"id","name","sex","age","phone"};
28 |
29 | private Context context;
30 | private MyDatabaseHelper dbHelper;
31 |
32 | public StudentDao(Context context) {
33 | this.context = context;
34 | dbHelper = new MyDatabaseHelper(context);
35 | }
36 | /**
37 | * 判断表中是否有数据
38 | */
39 | public boolean isDataExist(){
40 | int count = 0;
41 |
42 | SQLiteDatabase db = null;
43 | Cursor cursor = null;
44 |
45 | try {
46 | db = dbHelper.getReadableDatabase();
47 | // select count(Id) from Orders
48 | cursor = db.query("student", new String[]{"COUNT(Id)"}, null, null, null, null, null);
49 |
50 | if (cursor.moveToFirst()) {
51 | count = cursor.getInt(0);
52 | }
53 | if (count > 0) return true;
54 | }
55 | catch (Exception e) {
56 | Log.e(TAG, "", e);
57 | }
58 | finally {
59 | if (cursor != null) {
60 | cursor.close();
61 | }
62 | if (db != null) {
63 | db.close();
64 | }
65 | }
66 | return false;
67 | }
68 |
69 |
70 |
71 | /**
72 | * 根据学生Id查询学生信息
73 | */
74 |
75 | public List getStudent(int id){
76 | SQLiteDatabase db = null;
77 | Cursor cursor = null;
78 |
79 | try {
80 | db = dbHelper.getReadableDatabase();
81 | String sql = "select * from student where id = ?";
82 | cursor = db.rawQuery(sql,new String[]{String.valueOf(id)});
83 | if (cursor.getCount() > 0) {
84 | Student student = new Student();
85 | while(cursor.moveToNext()){
86 | student = parseStudent(cursor);
87 | }
88 |
89 | List StudentList = new ArrayList(5);
90 | Student_info sid = new Student_info(R.drawable.id,Integer.toString(student.getId()));
91 | StudentList.add(sid);
92 | Student_info sname = new Student_info(R.drawable.name,student.getName());
93 | StudentList.add(sname);
94 | Student_info sex = new Student_info(R.drawable.sex,student.getSex());
95 | StudentList.add(sex);
96 | Student_info age = new Student_info(R.drawable.age,Integer.toString(student.getAge()));
97 | StudentList.add(age);
98 | Student_info phone = new Student_info(R.drawable.phone,student.getPhone());
99 | StudentList.add(phone);
100 |
101 | return StudentList;
102 | }
103 | }
104 | catch (Exception e) {
105 | Log.e(TAG, "", e);
106 | }
107 | finally {
108 | if (cursor != null) {
109 | cursor.close();
110 | }
111 | if (db != null) {
112 | db.close();
113 | }
114 | }
115 | return null;
116 | }
117 | /**
118 | * 更新学生信息,学生用户自己修改个人信息,根据Id进行更新,无法更改Id
119 | */
120 | public Student updateStudent(Student student){
121 | SQLiteDatabase db = null;
122 | try {
123 | db = dbHelper.getWritableDatabase();
124 | db.beginTransaction();
125 | ContentValues value = new ContentValues();
126 | value.put("name",student.getName());
127 | value.put("sex",student.getSex());
128 | value.put("age",student.getAge());
129 | value.put("phone",student.getPhone());
130 | db.update("student",value,"id = ?",new String[]{String.valueOf(student.getId())});
131 | db.setTransactionSuccessful();
132 | return student; //直接返回了参数中的Student类对象,并没有重新查询数据库中刚进行更新的对象,结果是一样的
133 | }catch (Exception e) {
134 | Log.e(TAG, "", e);
135 | }
136 | finally {
137 | if (db != null) {
138 | db.endTransaction();
139 | db.close();
140 | }
141 | }
142 | return null;
143 | }
144 |
145 | /**
146 | * 插入学生信息,用户注册
147 | */
148 | public boolean insertStudent(Student student){
149 | SQLiteDatabase db = null;
150 | try {
151 | db = dbHelper.getWritableDatabase();
152 | db.beginTransaction();
153 | ContentValues values = new ContentValues();
154 | values.put("id",student.getId());
155 | values.put("name",student.getName());
156 | values.put("sex",student.getSex());
157 | values.put("age",student.getAge());
158 | values.put("phone",student.getPhone());
159 | db.insertOrThrow("student",null,values);
160 | db.setTransactionSuccessful();
161 | return true;
162 | }catch (SQLiteConstraintException e){
163 | //Toast.makeText(context, "主键重复", Toast.LENGTH_SHORT).show();
164 | return false;
165 | }catch (Exception e){
166 | Log.e(TAG, "", e);
167 | }finally {
168 | if (db != null) {
169 | db.endTransaction();
170 | db.close();
171 | }
172 | }
173 | return false;
174 | }
175 | /**
176 | * 转化为Student类
177 | * */
178 |
179 | private Student parseStudent(Cursor cursor) {
180 | Student student = new Student();
181 | student.setId(cursor.getInt(cursor.getColumnIndex("id")));
182 | student.setName(cursor.getString(cursor.getColumnIndex("name")));
183 | student.setSex(cursor.getString(cursor.getColumnIndex("sex")));
184 | student.setAge(cursor.getInt(cursor.getColumnIndex("age")));
185 | student.setPhone(cursor.getString(cursor.getColumnIndex("phone")));
186 | student.setImageId(R.drawable.health);
187 | return student;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Dao/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Dao;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteConstraintException;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.util.Log;
9 |
10 | import com.clutch.student.Entity.User;
11 |
12 | /**
13 | * Created by clutchyu on 2018/3/26.
14 | * 对log表进行数据库操作
15 | */
16 |
17 | public class UserDao {
18 | private Context context;
19 | private MyDatabaseHelper dbHelper;
20 |
21 | public UserDao(Context context) {
22 | this.context = context;
23 | dbHelper = new MyDatabaseHelper(context);
24 | }
25 |
26 | /**
27 | * 检查登录表中是否有对应的账号
28 | */
29 | public boolean check(int id, String password) {
30 | SQLiteDatabase db = null;
31 | Cursor cursor = null;
32 | String sql = "select password from log where student_id = ?";
33 | try {
34 | db = dbHelper.getReadableDatabase();
35 | cursor = db.rawQuery(sql, new String[]{String.valueOf(id)});
36 |
37 | if (cursor.getCount() > 0) {
38 | while (cursor.moveToNext()) {
39 | User user = new User();
40 | String passwd = cursor.getString(cursor.getColumnIndex("password"));
41 | if(passwd.equals(password)){
42 | return true;
43 | }
44 |
45 | }
46 |
47 | }
48 |
49 |
50 | } catch (Exception e) {
51 |
52 | } /*finally {
53 | if (cursor != null) {
54 | cursor.close();
55 | }
56 | if (db != null) {
57 | db.close();
58 | }
59 | }*/
60 |
61 | return false;
62 | }
63 | /**
64 | * 向表中插入数据
65 | */
66 | public boolean insertLog(int studentId,String password){
67 | SQLiteDatabase db = null;
68 | try {
69 | db = dbHelper.getWritableDatabase();
70 | db.beginTransaction();
71 | ContentValues values = new ContentValues();
72 | values.put("student_id",studentId);
73 | values.put("password",password);
74 | db.insertOrThrow("log",null,values);
75 | db.setTransactionSuccessful();
76 | return true;
77 | }catch (SQLiteConstraintException e){
78 | //Toast.makeText(context, "主键重复", Toast.LENGTH_SHORT).show();
79 | return false;
80 | }catch (Exception e){
81 |
82 | }finally {
83 | if (db != null) {
84 | db.endTransaction();
85 | db.close();
86 | }
87 | }
88 | return false;
89 | }
90 | /**
91 | * 修改密码
92 | */
93 | public boolean modifyPasswd(User user,String newPasswd){
94 | SQLiteDatabase db = null;
95 | String sql = "update log set password = ? where student_id = ?";
96 | try {
97 | db = dbHelper.getWritableDatabase();
98 | db.beginTransaction();
99 | if(check(user.getId(),user.getPassword())){
100 | db.execSQL(sql,new Object[]{newPasswd,user.getId()});
101 | db.setTransactionSuccessful();
102 | return true;
103 | }
104 | else {
105 | return false;
106 | }
107 | }catch (SQLiteConstraintException e){
108 | //Toast.makeText(context, "主键重复", Toast.LENGTH_SHORT).show();
109 | return false;
110 | }catch (Exception e){
111 |
112 | }finally {
113 | if (db != null) {
114 | db.endTransaction();
115 | db.close();
116 | }
117 | }
118 | return false;
119 | }
120 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/EditCheck.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/31.
5 | * 用于数据输入检验
6 | */
7 |
8 | public class EditCheck {
9 | private static String warning;
10 | public EditCheck(){
11 |
12 | }
13 | public static String getWarning(){return warning;}
14 | public static boolean CheckInt(String input,String label,int min,int max){
15 | if(input.equals("")) {
16 | warning = label + "不能为空!";
17 | return false;
18 | }
19 | else {
20 | try{
21 | int value = Integer.parseInt(input);
22 | if(valuemax) {
23 | warning = label + "应在" + min + "至" + max + "区间";
24 | return false;
25 | }
26 | }catch(RuntimeException e){
27 | warning =label+"格式错误!";
28 | return false;
29 | }
30 | }
31 | return true;
32 | }
33 | public static boolean CheckString(String input,String label,int size){
34 | if(input.equals("")) {
35 | warning = label + "不能为空!";
36 | return false;
37 | }
38 | else if(input.length()>size){
39 | warning = label + "长度错误!";
40 | }
41 | return true;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Entity/Course.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Entity;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/17.
5 | */
6 | /**
7 | * 课程类,课程号,课程名,学分,图片id
8 | */
9 | public class Course {
10 | private int courseId;
11 | private String courseName;
12 | private int credit;
13 | private int imageId;
14 | public Course(){
15 |
16 | }
17 | public Course(int courseId,String courseName,int credit,int imageId){
18 | this.courseId = courseId;
19 | this.courseName = courseName;
20 | this.credit = credit;
21 | this.imageId = imageId;
22 | }
23 |
24 | public int getId(){
25 | return courseId;
26 | }
27 | public void setId(int id){this.courseId = id;}
28 | public String getName(){
29 | return courseName;
30 | }
31 | public void setName(String name){this.courseName = name;}
32 | public int getCredit(){
33 | return credit;
34 | }
35 | public void setCredit(int credit){this.credit = credit;}
36 | public int getImageId(){
37 | return imageId;
38 | }
39 | public void setImageId(int id){this.imageId = id;}
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Entity/CourseSec.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Entity;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/21.
5 | * 展示学生选课及对应课程分数的类
6 | */
7 |
8 | public class CourseSec {
9 | private int course_id;
10 | private String course_name;
11 | private int credit;
12 | private int grade;
13 | private int imageId;
14 | public CourseSec(){
15 |
16 | }
17 | public CourseSec(int course_id,String course_name,int credit,int grade,int imageId){
18 | this.course_id = course_id;
19 | this.course_name = course_name;
20 | this.credit = credit;
21 | this.grade = grade;
22 | this.imageId = imageId;
23 | }
24 | public int getCourse_id(){return this.course_id;}
25 | public String getCourse_name(){return this.course_name;}
26 | public int getCredit(){return this.credit;}
27 | public int getGrade(){return this.grade;}
28 | public int getImageId(){return this.imageId;}
29 | public void setCourse_id(int course_id){this.course_id = course_id;}
30 | public void setCourse_name(String course_name){this.course_name = course_name;}
31 | public void setCredit(int credit){this.credit = credit;}
32 | public void setGrade(int grade){this.grade = grade;}
33 | public void setImageId(int imageId){this.imageId = imageId;}
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Entity/Score.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Entity;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/21.
5 | * 选课信息类,课程Id,学生Id,分别对应各自表中的属性,有外键约束
6 | * 成绩grade为可空属性,即学生选课并未结课,结课后由管理员录入成绩
7 | * 学生无权限修改该表中的数据
8 | */
9 |
10 | public class Score {
11 | private int course_id;
12 | private int student_id;
13 | private int grade;
14 | public Score(){
15 |
16 | }
17 | public Score(int course,int student,int grade){
18 | course_id = course;
19 | student_id = student;
20 | this.grade = grade;
21 | }
22 | public int getCourseId(){return this.course_id;}
23 | public void setCourseId(int course_id){this.course_id = course_id;}
24 | public int getStudentId(){return this.student_id;}
25 | public void setStudentId(int student_id){this.student_id = student_id;}
26 | public int getGrade(){return this.grade;}
27 | public void setGrade(int grade){this.grade = grade;}
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Entity/Student.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Entity;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/19.
5 | * 学生实体类,id,name,sex,age,phone
6 | */
7 |
8 | public class Student {
9 | private int id;
10 | private String name;
11 | private String sex;
12 | private int age;
13 | private String phone;
14 | private int imageId;
15 | public Student(){
16 |
17 | }
18 | public Student(int id,String name,String sex,int age,String phone,int imageId){
19 | this.id = id;
20 | this.name = name;
21 | this.sex = sex;
22 | this. age = age;
23 | this. phone = phone;
24 | this.imageId = imageId;
25 | }
26 | public int getId(){return id;}
27 | public void setId(int id){this.id=id;}
28 | public String getName(){return name;}
29 | public void setName(String name){this.name = name;}
30 | public String getSex(){return this.sex;}
31 | public void setSex(String sex){this.sex = sex;}
32 | public int getAge(){return this.age;}
33 | public void setAge(int age){this.age=age;}
34 | public String getPhone(){return this.phone;}
35 | public void setPhone(String phone){this.phone=phone;}
36 | public int getImageId(){return imageId;}
37 | public void setImageId(int id){this.imageId = id;}
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Entity/Student_info.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Entity;
2 |
3 |
4 | /**
5 | * Created by clutchyu on 2018/3/19.
6 | * 拆分学生信息的内部类,用于单项展示学生属性在RecycleView上
7 | */
8 |
9 | public class Student_info{
10 | private int image;
11 | private String info;
12 | public Student_info(){
13 |
14 | }
15 | public Student_info(int image,String info){
16 | this.image = image;
17 | this.info = info;
18 | }
19 | public int getImage(){return this.image;}
20 | public void setImage(int image){this.image = image;}
21 | public String getInfo(){return this.info;}
22 | public void setInfo(String info){this.info = info;}
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Entity/User.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Entity;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/26.
5 | * 登录信息类
6 | */
7 |
8 | public class User {
9 | private int student_id;
10 | private String password;
11 | public User(){
12 |
13 | }
14 | public User(int student_id, String password){
15 | this.student_id = student_id;
16 | this.password = password;
17 | }
18 | public int getId(){return student_id;}
19 | public void setStudent_id(int id){student_id=id;}
20 | public String getPassword(){return password;}
21 | public void setPassword(String password){this.password=password;}
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Fragment/FirstFragment.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Fragment;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/17.
5 | * BottomNavigationView对应的第一个Fragment
6 | * 显示学生已选课程信息,整个页面布局为一个RecyclerView
7 | */
8 |
9 |
10 | import android.content.Context;
11 | import android.os.Bundle;
12 | import android.support.v4.app.Fragment;
13 | import android.support.v7.widget.DividerItemDecoration;
14 | import android.support.v7.widget.LinearLayoutManager;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 |
19 |
20 | import com.clutch.student.Adapter.CourseSecAdapter;
21 | import com.clutch.student.Dao.ScoreDao;
22 | import com.clutch.student.Entity.CourseSec;
23 | import com.clutch.student.MainActivity;
24 | import com.clutch.student.MyApplication;
25 | import com.clutch.student.R;
26 | import android.support.v7.widget.RecyclerView;
27 | import android.widget.TextView;
28 | import java.util.List;
29 |
30 |
31 | public class FirstFragment extends Fragment {
32 | static Context context = MyApplication.getInstance();
33 | private static ScoreDao course = new ScoreDao(context);
34 | private static RecyclerView recyclerView;
35 | private static TextView emptyText;
36 | private static List CourseList;
37 | public FirstFragment() {
38 | // Required empty public constructor
39 | }
40 | @Override
41 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
42 | Bundle savedInstanceState) {
43 | View view = inflater.inflate(R.layout.fragment_first, container, false);
44 | // initCourse();
45 | recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
46 | emptyText = (TextView) view.findViewById(R.id.empty_text); //用于在无数据时进行提示
47 | CourseList = course.getScore(MainActivity.getStudentId()); //获取已选课程的List
48 | if(CourseList==null){
49 | //若数据为空,则显示emptyText,隐藏recyclerView
50 | emptyText.setVisibility(View.VISIBLE);
51 | recyclerView.setVisibility(View.GONE);
52 | }else {
53 | LinearLayoutManager layoutManager = new LinearLayoutManager(context); //线性布局
54 | recyclerView.setLayoutManager(layoutManager); //RecyclerView加载线性布局
55 | CourseSecAdapter adapter = new CourseSecAdapter(CourseList); //创建课程类适配器,参数为刚查询到的存有课程信息的CourseList
56 | recyclerView.setAdapter(adapter); //将适配器加载入recyclerView中
57 | //为RecyclerView中的每一项加分割线
58 | DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),layoutManager.getOrientation());
59 | recyclerView.addItemDecoration(mDividerItemDecoration);
60 | }
61 | // Inflate the layout for this fragment
62 | return view;
63 | }
64 | /**
65 | * 刷新数据,点击对应课程在Adapter中调用该函数实现页面刷新
66 | * 内容为重新查询数据库中的数据放入recyclerView
67 | */
68 | public static void update() {
69 | CourseList = course.getScore(MainActivity.getStudentId());
70 | if(CourseList==null){
71 | emptyText.setVisibility(View.VISIBLE);
72 | recyclerView.setVisibility(View.GONE);
73 | }else {
74 | emptyText.setVisibility(View.GONE);
75 | recyclerView.setVisibility(View.VISIBLE);
76 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
77 | recyclerView.setLayoutManager(layoutManager);
78 | CourseSecAdapter adapter = new CourseSecAdapter(CourseList);
79 | recyclerView.setAdapter(adapter);
80 | DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),layoutManager.getOrientation());
81 | recyclerView.addItemDecoration(mDividerItemDecoration);
82 | }
83 | }
84 |
85 |
86 |
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Fragment/ManagerFirstFragment.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Fragment;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v7.widget.DividerItemDecoration;
9 | import android.support.v7.widget.LinearLayoutManager;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.Button;
15 | import android.widget.TextView;
16 |
17 | import com.clutch.student.Adapter.CourseAdapter;
18 | import com.clutch.student.AddCourseActivity;
19 | import com.clutch.student.Dao.CourseDao;
20 | import com.clutch.student.Entity.Course;
21 | import com.clutch.student.Entity.CourseSec;
22 | import com.clutch.student.MainActivity;
23 | import com.clutch.student.MyApplication;
24 | import com.clutch.student.R;
25 |
26 | import java.util.List;
27 |
28 | /**
29 | * Created by clutchyu on 2018/3/27.
30 | * 以管理员身份登入系统的第一个界面,显示所有课程信息及选课人数,底部有添加课程和删除课程的按钮
31 | */
32 |
33 | public class ManagerFirstFragment extends Fragment {
34 | static Context context = MyApplication.getInstance();
35 | private CourseDao course = new CourseDao(context);
36 | private static RecyclerView recyclerView;
37 | private static TextView emptyText;
38 | private Button add;
39 | private static List CourseList;
40 | public ManagerFirstFragment(){}
41 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
42 | Bundle savedInstanceState) {
43 | View view = inflater.inflate(R.layout.fragment_manager_first, container, false);
44 | recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
45 | emptyText = (TextView) view.findViewById(R.id.empty_text);
46 | add = (Button) view.findViewById(R.id.add);
47 | CourseList = course.getCourse();
48 | if(CourseList==null){
49 | emptyText.setVisibility(View.VISIBLE);
50 | recyclerView.setVisibility(View.GONE);
51 | }else{
52 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
53 | recyclerView.setLayoutManager(layoutManager);
54 | CourseAdapter adapter = new CourseAdapter(CourseList);
55 | recyclerView.setAdapter(adapter);
56 | DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),layoutManager.getOrientation());
57 | recyclerView.addItemDecoration(mDividerItemDecoration);
58 | }
59 |
60 | add.setOnClickListener(new View.OnClickListener(){
61 | public void onClick(View v) {
62 | //跳转到添加课程页面
63 | Intent intent = new Intent(context, AddCourseActivity.class);
64 | startActivity(intent);
65 | }
66 | });
67 |
68 |
69 |
70 | return view;
71 | }
72 | public void onResume(){
73 | super.onResume();
74 | CourseList = course.getCourse();
75 | if(CourseList==null){
76 | emptyText.setVisibility(View.VISIBLE);
77 | recyclerView.setVisibility(View.GONE);
78 | }else{
79 | emptyText.setVisibility(View.GONE);
80 | recyclerView.setVisibility(View.VISIBLE);
81 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
82 | recyclerView.setLayoutManager(layoutManager);
83 | CourseAdapter adapter = new CourseAdapter(CourseList);
84 | recyclerView.setAdapter(adapter);
85 | DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),layoutManager.getOrientation());
86 | recyclerView.addItemDecoration(mDividerItemDecoration);
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Fragment/ManagerSecondFragment.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Fragment;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.DialogInterface;
5 | import android.support.v4.app.Fragment;
6 | import android.content.Context;
7 | import android.os.Bundle;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.Button;
12 | import android.widget.EditText;
13 | import android.widget.Toast;
14 |
15 | import com.clutch.student.AddCourseActivity;
16 | import com.clutch.student.Dao.ScoreDao;
17 | import com.clutch.student.EditCheck;
18 | import com.clutch.student.Entity.Score;
19 | import com.clutch.student.MainActivity;
20 | import com.clutch.student.MyApplication;
21 | import com.clutch.student.R;
22 |
23 | /**
24 | * Created by clutchyu on 2018/3/27.
25 | * 以管理员身份登入系统的第二个界面,修改学生选课成绩
26 | */
27 |
28 | public class ManagerSecondFragment extends Fragment {
29 | static Context context = MyApplication.getInstance();
30 | private Score score = new Score();
31 | private EditText studentText;
32 | private EditText courseText;
33 | private EditText creditText;
34 | public void ManagerSecondFragment(){}
35 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
36 | Bundle savedInstanceState) {
37 | View view = inflater.inflate(R.layout.fragment_manager_second, container, false);
38 | studentText = (EditText)view.findViewById(R.id.editText);
39 | courseText = (EditText)view.findViewById(R.id.editText2);
40 | creditText = (EditText)view.findViewById(R.id.editText3);
41 | Button commit = (Button)view.findViewById(R.id.commit);
42 | Button cancel = (Button)view.findViewById(R.id.cancel_s);
43 | commit.setOnClickListener(new View.OnClickListener(){
44 | public void onClick(View v){
45 | if(!EditCheck.CheckInt(studentText.getText().toString(),"学生学号",10000,99999)){
46 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
47 | }
48 | else if(!EditCheck.CheckInt(courseText.getText().toString(),"课程号",10000,99999)){
49 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
50 | }
51 | else if(!EditCheck.CheckInt(creditText.getText().toString(),"成绩",0,100)){
52 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
53 | }
54 | else if(writeDatabase()){
55 | String word = "录入成功!";
56 | studentText.setText("");
57 | courseText.setText("");
58 | creditText.setText("");
59 | Toast.makeText(v.getContext(),word, Toast.LENGTH_SHORT).show();
60 | }else{
61 | String word = "录入失败\n不存在此学生或此学生未选课";
62 | Toast.makeText(v.getContext(),word, Toast.LENGTH_SHORT).show();
63 | }
64 | }
65 | });
66 | cancel.setOnClickListener(new View.OnClickListener(){
67 | public void onClick(View v){
68 | //清空输入框
69 | studentText.setText("");
70 | courseText.setText("");
71 | creditText.setText("");
72 |
73 | }
74 | });
75 |
76 |
77 | return view;
78 | }
79 |
80 | public boolean writeDatabase(){
81 | ScoreDao scoreDao = new ScoreDao(MyApplication.getInstance());
82 | int studentId = Integer.parseInt(studentText.getText().toString());
83 | int courseId = Integer.parseInt(courseText.getText().toString());
84 | int grade = Integer.parseInt(creditText.getText().toString());
85 | score.setStudentId(studentId);
86 | score.setCourseId(courseId);
87 | score.setGrade(grade);
88 | boolean flag = scoreDao.writeScore(score);
89 | if(flag){
90 | return true;
91 | }
92 | else {
93 | return false;
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Fragment/ManagerThirdFragment.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Fragment;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 | import android.widget.RadioButton;
12 | import android.widget.Toast;
13 |
14 | import com.clutch.student.Dao.StudentDao;
15 | import com.clutch.student.Dao.UserDao;
16 | import com.clutch.student.EditCheck;
17 | import com.clutch.student.Entity.Student;
18 | import com.clutch.student.MyApplication;
19 | import com.clutch.student.R;
20 |
21 | /**
22 | * Created by clutchyu on 2018/3/29.
23 | * 以管理员身份登入系统的第三个界面,添加学生
24 | */
25 |
26 | public class ManagerThirdFragment extends Fragment {
27 | static Context context = MyApplication.getInstance();
28 | private EditText id;
29 | private EditText name;
30 | private RadioButton mMaleRb;
31 | private RadioButton mFamaleRb;
32 | private EditText age;
33 | private EditText phone;
34 | public ManagerThirdFragment() {
35 | }
36 |
37 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
38 | Bundle savedInstanceState) {
39 | View view = inflater.inflate(R.layout.fragment_manager_third, container, false);
40 | id = (EditText)view.findViewById(R.id.id_t);
41 | Button save = (Button)view.findViewById(R.id.save_t);
42 | Button cancel = (Button)view.findViewById(R.id.cancel_t);
43 | name = (EditText)view.findViewById(R.id.name_t);
44 | mMaleRb = (RadioButton)view.findViewById(R.id.male_rb_t);
45 | mFamaleRb = (RadioButton)view.findViewById(R.id.famale_rb_t);
46 | age = (EditText)view.findViewById(R.id.age_t);
47 | phone = (EditText)view.findViewById(R.id.phone_t);
48 | save.setOnClickListener(new View.OnClickListener(){
49 | public void onClick(View v){
50 | String sname = name.getText().toString();
51 | String ssex ="";
52 | if (mMaleRb.isChecked()){
53 | ssex="男";
54 | }
55 | else if (mFamaleRb.isChecked()){
56 | ssex="女";
57 | }
58 | String sage = age.getText().toString();
59 | String sphone = phone.getText().toString();
60 | if(!EditCheck.CheckInt(id.getText().toString(),"学号",10000,99999)){
61 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
62 | }
63 | else if(!EditCheck.CheckString(sname,"名字",6)){
64 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
65 | }
66 | else if(!mMaleRb.isChecked()&&!mFamaleRb.isChecked()){
67 | Toast.makeText(v.getContext(),"性别不能为空!",Toast.LENGTH_SHORT).show();
68 | }
69 | else if(!EditCheck.CheckInt(sage,"年龄",10,60)){
70 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
71 | }
72 | else if(!EditCheck.CheckString(sphone,"电话",15)){
73 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
74 | }
75 | else {
76 | int sid = Integer.parseInt(id.getText().toString());
77 | Student student = new Student(sid, sname, ssex, Integer.parseInt(sage), sphone, R.drawable.health);
78 | if(writeDatabase(student)){
79 | Toast.makeText(v.getContext(),"添加学生信息成功!",Toast.LENGTH_SHORT).show();
80 | id.setText("");
81 | name.setText("");
82 | age.setText("");
83 | phone.setText("");
84 | mFamaleRb.setChecked(false);
85 | mMaleRb.setChecked(false);
86 | }else{
87 | Toast.makeText(v.getContext(),"写入失败,请重试!(可能原因为学号重复)",Toast.LENGTH_SHORT).show();
88 | }
89 |
90 | }
91 | }
92 | });
93 | cancel.setOnClickListener(new View.OnClickListener(){
94 | public void onClick(View v){
95 | //清空输入框
96 | id.setText("");
97 | name.setText("");
98 | age.setText("");
99 | phone.setText("");
100 | mFamaleRb.setChecked(false);
101 | mMaleRb.setChecked(false);
102 | }
103 | });
104 | return view;
105 | }
106 | public boolean writeDatabase(Student student){
107 | Context context = MyApplication.getInstance();
108 | StudentDao stuDao = new StudentDao(context);
109 | UserDao user = new UserDao(context);
110 | if(stuDao.insertStudent(student)) {
111 | //插入学生信息后,设置默认登录密码为123456,账号为学号
112 | user.insertLog(student.getId(),"123456");
113 | return true;
114 | }
115 | else
116 | return false;
117 | }
118 |
119 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Fragment/SecondFragment.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Fragment;
2 |
3 | /**
4 | * Created by clutch on 2018/3/17.
5 | * BottomNavigationView对应的第二个Fragment
6 | * 用于学生选课,学生点击对应课程即可提示选课成功
7 | */
8 |
9 | import android.content.Context;
10 | import android.os.Bundle;
11 | import android.support.v4.app.Fragment;
12 | import android.support.v7.widget.DividerItemDecoration;
13 | import android.support.v7.widget.LinearLayoutManager;
14 | import android.support.v7.widget.RecyclerView;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.widget.TextView;
19 |
20 | import com.clutch.student.Adapter.ScoreAdapter;
21 | import com.clutch.student.Dao.ScoreDao;
22 | import com.clutch.student.Entity.Course;
23 | import com.clutch.student.MainActivity;
24 | import com.clutch.student.MyApplication;
25 | import com.clutch.student.R;
26 | import java.util.List;
27 |
28 |
29 |
30 |
31 | public class SecondFragment extends Fragment {
32 | static Context context = MyApplication.getInstance();
33 | private static ScoreDao uncourse = new ScoreDao(context); //未选的课程
34 | private static RecyclerView recyclerView_undo;
35 | private static List undoList;
36 | private static ScoreAdapter adapter;
37 | private static TextView emptyText;
38 | public SecondFragment() {
39 | // Required empty public constructor
40 | }
41 |
42 |
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
45 | Bundle savedInstanceState) {
46 | // Inflate the layout for this fragment
47 | View view = inflater.inflate(R.layout.fragment_second, container, false);
48 | recyclerView_undo = (RecyclerView) view.findViewById(R.id.recycler_undo);
49 | emptyText = (TextView) view.findViewById(R.id.empty_text) ;
50 | undoList = uncourse.getUnCourse(MainActivity.getStudentId());
51 | if(undoList==null){
52 | emptyText.setVisibility(View.VISIBLE);
53 | recyclerView_undo.setVisibility(View.GONE);
54 | }else {
55 | //StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
56 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
57 | recyclerView_undo.setLayoutManager(layoutManager);
58 | ScoreAdapter adapter = new ScoreAdapter(undoList);
59 | recyclerView_undo.setAdapter(adapter);
60 | DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView_undo.getContext(),layoutManager.getOrientation());
61 | recyclerView_undo.addItemDecoration(mDividerItemDecoration);
62 | }
63 | return view;
64 | }
65 |
66 | /**
67 | * 刷新数据,点击对应课程在Adapter中调用该函数实现页面刷新
68 | */
69 | public static void updata() {
70 | undoList = uncourse.getUnCourse(MainActivity.getStudentId());
71 | if(undoList==null){
72 | emptyText.setVisibility(View.VISIBLE);
73 | recyclerView_undo.setVisibility(View.GONE);
74 | }else {
75 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
76 | recyclerView_undo.setLayoutManager(layoutManager);
77 | ScoreAdapter adapter = new ScoreAdapter(undoList);
78 | recyclerView_undo.setAdapter(adapter);
79 | DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView_undo.getContext(),layoutManager.getOrientation());
80 | recyclerView_undo.addItemDecoration(mDividerItemDecoration);
81 |
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/Fragment/ThirdFragment.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student.Fragment;
2 |
3 | /**
4 | * Created by asus on 2018/3/17.
5 | * BottomNavigationView对应的第三个Fragment
6 | * 显示个人信息
7 | * 从修改信息的界面返回ThirdFragment时,状态为onResume,重写onResume方法实现刷新数据。
8 | */
9 |
10 | import android.content.Context;
11 | import android.content.Intent;
12 | import android.os.Bundle;
13 | import android.support.v4.app.Fragment;
14 | import android.support.v7.widget.DividerItemDecoration;
15 | import android.support.v7.widget.LinearLayoutManager;
16 | import android.support.v7.widget.RecyclerView;
17 | import android.view.LayoutInflater;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.Button;
21 |
22 | import com.clutch.student.Adapter.StudentAdapter;
23 | import com.clutch.student.Dao.StudentDao;
24 | import com.clutch.student.Entity.Student_info;
25 | import com.clutch.student.MainActivity;
26 | import com.clutch.student.MyApplication;
27 | import com.clutch.student.R;
28 | import com.clutch.student.StudentChangeActivity;
29 |
30 | import java.util.List;
31 |
32 |
33 |
34 | public class ThirdFragment extends Fragment {
35 | Context context = MyApplication.getInstance();
36 | private StudentDao student = new StudentDao(context);
37 | private List StudentList = student.getStudent(MainActivity.getStudentId());
38 | private RecyclerView recyclerView;
39 | private int studentId = MainActivity.getStudentId();
40 | public ThirdFragment() {
41 | // Required empty public constructor
42 | }
43 |
44 |
45 | @Override
46 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
47 | final Bundle savedInstanceState) {
48 | // Inflate the layout for this fragment
49 | View view = inflater.inflate(R.layout.fragment_third, container, false);
50 | //initCourse();
51 | recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
52 | //StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
53 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
54 | recyclerView.setLayoutManager(layoutManager);
55 | StudentAdapter adapter = new StudentAdapter(StudentList);
56 | recyclerView.setAdapter(adapter);
57 | DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),layoutManager.getOrientation());
58 | recyclerView.addItemDecoration(mDividerItemDecoration);
59 |
60 | Button button = (Button) view.findViewById (R.id.click);
61 | button.setOnClickListener(new View.OnClickListener(){
62 | public void onClick(View v) {
63 |
64 | Intent intent = new Intent(context, StudentChangeActivity.class);
65 | intent.putExtra("id",studentId);
66 | startActivity(intent);
67 |
68 | }
69 |
70 | });
71 |
72 | // Inflate the layout for this fragment
73 | return view;
74 | }
75 | public void onResume(){
76 | super.onResume();
77 | StudentList = student.getStudent(MainActivity.getStudentId());
78 | StudentAdapter adapter = new StudentAdapter(StudentList);
79 | recyclerView.setAdapter(adapter);
80 |
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 |
13 | import com.clutch.student.Dao.MyDatabaseHelper;
14 | import com.clutch.student.Dao.UserDao;
15 |
16 | public class LoginActivity extends AppCompatActivity {
17 | private MyDatabaseHelper dbHelper;
18 | private EditText account;
19 | private EditText password;
20 | private Button log;
21 | private Button sign;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_login);
27 | dbHelper = new MyDatabaseHelper(this);
28 | dbHelper.getWritableDatabase();
29 | account = findViewById(R.id.account);
30 | password = findViewById(R.id.password);
31 | log = findViewById(R.id.login);
32 | sign = findViewById(R.id.signin);
33 | final UserDao user = new UserDao(this);
34 | log.setOnClickListener(new View.OnClickListener() { //点击登录,跳转到MainActivity,传入对应id
35 | @Override
36 | public void onClick(View view) {
37 | String id_str = account.getText().toString();
38 | // int id = Integer.parseInt(id_str);
39 | String passwd = password.getText().toString();
40 | if(!EditCheck.CheckInt(id_str,"账号",0,99999)){
41 | showNormalDialog(EditCheck.getWarning());
42 | }
43 | else if(!EditCheck.CheckString(passwd,"密码",20)){
44 | showNormalDialog(EditCheck.getWarning());
45 | }
46 | else if(user.check(Integer.parseInt(id_str),passwd)){ //账号匹配成功,进入MainActivity
47 | Intent intent = new Intent(LoginActivity.this,MainActivity.class);
48 | intent.putExtra("id",Integer.parseInt(id_str));
49 | startActivity(intent);
50 | finish();
51 | }else{ //弹出错误提示框
52 | String word = "账号或密码错误!";
53 | showNormalDialog(word);
54 | }
55 |
56 | }
57 | });
58 | sign.setOnClickListener(new View.OnClickListener(){
59 | public void onClick(View view){
60 | Intent intent = new Intent(LoginActivity.this,ModifyPasswdActivity.class);
61 | startActivity(intent);
62 | }
63 | });
64 | }
65 |
66 | private void showNormalDialog(String word){
67 |
68 | final AlertDialog.Builder normalDialog =
69 | new AlertDialog.Builder(LoginActivity.this);
70 | normalDialog.setTitle("提示");
71 | normalDialog.setMessage(word);
72 | normalDialog.setPositiveButton("确定",
73 | new DialogInterface.OnClickListener() {
74 | @Override
75 | public void onClick(DialogInterface dialog, int which) {
76 | normalDialog.setCancelable(true);
77 | //...To-do
78 | }
79 | });
80 |
81 | // 显示
82 | normalDialog.show();
83 | }
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 |
3 | /**
4 | * Created by clutchyu on 2018/3/17.
5 | * 主界面,包含三个Fragment,以学生身份和管理员身份登入系统时对应界面不同
6 | */
7 |
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.os.Bundle;
11 | import android.support.annotation.NonNull;
12 | import android.support.design.widget.BottomNavigationView;
13 | import android.support.v4.view.ViewPager;
14 | import android.support.v7.app.AppCompatActivity;
15 | import android.util.Log;
16 | import android.view.Menu;
17 | import android.view.MenuItem;
18 | import com.clutch.student.Adapter.ViewPagerAdapter;
19 | import com.clutch.student.Fragment.FirstFragment;
20 | import com.clutch.student.Fragment.ManagerFirstFragment;
21 | import com.clutch.student.Fragment.ManagerSecondFragment;
22 | import com.clutch.student.Fragment.ManagerThirdFragment;
23 | import com.clutch.student.Fragment.SecondFragment;
24 | import com.clutch.student.Fragment.ThirdFragment;
25 | import com.clutch.student.Dao.MyDatabaseHelper;
26 | public class MainActivity extends AppCompatActivity {
27 |
28 | //dbHelper
29 | private MyDatabaseHelper dbHelper;
30 | private static int studentId;
31 | BottomNavigationView bottomNavigationView;
32 | //This is our viewPager
33 | private ViewPager viewPager;
34 |
35 | private ViewPagerAdapter adapter;
36 | //Fragments
37 | FirstFragment firstFragment;
38 | SecondFragment secondFragment;
39 | ThirdFragment thirdFragment;
40 | ManagerFirstFragment managerFirstFragment;
41 | ManagerSecondFragment managerSecondFragment;
42 | ManagerThirdFragment managerThirdFragment;
43 | MenuItem prevMenuItem;
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_main);
49 | Intent intent = getIntent();
50 | studentId = intent.getIntExtra("id",-1);
51 | //创建或打开数据库
52 | dbHelper = new MyDatabaseHelper(this);
53 | dbHelper.getWritableDatabase();
54 | //Initializing viewPager
55 | viewPager = (ViewPager) findViewById(R.id.viewpager);
56 |
57 | //Initializing the bottomNavigationView
58 | bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);
59 |
60 | bottomNavigationView.setOnNavigationItemSelectedListener(
61 | new BottomNavigationView.OnNavigationItemSelectedListener() {
62 | @Override
63 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
64 | switch (item.getItemId()) {
65 | case R.id.action_first:
66 | viewPager.setCurrentItem(0);
67 | break;
68 | case R.id.action_second:
69 | viewPager.setCurrentItem(1);
70 | break;
71 | case R.id.action_third:
72 | viewPager.setCurrentItem(2);
73 | break;
74 | }
75 | return false;
76 | }
77 | });
78 |
79 | viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
80 | @Override
81 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
82 |
83 | }
84 |
85 | @Override
86 | public void onPageSelected(int position) {
87 | if (prevMenuItem != null) {
88 | prevMenuItem.setChecked(false);
89 | }
90 | else
91 | {
92 | bottomNavigationView.getMenu().getItem(0).setChecked(false);
93 | }
94 | Log.d("page", "onPageSelected: "+position);
95 | bottomNavigationView.getMenu().getItem(position).setChecked(true);
96 | prevMenuItem = bottomNavigationView.getMenu().getItem(position);
97 |
98 | }
99 |
100 | @Override
101 | public void onPageScrollStateChanged(int state) {
102 |
103 | }
104 | });
105 |
106 |
107 |
108 | setupViewPager(viewPager);
109 | }
110 |
111 | @Override
112 | public boolean onCreateOptionsMenu(Menu menu) {
113 | getMenuInflater().inflate(R.menu.main,menu);
114 | return true;
115 | }
116 |
117 | @Override
118 | public boolean onOptionsItemSelected(MenuItem item) {
119 | switch (item.getItemId()){
120 | case R.id.switch_item:
121 | Intent intent = new Intent(MainActivity.this,LoginActivity.class);
122 | startActivity(intent);
123 | finish();
124 | break;
125 | case R.id.quit_item:
126 | finish();
127 | break;
128 | default:
129 | }
130 | return true;
131 | }
132 |
133 | public static int getStudentId(){
134 | return studentId;
135 | }
136 | public Context context(){return this;}
137 | private void setupViewPager(ViewPager viewPager) {
138 | ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
139 | if(getStudentId()==0){
140 | managerFirstFragment=new ManagerFirstFragment();
141 | managerSecondFragment=new ManagerSecondFragment();
142 | managerThirdFragment=new ManagerThirdFragment();
143 | adapter.addFragment(managerFirstFragment);
144 | adapter.addFragment(managerSecondFragment);
145 | adapter.addFragment(managerThirdFragment);
146 | }else {
147 | firstFragment = new FirstFragment();
148 | secondFragment = new SecondFragment();
149 | thirdFragment = new ThirdFragment();
150 | adapter.addFragment(firstFragment);
151 | adapter.addFragment(secondFragment);
152 | adapter.addFragment(thirdFragment);
153 | }
154 | viewPager.setAdapter(adapter);
155 | }
156 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/ModifyPasswdActivity.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.DialogInterface;
5 | import android.os.Handler;
6 | import android.renderscript.Script;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.EditText;
12 |
13 | import com.clutch.student.Dao.UserDao;
14 | import com.clutch.student.Entity.User;
15 |
16 | public class ModifyPasswdActivity extends AppCompatActivity {
17 | private EditText account;
18 | private EditText passwdOld;
19 | private EditText passwdNew;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_modify_passwd);
25 | account = (EditText)findViewById(R.id.account_m);
26 | passwdOld = (EditText)findViewById(R.id.passwd_o);
27 | passwdNew = (EditText)findViewById(R.id.passwd_n);
28 | Button commit = (Button)findViewById(R.id.commit_m);
29 | Button cancel = (Button)findViewById(R.id.cancel_m);
30 | commit.setOnClickListener(new View.OnClickListener(){
31 | public void onClick(View v){
32 | String word;
33 | if(!EditCheck.CheckInt(account.getText().toString(),"账号",10000,99999)){
34 | showNormalDialog(EditCheck.getWarning());
35 | }
36 | else if(!EditCheck.CheckString(passwdOld.getText().toString(),"旧密码",20)) {
37 | showNormalDialog(EditCheck.getWarning());
38 | }
39 | else if(!EditCheck.CheckString(passwdNew.getText().toString(),"新密码",20)){
40 | showNormalDialog(EditCheck.getWarning());
41 | }
42 | else {
43 | User user = new User(Integer.parseInt(account.getText().toString()),passwdOld.getText().toString());
44 | String password = passwdNew.getText().toString();
45 | if(writeDatabase(user,password)){
46 | word = "修改密码成功!";
47 | showNormalDialog(word);
48 | //延时1s
49 | Handler handler = new Handler();
50 | handler.postDelayed(new Runnable() {
51 | @Override
52 | public void run() {
53 | finish();
54 | }
55 | }, 1000);
56 | }
57 | else{
58 | word="修改失败!账号与原密码不匹配!请重试:";
59 | showNormalDialog(word);
60 | }
61 | }
62 |
63 | }
64 | });
65 | cancel.setOnClickListener(new View.OnClickListener(){
66 | public void onClick(View v){
67 | finish();
68 | }
69 | });
70 | }
71 | private void showNormalDialog(String word){
72 |
73 | final AlertDialog.Builder normalDialog =
74 | new AlertDialog.Builder(ModifyPasswdActivity.this);
75 | normalDialog.setTitle("提示");
76 | normalDialog.setMessage(word);
77 | normalDialog.setPositiveButton("确定",
78 | new DialogInterface.OnClickListener() {
79 | @Override
80 | public void onClick(DialogInterface dialog, int which) {
81 | normalDialog.setCancelable(true);
82 | //...To-do
83 | }
84 | });
85 |
86 | // 显示
87 | normalDialog.show();
88 | }
89 | private boolean writeDatabase(User user,String passwd){
90 | UserDao userDao = new UserDao(MyApplication.getInstance());
91 | if(userDao.modifyPasswd(user,passwd))
92 | return true;
93 | else
94 | return false;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 | import android.app.Application;
3 |
4 | import com.facebook.stetho.Stetho;
5 | /**
6 | * Created by clutchyu on 2018/3/17.
7 | */
8 |
9 | public class MyApplication extends Application {
10 | private static MyApplication instance;
11 | public void onCreate() {
12 | super.onCreate();
13 | instance = this;
14 | Stetho.initializeWithDefaults(this);
15 | }
16 | public static MyApplication getInstance(){
17 | // 因为我们程序运行后,Application是首先初始化的,如果在这里不用判断instance是否为空
18 | return instance;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/clutch/student/StudentChangeActivity.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 | /**
3 | * 修改个人信息界面
4 | */
5 |
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.support.v4.view.ViewPager;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.os.Bundle;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.RadioButton;
15 | import android.widget.RadioGroup;
16 | import android.widget.Toast;
17 |
18 | import com.clutch.student.Adapter.*;
19 | import com.clutch.student.Dao.StudentDao;
20 | import com.clutch.student.Entity.Student;
21 |
22 |
23 | public class StudentChangeActivity extends AppCompatActivity implements View.OnClickListener{
24 | private EditText name;
25 | private RadioButton mMaleRb;
26 | private RadioButton mFamaleRb;
27 | private EditText age;
28 | private EditText phone;
29 | private int studentId;
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_student_change);
34 | Intent intent = getIntent();
35 |
36 | studentId = intent.getIntExtra("id",-1);
37 | Button save = (Button)findViewById(R.id.save);
38 | Button cancel = (Button)findViewById(R.id.cancel);
39 | name = (EditText)findViewById(R.id.name);
40 | //sex = (EditText)findViewById(R.id.sex);
41 | mMaleRb = (RadioButton)findViewById(R.id.male_rb);
42 | mFamaleRb = (RadioButton)findViewById(R.id.famale_rb);
43 | age = (EditText)findViewById(R.id.age);
44 | phone = (EditText)findViewById(R.id.phone);
45 | save.setOnClickListener(this);
46 | cancel.setOnClickListener(new View.OnClickListener(){
47 | public void onClick(View v){
48 | finish();
49 | }
50 |
51 | });
52 | }
53 | public void onClick(View v){
54 | switch(v.getId()){
55 | case R.id.save:
56 | String sname = name.getText().toString();
57 | String ssex ="";
58 | if (mMaleRb.isChecked()){
59 | ssex="男";
60 | }
61 | else if (mFamaleRb.isChecked()){
62 | ssex="女";
63 | }
64 | String sage = age.getText().toString();
65 | String sphone = phone.getText().toString();
66 | if(!EditCheck.CheckString(sname,"名字",6)){
67 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
68 | break;
69 | }
70 | else if(!mMaleRb.isChecked()&&!mFamaleRb.isChecked()){
71 | Toast.makeText(v.getContext(),"性别不能为空!",Toast.LENGTH_SHORT).show();
72 | break;
73 | }
74 | else if(!EditCheck.CheckInt(sage,"年龄",10,60)){
75 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
76 | break;
77 | }
78 | else if(!EditCheck.CheckString(sphone,"电话",15)){
79 | Toast.makeText(v.getContext(),EditCheck.getWarning(),Toast.LENGTH_SHORT).show();
80 | break;
81 | }
82 | Student student = new Student(studentId,sname,ssex,Integer.parseInt(sage),sphone,R.drawable.health);
83 | writeDatabase(student);
84 | finish();
85 | break;
86 | case R.id.cancel:
87 | finish();
88 | break;
89 | default:
90 | break;
91 | }
92 | }
93 |
94 | /**
95 | * 写入数据库
96 | */
97 | private void writeDatabase(Student student){
98 | Context context = MyApplication.getInstance();
99 | StudentDao stuDao = new StudentDao(context);
100 | stuDao.updateStudent(student);
101 |
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_call.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable-hdpi/ic_call.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_chat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable-hdpi/ic_chat.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_contact.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable-hdpi/ic_contact.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/age.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/age.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/background.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bottom_navigation_color_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/chemistry.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/chemistry.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/chinese.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/chinese.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/english.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/english.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/geography.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/geography.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/health.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/health.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/history.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/history.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/id.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/id.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/math.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/math.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/name.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/name.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/origin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/origin.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/phone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/physic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/physic.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/sex.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sport.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/drawable/sport.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_add_course.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
25 |
26 |
43 |
44 |
61 |
62 |
74 |
75 |
87 |
88 |
102 |
103 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
24 |
25 |
39 |
40 |
49 |
50 |
61 |
62 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 | / app:layout_behavior="@string/appbar_scrolling_view_behavior" />
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_modify_passwd.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
24 |
25 |
39 |
40 |
54 |
55 |
64 |
65 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_student_change.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
24 |
25 |
34 |
39 |
40 |
46 |
47 |
48 |
62 |
63 |
77 |
78 |
89 |
90 |
101 |
102 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/course_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_first.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
13 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_manager_first.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
23 |
24 |
30 |
31 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_manager_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
23 |
24 |
37 |
38 |
51 |
52 |
64 |
65 |
74 |
75 |
89 |
90 |
104 |
105 |
119 |
120 |
134 |
135 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_manager_third.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
24 |
38 |
39 |
48 |
49 |
54 |
55 |
61 |
62 |
63 |
77 |
78 |
92 |
93 |
104 |
105 |
116 |
117 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_second.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
13 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_third.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
22 |
23 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/student_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_bottom_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #354355
4 | #26303D
5 | #F3CD70
6 | #FFFFFF
7 | #FFFFFF
8 |
9 | #979797
10 | #FFFFFF
11 | #F3CD70
12 | #FFFFFF
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 学生选课系统
3 |
4 | 课表
5 | 选课
6 | 个人信息
7 | Sign in
8 | 无未选课程
9 | 无已选课程
10 | 无课程信息
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
15 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/test/java/com/clutch/student/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.clutch.student;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clutchyu/AndroidDemo/cafa9acaf9e559250fcfd55a2ae8b81115902278/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 17 15:42:15 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------