#在android studio中维护日程管理系统

1、首先打开日程管理系统,主要看看java包和.xml,熟悉一下代码要实现具体功能。你可以发现,这个java程序全都放在一个包里,当然,这个是一个小的程序,java程序还不算太多。要是可以更加的规范,把实现不能功能的java程序分别打包,那就更好了。

2、然后找到程序的入口,在AndroidManifest中有很多你建的activity,其中有个特殊的就是intent-filer这个就是表示你这个程序的入口,那么我们这个工程的入口就是

WelcomeActivity,接下来我们就去看WelcomeActivity

3、查看欢迎界面的xmlWelcomeActivity,找出是否有错误

、、、
package com.example.tasks;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.avos.avoscloud.AVUser;//第三方云库

public class WelcomeActivity extends Activity {

Handler handler = new Handler();

//调转到登录界面
Runnable runnable = new Runnable() {

	public void run() {
		Intent intent = new Intent(WelcomeActivity.this, LoginActivity.class);
		startActivity(intent);
		finish();

	}

};
//调转到主界面
Runnable runnable1 = new Runnable() {

	public void run() {
		Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
		startActivity(intent);
		finish();

	}

};

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_welcome);
	AVUser currentUser = AVUser.getCurrentUser();//加载第三方云库
	handler.postDelayed(runnable,2000);//闪频维持二十秒再次跳转至登录界面

	//以下的是错误的地方的修改,之前没有这段代码,所以欢迎界面显示不出来
    if (currentUser != null) {
        // 跳转到首页,
    	handler.postDelayed(runnable1, 2000);
    } else {
        //缓存用户对象为空时,可打开用户注册界面…
    	handler.postDelayed(runnable, 2000);
    }

}

}
、、、

4、现在阅读注册界面java代码** RegistActivity**

、、、

public class RegistActivity extends Activity {
EditText RegistName;
EditText RegistPwd;
EditText RegistPwd2;
Button Regist;
String RName;
String RPwd;
String RPwd2;
String regist;

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_regist);
	RegistName = (EditText) findViewById(R.id.RegistName);
	RegistPwd = (EditText) findViewById(R.id.RegistPwd);
	RegistPwd2 = (EditText) findViewById(R.id.RegistPwd2);
	Regist = (Button) findViewById(R.id.Regist);



	// 修改状态栏颜色,4.4+生效
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		setTranslucentStatus();
	}
	SystemBarTintManager tintManager = new SystemBarTintManager(this);
	tintManager.setStatusBarTintEnabled(true);
	tintManager.setStatusBarTintResource(R.drawable.iphone);//通知栏所需颜色

	Regist.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub

			RName = RegistName.getText().toString();
			RPwd = RegistPwd.getText().toString();
			RPwd2 = RegistPwd2.getText().toString();
        //这个if少了个异常处理的,如果都为空,报错
			if (!"".equals(RName) && !"".equals(RPwd) && !"".equals(RPwd2)) {
				if (!RPwd.equals(RPwd2)) {
					Toast.makeText(RegistActivity.this, "两次输入的密码不一致", Toast.LENGTH_LONG).show();
				} else {
					AVUser user = new AVUser();// 新建 AVUser 对象实例
					user.setUsername(RName);// 设置用户名
					user.setPassword(RPwd);// 设置密码
					user.signUpInBackground(new SignUpCallback() {
						@Override
						public void done(AVException e) {
							if (e == null) {
								// 注册成功
								Toast.makeText(RegistActivity.this, "注册成功", Toast.LENGTH_LONG).show();
								Handler handler = new Handler();
								Runnable runnable = new Runnable() {

									@Override
									public void run() {
										// TODO Auto-generated method stub
										Intent intent = new Intent(RegistActivity.this, LoginActivity.class);
										startActivity(intent);
										finish();

									}
								};
								handler.postDelayed(runnable, 2000);
							} else {
								// 失败的原因可能有多种,常见的是用户名已经存在。
								Toast.makeText(RegistActivity.this, "用户名已存在", Toast.LENGTH_LONG).show();
							}

						}

					});
				}
			}else {
				//加个报错的Toast
				Toast.makeText(RegistActivity.this, "账号密码不能为空", Toast.LENGTH_LONG).show();
			}
		}
	});

}

private void setTranslucentStatus() {

	Window window = this.getWindow();
	// Translucent status bar
	window.setFlags(
			WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
			WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}

}

修改完运行结果如下

、、、

5、用户注册完之后,数据库里就有了用户的账号,然后点击登录,以下是修改的代码

、、、

public class LoginActivity extends Activity {
TextView LoginName;
TextView LoginPwd;
Button Login;
TextView Regist1;
String LN;
String LP;

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_login);
	LoginName=(TextView) findViewById(R.id.LoginName);
	LoginPwd=(TextView) findViewById(R.id.LoginPwd);
	Login=(Button) findViewById(R.id.Login);
	Regist1=(TextView) findViewById(R.id.Regist1);


	// 修改状态栏颜色,4.4+生效
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		setTranslucentStatus();
	}
	SystemBarTintManager tintManager = new SystemBarTintManager(this);
	tintManager.setStatusBarTintEnabled(true);
	tintManager.setStatusBarTintResource(R.drawable.iphone);//通知栏所需颜色
	Login.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			LN=LoginName.getText().toString();
			LP=LoginPwd.getText().toString();
			//云数据库,使用此类
			AVUser.logInInBackground(LN, LP, new LogInCallback<AVUser>() {
	            @Override
	            public void done(AVUser avUser, AVException e) {
	            	//判断是否为空,此处错误,只有if语句,缺少else语句,做出个Toast
	            	if (avUser!=null) {
	            		Intent intent=new Intent(LoginActivity.this, MainActivity.class);
	            		startActivity(intent);
	            		finish();
					}else{
						Toast.makeText(LoginActivity.this, "账号密码不能为空", Toast.LENGTH_LONG).show();
					}


	            }
	        });
		}
	});
	Regist1.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent=new Intent(LoginActivity.this,RegistActivity.class);
			startActivity(intent);
			
		}
	});
}

private void setTranslucentStatus() {


	Window window = this.getWindow();
	// Translucent status bar
	window.setFlags(
			WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
			WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}

}
、、、

以下是修改过之后的运行结果

posted @ 2017-03-29 10:45  张佳慧1502720137  阅读(1315)  评论(0编辑  收藏  举报