Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.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.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.ApiException;
- 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;
- private static final String TAG = "LOGIN";
- private GoogleSignInClient mGoogleSignInClient;
- @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));
- }*/
- }
- @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, "Dogru", Toast.LENGTH_SHORT).show();
- startActivity(new Intent(getApplicationContext(), com.app.surebettips.AnaEkran.class));
- }else{
- Toast.makeText(Login.this, "Sacmalama kamil", 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()) {
- Toast.makeText(getApplicationContext(), "Adam oldun", Toast.LENGTH_LONG).show();
- FirebaseUser user = mAuth.getCurrentUser();
- System.out.println("OK Halloldu");
- // 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");
- Toast.makeText(getApplicationContext(), "Adam OLAMADIN", Toast.LENGTH_LONG).show();
- }
- // ...
- }
- });
- }
- }
- public void reg(View view) {
- startActivity(new Intent(getApplicationContext(), com.app.surebettips.Register.class));
- }
- /*private void signIn() {
- Intent signInIntent = mGoogleSignInClient.getSignInIntent();
- startActivityForResult(signInIntent, RC_SIGN_IN);
- }*/
- private void signIn() {
- Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
- startActivityForResult(signInIntent, RC_SIGN_IN);
- }
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == RC_SIGN_IN) {
- try {
- Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
- GoogleSignInAccount account = task.getResult(ApiException.class);
- // User is logged in on google platform
- Log.v(TAG, "Account token:" + account.getIdToken()); //NON-NLS
- // Signed in successfully, show authenticated UI.
- } catch (ApiException e) {
- // The ApiException status code indicates the detailed failure reason.
- // Please refer to the GoogleSignInStatusCodes class reference for more information.
- Log.w(TAG, "Google sign in failed", e); //NON-NLS
- String messageToDisplay = "Authentication failed.";
- switch (e.getStatusCode()) {
- case CommonStatusCodes.API_NOT_CONNECTED: //17
- messageToDisplay += "The client attempted to clearPreferences a method from an API that failed to connect.";
- break;
- case CommonStatusCodes.DEVELOPER_ERROR: //10
- messageToDisplay += "The application is misconfigured.";
- break;
- case CommonStatusCodes.ERROR: //13
- messageToDisplay += "The operation failed with no more detailed information.";
- break;
- case CommonStatusCodes.INTERNAL_ERROR: //8
- messageToDisplay += "An internal error occurred.";
- break;
- case CommonStatusCodes.INVALID_ACCOUNT: //8
- messageToDisplay += "Invalid account name specified.";
- break;
- case CommonStatusCodes.SIGN_IN_REQUIRED: //8
- messageToDisplay += "Please Sign In to continue.";
- break;
- }
- }
- }
- }
- 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) {
- Log.d(TAG, "signInWithCredential:success" + task.isSuccessful());
- FirebaseUser user = mAuth.getCurrentUser();
- //updateUI(user);
- if (!task.isSuccessful()){
- Log.w(TAG, "signInWithCredential:failure", task.getException());
- //updateUI(null);
- }
- }
- });
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.app.surebettips">
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="com.android.vending.BILLING" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/logo"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".Login">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".Register" />
- <meta-data
- android:name="preloaded_fonts"
- android:resource="@array/preloaded_fonts" />
- <activity android:name=".AnaEkran" />
- <service android:name=".MyFirebaseMessagingService">
- <intent-filter>
- <action android:name="com.google.firebase.MESSAGING_EVENT" />
- </intent-filter>
- </service>
- <service android:name=".MyFirebaseInstanceIDService">
- <intent-filter>
- <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
- </intent-filter>
- </service>
- <activity android:name=".Buy" />
- <activity android:name=".AdminPanel" />
- <activity android:name=".Inputlar" />
- <activity android:name=".Fikstur"></activity>
- </application>
- </manifest>
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 27
- lintOptions {
- checkReleaseBuilds false
- }
- defaultConfig {
- applicationId "com.app.surebettips"
- minSdkVersion 17
- targetSdkVersion 27
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
- dependencies {
- implementation fileTree(include: ['*.jar'], dir: 'libs')
- implementation 'com.android.support:appcompat-v7:27.1.0'
- implementation 'com.android.support.constraint:constraint-layout:1.1.0'
- implementation 'com.google.firebase:firebase-core:15.0.2'
- implementation 'com.github.jd-alexander:android-flat-button:v1.1'
- implementation 'com.anjlab.android.iab.v3:library:1.0.44'
- implementation 'com.google.firebase:firebase-auth:15.0.0'
- implementation 'com.google.firebase:firebase-database:15.0.0'
- implementation 'com.google.android.gms:play-services-ads:15.0.0'
- implementation 'com.google.firebase:firebase-messaging:15.0.2'
- implementation 'com.google.android.gms:play-services-auth:15.0.0'
- implementation 'com.github.florent37:materialtextfield:1.0.7'
- testImplementation 'junit:junit:4.12'
- androidTestImplementation 'com.android.support.test:runner:1.0.2'
- androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
- implementation 'com.android.support:design:27.1.0'
- }
- apply plugin: 'com.google.gms.google-services'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement