Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.top.mobigold;
- import androidx.annotation.Nullable;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.os.Handler;
- import android.util.Log;
- import android.view.View;
- 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.Task;
- public class MainActivity extends AppCompatActivity {
- private GoogleSignInClient mGoogleSignInClient;
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- SharedPreferences mPreferences = this.getSharedPreferences("first_time", Context.MODE_PRIVATE);
- boolean firstTime = mPreferences.getBoolean("firstTime", true);
- if(firstTime){
- for (final int i: new int []{10, 30, 60, 120, 300}) {
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- Log.w("Event11", "Event after " + i + " seconds");
- // YandexMetrica.reportEvent("Event after " + i + " seconds");
- }}, i * 1000);
- }
- }
- SharedPreferences.Editor editor = mPreferences.edit();
- editor.putBoolean("firstTime", false);
- editor.apply();
- GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
- if(account != null){
- Intent intent = new Intent(getApplicationContext(), WebActivity.class);
- intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
- startActivity(intent);
- Log.w("Cash", "finished");
- }
- setContentView(R.layout.activity_main);
- GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
- .requestEmail()
- .build();
- mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
- SignInButton signInButton = findViewById(R.id.sign_in_button);
- signInButton.setSize(SignInButton.SIZE_STANDARD);
- signInButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent signInIntent = mGoogleSignInClient.getSignInIntent();
- startActivityForResult(signInIntent, 9001);
- }
- });
- }
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- Log.w("Cash", "onActivityResult " + requestCode + " " + resultCode);
- // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
- if (requestCode == 9001) {
- // The Task returned from this call is always completed, no need to attach a listener.
- Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
- handleSignInResult(task);
- }
- }
- private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
- try {
- GoogleSignInAccount account = completedTask.getResult(ApiException.class);
- if(account != null){
- // Signed in successfully, show authenticated UI.
- Intent intent = new Intent(getApplicationContext(), MainActivity.class);
- intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
- startActivity(intent);
- }
- } catch (ApiException e) {
- Log.w("Cash", "" + e.getStatusCode());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement