Advertisement
Guest User

Untitled

a guest
Sep 6th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.21 KB | None | 0 0
  1. package com.app.surebettips;
  2.  
  3. import android.accounts.Account;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.annotation.NonNull;
  7. import android.support.v4.content.ContextCompat;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.text.TextUtils;
  10. import android.util.Log;
  11. import android.view.View;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.ImageView;
  15. import android.widget.Toast;
  16.  
  17. import com.google.android.gms.auth.api.Auth;
  18. import com.google.android.gms.auth.api.signin.GoogleSignIn;
  19. import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
  20. import com.google.android.gms.auth.api.signin.GoogleSignInClient;
  21. import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
  22. import com.google.android.gms.auth.api.signin.GoogleSignInResult;
  23. import com.google.android.gms.common.ConnectionResult;
  24. import com.google.android.gms.common.SignInButton;
  25. import com.google.android.gms.common.api.ApiException;
  26. import com.google.android.gms.common.api.GoogleApiClient;
  27. import com.google.android.gms.tasks.OnCompleteListener;
  28. import com.google.android.gms.tasks.Task;
  29. import com.google.firebase.auth.AuthCredential;
  30. import com.google.firebase.auth.AuthResult;
  31. import com.google.firebase.auth.FirebaseAuth;
  32. import com.google.firebase.auth.FirebaseUser;
  33. import com.google.firebase.auth.GoogleAuthProvider;
  34. import com.google.firebase.database.DatabaseReference;
  35. import com.google.firebase.database.FirebaseDatabase;
  36.  
  37.  
  38. public class Login extends AppCompatActivity {
  39.  
  40. Button loginButton;
  41. EditText logMail;
  42. EditText logPass;
  43. Button registerButton;
  44. FirebaseUser currentUser;
  45. FirebaseDatabase database = FirebaseDatabase.getInstance();
  46. DatabaseReference myRef = database.getReference();
  47. ImageView imageView;
  48. int counter;
  49. private FirebaseAuth mAuth;
  50. private SignInButton mGoogleBtn;
  51. private static final int RC_SIGN_IN = 1;
  52. private GoogleApiClient mGoogleApiClient;
  53. private FirebaseAuth.AuthStateListener mAuthListener;
  54. private static final String TAG = "LOGIN";
  55. private GoogleSignInClient mGoogleSignInClient;
  56.  
  57.  
  58. @Override
  59. public void onStart() {
  60. super.onStart();
  61. // Check if user is signed in (non-null) and update UI accordingly.
  62. // currentUser = mAuth.getCurrentUser();
  63.  
  64. //Asagi biz ekledik tek satir
  65. mAuth.addAuthStateListener(mAuthListener);
  66. //Yukari biz ekledik tek satir
  67.  
  68.  
  69. /*if (mAuth != null && currentUser != null) {
  70. startActivity(new Intent(getApplicationContext(), com.app.surebettips.AnaEkran.class));
  71. }*/
  72. }
  73.  
  74. @Override
  75. protected void onCreate(Bundle savedInstanceState) {
  76. super.onCreate(savedInstanceState);
  77. setContentView(R.layout.activity_login);
  78. loginButton = findViewById(R.id.loginButton);
  79.  
  80.  
  81.  
  82. mAuth = FirebaseAuth.getInstance();
  83. mAuthListener = new FirebaseAuth.AuthStateListener() {
  84. @Override
  85. public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
  86. if(firebaseAuth.getCurrentUser() != null){
  87. Toast.makeText(Login.this, "Dogru", Toast.LENGTH_SHORT).show();
  88.  
  89. startActivity(new Intent(getApplicationContext(), com.app.surebettips.AnaEkran.class));
  90. }else{
  91. Toast.makeText(Login.this, "Sacmalama kamil", Toast.LENGTH_SHORT).show();
  92.  
  93. }
  94. }
  95. };
  96.  
  97. mGoogleBtn = (SignInButton) findViewById(R.id.googleBtn);
  98.  
  99. // Configure sign-in to request the user's ID, email address, and basic
  100. // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
  101. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
  102. .requestEmail()
  103. .build();
  104.  
  105.  
  106. mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
  107. .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener(){
  108. @Override
  109. public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
  110. Toast.makeText(Login.this, "Something went wrong", Toast.LENGTH_SHORT).show();
  111. }
  112. })
  113.  
  114. .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
  115. .build();
  116.  
  117.  
  118. mGoogleBtn.setOnClickListener(new View.OnClickListener() {
  119. @Override
  120. public void onClick(View view) {
  121. signIn();
  122. }
  123. });
  124. counter = 0;
  125.  
  126. imageView = findViewById(R.id.imageView);
  127.  
  128. try {
  129. imageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.arkaplan));
  130. } catch (Exception e) {
  131. Toast.makeText(getApplicationContext(), "Arka plan, cihazınızda desteklenmediği için düz renk olarak atanmıştır", Toast.LENGTH_LONG).show();
  132. }
  133.  
  134. imageView.setOnClickListener(new View.OnClickListener() {
  135. @Override
  136. public void onClick(View v) {
  137. countdatabase(v);
  138. }
  139. });
  140.  
  141.  
  142. logMail = (EditText) findViewById(R.id.logMail);
  143. logPass = (EditText) findViewById(R.id.logPass);
  144.  
  145. registerButton = (Button) findViewById(R.id.registerButton);
  146.  
  147.  
  148. loginButton.setOnClickListener(new View.OnClickListener() {
  149. @Override
  150. public void onClick(View v) {
  151. login(v);
  152. }
  153. });
  154.  
  155. registerButton.setOnClickListener(new View.OnClickListener() {
  156. @Override
  157. public void onClick(View v) {
  158. reg(v);
  159. }
  160. });
  161. }
  162.  
  163. private void countdatabase(View v) {
  164.  
  165. // counter++;
  166.  
  167. if (counter == 15) {
  168.  
  169. myRef.child("maç1").child("Oynayanlar").setValue("Maç1 - Maç2");
  170. myRef.child("maç1").child("Kredi").setValue("20");
  171. myRef.child("maç1").child("Tahmin").setValue("ÜST");
  172. myRef.child("maç1").child("Güven").setValue("%90");
  173. myRef.child("maç1").child("Oran").setValue("1.8");
  174. myRef.child("maç1").child("Saat").setValue("20:00");
  175. myRef.child("maç1").child("Prediction").setValue("Win");
  176.  
  177. myRef.child("maç2").child("Oynayanlar").setValue("Maç1 - Maç2");
  178. myRef.child("maç2").child("Kredi").setValue("20");
  179. myRef.child("maç2").child("Tahmin").setValue("ÜST");
  180. myRef.child("maç2").child("Güven").setValue("%90");
  181. myRef.child("maç2").child("Oran").setValue("1.8");
  182. myRef.child("maç2").child("Saat").setValue("20:00");
  183. myRef.child("maç2").child("Prediction").setValue("Win");
  184.  
  185. myRef.child("maç3").child("Oynayanlar").setValue("Maç1 - Maç2");
  186. myRef.child("maç3").child("Kredi").setValue("20");
  187. myRef.child("maç3").child("Tahmin").setValue("ÜST");
  188. myRef.child("maç3").child("Güven").setValue("%90");
  189. myRef.child("maç3").child("Oran").setValue("1.8");
  190. myRef.child("maç3").child("Saat").setValue("20:00");
  191. myRef.child("maç3").child("Prediction").setValue("Win");
  192.  
  193. myRef.child("maç4").child("Oynayanlar").setValue("Maç1 - Maç2");
  194. myRef.child("maç4").child("Kredi").setValue("20");
  195. myRef.child("maç4").child("Tahmin").setValue("ÜST");
  196. myRef.child("maç4").child("Güven").setValue("%90");
  197. myRef.child("maç4").child("Oran").setValue("1.8");
  198. myRef.child("maç4").child("Saat").setValue("20:00");
  199. myRef.child("maç4").child("Prediction").setValue("Win");
  200.  
  201. myRef.child("maç5").child("Oynayanlar").setValue("Maç1 - Maç2");
  202. myRef.child("maç5").child("Kredi").setValue("20");
  203. myRef.child("maç5").child("Tahmin").setValue("ÜST");
  204. myRef.child("maç5").child("Güven").setValue("%90");
  205. myRef.child("maç5").child("Oran").setValue("1.8");
  206. myRef.child("maç5").child("Saat").setValue("20:00");
  207. myRef.child("maç5").child("Prediction").setValue("Win");
  208.  
  209. myRef.child("maç6").child("Oynayanlar").setValue("Maç1 - Maç2");
  210. myRef.child("maç6").child("Kredi").setValue("20");
  211. myRef.child("maç6").child("Tahmin").setValue("ÜST");
  212. myRef.child("maç6").child("Güven").setValue("%90");
  213. myRef.child("maç6").child("Oran").setValue("1.8");
  214. myRef.child("maç6").child("Saat").setValue("20:00");
  215. myRef.child("maç6").child("Prediction").setValue("Win");
  216.  
  217. myRef.child("maç7").child("Oynayanlar").setValue("Maç1 - Maç2");
  218. myRef.child("maç7").child("Kredi").setValue("20");
  219. myRef.child("maç7").child("Tahmin").setValue("ÜST");
  220. myRef.child("maç7").child("Güven").setValue("%90");
  221. myRef.child("maç7").child("Oran").setValue("1.8");
  222. myRef.child("maç7").child("Saat").setValue("20:00");
  223. myRef.child("maç7").child("Prediction").setValue("Win");
  224.  
  225. myRef.child("maç8").child("Oynayanlar").setValue("Maç1 - Maç2");
  226. myRef.child("maç8").child("Kredi").setValue("20");
  227. myRef.child("maç8").child("Tahmin").setValue("ÜST");
  228. myRef.child("maç8").child("Güven").setValue("%90");
  229. myRef.child("maç8").child("Oran").setValue("1.8");
  230. myRef.child("maç8").child("Saat").setValue("20:00");
  231. myRef.child("maç8").child("Prediction").setValue("Win");
  232.  
  233. myRef.child("maç9").child("Oynayanlar").setValue("Maç1 - Maç2");
  234. myRef.child("maç9").child("Kredi").setValue("20");
  235. myRef.child("maç9").child("Tahmin").setValue("ÜST");
  236. myRef.child("maç9").child("Güven").setValue("%90");
  237. myRef.child("maç9").child("Oran").setValue("1.8");
  238. myRef.child("maç9").child("Saat").setValue("20:00");
  239. myRef.child("maç9").child("Prediction").setValue("Win");
  240.  
  241. myRef.child("maç10").child("Oynayanlar").setValue("Maç1 - Maç2");
  242. myRef.child("maç10").child("Kredi").setValue("20");
  243. myRef.child("maç10").child("Tahmin").setValue("ÜST");
  244. myRef.child("maç10").child("Güven").setValue("%90");
  245. myRef.child("maç10").child("Oran").setValue("1.8");
  246. myRef.child("maç10").child("Saat").setValue("20:00");
  247. myRef.child("maç10").child("Prediction").setValue("Win");
  248.  
  249. myRef.child("maç11").child("Oynayanlar").setValue("Maç1 - Maç2");
  250. myRef.child("maç11").child("Kredi").setValue("20");
  251. myRef.child("maç11").child("Tahmin").setValue("ÜST");
  252. myRef.child("maç11").child("Güven").setValue("%90");
  253. myRef.child("maç11").child("Oran").setValue("1.8");
  254. myRef.child("maç11").child("Saat").setValue("20:00");
  255. myRef.child("maç11").child("Prediction").setValue("Win");
  256.  
  257. myRef.child("maç12").child("Oynayanlar").setValue("Maç1 - Maç2");
  258. myRef.child("maç12").child("Kredi").setValue("20");
  259. myRef.child("maç12").child("Tahmin").setValue("ÜST");
  260. myRef.child("maç12").child("Güven").setValue("%90");
  261. myRef.child("maç12").child("Oran").setValue("1.8");
  262. myRef.child("maç12").child("Saat").setValue("20:00");
  263. myRef.child("maç12").child("Prediction").setValue("Win");
  264.  
  265. myRef.child("maç13").child("Oynayanlar").setValue("BurayıDoldur");
  266. myRef.child("maç13").child("Kredi").setValue("20");
  267. myRef.child("maç13").child("Tahmin").setValue("ÜST");
  268. myRef.child("maç13").child("Güven").setValue("%90");
  269. myRef.child("maç13").child("Oran").setValue("1.8");
  270. myRef.child("maç13").child("Saat").setValue("20:00");
  271. myRef.child("maç13").child("Prediction").setValue("Win");
  272.  
  273. myRef.child("maç14").child("Oynayanlar").setValue("Maç1 - Maç2");
  274. myRef.child("maç14").child("Kredi").setValue("20");
  275. myRef.child("maç14").child("Tahmin").setValue("ÜST");
  276. myRef.child("maç14").child("Güven").setValue("%90");
  277. myRef.child("maç14").child("Oran").setValue("1.8");
  278. myRef.child("maç14").child("Saat").setValue("20:00");
  279. myRef.child("maç14").child("Prediction").setValue("Win");
  280.  
  281. myRef.child("maç15").child("Oynayanlar").setValue("Maç1 - Maç2");
  282. myRef.child("maç15").child("Kredi").setValue("20");
  283. myRef.child("maç15").child("Tahmin").setValue("ÜST");
  284. myRef.child("maç15").child("Güven").setValue("%90");
  285. myRef.child("maç15").child("Oran").setValue("1.8");
  286. myRef.child("maç15").child("Saat").setValue("20:00");
  287. myRef.child("maç15").child("Prediction").setValue("Win");
  288.  
  289. myRef.child("Reklam Kredisi").setValue("15");
  290. myRef.child("Kayan Yazı").setValue("...Kayan Yazı Alanı...");
  291.  
  292. Toast.makeText(getApplicationContext(), "Tüm database güncellendi", Toast.LENGTH_LONG).show();
  293.  
  294. counter = 0;
  295. }
  296.  
  297. }
  298.  
  299.  
  300. public void login(View view) {
  301. if (!TextUtils.isEmpty(logMail.getText().toString()) && !TextUtils.isEmpty(logPass.getText().toString())) {
  302. mAuth.signInWithEmailAndPassword(logMail.getText().toString(), logPass.getText().toString())
  303. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  304. @Override
  305. public void onComplete(@NonNull Task<AuthResult> task) {
  306. if (task.isSuccessful()) {
  307. Toast.makeText(getApplicationContext(), "Adam oldun", Toast.LENGTH_LONG).show();
  308. FirebaseUser user = mAuth.getCurrentUser();
  309. System.out.println("OK Halloldu");
  310. // Toast.makeText(getApplicationContext(), "Sayın " + user.getEmail() + " hoşgeldiniz", Toast.LENGTH_SHORT).show();
  311. startActivity(new Intent(getApplicationContext(), com.app.surebettips.AnaEkran.class));
  312.  
  313. } else {
  314. Toast.makeText(getApplicationContext(), "Başarısız", Toast.LENGTH_SHORT).show();
  315. System.out.println("NOT OK");
  316. Toast.makeText(getApplicationContext(), "Adam OLAMADIN", Toast.LENGTH_LONG).show();
  317.  
  318.  
  319. }
  320.  
  321. // ...
  322. }
  323. });
  324. }
  325.  
  326. }
  327.  
  328. public void reg(View view) {
  329. startActivity(new Intent(getApplicationContext(), com.app.surebettips.Register.class));
  330. }
  331.  
  332. /*private void signIn() {
  333. Intent signInIntent = mGoogleSignInClient.getSignInIntent();
  334. startActivityForResult(signInIntent, RC_SIGN_IN);
  335. }*/
  336.  
  337.  
  338. private void signIn() {
  339. Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
  340. startActivityForResult(signInIntent, RC_SIGN_IN);
  341.  
  342. }
  343.  
  344.  
  345.  
  346.  
  347.  
  348. @Override
  349. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  350. super.onActivityResult(requestCode, resultCode, data);
  351. if (requestCode == RC_SIGN_IN) {
  352. try {
  353. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
  354. GoogleSignInAccount account = task.getResult(ApiException.class);
  355. // User is logged in on google platform
  356. Log.v(TAG, "Account token:" + account.getIdToken()); //NON-NLS
  357. // Signed in successfully, show authenticated UI.
  358. } catch (ApiException e) {
  359. // The ApiException status code indicates the detailed failure reason.
  360. // Please refer to the GoogleSignInStatusCodes class reference for more information.
  361. Log.w(TAG, "Google sign in failed", e); //NON-NLS
  362.  
  363. String messageToDisplay = "Authentication failed.";
  364. switch (e.getStatusCode()) {
  365. case CommonStatusCodes.API_NOT_CONNECTED: //17
  366. messageToDisplay += "The client attempted to clearPreferences a method from an API that failed to connect.";
  367. break;
  368.  
  369. case CommonStatusCodes.DEVELOPER_ERROR: //10
  370. messageToDisplay += "The application is misconfigured.";
  371. break;
  372.  
  373. case CommonStatusCodes.ERROR: //13
  374. messageToDisplay += "The operation failed with no more detailed information.";
  375. break;
  376.  
  377. case CommonStatusCodes.INTERNAL_ERROR: //8
  378. messageToDisplay += "An internal error occurred.";
  379. break;
  380.  
  381. case CommonStatusCodes.INVALID_ACCOUNT: //8
  382. messageToDisplay += "Invalid account name specified.";
  383. break;
  384.  
  385. case CommonStatusCodes.SIGN_IN_REQUIRED: //8
  386. messageToDisplay += "Please Sign In to continue.";
  387. break;
  388. }
  389. }
  390. }
  391. }
  392.  
  393.  
  394.  
  395. private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
  396.  
  397. AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
  398. mAuth.signInWithCredential(credential)
  399. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  400. @Override
  401. public void onComplete(@NonNull Task<AuthResult> task) {
  402.  
  403.  
  404. Log.d(TAG, "signInWithCredential:success" + task.isSuccessful());
  405. FirebaseUser user = mAuth.getCurrentUser();
  406.  
  407. //updateUI(user);
  408. if (!task.isSuccessful()){
  409. Log.w(TAG, "signInWithCredential:failure", task.getException());
  410. //updateUI(null);
  411.  
  412. }
  413. }
  414.  
  415.  
  416. });
  417.  
  418. }
  419.  
  420.  
  421.  
  422.  
  423.  
  424. }
  425.  
  426. <?xml version="1.0" encoding="utf-8"?>
  427. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  428. package="com.app.surebettips">
  429.  
  430. <uses-permission android:name="android.permission.INTERNET" />
  431. <uses-permission android:name="com.android.vending.BILLING" />
  432.  
  433. <application
  434. android:allowBackup="true"
  435. android:icon="@drawable/logo"
  436. android:label="@string/app_name"
  437. android:roundIcon="@mipmap/ic_launcher_round"
  438. android:supportsRtl="true"
  439. android:theme="@style/AppTheme">
  440. <activity android:name=".Login">
  441. <intent-filter>
  442. <action android:name="android.intent.action.MAIN" />
  443.  
  444. <category android:name="android.intent.category.LAUNCHER" />
  445. </intent-filter>
  446. </activity>
  447. <activity android:name=".Register" />
  448.  
  449. <meta-data
  450. android:name="preloaded_fonts"
  451. android:resource="@array/preloaded_fonts" />
  452.  
  453. <activity android:name=".AnaEkran" />
  454.  
  455. <service android:name=".MyFirebaseMessagingService">
  456. <intent-filter>
  457. <action android:name="com.google.firebase.MESSAGING_EVENT" />
  458. </intent-filter>
  459. </service>
  460. <service android:name=".MyFirebaseInstanceIDService">
  461. <intent-filter>
  462. <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
  463. </intent-filter>
  464. </service>
  465.  
  466. <activity android:name=".Buy" />
  467. <activity android:name=".AdminPanel" />
  468. <activity android:name=".Inputlar" />
  469. <activity android:name=".Fikstur"></activity>
  470. </application>
  471.  
  472. </manifest>
  473.  
  474. apply plugin: 'com.android.application'
  475.  
  476. android {
  477. compileSdkVersion 27
  478.  
  479. lintOptions {
  480.  
  481. checkReleaseBuilds false
  482.  
  483. }
  484. defaultConfig {
  485. applicationId "com.app.surebettips"
  486. minSdkVersion 17
  487. targetSdkVersion 27
  488. versionCode 1
  489. versionName "1.0"
  490. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  491. }
  492. buildTypes {
  493. release {
  494. minifyEnabled false
  495. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  496. }
  497. }
  498. }
  499.  
  500. dependencies {
  501. implementation fileTree(include: ['*.jar'], dir: 'libs')
  502. implementation 'com.android.support:appcompat-v7:27.1.0'
  503. implementation 'com.android.support.constraint:constraint-layout:1.1.0'
  504. implementation 'com.google.firebase:firebase-core:15.0.2'
  505. implementation 'com.github.jd-alexander:android-flat-button:v1.1'
  506. implementation 'com.anjlab.android.iab.v3:library:1.0.44'
  507. implementation 'com.google.firebase:firebase-auth:15.0.0'
  508. implementation 'com.google.firebase:firebase-database:15.0.0'
  509. implementation 'com.google.android.gms:play-services-ads:15.0.0'
  510. implementation 'com.google.firebase:firebase-messaging:15.0.2'
  511. implementation 'com.google.android.gms:play-services-auth:15.0.0'
  512. implementation 'com.github.florent37:materialtextfield:1.0.7'
  513.  
  514. testImplementation 'junit:junit:4.12'
  515. androidTestImplementation 'com.android.support.test:runner:1.0.2'
  516. androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  517. implementation 'com.android.support:design:27.1.0'
  518. }
  519. apply plugin: 'com.google.gms.google-services'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement