结对项目总结-软件1703顾云开
结对项目———带UI的中小学试卷生成系统
-
项目已在GitHub开源,地址为https://github.com/GUTINGLIAO/PaperProducer
-
本项目是基于第一版的APP做出的改进,实现的功能如下
- 优化了UI
- 新增用户注册页面,通过发送验证码绑定手机号
- 实现题目自动生成答案
- 新增答题界面,答题完成后自动计算得分并显示
-
功能具体实现
-
首先,我优化了用户登录的界面,其实只是添加了几个样式
-
添加CircleImageView库,可以在登录界面上添加圆形头像框,我这里自己加了一张图片
-
在res/values/colors.xml中利用resource标签定义各类要使用的颜色,我将背景颜色设置为了#F7F7F7
-
在drawable中自定义EditText输入框的样式,新建rectangle_text_view.xml样式文件,将shape设置为矩形,corners设置为圆角,stroke设置内填充颜色
-
输入框属性
<RelativeLayout android:id="@+id/rl_grade" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/rl_username" android:layout_marginLeft="40dp" android:layout_marginTop="1dp" android:layout_marginRight="40dp" android:background="@drawable/rectangle_text_view3"> <ImageView android:id="@+id/iv_user_icon_grade" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="30dp" android:layout_marginTop="15dp" android:layout_marginBottom="15dp" android:src="@mipmap/ic_edittextuname" /> <View android:id="@+id/view_grade" android:layout_width="1dip" android:layout_height="20dp" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@+id/iv_user_icon_grade" android:background="@color/colorCursor" /> <EditText android:id="@+id/ed_grade" android:layout_width="match_parent" android:layout_height="30dp" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@+id/view_grade" android:background="@null" android:ems="19" android:hint="学历" android:textColorHint="@color/colorCursor" android:textCursorDrawable="@drawable/color_cursor" android:textSize="15sp" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="20dp" android:src="@mipmap/ic_backspace_grey600_24dp" android:visibility="invisible" /> </RelativeLayout>
-
-
之后,我实现了用户注册界面,基本就是登录界面的重用,这里重点讲讲如何实现短信验证功能
-
要实现这个功能,首先需要找到短信服务供应商,这里我选择了WghtStudio的短信服务
-
通过阅读官方文档,我需要向其服务器提供的短信接口发送一个get请求,即可使其向指定手机发送短信,接着将收到的验证码包装后在向其验证接口发送一个get请求即可根据返回数据完成验证
-
引入okhttp3开源库
implementation 'com.squareup.okhttp3:okhttp:4.1.0' -
在util目录下新建HttpUtils工具类,加入发送get请求的方法
//Get请求 public static void sendGetRequest(String url, okhttp3.Callback callback) { OkHttpClient okHttpClient = new OkHttpClient(); Request request = new Request.Builder() .url(url) .build(); okHttpClient.newCall(request).enqueue(callback); } -
通过弹出Toast来向用户反馈验证结果,如果验证成功则自动跳转至登录界面
-
-
自动生成题目答案的算法部分由胡同学完成,具体实现请移步胡同学的博客
-
最后是最重要的答题界面
-
采用了ViewPager加Fragment的结构来实现,需要用到的有,ViewPager控件,答题Fragment,FragmentViewPager适配器
-
基本思路就是,将题目存在一个ArrayList中,将答案存在一个double[]中,将用户得分存在Mark[]数组中
-
继承FragmentStatePagerAdapter类,通过构造函数从答题活动中传递题目数量到适配器,生成指定数量的Fragment,为了使每一个碎片生成时都能由特定的数据初始化视图,通过Bundle向每一个碎片传递一个题号的参数,便于每一个碎片获取各自的题目数据
-
新建MyFragment类,重载视图载入方法,初始化各个控件,同时,在活动创建方法中添加点击事件
-
通过调用主活动中的pubic方法实现活动和碎片的通信
-
-
浙公网安备 33010602011771号