Android QQ course design

1. Preface: for the small project written after learning Android for a month in 2017, the document has only been completed recently. The project and document are original and released to remember a few years ago. Due to the projects written in 2017, the code and technology are backward, but it can provide some ideas for writing similar projects and the preparation of curriculum design documents.

2. Project link:

3. Project video: Android QQ imitates QQApp_ Beep beep beep_ bilibili

4. Brief description of project functions

In the Android, the URL is called for backstage access, and the value is transmitted by JSON. The development of QQ is simulated, and the three functions of chat, friend and dynamic are completed.

  • User module: user login and registration, avatar image selection, personal information and data modification
  • Friend module: friend list, friend addition, friend deletion, friend mobile grouping, friend data
  • Chat module: send and accept messages
  • Dynamic module: view the news of friends and publish your own news

5. The project documents are as follows:

catalogue

1, Introduction two

1.1 research background and significance two

1.2 main contents of this paper two

2, Related technologies and development environment two

2.1 key technologies two

2.1.1Struts2. 2

2.1.2Hibernate.. 3

2.1.3Spring.. 3

2.1.3android-async-http. 3

2.2 development environment and platform three

2.2.1Eclipse. 3

2.2.2 Tomcat server four

2.2.3 application platform Android four

3, System analysis and Design five

3.1 demand analysis five

3.1.1 system objectives and requirements five

3.1.2 feasibility analysis five

3.2 system outline design five

3.2.1 division of modules five

3.2.2 design of mobile terminal function module five

3.3 database design seven

3.3.1 database demand analysis seven

3.3.2 database E-R diagram design seven

3.3.3 data sheet design nine

4, System implementation eleven

4.1 Android platform system implementation eleven

4.1.1 function description eleven

4.1.2 program running effect eleven

4.1.3 function summary and key code thirty-one

4.2 summary of server-side implementation forty-five

5, Conclusion forty-six

introduction

Research background and significance

Instant messaging software is produced by people's needs. As early as ancient times, flying pigeons sent books to convey information, and then to telegrams and mail envelopes. The development of communication between people is necessary. The emergence of communication software makes the distance between people shorter. In real time, it can also convey each other's thoughts thousands of miles apart. Communication software is faster than flying pigeons, easier to read than telegrams and shorter than envelope mail. It is a good helper for transmitting information.

Main contents of this paper

This paper introduces the development process of the system. This paper discusses in detail the whole development process from demand analysis, system analysis, outline design, detailed design, testing and debugging. Firstly, the background and significance of the system are systematically studied. Then it introduces the Android platform environment for system development and the implementation of database SqlServer. At the same time, the functions and methods of the above tools are briefly introduced.

The outline design mainly explains the client operation design, and introduces the establishment and maintenance of the database. The detailed design mainly expounds the realization of user management, friend management, chat management and dynamic management, and gives some design codes of the system.

2.1 key technologies

Struts2

Is a Web application framework based on MVC design pattern. It is essentially equivalent to a servlet. In MVC design pattern, struts 2 acts as a controller to establish the data interaction between model and view. Struts 2 is the next generation product of struts. It is a new struts 2 framework based on the technology of Struts 1 and WebWork. The architecture of its new struts 2 is very different from that of Struts 1. Struts 2 takes WebWork as the core and uses the interceptor mechanism to process user requests. This design also enables the business logic controller to be completely separated from the servlet API. Therefore, struts 2 can be understood as an updated product of WebWork. Although there are great changes from Struts 1 to struts 2, the change of struts 2 is very small compared with WebWork.

Hibernate

Hibernate is responsible for database Handover of. By persisting data objects, the mapping of object relationships is carried out, and the database is accessed from the perspective of objects. By encapsulating JDBC, developers can manipulate the database with the idea of object-oriented programming, so as to get rid of the "rigid" operation when using JDBC programming in the past. Via hibernate cfg. XML file to replace the previous JDBC connection database of a large string of code, through XXX (class name of entity Bean) hbm.xml file to map with the specific table of the database. And Hibernate has its own HQL statement, which is similar to the SQL statement of the database, but the difference is that from the perspective of object-oriented programming, HQL statement creates a query object through the createQuery method of Session, which can complete the operations of adding, deleting, modifying and querying the database. Call the business processing in Dao layer through the return value of Action in struts 2.

Spring

Spring uses the basic entity JavaBean to accomplish things that can only be done with EJB before. Its core is control inversion (IOC) and aspect oriented programming (AOP). Using spring means that the creation of an object is no longer created by itself, but is completely handed over to the IOC container for instantiation. At the same time, spring injects the attributes of this object through the Setter and Getter methods of attributes by means of dependency injection (DI), which has the advantage that it does not completely depend on the container API And the query dependency is decoupled from the code. AOP separates the application business logic from system level services (such as transactions) for cohesive development. The application object is only responsible for completing the business logic and does not care about the processing of logs or transactions.  

android-async-http

The mobile terminal uses Android async HTTP open source framework to make it easy for us to obtain network data or send data to the server. The most important thing is that it is an asynchronous framework. It uses thread pool to process concurrent requests at the bottom, which is very efficient and easy to use.

2 development environment and platform

Eclipse is an open source and Java based extensible development platform. In itself, it is just a framework and a set of services for building a development environment through plug-in components. Fortunately, eclipse comes with a standard set of plug-ins, including Java Development Tools (JDT). Eclipse is a famous cross platform free integrated development environment (IDE). Initially, it was mainly used for Java language development, but at present, some people use it as a development tool for other computer languages such as C + + and Python through plug-ins. Eclipse itself is only a framework platform, but the support of many plug-ins makes it difficult for eclipse to have the flexibility of IDE software with relatively fixed functions. Many software developers develop their own ide based on eclipse.

The server

Tomcat is a core project of the Jakarta project of the Apache Software Foundation, which is jointly developed by Apache, Sun and some other companies and individuals. With the participation and support of Sun, the latest Servlet and JSP specifications can always be reflected in Tomcat. Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because Tomcat technology is advanced, stable and free, it is loved by Java enthusiasts and has been recognized by some software developers. It has become a popular Web application server.

Application platform Android

Android is a free and open source operating system based on Linux kernel (excluding GNU components). It is mainly used in mobile devices, such as smartphones and tablets. It is led and developed by Google and the open mobile alliance. The Android operating system was originally developed by Andy Rubin and mainly supports mobile phones. It was acquired and invested by Google in August 2005. In November 2007, Google formed an open mobile phone alliance with 84 hardware manufacturers, software developers and telecom operators to jointly develop and improve the Android system. Subsequently, Google released the source code of Android under the license of Apache open source license. The first Android smartphone was released in October 2008. Android has gradually expanded to tablet computers and other fields, such as TVs, digital cameras, game consoles, smart watches and so on. In the first quarter of 2011, Android surpassed Symbian system in the global market share for the first time, ranking first in the world. In the fourth quarter of 2013, the global market share of Android platform mobile phones has reached 78.1%. On September 24, 2013, Android, the operating system developed by Google, celebrated its fifth birthday in. The number of devices using this system has reached 1 billion around the world.

System analysis and design

requirement analysis

System objectives and requirements

The purpose of communication is the key, so the following requirements need to be met.

  1. The most important thing is that the two users can communicate and talk, and the page operation is simple and the interface is friendly: the full control page layout displays chat information.
  2. Instant visible: the message sent by the user and accepted by the other party should not be too long

In addition to chatting, we should add dynamic module and friend management module to enhance the integrity of the system

feasibility analysis

The graduation project is based on Android platform to develop communication system. Android platform provides us with a huge free space, and then the use of Java object-oriented language makes the system more powerful. SqlServer is an outstanding database platform with powerful functions, security and reliability. It can be used for small and medium-sized online transaction processing, data warehouse and e-commerce.

High-Level System Design

The outline design of the system mainly studies how to design the overall function of the system, how to divide modules, and how to design the database of the system. It paves the way for the detailed design of the system. It plays a very important role in the design process of the system.

Division of modules

The system is mainly divided into two parts:

1. The web system provides data to the mobile terminal

2. The mobile terminal carries out specific operations. It can register, log in, query friends, add and delete friends, chat with friends, view updates, publish updates and other functions

Design of mobile terminal function module

1. Overall design

The mobile terminal is mainly composed of the following modules: user information, chat function, friend management, dynamic and other functions

2. Detailed functional design

 

Database design

Database requirement analysis

Android communication system takes the user's individual as the theme, so a user table is needed to save user information. So use the number as the primary key. Users need to chat on the system, so they need a user table to save users' friends. Users need specific chat when they have chat objects, so they need a table to save chat contents. In order to improve the system, it is necessary for a friend to send dynamic messages to each other to show the spatial function of his mood at this time, so a dynamic table is needed.

Database E-R diagram design

The conceptual design of database is to design the schema of conceptual database by using data model. According to the requirements of Android communication system, the following entity relationship model (E-R) is designed, as shown in the figure.

Figure 3-3 entity contact diagram

Figure 3-4 entity contact diagram

Figure 3-5 entity contact diagram

Data sheet design

The logical design of database, that is to change the conceptual database schema obtained by conceptual design into logical data schema, which depends on DBMS. According to the analysis of Android communication system and the conceptual design of database, the database Android qqdata is established.

Database creation statement: create database androidqqdata;

The structure of the design table is shown in the figure below:

Table 3.1 user information table (android_qq_user)

Listing

data type

Allow to be empty

explain

qq_id

int

no

Serial number (primary key)

qq_zhanghao

varchar(15)

no

account number

qq_mima

varchar(11)

no

password

qq_touxiang

varchar(100)

yes

head portrait

qq_name

varchar(20)

yes

nickname

qq_mark

varchar(100)

yes

Personal signature

qq_sex

varchar(2)

yes

Gender

qq_address

varchar(80)

yes

address

qq_phone

varchar(11)

yes

Telephone

qq_statu

Int

yes

0 offline, 1 Online

Table 3.2 friend information table (android_qq_hy)

Listing

data type

Allow to be empty

explain

hy_id

int

no

Serial number (primary key)

myqq_id

int

yes

My id number

myqq_zhanghao

varchar(15)

yes

My Account

myqq_name

varchar(20)

yes

My nickname

myqq_fengzu

int

yes

My group

hyqq_id

int

yes

Friend id number

hyqq_zhanghao

varchar(15)

yes

Friend account

hyqq_name

varchar(20)

yes

Friend nickname

hyqq_statu

Int

yes

Group Friends

Table 3.3 message table (android_qq_message)

Listing

data type

Allow to be empty

explain

m_id

int

no

Serial number (primary key)

qq_id

int

yes

Sender ID

qq_zhanghao

varchar(15)

yes

Sender account

qq_name

varchar(20)

yes

Sender nickname

m_message

varchar(200)

yes

Message content

m_date

datetime

yes

Sender time

m_jsid

Int

yes

Recipient ID

m_zhanghao

varchar(15)

yes

Recipient account number

m_name

varchar(20)

yes

Recipient nickname

Table 3.4 show message table (android_qq_dynamic)

Listing

data type

Allow to be empty

explain

sm_id

int

no

Serial number (primary key)

qq_id

int

yes

Qqid

qq_zhanghao

varchar(15)

yes

Qq account

qq_name

varchar(20)

yes

nickname

qq_touxiang

varchar(100)

yes

head portrait

hy_id

Int

yes

Friend id

hy_zhanghao

varchar(15)

yes

Friend account

hy_name

varchar(20)

yes

Friend nickname

hy_touxiang

varchar(100)

yes

Friend Avatar

sm_content

varchar(100)

yes

Message content

sm_date

datetime

yes

Sending time

Table 3.5 dynamic table (android_qq_dynamic)

Listing

data type

Allow to be empty

explain

dy_id

int

no

Serial number (primary key)

qq_id

int

yes

Qqid

qq_zhanghao

varchar(15)

yes

Qq account

qq_name

varchar(20)

yes

nickname

dy_date

Datetime

yes

Publication date

dy_content

varchar(500)

yes

Published content

dy_photos

varchar(500)

yes

Publish a picture

system implementation

Android platform system implementation

Function description

The whole project has perfect functions, including login and registration, friend list, friend information, search for friends, add and delete friends, chat with friends, friend updates and other functional modules. Each module constitutes the whole system function, with perfect function and real QQ function.

Program running effect

The registration interface is mainly used to register login users. It is the basic operation unit used to realize follow-up friends, chat, search friends, add and delete friends.

Figure 4-1 screenshot of registration

Enter the data and register successfully. Jump to the login interface:

 

Figure 4-2 screenshot of successful registration

The login interface is mainly operated by users, so it should be simple, clear and easy to operate. Use the database to check the user information. After checking it correctly, use the interface to jump to the QQ main interface. The user's account and password are registered in the registration interface and saved in the server database in advance. Each user has its own unique account and password to log in.

 

Figure 4-3 login screenshot

After successful login, enter the main interface:

Figure 4-4 main interface

Add friends:

Search for friends: enter the qq account you want to search in the specified text box

Figure 4-5 input qq account number

After entering the account number, you will find the person: 1, which means to find a qq user with qq number 1 or nickname 1

Figure 4-6 finding qq users

Enter again to filter the specified qq users again:

 

Add friends: click qq user list to enter qq user details page to add friends

Figure 4-7 adding friends

After clicking add friends, a prompt appears:

Figure 4-8 successfully initiated friend application

Log in to the account of the added friend, and there will be a friend information prompt on the main interface:

                         

Figure 4-9 friend verification display

Click the new friend icon to enter the application list of all friends:

 

Figure 4-10 friend application list

Click on the applicant's information and you can choose to agree or refuse:

 

Figure 4-11 agree or reject

Click agree and you will have this new friend in the friends list on the main interface:

 

Figure 4-12 successfully adding friends

Click a new friend avatar to enter the chat interface and send a message:

 

Figure 4-13 chat interface

Chat messages will be saved in the database, and they will be received when friends go online and when friends reply to messages.

Wait for your friend to reply and send a new message again:

 

Figure 4-14 chat

Go back to the home page and click Update to enter the friend update page.

 

Figure 4-15 friend dynamic interface

The friend news function can publish the attached pictures, view the news published by friends, and display the latest news in the front.

Click the + sign in the upper right corner to release a new message:

Figure 4-16 writing

Enter text and select pictures:

 

Figure 4-17 delete the selected picture

The selected picture can be deleted and published after deletion:

 

Figure 4-18 published comments

Log in to another account to check if there is any news about this friend and post the latest news:

 

Figure 4-19 viewing friends' comments

Figure 4-20 I also sent a picture

Click the friend avatar to enter the details:

 

Figure 4-21 friend information

Friend management can operate and group your friends into family, friends, classmates and friend groups, and delete friends.  

Click Move group:

                

Figure 4-22 mobile packet

Select the items to be divided into family and click Finish:

 

Figure 4-22 successful mobile grouping

Click your friend's Avatar again to enter the details:

Figure 4-23 deleting

Click Delete friend:

Figure 4-24 deleting friends successfully

3 function summary and key codes

1. Add friends

On Android_ qq_ In the hy table, myQQ is important_ ID, and hyqq_id,myqq_id is the user who initiated adding friends, hyqq_id is the user who is added as a friend. Suppose: Xiaoming sends a friend request to Xiaohua.

(1) In HyUserZiliaoActivity, Xiaoming sends an application, and the added person is Xiaohua. Directly add a row of friend data to the database friend table, where myqq_id is the person who initiated Xiaoming to add friends, hyqq_id is the person to whom Xiaohua is added as a friend, but the status is 0, which means Xiaohua doesn't agree.

public void addRen(AndroidQqUser hyuser){

         AsyncHttpClient client = new AsyncHttpClient();// Open network request object class

         String uri =URI_IP.URI+"Android_Service/QQ/becomeQqhy";//Set the requested network path

         RequestParams params = new RequestParams();// Parameters to attach to the request

         // Specific data information

         params.put("qqhy.myqqId",qquser.getQqId()+"");// My id

         params.put("qqhy.myqqZhanghao",qquser.getQqZhanghao());

         params.put("qqhy.myqqName",qquser.getQqName());

         params.put("qqhy.myqqTouxiang",qquser.getQqTouxiang());

         params.put("qqhy.myqqMark",qquser.getQqMark());

         params.put("qqhy.myqqStatu",qquser.getQqStatu()+"");//Online or offline

         params.put("qqhy.myqqFengzu", 0+"");//Default friend

         params.put("qqhy.hyqqId",hyuser.getQqId()+"");// id of the added friend

         params.put("qqhy.hyqqZhanghao",hyuser.getQqZhanghao());

         params.put("qqhy.hyqqName",hyuser.getQqName());

         params.put("qqhy.hyqqTouxiang",hyuser.getQqTouxiang());

         params.put("qqhy.hyqqMark",hyuser.getQqMark());

         params.put("qqhy.hyqqStatu",hyuser.getQqStatu()+"");

         params.put("qqhy.hyqqFengzu", 0+"");//The default group moves under friends, etc

         params.put("qqhy.hyStatu",0+"");

        

         client.post(uri,params,new JsonHttpResponseHandler(){

             @Override

             public void onStart() {      

             }

             @Override

             public void onFailure(Throwable arg0, String arg1) {

                 //Login failure - network problem

                 handler.sendEmptyMessage(2);

             }

             @Override

             public void onSuccess(int arg0, JSONObject arg1) {

                 //If the value obtained by Jsonobject is incorrect (jsonview), it will not continue

                 int result=arg1.optInt("result");

                 if(result==1){// When it is 1, it means successful insertion in the database

                      handler.sendEmptyMessage(3);

                 }else{

                      handler.sendEmptyMessage(4);

                 }

             }

             @Override

             public void onFinish() {

             }

         });

    }

(2) On the server side, specifically operate the database and add a row of data action to the friend table

public String becomeQqhy(){//Status is 0

         try{

             PrintWriter out = response.getWriter();

             boolean bln=ss.addQqhy(qqhy);

             if(bln){

                 result=new ResultFail(1);

             }else{

                 result=new ResultFail(0);

             }

             out.print(JSON.toJSONString(result));

             out.close();

         }catch(Exception e){

         }

         return null;

    }

(3) After Xiaohua logs in, click agree friend to change the status of this line of data to 1, which means she agrees.

private int hystatu;

    public String UpdHaoYou(){

         System.out.println(hyId);

         System.out.println(hystatu);

         try{

             PrintWriter out = response.getWriter();

             AndroidQqHy qqhys = ss.getQqhy(hyId);// First find out which row of data it is through the primary key

             qqhys.setHyStatu((long)hystatu);// Check whether the status of the incoming is yes or no

             boolean bln=ss.updHaoYouStatu(qqhys);// modify

             System.out.println(bln);

             if(bln){//Success or failure

                 result = new ResultFail(1);

             }else{

                 result = new ResultFail(0);

             }

             out.print(JSON.toJSONString(result));

            

             out.close();

         }catch(Exception e){

         }

         return null;

    }

Note: there is only one piece of data about the relationship between Xiaoming and Xiaohua in the database. The important concept is

When Xiao Ming logs in to his account, hyqq_id is the id of Xiaohua, indicating that Xiaoming's friend has Xiaohua.

When Xiaohua logs in to her account, myqq_id is Xiao Ming's id, hyqq_id is Xiaohua's id, which needs to be converted into Xiaoming, Xiaohua's friend.

2. Chat

On Android_ qq_ In the message table, qq_id is the current login account for sending the message, m_jsid is the friend account of the sent message, which is connected with the friend Android_ qq_ Like the hy table, the sender and receiver can be converted in different accounts.

(1) In ChartActivity, Xiaoming sends a message "Hello Xiaohua" to Xiaohua. The sender is Xiaoming, that is, myQQ in the friends list_ The recipient of ID is Xiaohua, that is, hyqq in the friends list_ ID person. The chat interface shows Xiaoming's head and "Hello Xiaohua" on the right

   public void sendMsgTodateOfHy(String str){

         sendmsg=new AndroidQqMessage(); // This message object is to send a message directly in the message list instead of finding it in the database

         //date

         Date date=new Date();//

         AsyncHttpClient client = new AsyncHttpClient();// Send network request object

         String uri =URI_IP.URI+"Android_Service/QQ/sendMessage";// address

         RequestParams params = new RequestParams();// Parameter composition

         // qqname is the current chat object, which is the nickname of my friend. qqhy is the data stored in the database between me and my friend

         // When a friend's nickname is a friend added in the qqhy table, the sender is me and the receiver is a friend

         if(qqname.equals(qqhy.getHyqqName())){

             params.put("msg.qqId", qqhy.getMyqqId()+"");// Set sender id

             params.put("msg.qqZhanghao", qqhy.getMyqqZhanghao());// Set sender qq account

             params.put("msg.qqName", qqhy.getMyqqName());// Set sender nickname

             params.put("msg.qqTouxiang", qqhy.getMyqqTouxiang());// Set sender Avatar

             params.put("msg.MJsid", qqhy.getHyqqId()+"");// Set recipient id

             params.put("msg.MZhanghao", qqhy.getHyqqZhanghao());// Set recipient account

             params.put("msg.MName", qqhy.getHyqqName());// Set recipient nickname

             params.put("msg.MTouxiang", qqhy.getHyqqTouxiang());// Set recipient Avatar

             sendmsg.setQqId(qqhy.getMyqqId());

             sendmsg.setQqZhanghao(qqhy.getMyqqZhanghao());

             sendmsg.setQqName(qqhy.getMyqqName());

             sendmsg.setQqTouxiang(qqhy.getMyqqTouxiang());

             sendmsg.setMJsid(qqhy.getHyqqId());

             sendmsg.setMZhanghao(qqhy.getHyqqZhanghao());

             sendmsg.setMName(qqhy.getHyqqName());

             sendmsg.setMTouxiang(qqhy.getHyqqTouxiang());

         }else{// When a friend's nickname is added in the qqhy table, the sender is a friend and the recipient is me

             params.put("msg.qqId", qqhy.getHyqqId()+"");

             params.put("msg.qqZhanghao", qqhy.getHyqqZhanghao());

             params.put("msg.qqName", qqhy.getHyqqName());

             params.put("msg.qqTouxiang", qqhy.getHyqqTouxiang());

             params.put("msg.MJsid", qqhy.getMyqqId()+"");

             params.put("msg.MZhanghao",  qqhy.getMyqqZhanghao());

             params.put("msg.MName", qqhy.getMyqqName());

             params.put("msg.MTouxiang", qqhy.getMyqqTouxiang());

             sendmsg.setQqId(qqhy.getHyqqId());

             sendmsg.setQqZhanghao(qqhy.getHyqqZhanghao());

             sendmsg.setQqName(qqhy.getHyqqName());

             sendmsg.setQqTouxiang(qqhy.getHyqqTouxiang());

             sendmsg.setMJsid(qqhy.getMyqqId());

             sendmsg.setMZhanghao(qqhy.getMyqqZhanghao());

             sendmsg.setMName(qqhy.getMyqqName());

             sendmsg.setMTouxiang(qqhy.getMyqqTouxiang());

         }

         params.put("msg.MMessage", str);// Set up chat messages

         params.put("msg.MStatu", 0+"");

         sendmsg.setMMessage(str);// Set up chat messages

         sendmsg.setMDate(date.getTime());

         sendmsg.setMStatu((long)0);

         client.post(uri,params,new JsonHttpResponseHandler(){

             @Override

             public void onStart() {      

             }

             @Override

             public void onFailure(Throwable arg0, String arg1) {

                 //Login failure - network problem

                 handler.sendEmptyMessage(2);

             }

             @Override

             public void onSuccess(int arg0, JSONObject arg1) {

                 int result=arg1.optInt("result");

                 if(result==1){// Send successfully

                      handler.sendEmptyMessage(1);

                 }else{

                      handler.sendEmptyMessage(0);

                 }

             }

             @Override

             public void onFinish() {

             }

         });

    }

2) Add a row of message records into the data table on the server side

   public String sendMessage(){

         try{

             PrintWriter out = response.getWriter();

              Date dd=new Date();

              msg.setMDate(dd);

             boolean bln = ss.addMsg(msg);

             System.out.println(bln);

             //Return success, wait for the picture to be added to the list

             if(bln){

                 result = new ResultFail(1);//success

             }else{

                 result = new ResultFail(0);//Failure will pop up the failed picture

             }

             out.print(JSON.toJSONString(result));

            

             out.close();

        }catch(Exception e){

             e.printStackTrace();

         }  

         return null;

    }

(3) When receiving information on Xiaohua's mobile phone, find the information line that the sender is Xiaoming, the receiver is Xiaohua, or the sender is Xiaohua and the receiver is Xiaoming.

//List of messages obtained in the chat interface

    public List getChartList(Long qqId,Long hyId){

         return listbysql("select m_id from android_qq_message where (qq_id="+qqId+" and  m_jsid="+hyId+") or (qq_id="+hyId+" and  m_jsid="+qqId+") order by m_date");

    }

(4) When the message in the chat interface on Xiaohua's mobile phone shows that the sender is Xiaoming and the receiver is Xiaohua, but the sender is not the current login Xiaohua, so this message "Hello Xiaohua" will be placed on the left.

(5) When Xiaohua replies to Xiaoming with a message "Hello Xiaoming, what's the matter", the sender is Xiaohua, the receiver is Xiaoming, and the sender is Xiaohua, the current login, so this message "Hello Xiaoming, what's the matter" will be placed on the right

(6) In Xiaoming's mobile phone, the message "Hello, Xiaoming, what's the matter" sent by Xiaohua is received. At this time, the sender is Xiaohua and the receiver is Xiaoming, but the sender is not the current login Xiaoming, so this message will be placed on the left

The explicit code of chat page is in chartbasadapter Java file

(7) Obtaining the information sent by the other party in real time is realized by sending delay information to query the database through the Handler.

handler.sendEmptyMessageDelayed(6, 12000);//Always query

private Handler handler = new Handler(){

         @Override

         public void handleMessage(Message msg) {

             int what = msg.what;

             switch (what) {

             case 0://Failed to send message

                 break;

             case 1://Send successfully added to list

                 chartlist.add(sendmsg);

                 //Refresh

                 notifylist();

                 //If the first message is to be displayed in the message list and I am the sender, it will be displayed with broadcast and global msglist, and compared with sendmsg and msglist

                 //checkifExit(sendmsg);

                 break;

             case 2://network

                 Toast.makeText(ChartActivity.this, "Network connection failed", 0).show();

                 break;

             case 3:

                 //Show in chat list

                 notifylist();

                 break;

             case 4:

                 Toast.makeText(ChartActivity.this, "Network connection failed", 0).show();

                 break;

             case 5://no message

                 handler.sendEmptyMessageDelayed(6, 12000);//Always query

                 //new chartlist

                 chartlist = new ArrayList<AndroidQqMessage>();

                 break;

             case 6:

                 getMsgOfdate();

                 break;

             default:

                 break;

             }

         }

    };
  1. Friend update function

Main file: dongtaiactivity java

The friend news function can view the comments published by friends. The most important thing is to query the news of your friends and sort them in reverse order according to time, as well as the uploaded pictures.

(1) Xiao Ming clicks the dynamic icon to pop up a new page, in which there are friends' comments. You need to query the data in the background. And add Xiaoming's own words.

   public String dynamic(){

         try{

             System.out.println(CurrPage);

             System.out.println(PageCount);

             PrintWriter out = response.getWriter();

             //According to qq_id query friend encapsulated as Arraylist

             List hylist = ss.selhy(qqId);//There are three fields, mainly to obtain myqq_id and hyqq_id

             //According to myqq_id or hyqq_id lookup dynamically filters friends based on qqId

             qqhyidlist = new ArrayList();//QQ friend id list

             for(int i=0;i<hylist.size();i++){

                 Map hymap = (Map)hylist.get(i);

                 Long hyqq_id = Long.parseLong(hymap.get("hyqq_id")+"");

                 Long myqq_id = Long.parseLong(hymap.get("myqq_id")+"");

                 if(hyqq_id==qqId){//If you are a friend

                      System.out.println("Come in hyqq_id");

                      qqhyidlist.add(myqq_id);

                 }else if(myqq_id==qqId){

                      System.out.println("Come in myqq_id");

                      qqhyidlist.add(hyqq_id);

                 }

             }

             qqhyidlist.add(qqId);//Add me

             List dynamiclist = ss.seldynamic(qqhyidlist,(CurrPage-1)*PageCount,PageCount);//QQ friend news is the beginning and end of the first few days

             List dynamiclists = new ArrayList<AndroidQqDynamic>(dynamiclist.size());//Convert to dynamic object list

             for(int j=0;j<dynamiclist.size();j++){

                 Map map = (Map)dynamiclist.get(j);

                 Long dyId=Long.parseLong(map.get("dy_id")+"");

                 AndroidQqDynamic dy = ss.getdynamic(dyId);

                 dynamiclists.add(dy);

             }

             qqdtlist = new AndroidQqDynamicList(1,dynamiclists);

             out.print(JSON.toJSONString(qqdtlist));

            

             out.close();

         }catch (Exception e) {

         }

        

         return null;

    }

(2) Xiao Mingfa said that after adding pictures and entering text and clicking send, the picture files will be saved in the server, while Android_ qq_ Dy in dynamic_ The photos field saves the path of the picture file saved in the server + Xiaoming QQ number + file name, and the files of multiple pictures are comma. Sending text and uploading pictures to the server are separated. Pictures have their own specified actions, and table data also has special actions to execute.

a. Upload files to the specified location on the server

Android terminal code:

public void sendPhotos(){

         for(int i=0;i<file.length;i++){// Selected image file array

             if(file[i]!=null){

                 AsyncHttpClient client = new AsyncHttpClient();// Network request

                 String uri=URI_IP.URI+"Android_Service/QQ/saveDtPhotos";// address

                 RequestParams params = new RequestParams();// Composition parameters

                 try {

                      params.put("file", file[i]);// Picture files can be imported directly

                 } catch (Exception e) {

                      // catch block automatically generated by TODO

                      e.printStackTrace();

                 }

                 params.put("dynamicnamephoto",dynamicnamephoto[i]);//dynamicnamephoto is the name of the selected picture

                 client.post(uri,params,new JsonHttpResponseHandler(){

                      @Override

                      public void onStart() {      

                      }

                      @Override

                      public void onFailure(Throwable arg0, String arg1) {

                          //Login failure - network problem

                          handler.sendEmptyMessage(2);

                      }

                      @Override

                      public void onSuccess(int arg0, JSONObject arg1) {

                          //If the value obtained by Jsonobject is incorrect (jsonview), it will not continue

                          int result=arg1.optInt("result");

                          if(result==1){

                              handler.sendEmptyMessage(3);

                          }else{

                              handler.sendEmptyMessage(4);

                          }

                      }

                      @Override

                      public void onFinish() {

                      }

                 });

             }else{

                 i=file.length;

             }

         }

         handler.sendEmptyMessage(3);

    }

Server code:

public String saveDtPhotos(){

         try {

             PrintWriter out = response.getWriter();

             System.out.println(file[0].getName());

             // Use file output stream to output pictures

             FileOutputStream fos=new FileOutputStream(this.savePath+dynamicnamephoto[0]);

             // First convert the uploaded file into a file input stream

             FileInputStream fil=new FileInputStream(this.file[0]);

             // The size of each read and write.

             // io stream is to first read 1024 bytes from the file input stream, and then output 1024 bytes from the file output stream to the folder (this.savePath+dynamicnamephoto[0])

             byte[] b=new byte[1024];

             int real=fil.read(b);

             int ii=0;

             while(real>0){

                 fos.write(b, 0, real);

                

                 real=fil.read(b);//Each time you read in and write out a file, you will miss this part, so this 1kb1kb writing knows that you can't read in

                

                 ii++;

             }

             System.out.println(ii);

             fos.close();fil.close();

             result = new ResultFail(1);

             out.print(JSON.toJSONString(result));

         } catch (Exception e) {

             // TODO Auto-generated catch block

             e.printStackTrace();

         }

         return null;

    }

b. Upload a row of table data to action to save

Android terminal code:

public void add(){

         Date date = new Date();

         AsyncHttpClient client = new AsyncHttpClient();

         String uri=URI_IP.URI+"Android_Service/QQ/adddynamic";

         RequestParams params = new RequestParams();

         params.put("qqdynamic.qqId", qquser.getQqId()+"");

         params.put("qqdynamic.qqZhanghao", qquser.getQqZhanghao());

         params.put("qqdynamic.qqName", qquser.getQqName());

         params.put("qqdynamic.qqTouxiang", qquser.getQqTouxiang());

         params.put("qqdynamic.dyDate",date.toLocaleString());

         params.put("qqdynamic.dyContent",adddt_rl2_et1.getText().toString());

         for(int i=0;i<dynamicnamephoto.length;i++){

             Object obj = dynamicnamephoto[i];

             if(obj!=null){

                 dyPhotos+=dynamicnamephoto[i]+",";//Database string

             }else{

                 i=dynamicnamephoto.length;

             }

         }

         params.put("qqdynamic.dyPhotos", dyPhotos+"");//Multiple pictures are separated by numbers, which is also... This file name needs to be redefined in the composition

         client.post(uri,params,new JsonHttpResponseHandler(){

             @Override

             public void onStart() {      

             }

             @Override

             public void onFailure(Throwable arg0, String arg1) {

                 //Login failure - network problem

                 handler.sendEmptyMessage(2);

             }

             @Override

             public void onSuccess(int arg0, JSONObject arg1) {

                 //If the value obtained by Jsonobject is incorrect (jsonview), it will not continue

                 int result=arg1.optInt("result");

                 if(result==1){

                      handler.sendEmptyMessage(1);

                 }else{

                      handler.sendEmptyMessage(0);

                 }

             }

             @Override

             public void onFinish() {

             }

         });

    }

Server code:

 //Name of uploaded file

    private String[] dynamicnamephoto;

    public String adddynamic(){

         //Return json

         try {

             PrintWriter out = response.getWriter();

             boolean bln= ss.addQqDt(qqdynamic);

             System.out.println(bln);     

             //Upload successfully and get the refresh page again

             if(bln){

                 result = new ResultFail(1);

             }else{

                 result = new ResultFail(0);

             }

             out.print(JSON.toJSONString(result));

             out.close();

         } catch (IOException e) {

             // catch block automatically generated by TODO

             e.printStackTrace();

         }

         return null;

    }

Summary of server-side implementation

  1. Server side functions

The main control computer processes the data information sent by each wireless terminal, processes, processes (and feeds back information if necessary) and sends, so as to carry out a series of functional operations.

The server mainly operates the database, and sets the server applet responding to the corresponding functions for each module of the wireless terminal. The main Servlet (as shown in the figure).

Figure 4-17 server function diagram

2. Server side code example

action

//1. Registered user

    public String zhuce(){

         try{

             // Get the data from the mobile terminal

             PrintWriter out = response.getWriter();

             System.out.println("Come in register");

             System.out.println(qquser.getQqAddress()+qquser.getQqZhanghao());

             // Add to database

             boolean bln=ss.addUser(qquser);

             // Returns whether it was added successfully

             if(bln){

                 result=new ResultFail(1);

             }else{

                 result=new ResultFail(0);

             }

             out.print(JSON.toJSONString(result));// Return json format data

            

             out.close();

         }catch (Exception e) {

         }

         return null;

    }

On

Through the development of the system, I have comprehensively mastered the basic knowledge and programming skills of JAVA-Android development, and my development ability has been further improved in the development process. For example, further understand Android development, the use of SQL language and the ability to solve bugs.

In the development process, I learned some experience: the quality of system analysis will determine the success of system development, and a good analysis and design will be the main factor for successful development. We should not rush to program before starting development. We should take a long time to do a good job in analysis, database design and write relevant development documents. Then start to write the program code, so that each step of writing the code has a clear idea and no details.

In addition, I also feel that I have taken many detours in this design. This is mainly due to the lack of experience in software development and application, which requires more efforts in the future.

For me, the impact of this design itself is far from over. I learned a lot of knowledge from this graduation project that is not in the textbooks. Through their own learning and efforts; Through the guidance and education of teachers, I have greatly improved my knowledge level and ability to solve practical problems. Also from the depths of thought, I realized the various difficulties I would face when I wanted to turn what I learned into reality.

Keywords: Java Android Apache

Added by Felex on Wed, 23 Feb 2022 16:05:41 +0200