微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

第二阶段冲刺总结

由于临近期末,最近比较忙,作业比较多,所以第二阶段开始的比较晚,也比较仓促,每天都是挤时间做一些。自从5月31号分配完任务开始,我们便各自开始了各自的任务,一开始,我们一起做播放音频的任务,后来效率实在缓慢,便分开做了,我负责了登陆注册功能的实现,以及观看视频的功能,经过6天的努力和今天一天的整合,我们的项目基本上算是完成了,虽然很多功能还不能尽善尽美,但是完成我们:“让在校学生能观看歌唱比赛的一些现场视频” 的功能已经能够实现了。下面是我完成部分的代码。(由于另一位组员也实现了登陆和注册,我们在6月5号的小会议上经过任务再划分和比较决定使用他的注册登录界面和后台,我使用的是Android studio自带sqlite)

 

shipin.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.example.dell.schoolmusic.MainActivity">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="300dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始"
android:layout_marginLeft="20dp"/>

<Button
android:id="@+id/btn_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="结束" />
</LinearLayout>
</LinearLayout>

shipin.java:

package com.example.dell.schoolmusic;


import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;

public class shipinActivity extends AppCompatActivity {
private VideoView videoView;
private Button btn_start,btn_end;
private MediaController mediaController;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shipin);
initView();
}

private void initView() {
videoView= (VideoView) findViewById(R.id.videoView);
btn_start= (Button) findViewById(R.id.btn_start);
btn_end= (Button) findViewById(R.id.btn_end);


btn_start.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
init();
}
});
btn_end.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
videoView.stopPlayback();
}
});
}

private void init() {
videoView = (VideoView) findViewById(R.id.videoView);
mediaController = new MediaController(this);
String uri = "android.resource://" + getPackageName() + "/" + R.raw.ass;
videoView.setVideoURI(Uri.parse(uri));
videoView.setMediaController(mediaController);
mediaController.setMediaPlayer(videoView);
videoView.requestFocus();
videoView.start();
}
}

(这里面使用的是本地的路径观看的视频,是将视频放到res包下的raw包中)


登录注册的.xml文件就不放了,只是一些简单的EditText和Button的布局,直接上java代码部分:


service包下:
DatabaseHelper:
package com.example.dell.schoolmusic.service;

/**
* Created by DELL on 2020/6/4.
*/

import android.content.Context;
import android.database.sqlite.sqliteDatabase;
import android.database.sqlite.sqliteDatabase.CursorFactory;
import android.database.sqlite.sqliteOpenHelper;

public class DatabaseHelper extends sqliteOpenHelper {
static String name="user.db";
static int dbVersion=1;
public DatabaseHelper(Context context) {
super(context, name, null, dbVersion);
}

public void onCreate(sqliteDatabase db) {
String sql="create table user(id integer primary key autoincrement,username varchar(20),password varchar(20))";
db.execsql(sql);
}
public void onUpgrade(sqliteDatabase db, int oldVersion, int newVersion) {

}
}

UserService:
package com.example.dell.schoolmusic.service;

/**
* Created by DELL on 2020/6/4.
*/

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.sqliteDatabase;

import com.example.dell.schoolmusic.User;


public class UserService {
private DatabaseHelper dbHelper;
public UserService(Context context){
dbHelper=new DatabaseHelper(context);
}

public boolean login(String username,String password){
sqliteDatabase sdb=dbHelper.getReadableDatabase();
String sql="select * from user where username=? and password=?";
Cursor cursor=sdb.rawQuery(sql, new String[]{username,password});
if(cursor.movetoFirst()==true){
cursor.close();
return true;
}
return false;
}
public boolean register(User user){
sqliteDatabase sdb=dbHelper.getReadableDatabase();
String sql="insert into user(username,password) values(?,?)";
Object obj[]={user.getUsername(),user.getpassword()};
sdb.execsql(sql, obj);
return true;
}
}

Login:
package com.example.dell.schoolmusic;

import android.content.Intent;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.dell.schoolmusic.service.UserService;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class LoginActivity extends AppCompatActivity {
private EditText username;
private EditText password;
private Button mBtnlogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mBtnlogin = (Button)findViewById(R.id.login1);
username=(EditText) findViewById(R.id.edit_lg1);
password=(EditText) findViewById(R.id.edit_lg2);
mBtnlogin.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name=username.getText().toString();
System.out.println(name);
String pass=password.getText().toString();
System.out.println(pass);
Log.i("TAG",name+"_"+pass);
UserService uService=new UserService(LoginActivity.this);
boolean flag = uService.login(name,pass);

if(flag){
Log.i("TAG","登陆成功");
Toast.makeText(LoginActivity.this,"登陆成功",Toast.LENGTH_LONG).show();
Intent intent = new Intent(LoginActivity.this,Sz_indexActivity.class);
startActivity(intent);
}else{
Log.i("TAG","登录失败");
Toast.makeText(LoginActivity.this,"账号或密码错误",Toast.LENGTH_LONG).show();

}
}
});
}
}

register:
package com.example.dell.schoolmusic;

/**
* Created by DELL on 2020/6/5.
*/
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.dell.schoolmusic.service.UserService;

public class Registeractivity extends Activity {

EditText username;
EditText password;
Button register;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
findViews();
register.setonClickListener(new View.OnClickListener() {
public void onClick(View v) {
String name=username.getText().toString().trim();
String pass=password.getText().toString().trim();
Log.i("TAG",name+"_"+pass);
UserService uService=new UserService(Registeractivity.this);
User user=new User();
user.setUsername(name);
user.setPassword(pass);
uService.register(user);
Toast.makeText(Registeractivity.this, "注册成功", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Registeractivity.this, MainActivity.class);
startActivity(intent);
}
});
}
private void findViews() {
username=(EditText) findViewById(R.id.edit_reg1);
password=(EditText) findViewById(R.id.edit_reg2);
register=(Button) findViewById(R.id.register1);

}
}

User:

package com.example.dell.schoolmusic;

/**
* Created by DELL on 2020/6/4.
*/

import java.io.Serializable;

public class User implements Serializable{
private int id;
private String username;
private String password;
public User() {
super();
// Todo Auto-generated constructor stub
}
public User(String username, String password) {
super();
this.username = username;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getpassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", password="
+ password + "]";
}

}




 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐