Android class-based report 123 Zhao dry

Based on Android design and implementation of Meow day shopping system

A , purpose and significance of topics

With the popularity of smart phones, on -demand applications on the Android platform more and more. By theoretical knowledge learned in courses three years before the design and development of computer systems to verify and expand undergraduate, in practice, in-depth understanding of the important and difficult in which to improve the basic theoretical level, solid foundation of knowledge, to master the computer systems design and development basic skills, capacity flexible use of theoretical knowledge to analyze and solve practical problems.

The moment we are in the era of big data network, no doubt, stand out online shopping, since that is Ma founded Alibaba, online shopping has become the source of people's increasing demand for shopping, and its simple and convenient, homes will be able to buy their favorite items, deep loved by the public. So I made this topic meow day shopping system.

  1. Use of technology

(1) UI design: for page design.

(2) SQLite database: used to implement the shopping cart functionality, and add CRUD functionality.

(. 3) Activity application component: a plurality Activity handover.

(4) ListView use: for page layout.

(5) MD5 algorithm used: for registered users.

 

Field name

type of data

length

Primary key

index

Foreign key

Name

Char

50

Yes

 

no

Balance

Int

11

no

 

no

 

 

 

 

Second, the system needs analysis

2.1 user needs

Meow day shopping systems can be used for e-commerce sellers electricity supplier platform that provides an opportunity for online transactions, and support updates and maintenance, ease of use, ease of use and strong. Approximate function of the system implementation; registered user login. It provides information for the goods, add, modify, delete; entry of user information, modify, delete, query and other functions. Management has the highest administrator privileges.

2.2  Functional Requirements

1. System Log: add at the beginning of the interface in the bottom three navigation buttons to enter the items I classify interface and management interface are my management interface are arranged three buttons, each registered user login, user's personal information and shopping cart page, and then to realize the function of each module between each other by jumping activity.

2. Add Product Info: opens a page in my shopping cart interface, item information has been added by entering the fast query product information.

3. Modify the product information: product design ideas and add similar information, can modify the product information has been added.

4, delete product information: After selecting product information to be deleted by clicking the trash button to complete the delete function can delete the product information has been added.

 

 

 

2.3 UML class diagram

                                            Meow day shopping system

 

 

 

 

 

 

 

 

 three. System design, implementation and testing

1. Design System

 

1.1 FIG. Analysis Example

 

 

 

 

 Figure 3.1 Tian Meow shopping system ER diagram

 

1.2 File List

 

 

 

 

 

 

 

 

 

 

 

 

 2. implement the system

The original file code

 

J Ava  MainActivity original码

package com.neusoft.constellation;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {


    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Intent intent = null;
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    return true;
                case R.id.navigation_dashboard:
                    intent = new Intent(MainActivity.this, ShopActivity.class);
                    startActivity(intent);
                    return true;
                case R.id.navigation_notifications:
                    intent = new Intent(MainActivity.this, MyActivity.class);
                    startActivity(intent);
                    return true;
            }
            return false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }

}

 

类说明:主页面即通过底部导航跳转到其他页面

 

Java Main2Activity原码

 

package com.neusoft.constellation;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


public class Main2Activity extends AppCompatActivity {
    private String userName,psw,spPsw;
    private EditText et_user_name,et_psw;
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        init();
    }

    private void init() {
        TextView tv_register = (TextView) findViewById(R.id.tv_register);
        TextView tv_find_psw = (TextView) findViewById(R.id.tv_find_psw);
        Button btn_login = (Button) findViewById(R.id.btn_login);
        et_user_name= (EditText) findViewById(R.id.et_user_name);
        et_psw= (EditText) findViewById(R.id.et_psw);

        tv_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent(com.neusoft.constellation.Main2Activity.this, RegisterActivity.class);
                startActivityForResult(intent, 1);
            }
        });

        tv_find_psw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(com.neusoft.constellation.Main2Activity.this, LostFindndActivity.class));
            }
        });

        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                userName = et_user_name.getText().toString().trim();
                psw = et_psw.getText().toString().trim();

                String md5Psw = MD5Utils.md5(psw);

                spPsw = readPsw(userName);

                if (TextUtils.isEmpty(userName)) {
                    Toast.makeText(com.neusoft.constellation.Main2Activity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
                } else if (TextUtils.isEmpty(psw)) {
                    Toast.makeText(com.neusoft.constellation.Main2Activity.this, "请输入密码", Toast.LENGTH_SHORT).show();

                } else if (md5Psw.equals(spPsw)) {
                    Toast.makeText(com.neusoft.constellation.Main2Activity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    saveLoginStatus(true, userName);
                    Intent data = new Intent();
                    data.putExtra("isLogin", true);
                    setResult(RESULT_OK, data);
                    com.neusoft.constellation.Main2Activity.this.finish();
                    startActivity(new Intent(com.neusoft.constellation.Main2Activity.this, MainActivity.class));
                } else if ((spPsw != null && !TextUtils.isEmpty(spPsw) && !md5Psw.equals(spPsw))) {
                    Toast.makeText(com.neusoft.constellation.Main2Activity.this, "输入的用户名和密码不一致", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(com.neusoft.constellation.Main2Activity.this, "此用户名不存在", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private String readPsw(String userName){
        SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);
        return sp.getString(userName , "");
    }
    private void saveLoginStatus(boolean status,String userName){
        SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putBoolean("isLogin", status);
        editor.putString("loginUserName", userName);
        editor.apply();
    }

    @Override

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(data!=null){
            String userName=data.getStringExtra("userName");
            if(!TextUtils.isEmpty(userName)){
                et_user_name.setText(userName);
                et_user_name.setSelection(userName.length());
            }
        }
    }
}

 

 

类说明:实现的用户登录及跳转到注册页面或我的页面

Java RegisterActivity原码

 

 

 

package com.neusoft.constellation;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;


public class RegisterActivity extends AppCompatActivity {
    private EditText et_user_name,et_psw,et_psw_again;
    private String userName,psw,pswAgain;
    private RadioGroup Sex;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        init();
    }

    private void init() {
        Button btn_register = (Button) findViewById(R.id.btn_register);
        et_user_name= (EditText) findViewById(R.id.et_user_name);
        et_psw= (EditText) findViewById(R.id.et_psw);
        et_psw_again= (EditText) findViewById(R.id.et_psw_again);
        Sex= (RadioGroup) findViewById(R.id.SexRadio);
        btn_register.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                getEditString();
                int sex;
                int sexChoseId = Sex.getCheckedRadioButtonId();
                switch (sexChoseId) {
                    case R.id.mainRegisterRdBtnFemale:
                        sex = 0;
                        break;
                    case R.id.mainRegisterRdBtnMale:
                        sex = 1;
                        break;
                    default:
                        sex = -1;
                        break;
                }

                if(TextUtils.isEmpty(userName)){
                    Toast.makeText(com.neusoft.constellation.RegisterActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
                }else if(TextUtils.isEmpty(psw)){
                    Toast.makeText(com.neusoft.constellation.RegisterActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
                }else if(TextUtils.isEmpty(pswAgain)) {
                    Toast.makeText(com.neusoft.constellation.RegisterActivity.this, "请再次输入密码", Toast.LENGTH_SHORT).show();
                } else if (sex<0){
                    Toast.makeText(com.neusoft.constellation.RegisterActivity.this, "请选择性别", Toast.LENGTH_SHORT).show();
                }else if(!psw.equals(pswAgain)){
                    Toast.makeText(com.neusoft.constellation.RegisterActivity.this, "输入两次的密码不一样", Toast.LENGTH_SHORT).show();
                }else if(isExistUserName(userName)){
                    Toast.makeText(com.neusoft.constellation.RegisterActivity.this, "此账户名已经存在", Toast.LENGTH_SHORT).show();

                }else{
                    Toast.makeText(com.neusoft.constellation.RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                    saveRegisterInfo(userName, psw);
                    Intent data = new Intent();
                    data.putExtra("userName", userName);
                    setResult(RESULT_OK, data);
                    com.neusoft.constellation.RegisterActivity.this.finish();
                }
            }
        });
    }
    private void getEditString(){
        userName=et_user_name.getText().toString().trim();
        psw=et_psw.getText().toString().trim();
        pswAgain=et_psw_again.getText().toString().trim();
    }
    private boolean isExistUserName(String userName){
        boolean has_userName=false;
        SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);
        String spPsw=sp.getString(userName, "");
        if(!TextUtils.isEmpty(spPsw)) {
            has_userName=true;
        }
        return has_userName;
    }
    private void saveRegisterInfo(String userName,String psw){
        String md5Psw = MD5Utils.md5(psw);
        SharedPreferences sp=getSharedPreferences("loginInfo", MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putString(userName, md5Psw);
        editor.apply();
    }
}

 

 

 

 

 

 

 

类说明:实现的注册及返回登陆页面

 

Java MD5Utils原码

 

package com.neusoft.constellation;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Utils {
    public static String md5(String text) {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("md5");
            byte[] result = digest.digest(text.getBytes());
            StringBuffer sb = new StringBuffer();
            for (byte b : result){
                int number = b & 0xff;
                String hex = Integer.toHexString(number);
                if (hex.length() == 1){
                    sb.append("0"+hex);
                }else {
                    sb.append(hex);
                }
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return "";
        }
    }
}

 

 

 

类说明:运用MD5算法实现注册

 

Java DbHelper原码

 

package com.neusoft.constellation;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {
    public DbHelper(Context context) {
        super(context, "fruit.db", null, 2);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        System.out.println("OnCreate");
        db.execSQL("Create TABLE fruit(id INTEGER PRIMARY KEY AUTOINCREMENT,name VARCHAR(20), balance INTEGER)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        System.out.println("OnUpgrade");
    }
}

 

 

类说明:建立SQL数据库

 

Java FruitDao原码

 

package com.neusoft.constellation;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.List;

public class FruitDao {
    private DbHelper dbHelper;

    public FruitDao(Context context) {
        dbHelper =new DbHelper(context);
    }
    public void insert(Fruit fruit){
        SQLiteDatabase db =dbHelper.getWritableDatabase();
        ContentValues values =new ContentValues();
        values.put("name",fruit.getName());
        values.put("balance",fruit.getBalance());
        long id = db.insert("fruit",null,values);
        fruit.setId(id);
        db.close();
    }
    public  int delete(long id){
        SQLiteDatabase db =dbHelper.getWritableDatabase();
        int count=db.delete("fruit","_id=?",new String[]{id+""});
        db.close();
        return count;
    }
    public List<Fruit> getAll(){
        SQLiteDatabase db =dbHelper.getReadableDatabase();
        Cursor c =db.query("fruit",null,null,null,null,null,"balance DESC");
        List<Fruit> list =new ArrayList<>();
        while (c.moveToNext()){
            long id =c.getLong(c.getColumnIndex("id"));
            String name = c.getString(1);
            int balance =c.getInt(2);
            list.add(new Fruit(id,name,balance));
        }
        c.close();
        db.close();
        return list;
    }
}

 

类说明:实现数据库的增删改查功能

 

  1. 系统的测试

3.1测试环境

1.设计环境:Android studio

2.测试环境:Android studio虚拟机及真机调试

3.2测试过程

  1. 测试能否正常运行程序
  2. 测试添加页面能否正常添加商品
  3. 测试能否查询商品信息
  4. 测试能否修改商品信息
  5. 测试能否删除商品信息
  6. 测试能否实现用户登录和注册

测试结果

  1. 测试能否正常运行程序

 

 

 

 

2.测试添加页面能否正常添加商品

 

 

 

 

3.测试能否查询商品信息

 

 

 

4.测试能否修改商品信息

 

 

 

 

5.测试能否删除商品信息

 

 

 

 

6. 测试能否实现用户登录和注册

 

 

 

 

 

四. 课程设计总结

此系统是我做的一个简单的天喵购物城系统,用到了Android和Java以及之前所学到的相关知识。它的优点在于简单明了,容易上手操作,便于实现功能,从系统代码也比较容易修改,缺点是功能不是很完善,而且代码有些地方比较繁琐,仅仅是一个设计,在实际用途中还是有一定的技术差距。

在设计中我深知自己掌握的知识还远远不够,掌握的一些理论知识应用到实践中去,总会出现这样的问题,光知道书本上的知识是远远不够的,一定要把理论知识和实践结合起来。把学到的知识应用到时间中去,多做多练,才可以把理论的精华发挥出来,知识不是知道,了解就好,而是要去应用并且发展它,让它得到充分的应用,从而解决一些问题,这才是学习的根本目的。在这次课程设计中,得到了老师和同学们很多的帮助,学到了很多书本上学不到的知识,今后,我还要加强学习,努力使自己成为一位专业的计算机人员,为我今后从事的工作。

 最后,感谢学校和老师给了我这次锻炼的机会,希望以后还有这样锻炼自己的机会。

Guess you like

Origin www.cnblogs.com/zq542960954/p/12000019.html