--- twinning project with the primary and secondary UI Paper Generation System
Project on GitHub open source, address https://github.com/GUTINGLIAO/PaperProducer
This project is the first edition of the APP to make improvements based on the realization of the following functions
- Optimized UI
- New user registration page, to bind phone number by sending a verification code
- Achieve answer automatically generated topic
- Answer new interface, the score is automatically calculated and displayed after completion answer
Function realization
First of all, I optimized the user login interface, in fact, just add a few style
Add CircleImageView library, you can add circular avatar box on the login screen, I added a picture of yourself here
Tag defines various types of resource use color to be used in the res / values / colors.xml, I'll set the background color to # F7F7F7
Custom EditText drawable input box in the style, the new style rectangle_text_view.xml file, set a rectangular shape, a rounded Corners set, setting the stroke fill color
Input Box Properties
<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>
After that, I realized the user registration interface, the basic is to reuse the login screen, the focus here talk about how to implement SMS verification function
To achieve this function, you first need to find the SMS service provider, here I chose WghtStudio SMS service
By reading official documents, I need to interface to send its SMS server provides a get request, it can send text messages to designated mobile phone, then the package will receive the verification code in the verification interface to send a get request according to its return data to complete verification
The introduction of open source libraries okhttp3
implementation 'com.squareup.okhttp3:okhttp:4.1.0'
New tools in HttpUtils util directory, get request transmission method is added
//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); }
By Toast pops up to verify the results of feedback to the user, if the authentication is successful then automatically jump to the login screen
The algorithm automatically generated topic answers in part by students Hu, Hu concrete realization of the venue and students blog
The last is the most important answer interface
Fragment of using ViewPager add structure to achieve, need to use there, ViewPager controls, the answer Fragment, FragmentViewPager adapter
The basic idea is that there will be an ArrayList, the answer is there is a double [], the presence of a user score Mark [] array title
FragmentStatePagerAdapter inheritance class, the number of items transferred from the answer by the constructor activities to the adapter, generate the specified number of Fragment, in order to make each fragment can pass a problem generated by a specific number when the data to initialize the view through the Bundle of each fragment parameters, each fragment to facilitate the acquisition of each data subject
New MyFragment class, overloaded view loading method, initialize each control, while adding click event in the active creation method
For communication activities and debris by pubic method calls the main activities