add-login
parent
926aa8f9fa
commit
385b58d879
@ -0,0 +1,207 @@
|
||||
package com.echo.colorizeit.ui.a_login_activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.echo.colorizeit.MainActivity;
|
||||
import com.echo.colorizeit.ui.BaseActivity;
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.databinding.LoginMainBinding;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import cn.leancloud.LCUser;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* @Author: WangYuyang
|
||||
* @Date: 2021/11/1-13:29
|
||||
* @Project: My Application
|
||||
* @Package: com.echo.colorizeit.ui.a_login_activity
|
||||
* @Description:
|
||||
**/
|
||||
public class LoginViewActivity extends BaseActivity {
|
||||
private LoginMainBinding binding;
|
||||
private LoginViewModel model;
|
||||
private LoginViewActivity _this = this;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = LoginMainBinding.inflate(getLayoutInflater());
|
||||
model = new ViewModelProvider(this).get(LoginViewModel.class);
|
||||
makeFullScreen();
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
int h = c.get(Calendar.HOUR_OF_DAY);
|
||||
System.out.println(h);
|
||||
if(h >= 12 && h <=17 ){
|
||||
binding.textView6.setText("Afternoon");
|
||||
}
|
||||
else if(h >= 18 || h <= 4){
|
||||
binding.textView6.setText("Evening");
|
||||
}
|
||||
else{
|
||||
binding.textView6.setText("Morning");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
binding.signInButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String username = binding.loginEmailInput.getText().toString();
|
||||
String password = binding.loginPasswordInput.getText().toString();
|
||||
if (!validateInput(username, password)) {
|
||||
showSnackbar("Input is invalid, please check your input.");
|
||||
return;
|
||||
}
|
||||
LCUser.logIn(username, password).subscribe(new Observer<LCUser>() {
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
}
|
||||
|
||||
public void onNext(LCUser user) {
|
||||
// 登录成功
|
||||
LCUser.changeCurrentUser(user, true);
|
||||
showSnackbar("Login success !");
|
||||
Intent intent = new Intent(_this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void onError(Throwable throwable) {
|
||||
// 登录失败(可能是密码错误)
|
||||
showSnackbar(throwable.getMessage());
|
||||
}
|
||||
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
binding.loginEmailInput.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (Pattern.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", s.toString())) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.loginPasswordInput.setTextColor(getColor(R.color.white));
|
||||
}
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.loginEmailInput.setTextColor(getColor(R.color.holo_red_dark));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
binding.loginPasswordInput.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (s.toString().length() >= 6) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.loginPasswordInput.setTextColor(getColor(R.color.white));
|
||||
}
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.loginPasswordInput.setTextColor(getColor(R.color.holo_red_dark));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
binding.signUpButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String username = binding.loginEmailInput.getText().toString();
|
||||
String password = binding.loginPasswordInput.getText().toString();
|
||||
|
||||
if (!validateInput(username, password)) {
|
||||
showSnackbar("Input is invalid, please check your input.");
|
||||
return;
|
||||
}
|
||||
|
||||
LCUser currentUser = new LCUser();
|
||||
currentUser.setUsername(username);
|
||||
currentUser.setPassword(password);
|
||||
|
||||
currentUser.signUpInBackground().subscribe(new Observer<LCUser>() {
|
||||
public void onSubscribe(Disposable disposable) {
|
||||
}
|
||||
|
||||
public void onNext(LCUser user) {
|
||||
LCUser.changeCurrentUser(user, true);
|
||||
showSnackbar("Login success !");
|
||||
Intent intent = new Intent(_this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void onError(Throwable throwable) {
|
||||
// 注册失败(通常是因为用户名已被使用)
|
||||
showSnackbar(throwable.getMessage());
|
||||
}
|
||||
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private Boolean validateInput(String username, String password) {
|
||||
if (Pattern.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", username)) {
|
||||
if (password.length() >= 6) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public void makeFullScreen() {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.echo.colorizeit.ui.a_login_activity;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
/**
|
||||
* @Author: WangYuyang
|
||||
* @Date: 2021/11/1-13:29
|
||||
* @Project: My Application
|
||||
* @Package: com.echo.colorizeit.ui.a_login_activity
|
||||
* @Description:
|
||||
**/
|
||||
public class LoginViewModel extends ViewModel {
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="500"
|
||||
android:fromAlpha="0"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:toAlpha="1" />
|
||||
</set>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="8dp" />
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<stroke android:color="#96ffffff"
|
||||
android:width="2dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#96ffffff"
|
||||
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
|
||||
</vector>
|
Binary file not shown.
@ -0,0 +1,189 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/backgraoundImage"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:contentDescription="TODO"
|
||||
android:src="@mipmap/good_morning_img"
|
||||
android:scaleType="centerCrop"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:srcCompat="@mipmap/good_morning_img" />
|
||||
|
||||
<com.airbnb.lottie.LottieAnimationView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:scaleType="centerCrop"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:lottie_autoPlay="true"
|
||||
app:lottie_repeatCount="10000"
|
||||
app:lottie_repeatMode="restart"
|
||||
app:lottie_rawRes="@raw/underwater_ocean_fish_and_turtle"
|
||||
></com.airbnb.lottie.LottieAnimationView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/aclonica"
|
||||
android:text="Good "
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="34sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/abril_fatface"
|
||||
android:text="Morning"
|
||||
android:textColor="#FAFAFA"
|
||||
android:textSize="34sp" />
|
||||
|
||||
<View
|
||||
android:id="@+id/view2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:background="#FDD835"
|
||||
android:padding="2dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginStart="16dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="32dp"
|
||||
android:paddingRight="32dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/linearLayout">
|
||||
|
||||
|
||||
<EditText
|
||||
android:id="@+id/login_email_input"
|
||||
style="@style/EditScreenTextInputLayoutStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:drawableEnd="@drawable/ic_baseline_email_24"
|
||||
android:drawablePadding="16dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:hint="Email"
|
||||
android:inputType="textEmailAddress"
|
||||
android:maxLines="1"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
tools:ignore="SpeakableTextPresentCheck" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/login_password_input"
|
||||
style="@style/EditScreenTextInputLayoutStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:drawableEnd="@drawable/ic_lock_white_24dp"
|
||||
android:drawablePadding="16dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:hint="Password"
|
||||
android:inputType="textPassword"
|
||||
android:maxLines="1"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
tools:ignore="SpeakableTextPresentCheck" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/signUpButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/buttonshapewhitebg"
|
||||
android:fontFamily="@font/aclonica"
|
||||
android:text="Sign up"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="#FFFFFFFF"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/signInButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:background="@drawable/buttonshapewhitebg"
|
||||
android:fontFamily="@font/aclonica"
|
||||
android:text="Sign in"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:text="Forgot Password?"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#96ffffff"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:fontFamily="casual"
|
||||
android:text="Wish you have a great day !"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="@+id/linearLayout"
|
||||
app:layout_constraintStart_toStartOf="@+id/linearLayout"
|
||||
app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Binary file not shown.
After Width: | Height: | Size: 759 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue