Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
- .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener(){
- @Override
- public void OnConnectionFailed(@NonNull ConnectionResult connectionResult) {
- Toast.makeText(Login.this, "Something went wrong", Toast.LENGTH_SHORT).show();
- }
- })
- package com.app.surebettips;
- import android.accounts.Account;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.annotation.NonNull;
- import android.support.v4.content.ContextCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.text.TextUtils;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.Toast;
- import com.google.android.gms.auth.api.Auth;
- import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
- import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
- import com.google.android.gms.auth.api.signin.GoogleSignInResult;
- import com.google.android.gms.common.ConnectionResult;
- import com.google.android.gms.common.SignInButton;
- import com.google.android.gms.common.api.GoogleApiClient;
- 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;
- import com.google.firebase.database.DatabaseReference;
- import com.google.firebase.database.FirebaseDatabase;
- public class Login extends AppCompatActivity {
- Button loginButton;
- EditText logMail;
- EditText logPass;
- Button registerButton;
- FirebaseUser currentUser;
- FirebaseDatabase database = FirebaseDatabase.getInstance();
- DatabaseReference myRef = database.getReference();
- ImageView imageView;
- int counter;
- private FirebaseAuth mAuth;
- private SignInButton mGoogleBtn;
- private static final int RC_SIGN_IN = 1;
- private GoogleApiClient mGoogleApiClient;
- private FirebaseAuth.AuthStateListener mAuthListener;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- loginButton = findViewById(R.id.loginButton);
- mAuth = FirebaseAuth.getInstance();
- mAuthListener = new FirebaseAuth.AuthStateListener() {
- @Override
- public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
- if(firebaseAuth.getCurrentUser() != null){
- Toast.makeText(Login.this, "You're here", Toast.LENGTH_SHORT).show();
- }
- }
- };
- mGoogleBtn = (SignInButton) findViewById(R.id.googleBtn);
- // Configure sign-in to request the user's ID, email address, and basic
- // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
- GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
- .requestEmail()
- .build();
- mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
- .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener(){
- @Override
- public void OnConnectionFailed(@NonNull ConnectionResult connectionResult) {
- Toast.makeText(Login.this, "Something went wrong", Toast.LENGTH_SHORT).show();
- }
- })
- .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
- .build();
- mGoogleBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- signIn();
- }
- });
- counter = 0;
- imageView = findViewById(R.id.imageView);
- try {
- imageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.arkaplan));
- } catch (Exception e) {
- Toast.makeText(getApplicationContext(), "Arka plan, cihazınızda desteklenmediği için düz renk olarak atanmıştır", Toast.LENGTH_LONG).show();
- }
- imageView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- countdatabase(v);
- }
- });
- logMail = (EditText) findViewById(R.id.logMail);
- logPass = (EditText) findViewById(R.id.logPass);
- registerButton = (Button) findViewById(R.id.registerButton);
- loginButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- login(v);
- }
- });
- registerButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- reg(v);
- }
- });
- }
- private void countdatabase(View v) {
- // counter++;
- if (counter == 15) {
- myRef.child("maç1").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç1").child("Kredi").setValue("20");
- myRef.child("maç1").child("Tahmin").setValue("ÜST");
- myRef.child("maç1").child("Güven").setValue("%90");
- myRef.child("maç1").child("Oran").setValue("1.8");
- myRef.child("maç1").child("Saat").setValue("20:00");
- myRef.child("maç1").child("Prediction").setValue("Win");
- myRef.child("maç2").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç2").child("Kredi").setValue("20");
- myRef.child("maç2").child("Tahmin").setValue("ÜST");
- myRef.child("maç2").child("Güven").setValue("%90");
- myRef.child("maç2").child("Oran").setValue("1.8");
- myRef.child("maç2").child("Saat").setValue("20:00");
- myRef.child("maç2").child("Prediction").setValue("Win");
- myRef.child("maç3").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç3").child("Kredi").setValue("20");
- myRef.child("maç3").child("Tahmin").setValue("ÜST");
- myRef.child("maç3").child("Güven").setValue("%90");
- myRef.child("maç3").child("Oran").setValue("1.8");
- myRef.child("maç3").child("Saat").setValue("20:00");
- myRef.child("maç3").child("Prediction").setValue("Win");
- myRef.child("maç4").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç4").child("Kredi").setValue("20");
- myRef.child("maç4").child("Tahmin").setValue("ÜST");
- myRef.child("maç4").child("Güven").setValue("%90");
- myRef.child("maç4").child("Oran").setValue("1.8");
- myRef.child("maç4").child("Saat").setValue("20:00");
- myRef.child("maç4").child("Prediction").setValue("Win");
- myRef.child("maç5").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç5").child("Kredi").setValue("20");
- myRef.child("maç5").child("Tahmin").setValue("ÜST");
- myRef.child("maç5").child("Güven").setValue("%90");
- myRef.child("maç5").child("Oran").setValue("1.8");
- myRef.child("maç5").child("Saat").setValue("20:00");
- myRef.child("maç5").child("Prediction").setValue("Win");
- myRef.child("maç6").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç6").child("Kredi").setValue("20");
- myRef.child("maç6").child("Tahmin").setValue("ÜST");
- myRef.child("maç6").child("Güven").setValue("%90");
- myRef.child("maç6").child("Oran").setValue("1.8");
- myRef.child("maç6").child("Saat").setValue("20:00");
- myRef.child("maç6").child("Prediction").setValue("Win");
- myRef.child("maç7").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç7").child("Kredi").setValue("20");
- myRef.child("maç7").child("Tahmin").setValue("ÜST");
- myRef.child("maç7").child("Güven").setValue("%90");
- myRef.child("maç7").child("Oran").setValue("1.8");
- myRef.child("maç7").child("Saat").setValue("20:00");
- myRef.child("maç7").child("Prediction").setValue("Win");
- myRef.child("maç8").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç8").child("Kredi").setValue("20");
- myRef.child("maç8").child("Tahmin").setValue("ÜST");
- myRef.child("maç8").child("Güven").setValue("%90");
- myRef.child("maç8").child("Oran").setValue("1.8");
- myRef.child("maç8").child("Saat").setValue("20:00");
- myRef.child("maç8").child("Prediction").setValue("Win");
- myRef.child("maç9").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç9").child("Kredi").setValue("20");
- myRef.child("maç9").child("Tahmin").setValue("ÜST");
- myRef.child("maç9").child("Güven").setValue("%90");
- myRef.child("maç9").child("Oran").setValue("1.8");
- myRef.child("maç9").child("Saat").setValue("20:00");
- myRef.child("maç9").child("Prediction").setValue("Win");
- myRef.child("maç10").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç10").child("Kredi").setValue("20");
- myRef.child("maç10").child("Tahmin").setValue("ÜST");
- myRef.child("maç10").child("Güven").setValue("%90");
- myRef.child("maç10").child("Oran").setValue("1.8");
- myRef.child("maç10").child("Saat").setValue("20:00");
- myRef.child("maç10").child("Prediction").setValue("Win");
- myRef.child("maç11").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç11").child("Kredi").setValue("20");
- myRef.child("maç11").child("Tahmin").setValue("ÜST");
- myRef.child("maç11").child("Güven").setValue("%90");
- myRef.child("maç11").child("Oran").setValue("1.8");
- myRef.child("maç11").child("Saat").setValue("20:00");
- myRef.child("maç11").child("Prediction").setValue("Win");
- myRef.child("maç12").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç12").child("Kredi").setValue("20");
- myRef.child("maç12").child("Tahmin").setValue("ÜST");
- myRef.child("maç12").child("Güven").setValue("%90");
- myRef.child("maç12").child("Oran").setValue("1.8");
- myRef.child("maç12").child("Saat").setValue("20:00");
- myRef.child("maç12").child("Prediction").setValue("Win");
- myRef.child("maç13").child("Oynayanlar").setValue("BurayıDoldur");
- myRef.child("maç13").child("Kredi").setValue("20");
- myRef.child("maç13").child("Tahmin").setValue("ÜST");
- myRef.child("maç13").child("Güven").setValue("%90");
- myRef.child("maç13").child("Oran").setValue("1.8");
- myRef.child("maç13").child("Saat").setValue("20:00");
- myRef.child("maç13").child("Prediction").setValue("Win");
- myRef.child("maç14").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç14").child("Kredi").setValue("20");
- myRef.child("maç14").child("Tahmin").setValue("ÜST");
- myRef.child("maç14").child("Güven").setValue("%90");
- myRef.child("maç14").child("Oran").setValue("1.8");
- myRef.child("maç14").child("Saat").setValue("20:00");
- myRef.child("maç14").child("Prediction").setValue("Win");
- myRef.child("maç15").child("Oynayanlar").setValue("Maç1 - Maç2");
- myRef.child("maç15").child("Kredi").setValue("20");
- myRef.child("maç15").child("Tahmin").setValue("ÜST");
- myRef.child("maç15").child("Güven").setValue("%90");
- myRef.child("maç15").child("Oran").setValue("1.8");
- myRef.child("maç15").child("Saat").setValue("20:00");
- myRef.child("maç15").child("Prediction").setValue("Win");
- myRef.child("Reklam Kredisi").setValue("15");
- myRef.child("Kayan Yazı").setValue("...Kayan Yazı Alanı...");
- Toast.makeText(getApplicationContext(), "Tüm database güncellendi", Toast.LENGTH_LONG).show();
- counter = 0;
- }
- }
- public void login(View view) {
- if (!TextUtils.isEmpty(logMail.getText().toString()) && !TextUtils.isEmpty(logPass.getText().toString())) {
- mAuth.signInWithEmailAndPassword(logMail.getText().toString(), logPass.getText().toString())
- .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if (task.isSuccessful()) {
- FirebaseUser user = mAuth.getCurrentUser();
- System.out.println("OK");
- // Toast.makeText(getApplicationContext(), "Sayın " + user.getEmail() + " hoşgeldiniz", Toast.LENGTH_SHORT).show();
- startActivity(new Intent(getApplicationContext(), com.app.surebettips.AnaEkran.class));
- } else {
- Toast.makeText(getApplicationContext(), "Başarısız", Toast.LENGTH_SHORT).show();
- System.out.println("NOT OK");
- }
- // ...
- }
- });
- }
- }
- public void reg(View view) {
- startActivity(new Intent(getApplicationContext(), com.app.surebettips.Register.class));
- }
- @Override
- public void onStart() {
- super.onStart();
- // Check if user is signed in (non-null) and update UI accordingly.
- currentUser = mAuth.getCurrentUser();
- //Asagi biz ekledik tek satir
- mAuth.addAuthStateListener(mAuthListener);
- //Yukari biz ekledik tek satir
- if (mAuth != null && currentUser != null) {
- startActivity(new Intent(getApplicationContext(), com.app.surebettips.AnaEkran.class));
- }
- }
- private void signIn() {
- Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
- startActivityForResult(signInIntent, RC_SIGN_IN);
- }
- @Override
- public void OnActivtyResult(int requestCode, int resultCode, Intent data){
- super.OnActivtyResult(requestCode,resultCode,data);
- if(requestCode == RC_SIGN_IN ){
- GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
- if(result.isSuccess()) {
- GoogleSignInAccount account = result.getSignInAccount();
- firebaseAuthWithGoogleAccount();
- }else {
- //ArmutSpor
- }
- }
- }
- private void firebaseAuthWithGoogleAccount(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) {
- Log.d("TAG", "signInWithCredential:success" + task.isSuccessful());
- //FirebaseUser user = mAuth.getCurrentUser();
- //updateUI(user);
- if (!task.isSu1ccessful()){
- Log.w("TAG", "signInWithCredential:failure", task.getException());
- Toast.makeText(Login.this, "Authentication failed", Toast.LENGTH_SHORT).show();
- //updateUI(null);
- }
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment