第一次迭代任务

1、欢迎界面
打开我们的app,会出现带有我们“速达”app Logo的欢迎界面,闪频20秒就会进入登录界面,界面如下

主要XML代码
、、、

、、、

主要Java代码
、、、
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);
   }

}

}
、、、

2、登录界面
有账号的输入账号密码,直接进入主界面,当然主界面的功能我们在第二次迭代的时候会实行
界面如下

主要XML代码
、、、

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">


        <EditText
            android:id="@+id/LoginName"
            android:layout_width="match_parent"
            android:layout_height="40dp"

            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="@android:color/transparent"
            android:hint="请输入用户名"
            android:inputType="text"
            />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="#000000" />

        <EditText
            android:id="@+id/LoginPwd"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"

            android:background="@android:color/transparent"
            android:hint="请输入密码"
            android:inputType="textPassword"
            />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="#000000"/>

        <Button
            android:id="@+id/Login"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="20dp"
            android:background="#FFC125"
            android:text="登录"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center_horizontal"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="没有账号?" />

            <TextView
                android:id="@+id/Regist1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="马上注册"
                android:textColor="@android:color/holo_blue_bright" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

、、、

主要java代码如下
、、、
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);



    Login.setOnClickListener(new View.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 (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 View.OnClickListener() {

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

        }
    });
}

、、、

3、注册界面
如果没有账号需注册再行登录

主要XML代码
、、、

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <EditText
            android:id="@+id/RegistName"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="@android:color/transparent"
            android:ems="10"
            android:hint="请输入用户名"
            android:inputType="text" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="#000000" />

        <EditText
            android:id="@+id/RegistPwd"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="@android:color/transparent"
            android:ems="10"
            android:hint="请输入密码"
            android:inputType="textPassword" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="#000000" />

        <EditText
            android:id="@+id/RegistPwd2"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="@android:color/transparent"
            android:ems="10"
            android:hint="确认密码"
            android:inputType="textPassword" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="#000000" />

        <Button
            android:id="@+id/Regist"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:layout_marginTop="20dp"
            android:background="#FFC125"
            android:textColor="#ffffff"
            android:text="注册"
            android:textSize="20sp" />
    </LinearLayout>


</RelativeLayout>

、、、

主要java代码如下

、、、
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);

    Regist.setOnClickListener(new View.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 (!"".equals(RName) && !"".equals(RPwd) && !"".equals(RPwd2)) {
                if (!RPwd.equals(RPwd2)) {
                    Toast.makeText(RegistActivity.this, "两次输入的密码不一致", Toast.LENGTH_LONG).show();
                } else {
                    AVUser user = new 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();
            }
        }
    });

}

、、、

原文地址:https://www.cnblogs.com/zjh55/p/6776221.html