I am a newbie in Android programming. I have a splash screen after which I am trying to open an activity but after the splash screen my screen keeps flickering and the activity doesn't open. show anything. My code is as follows:
Splashscreen.java
public class splashscreen extends AppCompatActivity
{
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
imageView =(ImageView)findViewById(R.id.imageView);
Animation animation= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slideinright);
imageView.setAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
finish();
startActivity(new Intent(getApplicationContext(),MainActivity.class));
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
Loginpage.java
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.Profile;
import com.facebook.ProfileTracker;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class LoginActivity2 extends AppCompatActivity implements View.OnClickListener {
private Button loginbuttonRegister;
private EditText logineditTextEmail;
private EditText logineditTextPassword;
private TextView textViewLogin;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
private LoginButton loginButton;
private CallbackManager callbackManager;
private Profile profile;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login2);
progressDialog = new ProgressDialog(this);
firebaseAuth = FirebaseAuth.getInstance();
if( firebaseAuth.getCurrentUser() != null){
//display navigation activity
finish();
startActivity(new Intent(getApplicationContext(),MainActivity.class));
}
loginbuttonRegister = (Button) findViewById(R.id.loginbuttonRegister);
logineditTextEmail = (EditText) findViewById(R.id.logineditTextEmail);
logineditTextPassword = (EditText) findViewById(R.id.logineditTextPassword);
textViewLogin =(TextView) findViewById(R.id.textViewLogin);
loginbuttonRegister.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
loginbuttonRegister = (Button) findViewById(R.id.loginbuttonRegister);
if(v == loginbuttonRegister)
{
userLogin();
}
}
});
textViewLogin.setOnClickListener(this);
//Initializing Facebook Sdk.
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
//intialize callback manager
callbackManager = CallbackManager.Factory.create();
//initializing facebook login button
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
ProfileTracker profileTracker;
#Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(LoginActivity2.this,"Succesfully Logged In",Toast.LENGTH_SHORT).show();
profile = Profile.getCurrentProfile();
//check profile is fetched or not, if not then wait for sometime
// to load your profile using profile tracker
if(profile == null){
profileTracker = new ProfileTracker() {
#Override
protected void onCurrentProfileChanged(Profile profile, Profile profile1) {
if(profile1 != null){
startActivity(new Intent(LoginActivity2.this,MainActivity.class));
}
}
};
}else{
startActivity(new Intent(LoginActivity2.this,MainActivity.class));
}
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
}
});
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode,resultCode,data);
}
private void userLogin(){
String email = logineditTextEmail.getText().toString().trim();
String password = logineditTextPassword.getText().toString().trim();
if(TextUtils.isEmpty(email)){
//mail empty
Toast.makeText(this, "Please enter email!", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this, "Please enter Password!", Toast.LENGTH_SHORT).show();
return;
}
//if valid then shows progressbar
progressDialog.setMessage("Loggin in...!");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{ progressDialog.dismiss();
//start anvigation activity
finish();
startActivity(new Intent(getApplicationContext(),MainActivity.class));
}
else {progressDialog.dismiss();
Toast.makeText(LoginActivity2.this, "Failed to login! Try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
public void onClick(View view) {
if(view == textViewLogin)
{finish();
startActivity(new Intent(this,Registeruser.class));
}
}
}
Loginactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/content_login2"
android:layout_width="match_parent"
android:layout_height="match_parent"
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.example.dell.Swing.LoginActivity2"
tools:showIn="#layout/activity_login2"
android:background="#drawable/probeach">
<LinearLayout
android:id="#+id/registerlayout"
android:orientation="vertical"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_margin="10dp"
android:hint="Enter your E-mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:id="#+id/logineditTextEmail"
/>
<EditText
android:layout_margin="10dp"
android:hint="Enter your Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:id="#+id/logineditTextPassword" />
<Button
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/loginbuttonRegister"
android:text="Log In"
style="#style/Widget.AppCompat.Button.Colored"
android:background="#android:color/holo_red_dark"
android:elevation="0dp" />
<TextView
android:textAlignment="center"
android:text="Not Registered? Sign up Here"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textViewLogin" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="66dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:weightSum="1">
<TextView
android:id="#+id/orview"
android:text="Or"
android:gravity="center"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
android:layout_width="match_parent"
android:layout_weight="0.63"
android:layout_height="40dp" />
<com.facebook.login.widget.LoginButton
android:layout_margin="10dp"
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_below="#+id/orview"
/>
</LinearLayout>
Please check your background image resolution,
android:background="#drawable/probeach"
Related
After adding calligraphy to applied the font, password become blurred and cannot be viewed. I have applied android:fontFamily="sans-serif" but still it is still the same. Calligraphy that i am using is
implementation uk.co.chrisjenx:calligraphy:2.3.0, while my sdkVersion is 21, library is com.android.support:appcompat-v7:27.1.1
signin.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="#drawable/background_borenos"
tools:context="com.example.liew.idelivery.SignIn">
<LinearLayout
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/edtPhone"
android:hint="Phone Number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#android:color/white"
android:text="0128688032"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="phone"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_maxCharacters="12"
app:met_primaryColor="#android:color/white"
app:met_singleLineEllipsis="true"
/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/edtPassword"
android:hint="Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#android:color/white"
android:text="chau95"
android:fontFamily="sans-serif"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="textPassword"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_maxCharacters="12"
app:met_primaryColor="#android:color/white"
app:passwordToggleEnabled="true"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<com.rey.material.widget.CheckBox
android:id="#+id/ckbRemember"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Remember me"
android:textColor="#android:color/white"
app:cbd_strokeColor="#android:color/white"
app:cbd_tickColor="#android:color/black"
style="#style/Material.Drawable.CheckBox"
android:gravity="center_vertical"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#android:color/white"
android:id="#+id/txtForgotPwd"
android:text="#string/forgot_pwd"/>
</LinearLayout>
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="#+id/btnSignIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_alignParentBottom="true"
android:text="Sign In"
android:textColor="#android:color/white"
app:fButtonColor="#color/btnSignUp"
app:cornerRadius="4dp"
app:shadowColor="#android:color/black"
app:shadowEnabled="true"
app:shadowHeight="5dp" />
</RelativeLayout>
SignIn.java
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rengwuxian.materialedittext.MaterialEditText;
import com.rey.material.widget.CheckBox;
import io.paperdb.Paper;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public class SignIn extends AppCompatActivity {
EditText edtPhone,edtPassword;
Button btnSignIn;
CheckBox ckbRemember;
TextView txtForgotPwd;
FirebaseDatabase database;
DatabaseReference table_user;
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//add calligraphy
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/restaurant_font.otf")
.setFontAttrId(R.attr.fontPath)
.build());
setContentView(R.layout.activity_sign_in);
edtPhone = (MaterialEditText)findViewById(R.id.edtPhone);
edtPassword = (MaterialEditText)findViewById(R.id.edtPassword);
btnSignIn = (Button)findViewById(R.id.btnSignIn);
ckbRemember = (CheckBox)findViewById(R.id.ckbRemember);
txtForgotPwd = (TextView)findViewById(R.id.txtForgotPwd);
//Init paper
Paper.init(this);
//Init firebase
database =FirebaseDatabase.getInstance();
table_user = database.getReference("User");
txtForgotPwd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showForgotPwdDialog();
}
});
btnSignIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (Common.isConnectedToInternet(getBaseContext())) {
//save user & password
if(ckbRemember.isChecked()){
Paper.book().write(Common.USER_KEY, edtPhone.getText().toString());
Paper.book().write(Common.PWD_KEY, edtPassword.getText().toString());
}
final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
mDialog.setMessage("Please waiting...");
mDialog.show();
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
//check if user not exist in database
if (dataSnapshot.child(edtPhone.getText().toString()).exists()) {
//Get user information
mDialog.dismiss();
User user = dataSnapshot.child(edtPhone.getText().toString()).getValue(User.class);
// set phone
user.setPhone(edtPhone.getText().toString());
if (user.getpassword().equals(edtPassword.getText().toString())) {
Intent homeIntent = new Intent(SignIn.this, Home.class);
Common.currentUser = user;
startActivity(homeIntent);
finish();
table_user.removeEventListener(this);
} else {
Toast.makeText(SignIn.this, "Wrong Password!", Toast.LENGTH_SHORT).show();
}
} else {
mDialog.dismiss();
Toast.makeText(SignIn.this, "User not exist!", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
else{
Toast.makeText(SignIn.this, "Please check your internet connection!", Toast.LENGTH_SHORT).show();
return;
}
}
});
}
private void showForgotPwdDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Forgot Password");
builder.setMessage("Enter your secure code");
LayoutInflater inflater = this.getLayoutInflater();
View forgot_view = inflater.inflate(R.layout.forgot_password_layout, null);
builder.setView(forgot_view);
builder.setIcon(R.drawable.ic_security_black_24dp);
final MaterialEditText edtPhone = (MaterialEditText)forgot_view.findViewById(R.id.edtPhone);
final MaterialEditText edtSecureCode = (MaterialEditText)forgot_view.findViewById(R.id.edtSecureCode);
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//check if user still available
table_user.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.child(edtPhone.getText().toString())
.getValue(User.class);
if (user.getSecureCode().equals(edtSecureCode.getText().toString()))
Toast.makeText(SignIn.this, "Your password: "
+user.getpassword(), Toast.LENGTH_LONG).show();
else
Toast.makeText(SignIn.this, "Wrong secure code!", Toast.LENGTH_SHORT).show();
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
}
EditTextPassword.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);
Email and password is not shown in FIREBASE CONSOLE in sign in users option.It is showing Registered Successfully Toast.It is showing nothing in firebase console after refreshing also.Below is my code.After long press, it is showing success. Please help if anyone has any idea.
Already given INTERNET permission in manifest file.
Please help
Main Activity
package in.nic.edudel.doe.firebaseauthentication;//package name
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
public class MainActivity extends AppCompatActivity {
EditText name,password;
Button btn,btn2;
private FirebaseAuth mAuth;
SignInButton signInButton;
private GoogleSignInClient mGoogleSignInClient;
private static final int RC_SIGN_IN = 9001;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.editText2);
password = findViewById(R.id.editText3);
btn = findViewById(R.id.button2);
btn2 = findViewById(R.id.button3);
mAuth = FirebaseAuth.getInstance();
signInButton = findViewById(R.id.sign_in_button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
register();//function
}
});
btn.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
login();//function
return true;
}
});
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
reset();
}
});
signInButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
signIn();
}
});
}
private void signIn() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// [START initialize_auth]
// [END initialize_auth]
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN && resultCode == RESULT_OK) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w("MYSTEP", "Google sign in failed", e);
// ...
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Toast.makeText(MainActivity.this, "Login Successful !", Toast.LENGTH_SHORT).show();
} else {
// If sign in fails, display a message to the user.
Toast.makeText(MainActivity.this, "Login Failed ! ", Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
private void reset() {
mAuth.sendPasswordResetEmail(name.getText().toString().trim()).
addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful())
{
Toast.makeText(MainActivity.this, "Password Reset Email Sent !!!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "Email not found !", Toast.LENGTH_SHORT).show();
}
}
});
}
private void login() {
mAuth.signInWithEmailAndPassword(name.getText().toString().trim(),password.getText().toString().trim()).
addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
Toast.makeText(MainActivity.this, "Success !!!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "Login Failed !!! ", Toast.LENGTH_SHORT).show();
}
}
});
}
private void register() {
mAuth.createUserWithEmailAndPassword(name.getText().toString().trim(),password.getText().toString().trim()).
addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
Toast.makeText(MainActivity.this, "Registered Successfully!!!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "Please enter valid data !!!", Toast.LENGTH_SHORT).show();
}
}
});
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.nic.edudel.doe.firebaseauthentication.MainActivity">
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="64dp"
android:layout_marginStart="64dp"
android:layout_marginTop="35dp"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_alignStart="#+id/editText2"
android:layout_below="#+id/editText2"
android:layout_marginTop="52dp"
android:ems="10"
android:hint="Password"
android:inputType="textPersonName" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:text="Register" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="28dp"
android:layout_marginRight="28dp"
android:text="Reset Password" />
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button3"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp" />
</RelativeLayout>
I am working on an Android App which handles google,facebook as well as twitter login using Firebase-Realtime Database but I don't know how to implement three different logins inside single activity.
My Login Activity please check that code
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class LoginActivity extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private FirebaseAuth auth;
private ProgressBar progressBar;
private Button btnSignup, btnLogin, btnReset;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}
// set the view now
setContentView(R.layout.activity_login);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btnSignup = (Button) findViewById(R.id.btn_signup);
btnLogin = (Button) findViewById(R.id.btn_login);
btnReset = (Button) findViewById(R.id.btn_reset_password);
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();
btnSignup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, SignupActivity.class));
}
});
btnReset.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, ResetPasswordActivity.class));
}
});
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//authenticate user
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
progressBar.setVisibility(View.GONE);
if (!task.isSuccessful()) {
// there was an error
if (password.length() < 6) {
inputPassword.setError(getString(R.string.minimum_password));
} else {
Toast.makeText(LoginActivity.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
}
} else {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
});
}
});
}
}
Login XML
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:fitsSystemWindows="true"
tools:context="info.androidhive.firebase.LoginActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/colorPrimary"
android:gravity="center"
android:orientation="vertical"
android:padding="#dimen/activity_horizontal_margin">
<ImageView
android:layout_width="#dimen/logo_w_h"
android:layout_height="#dimen/logo_w_h"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:src="#mipmap/ic_launcher" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:hint="#string/hint_email"
android:inputType="textEmailAddress"
android:textColor="#android:color/white"
android:textColorHint="#android:color/white" />
</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="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:hint="#string/hint_password"
android:inputType="textPassword"
android:textColor="#android:color/white"
android:textColorHint="#android:color/white" />
</android.support.design.widget.TextInputLayout>
<!-- Login Button -->
<Button
android:id="#+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="#color/colorAccent"
android:text="#string/btn_login"
android:textColor="#android:color/black" />
<Button
android:id="#+id/btn_reset_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="#null"
android:text="#string/btn_forgot_password"
android:textAllCaps="false"
android:textColor="#color/colorAccent" />
<!-- Link to Login Screen -->
<Button
android:id="#+id/btn_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="#null"
android:text="#string/btn_link_to_register"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="15dp" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center|bottom"
android:layout_marginBottom="20dp"
android:visibility="gone" />
</android.support.design.widget.CoordinatorLayout>
you can use different requestCode like below code
public static final int RC_TWITTER_LOGIN = 2;
public static final int RC_GOOGLE_LOGIN = 1;
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Map<String, String> options = new HashMap<String, String>();
if (requestCode == RC_GOOGLE_LOGIN) {
/* This was a request by the Google API */
if (resultCode != RESULT_OK) {
mGoogleLoginClicked = false;
}
mGoogleIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
} else if (requestCode == RC_TWITTER_LOGIN) {
options.put("oauth_token", data.getStringExtra("oauth_token"));
options.put("oauth_token_secret", data.getStringExtra("oauth_token_secret"));
options.put("user_id", data.getStringExtra("user_id"));
authWithFirebase("twitter", options);
} else {
/* Otherwise, it's probably the request by the Facebook login button, keep track of the session */
mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data);
}
}
you can refer full code demo here
So I am creating an events app using Firebase as my database. I am an amateur developer so please bear with me. There are 3 main problems that I have been facing:
1) My main problem is that data is not being written to Firebase. I have changed the rules to 'true' in the database module. I also have an image input by the user which is being uploaded, but the data such as event_title and others is not being uploaded
2) I have used Intent to pass data from one activity to another but it is not passing. I used a textView on the next Activity to setText, but it changes to null. The data is also not shwoing in the Log, as much I know about Log.d
3) I don't for what reason !TextUtils.isEmpty is not working on my CreateEvent2. I need to comment the entire if - condition to go to the CreateEvent3. However it is working in CreateEvent3.java.
I tried a lot of methods but I do not know for what reasons these errors are coming.
Here is my code:
CreateEvent2.java
package com.example.admin.college20;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class CreateEvent2 extends AppCompatActivity {
private EditText mEventTitle, mEventLocation, mEventCategory, mContact;
private Button mNextButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_event2);
mEventTitle = (EditText) findViewById(R.id.event_title);
mEventLocation = (EditText) findViewById(R.id.event_location);
mEventCategory = (EditText) findViewById(R.id.event_category);
mContact = (EditText) findViewById(R.id.contact_info);
mNextButton = (Button) findViewById(R.id.nextButton);
final String event_title = mEventTitle.getText().toString().trim();
final String event_location = mEventLocation.getText().toString().trim();
final String event_category = mEventCategory.getText().toString().trim();
final String contact = mContact.getText().toString().trim();
mNextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/**if (!TextUtils.isEmpty(event_title)
&& !TextUtils.isEmpty(event_location)
&& !TextUtils.isEmpty(event_category)
&& !TextUtils.isEmpty(contact)) {**/
Intent i = new Intent(CreateEvent2.this, CreateEvent3.class);
i.putExtra("title", event_title);
i.putExtra("location", event_location);
i.putExtra("category", event_category);
i.putExtra("contact", contact);
startActivity(i);
}
});
}
}
activity_create_event2.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.admin.college20.CreateEvent2"
android:background="#drawable/create_event_1">
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="Event Title"
android:layout_marginTop="90dp"
android:id="#+id/event_title"
android:inputType="textMultiLine"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/event_location"
android:layout_alignEnd="#+id/event_location" />
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="Event Location"
android:id="#+id/event_location"
android:inputType="textMultiLine"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/contact_info"
android:layout_alignStart="#+id/contact_info" />
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="Event Category"
android:id="#+id/event_category"
android:inputType="textMultiLine"
android:layout_marginTop="32dp"
android:layout_below="#+id/event_location"
android:layout_alignLeft="#+id/contact_info"
android:layout_alignStart="#+id/contact_info" />
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:hint="Contact Number"
android:id="#+id/contact_info"
android:inputType="textMultiLine"
android:layout_above="#+id/nextButton"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="New Button"
android:id="#+id/nextButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="27dp" />
</RelativeLayout>
CreateEvent3.java
package com.example.admin.college20;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
public class CreateEvent3 extends AppCompatActivity {
private EditText mEventDesc, mEventFBUrl, mEventWebLink;
private TextView hello;
private Button upload_image_button, done_button;
private ProgressDialog progressDialog;
private static final int GALLERY_INTENT = 1;
private Uri imageUri = null;
private DatabaseReference mDatabaseReference;
private StorageReference mStorageRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_event3);
mEventDesc = (EditText) findViewById(R.id.event_desc);
mEventFBUrl = (EditText) findViewById(R.id.fb_event_url);
mEventWebLink = (EditText) findViewById(R.id.event_weblink);
upload_image_button = (Button) findViewById(R.id.upload_image_button);
done_button = (Button) findViewById(R.id.done_button);
hello = (TextView) findViewById(R.id.hello);
mDatabaseReference = FirebaseDatabase.
getInstance().
getReference().
child("Event");
mStorageRef = FirebaseStorage.getInstance().getReference();
progressDialog = new ProgressDialog(this);
upload_image_button.setVisibility(View.VISIBLE);
upload_image_button.setBackgroundColor(Color.TRANSPARENT);
upload_image_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_INTENT);
}
});
done_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startPosting();
Toast.makeText(CreateEvent3.this, "Button Selected", Toast.LENGTH_SHORT).show();
}
});
}
public void startPosting() {
progressDialog.setMessage("Uploading the Data");
Intent in = getIntent();
Bundle bundle = in.getExtras();
final String event_title = getIntent().getStringExtra("title");
final String event_location = getIntent().getStringExtra("location");
final String event_category = getIntent().getStringExtra("category");
final String contact = getIntent().getStringExtra("contact");
final String event_desc = mEventDesc.getText().toString().trim();
final String event_weblink = mEventWebLink.getText().toString().trim();
final String event_fb_url = mEventFBUrl.getText().toString().trim();
Log.d("Event Tile", event_title);
Log.d("Event Location", event_location);
Log.d("Event Category", event_category);
hello.setText(event_title);
if (!TextUtils.isEmpty(event_desc)
&& !TextUtils.isEmpty(event_weblink)
&& !TextUtils.isEmpty(event_fb_url)
&& imageUri != null) {
progressDialog.show();
StorageReference filepath = mStorageRef.child("Images").child(imageUri.getLastPathSegment());
filepath.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri uri = taskSnapshot.getDownloadUrl();
DatabaseReference newEvent = mDatabaseReference.push();
newEvent.child("title").setValue(event_title);
newEvent.child("location").setValue(event_location);
newEvent.child("category").setValue(event_category);
newEvent.child("contact").setValue(contact);
newEvent.child("desc").setValue(event_desc);
newEvent.child("web").setValue(event_weblink);
newEvent.child("fb").setValue(event_fb_url);
newEvent.child("imageUrl").setValue(uri.toString());
progressDialog.dismiss();
startActivity(new Intent(CreateEvent3.this, MainPage1.class));
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(CreateEvent3.this, "Upload Failed :(", Toast.LENGTH_SHORT).show();
}
});
}
else{
Toast.makeText(this, "Fill in the details", Toast.LENGTH_SHORT).show();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK) {
imageUri = data.getData();
}
}
}
activity_create_event3.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.admin.college20.CreateEvent3"
android:background="#drawable/create_event_2">
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/event_desc"
android:layout_marginTop="144dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:inputType="textMultiLine"
android:hint="Enter short description here..."
/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/fb_event_url"
android:layout_below="#+id/event_desc"
android:layout_alignLeft="#+id/event_desc"
android:layout_alignStart="#+id/event_desc"
android:layout_marginTop="134dp" />
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/event_weblink"
android:layout_marginTop="49dp"
android:layout_below="#+id/fb_event_url"
android:layout_alignLeft="#+id/fb_event_url"
android:layout_alignStart="#+id/fb_event_url" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="300dp"
android:layout_height="60dp"
android:id="#+id/upload_image_button"
android:layout_marginTop="50dp"
android:layout_below="#+id/event_desc"
android:layout_alignLeft="#+id/event_desc"
android:layout_alignStart="#+id/event_desc" />
<Button
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/done_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp" />
<TextView
android:text="Hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/event_desc"
android:layout_alignEnd="#+id/event_desc"
android:layout_marginRight="49dp"
android:layout_marginEnd="49dp"
android:layout_marginTop="33dp"
android:id="#+id/hello" />
</RelativeLayout>
The problem is that you're getting the text from the EditText on your CreateEvent2's onCreate method. You should get it on your OnClickListener. Like this:
mNextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String event_title = mEventTitle.getText().toString().trim();
final String event_location = mEventLocation.getText().toString().trim();
final String event_category = mEventCategory.getText().toString().trim();
final String contact = mContact.getText().toString().trim();
if (!TextUtils.isEmpty(event_title)
&& !TextUtils.isEmpty(event_location)
&& !TextUtils.isEmpty(event_category)
&& !TextUtils.isEmpty(contact)) {
Intent i = new Intent(CreateEvent2.this, CreateEvent3.class);
i.putExtra("title", event_title);
i.putExtra("location", event_location);
i.putExtra("category", event_category);
i.putExtra("contact", contact);
startActivity(i);
}
}
});
I would like to use TTS in my application. First of all I'm trying to run some examples, but every time TTS doesn't work on my device. In example I have the code:
MainActivity:
package com.example.tts;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements TextToSpeech.OnInitListener {
private TextToSpeech textToSpeech;
private Button button;
private EditText inputText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
inputText = (EditText) findViewById(R.id.inputText);
textToSpeech = new TextToSpeech(this, this);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
convertTextToSpeech();
}
});
convertTextToSpeech();
}
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("error", "This Language is not supported");
} else {
convertTextToSpeech();
}
} else {
Log.e("error", "Initilization Failed!");
}
}
#Override
public void onDestroy() {
textToSpeech.shutdown();
super.onDestroy();
}
private void convertTextToSpeech() {
//String text = "test";
String text = inputText.getText().toString();
if (null == text || "".equals(text)) {
text = "Please give some input.";
}
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
activity_main.xml:
<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"
tools:context=".TextToSpeechActivity" >
<EditText
android:id="#+id/inputText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="42dp"
android:layout_marginTop="28dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/inputText"
android:layout_below="#+id/inputText"
android:layout_marginTop="14dp"
android:text="Speak" />
</RelativeLayout>
After typing the word and clicking button application says nothing.
Does anyone have an idea how to solve it? Thanks in advance.