您的位置:首页 > 移动开发 > Android开发

android 毕业设计项目开发 -登录界面

2016-07-18 15:42 375 查看

APP登录界面

android 毕业设计项目开发

2016年3月

app包含注册登录功能,注册需要邮箱验证,邮箱会收到一条链接,点击验证即可激活。

Created with Raphaël 2.1.0开始我的操作确认?结束yesno

LoginActivity.java

package com.lgq.fruitgrower.view.act;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.lgq.fruitgrower.R;
import com.lgq.fruitgrower.model.beans.UserLogin;
import com.lgq.fruitgrower.model.constance.Constance;
import com.lgq.fruitgrower.model.servers.login.Login;
import com.lgq.fruitgrower.view.MainActivity;
import com.lgq.fruitgrower.view.base.BaseAct;
import com.lgq.fruitgrower.view.utils.ToastUtils;

import cn.bmob.v3.listener.SaveListener;

public class LoginActivity extends BaseAct implements View.OnClickListener{

private TextView btn_sign_email;
private TextView btn_sign_phone;
private TextView email;
private TextView password;
private Button email_sign_in_button;

//  private TextView test_web;

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

//init view
initView();

//设置监听事件
btn_sign_email.setOnClickListener(this);
email_sign_in_button.setOnClickListener(this);
btn_sign_phone.setOnClickListener(this);
}

private void initView() {
btn_sign_email = (TextView) findViewById(R.id.btn_sign_email);
btn_sign_phone = (TextView) findViewById(R.id.btn_sign_phone);
email = (TextView) findViewById(R.id.email);
password = (TextView) findViewById(R.id.password);
email_sign_in_button = (Button) findViewById(R.id.email_sign_in_button);
}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_sign_email:
//设置字体颜色的改变
btn_sign_email.setTextColor(Color.GRAY);
intent2Activity(SignActivity.class);

break;
case R.id.btn_sign_phone:
btn_sign_phone.setTextColor(Color.GREEN);
ToastUtils.showToast(this, "短信注册需要一定的费用,如果你有兴趣不妨小额的支持我,敬请期待。", Toast.LENGTH_LONG);
break;
case R.id.email_sign_in_button:
login();
break;

}

}
//使用的对应bmob服务器后台,对应有个UserLogin接口
private void login() {
UserLogin userLogin = new UserLogin();
if (email.getText().toString().isEmpty()){
ToastUtils.showToast(getApplicationContext(), "没有输入邮箱账号", Toast.LENGTH_SHORT);
return;
}
if (password.getText().toString().isEmpty()){
ToastUtils.showToast(getApplicationContext(),"没有输入密码", Toast.LENGTH_SHORT);
return;
}

userLogin.setUsername(email.getText().toString());
userLogin.setPassword(password.getText().toString());

userLogin.login(this, new SaveListener() {
@Override
public void onSuccess() {
intent2Activity(MainActivity.class);
//登陆成功的email,全局使用,还是必须写到sharePreference中

ToastUtils.showToast(getApplicationContext(), "登陆成功", Toast.LENGTH_SHORT);

//change aoto login values
setSharePre();
finish();
}

@Override
public void onFailure(int i, String s) {
ToastUtils.showToast(getApplicationContext(), "登陆失败:用户名或者密码不对"+s+i, Toast.LENGTH_SHORT);
}
});
}
//记住用户登录账号和密码,保存于本地
private void setSharePre(){
SharedPreferences sharedPreferences = getSharedPreferences(Constance.password, Context.MODE_PRIVATE);
SharedPreferences.Editor editor  = sharedPreferences.edit();
editor.putBoolean(Constance.LOGINVERIFIED, true );
editor.putString(Constance.LOGINEMAIL, email.getText().toString());
editor.commit();
}
}


对应的layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_agray"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.lgq.fruitgrower.view.act.LoginActivity"
tools:showIn="@layout/activity_login2">

<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />

<LinearLayout
android:id="@+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/txtsize_subhead"
android:orientation="vertical">

<ImageView
android:id="@+id/img_logo"
android:layout_width="@dimen/login_img_width"
android:layout_height="@dimen/login_img_height"
android:layout_gravity="center_horizontal"
android:src="@mipmap/logo" />

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />

</android.support.design.widget.TextInputLayout>

<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/title_activity_login"
android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/login_lr_height"
android:layout_marginTop="@dimen/text_margin"
android:gravity="center">

<TextView
android:id="@+id/btn_sign_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/email_sign"
android:textStyle="bold" />

<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:background="@color/bg_light" />

<TextView
android:id="@+id/btn_sign_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/phone_sign"
android:textStyle="bold" />
</LinearLayout>

</LinearLayout>
</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 毕业设计