Здесь я создаю экран входа в систему, где я должен ввести имя пользователя и пароль. В поле пароля я установил значок глаза. При вводе пароля пароль будет скрыт и после нажатия на значок глаза он должен отображать реальные символы. Я упомянул мой код XML и java. Пожалуйста, ознакомьтесь и помогите мне с решением. Нужно ли что-нибудь добавить в Gradle? Пожалуйста, sugggest. Спасибо
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="com.tecnotree.selfcare.ui.login.LoginActivity">
<VideoView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:visibility="gone"
android:id="@+id/background_video_view"
/>
<!-- Login progress -->
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="@string/tecnotree_selfcare"
android:src="@drawable/login_background"
android:scaleType="centerCrop"/>
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/email_login_form"
android:layout_width="match_parent"
android:padding="@dimen/paddingLarge"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="@drawable/sc_card_rounded_login"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/marginLarge"
android:layout_marginBottom="@dimen/marginLarge"
android:contentDescription="@string/tecnotree_selfcare"
android:src="@drawable/logo" />
<TextView
style="@style/AppTheme.TextWhiteLargeBold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Simple, Secure and Convenient"
android:textAlignment="center"
android:textSize="22dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="15dp"
/>
<TextView
style="@style/AppTheme.TextWhiteSmallRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin"
android:text="The convenience of managing your account at your fingertips"
android:textAlignment="center"
android:textSize="15dp"
android:paddingLeft="40dp"
android:paddingRight="40dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/marginLarge"
android:background="#fff"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp">
</LinearLayout>
<TextView
style="@style/AppTheme.TextWhiteLargeBold"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/margin"
android:text="Login to Selfcare"
android:textAlignment="center"
android:textSize="24dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="@dimen/marginLarge"
android:layout_marginLeft="38dp"
android:layout_marginRight="38dp"
>
<AutoCompleteTextView
android:id="@+id/email"
style="@style/AppTheme.EditTextAuto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/user_name_icon"
android:drawableLeft="@drawable/user_name_icon"
android:drawablePadding="@dimen/padding"
android:hint="@string/prompt_email_mobile"
android:textColorHint="@color/colorLight"
android:inputType="textEmailAddress"
android:maxLines="0"
android:singleLine="true"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marginLarge"
android:layout_marginLeft= "38dp"
android:layout_marginRight="38dp">
<EditText
android:id="@+id/password"
style="@style/AppTheme.EditText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:drawableStart="@drawable/enter_pswrd_icon"
android:drawableLeft="@drawable/enter_pswrd_icon"
android:drawableEnd="@drawable/see_pswrd"
android:drawablePadding="@dimen/padding"
android:hint="@string/prompt_password"
android:textColorHint="@color/colorLight"
android:imeActionId="6"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="0"
android:singleLine="true" />
</LinearLayout>
<Button
android:id="@+id/email_sign_in_button"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_sign_in"
android:textAllCaps="false"
android:layout_marginTop="@dimen/marginLarge"
android:textColor="@android:color/white"
android:textSize="20sp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
/>
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/marginLarge"
android:orientation="horizontal"
android:layout_marginBottom="15dp">
<TextView
android:id="@+id/register_now_button"
style="@style/AppTheme.TextWhiteLargeRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/paddingSmall"
android:text="Sign Up"
android:textSize="15dp"
android:layout_marginRight="40dp"/>
<TextView
android:id="@+id/forgot_password_button"
style="@style/AppTheme.TextWhiteLargeRegular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Forgot your password?"
android:textAlignment="center"
android:textSize="15dp"
android:layout_marginLeft="40dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
// Java Код для входа в систему ..
package com.tecnotree.selfcare.ui.login;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.VideoView;
import com.tecnotree.selfcare.App;
import com.tecnotree.selfcare.R;
import com.tecnotree.selfcare.ui.main.MainActivity;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class LoginActivity extends AppCompatActivity implements LoginScreenContract.View {
@Inject
LoginScreenPresenter loginPresenter;
@BindView(R.id.email)
EditText usernameInput;
@BindView(R.id.password)
EditText passwordInput;
@BindView(R.id.progressBar2)
public ProgressBar progressBar;
@BindView(R.id.background_video_view)
VideoView videoView;
MediaPlayer mMediaPlayer;
int mCurrentVideoPosition;
@OnClick(R.id.email_sign_in_button)
void delegateLogin() {
if (TextUtils.isEmpty(usernameInput.getText().toString()) && !TextUtils.isEmpty(passwordInput.getText().toString())) {
usernameInput.setError("Username Required");
} else if (!TextUtils.isEmpty(usernameInput.getText().toString()) && TextUtils.isEmpty(passwordInput.getText().toString())) {
passwordInput.setError("Password Required");
} else if (TextUtils.isEmpty(usernameInput.getText().toString()) && TextUtils.isEmpty(passwordInput.getText().toString())) {
usernameInput.setError("Username Required");
passwordInput.setError("Password Required");
} else if (!TextUtils.isEmpty(usernameInput.getText().toString()) && !TextUtils.isEmpty(passwordInput.getText().toString())) {
progressBar.setVisibility(View.VISIBLE);
loginPresenter.doLogin(usernameInput.getText().toString(), passwordInput.getText().toString());
}
}
@OnClick(R.id.register_now_button)
void registerNow(){
loginPresenter.doOpenRegisterScreen(this);
}
@OnClick(R.id.forgot_password_button)
void forgotPassword(){
loginPresenter.doOpenForgotPasswordScreen(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//String UrlPath = "android.resource://" +getPackageName()+"/"+ R.raw.mt_launch_screen;
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
DaggerLoginScreenComponent.builder()
.loginScreenModule(new LoginScreenModule(this))
.appComponent(App.getInstance().getApplicationWideDeps())
.build()
.inject(this);
loginPresenter.initScreen();
}
@Override
public void enableLogin() {
}
@Override
public void showValidationError() {
}
@Override
public void showCommunicationError(String message) {
Snackbar snackBar = Snackbar.make(passwordInput, message, Snackbar.LENGTH_LONG);
snackBar.show();
}
@Override
public void setCredentials(String username, String password) {
usernameInput.setText(username);
passwordInput.setText(password);
if(username != "" & password !="" ){
View someView = findViewById(R.id.email_sign_in_button);
someView.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.sc_card_rounded_sign_in));
}
usernameInput.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
}
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
View someView = findViewById(R.id.email_sign_in_button);
if (!TextUtils.isEmpty(usernameInput.getText().toString()) && !TextUtils.isEmpty(passwordInput.getText().toString())) {
someView.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.sc_card_rounded_sign_in));
}else {
someView.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.sc_card_rounded_transparent_sign_in));
}
}
public void afterTextChanged(final Editable s) {
}
});
passwordInput.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
}
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
View someView = findViewById(R.id.email_sign_in_button);
if (!TextUtils.isEmpty(usernameInput.getText().toString()) && !TextUtils.isEmpty(passwordInput.getText().toString())) {
someView.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.sc_card_rounded_sign_in));
}else {
someView.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.sc_card_rounded_transparent_sign_in));
}
}
public void afterTextChanged(final Editable s) {
}
});
}
}