package com.tokopedia.session.register.activity; import android.content.Intent; import android.content.IntentSender; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.Toast; import com.google.android.gms.auth.api.Auth; import com.google.android.gms.auth.api.credentials.Credential; import com.google.android.gms.auth.api.credentials.CredentialRequest; import com.google.android.gms.auth.api.credentials.CredentialRequestResult; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.CommonStatusCodes; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.tokopedia.session.R; public class SmartLockActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { private static final int RC_SAVE = 1; private static final int RC_READ = 3; // Add mGoogleApiClient and mIsResolving fields here. private boolean mIsResolving; private boolean mIsRequesting; private GoogleApiClient mGoogleApiClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_simple_fragment); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .enableAutoManage(this, 0, this) .addApi(Auth.CREDENTIALS_API) .build(); if (savedInstanceState != null) { mIsResolving = savedInstanceState.getBoolean(IS_RESOLVING); mIsRequesting = savedInstanceState.getBoolean(IS_REQUESTING); } } @Override public void onSaveInstanceState(Bundle savedInstanceState) { // Save the user's current sign in state savedInstanceState.putBoolean(IS_RESOLVING, mIsResolving); savedInstanceState.putBoolean(IS_REQUESTING, mIsRequesting); // Always call the superclass so it can save the view hierarchy state super.onSaveInstanceState(savedInstanceState); } /** * Start the Content Activity and finish this one. */ protected void goToContent() { // startActivity(new Intent(this, ContentActivity.class)); // finish(); } @Override public void onConnected(@Nullable Bundle bundle) { // Request Credentials once connected. If credentials are retrieved // the user will either be automatically signed in or will be // presented with credential options to be used by the application // for sign in. requestCredentials(); } @Override public void onConnectionSuspended(int i) { } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { } private void resolveResult(Status status, int requestCode) { // We don't want to fire multiple resolutions at once since that // can result in stacked dialogs after rotation or another // similar event. if (mIsResolving) { Log.w(TAG, "resolveResult: already resolving."); return; } Log.d(TAG, "Resolving: " + status); if (status.hasResolution()) { Log.d(TAG, "STATUS: RESOLVING"); try { status.startResolutionForResult(this, requestCode); mIsResolving = true; } catch (IntentSender.SendIntentException e) { Log.e(TAG, "STATUS: Failed to send resolution.", e); } } else { goToContent(); } } public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data); if (requestCode == RC_READ) { if (resultCode == RESULT_OK) { Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY); processRetrievedCredential(credential); } else { Log.e(TAG, "Credential Read: NOT OK"); // setSignInEnabled(true); } } else if (requestCode == RC_SAVE) { Log.d(TAG, "Result code: " + resultCode); if (resultCode == RESULT_OK) { Log.d(TAG, "Credential Save: OK"); } else { Log.e(TAG, "Credential Save Failed"); } goToContent(); } mIsResolving = false; } private void requestCredentials() { // setSignInEnabled(false); mIsRequesting = true; CredentialRequest request = new CredentialRequest.Builder() .setSupportsPasswordLogin(true) .build(); Auth.CredentialsApi.request(mGoogleApiClient, request).setResultCallback( new ResultCallback<CredentialRequestResult>() { @Override public void onResult(CredentialRequestResult credentialRequestResult) { mIsRequesting = false; Status status = credentialRequestResult.getStatus(); if (credentialRequestResult.getStatus().isSuccess()) { // Successfully read the credential without any user interaction, this // means there was only a single credential and the user has auto // sign-in enabled. Credential credential = credentialRequestResult.getCredential(); processRetrievedCredential(credential); } else if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) { // This is most likely the case where the user has multiple saved // credentials and needs to pick one. resolveResult(status, RC_READ); } else if (status.getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) { // This is most likely the case where the user does not currently // have any saved credentials and thus needs to provide a username // and password to sign in. Log.d(TAG, "Sign in required"); // setSignInEnabled(true); } else { Log.w(TAG, "Unrecognized status code: " + status.getStatusCode()); // setSignInEnabled(true); } } } ); } private void processRetrievedCredential(Credential credential) { if (CodelabUtil.isValidCredential(credential)) { goToContent(); } else { // This is likely due to the credential being changed outside of // Smart Lock, // ie: away from Android or Chrome. The credential should be deleted // and the user allowed to enter a valid credential. Log.d(TAG, "Retrieved credential invalid, so delete retrieved" + " credential."); Toast.makeText(this, "Retrieved credentials are invalid, so will be deleted.", Toast.LENGTH_LONG).show(); deleteCredential(credential); requestCredentials(); // setSignInEnabled(false); } } public void saveCredential(Credential credential) { // Credential is valid so save it. Auth.CredentialsApi.save(mGoogleApiClient, credential).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Log.d(TAG, "Credential saved"); goToContent(); } else { Log.d(TAG, "Attempt to save credential failed " + status.getStatusMessage() + " " + status.getStatusCode()); resolveResult(status, RC_SAVE); } } }); } private void deleteCredential(Credential credential) { Auth.CredentialsApi.delete(mGoogleApiClient, credential).setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Log.d(TAG, "Credential successfully deleted."); } else { // This may be due to the credential not existing, possibly // already deleted via another device/app. Log.d(TAG, "Credential not deleted successfully."); } } }); } }
Standard input is empty
Main.java:23: error: class SmartLockActivity is public, should be declared in a file named SmartLockActivity.java
public class SmartLockActivity extends AppCompatActivity implements
^
Main.java:3: error: package android.content does not exist
import android.content.Intent;
^
Main.java:4: error: package android.content does not exist
import android.content.IntentSender;
^
Main.java:5: error: package android.os does not exist
import android.os.Bundle;
^
Main.java:6: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
^
Main.java:7: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
Main.java:8: error: package android.support.v7.app does not exist
import android.support.v7.app.AppCompatActivity;
^
Main.java:9: error: package android.util does not exist
import android.util.Log;
^
Main.java:10: error: package android.widget does not exist
import android.widget.Toast;
^
Main.java:12: error: package com.google.android.gms.auth.api does not exist
import com.google.android.gms.auth.api.Auth;
^
Main.java:13: error: package com.google.android.gms.auth.api.credentials does not exist
import com.google.android.gms.auth.api.credentials.Credential;
^
Main.java:14: error: package com.google.android.gms.auth.api.credentials does not exist
import com.google.android.gms.auth.api.credentials.CredentialRequest;
^
Main.java:15: error: package com.google.android.gms.auth.api.credentials does not exist
import com.google.android.gms.auth.api.credentials.CredentialRequestResult;
^
Main.java:16: error: package com.google.android.gms.common does not exist
import com.google.android.gms.common.ConnectionResult;
^
Main.java:17: error: package com.google.android.gms.common.api does not exist
import com.google.android.gms.common.api.CommonStatusCodes;
^
Main.java:18: error: package com.google.android.gms.common.api does not exist
import com.google.android.gms.common.api.GoogleApiClient;
^
Main.java:19: error: package com.google.android.gms.common.api does not exist
import com.google.android.gms.common.api.ResultCallback;
^
Main.java:20: error: package com.google.android.gms.common.api does not exist
import com.google.android.gms.common.api.Status;
^
Main.java:21: error: cannot find symbol
import com.tokopedia.session.R;
^
symbol: class R
location: package com.tokopedia.session
Main.java:23: error: cannot find symbol
public class SmartLockActivity extends AppCompatActivity implements
^
symbol: class AppCompatActivity
Main.java:24: error: package GoogleApiClient does not exist
GoogleApiClient.ConnectionCallbacks,
^
Main.java:25: error: package GoogleApiClient does not exist
GoogleApiClient.OnConnectionFailedListener {
^
Main.java:37: error: cannot find symbol
private GoogleApiClient mGoogleApiClient;
^
symbol: class GoogleApiClient
location: class SmartLockActivity
Main.java:40: error: cannot find symbol
protected void onCreate(Bundle savedInstanceState) {
^
symbol: class Bundle
location: class SmartLockActivity
Main.java:57: error: cannot find symbol
public void onSaveInstanceState(Bundle savedInstanceState) {
^
symbol: class Bundle
location: class SmartLockActivity
Main.java:75: error: cannot find symbol
public void onConnected(@Nullable Bundle bundle) {
^
symbol: class Bundle
location: class SmartLockActivity
Main.java:90: error: cannot find symbol
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
^
symbol: class ConnectionResult
location: class SmartLockActivity
Main.java:94: error: cannot find symbol
private void resolveResult(Status status, int requestCode) {
^
symbol: class Status
location: class SmartLockActivity
Main.java:117: error: cannot find symbol
public void onActivityResult(int requestCode, int resultCode, Intent data) {
^
symbol: class Intent
location: class SmartLockActivity
Main.java:180: error: cannot find symbol
private void processRetrievedCredential(Credential credential) {
^
symbol: class Credential
location: class SmartLockActivity
Main.java:197: error: cannot find symbol
public void saveCredential(Credential credential) {
^
symbol: class Credential
location: class SmartLockActivity
Main.java:216: error: cannot find symbol
private void deleteCredential(Credential credential) {
^
symbol: class Credential
location: class SmartLockActivity
Main.java:75: error: cannot find symbol
public void onConnected(@Nullable Bundle bundle) {
^
symbol: class Nullable
location: class SmartLockActivity
Main.java:90: error: cannot find symbol
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
^
symbol: class NonNull
location: class SmartLockActivity
Main.java:39: error: method does not override or implement a method from a supertype
@Override
^
Main.java:41: error: cannot find symbol
super.onCreate(savedInstanceState);
^
symbol: variable super
location: class SmartLockActivity
Main.java:42: error: package R does not exist
setContentView(R.layout.activity_simple_fragment);
^
Main.java:47: error: cannot find symbol
.addApi(Auth.CREDENTIALS_API)
^
symbol: variable Auth
location: class SmartLockActivity
Main.java:44: error: package GoogleApiClient does not exist
mGoogleApiClient = new GoogleApiClient.Builder(this)
^
Main.java:56: error: method does not override or implement a method from a supertype
@Override
^
Main.java:63: error: cannot find symbol
super.onSaveInstanceState(savedInstanceState);
^
symbol: variable super
location: class SmartLockActivity
Main.java:74: error: method does not override or implement a method from a supertype
@Override
^
Main.java:84: error: method does not override or implement a method from a supertype
@Override
^
Main.java:89: error: method does not override or implement a method from a supertype
@Override
^
Main.java:99: error: cannot find symbol
Log.w(TAG, "resolveResult: already resolving.");
^
symbol: variable Log
location: class SmartLockActivity
Main.java:103: error: cannot find symbol
Log.d(TAG, "Resolving: " + status);
^
symbol: variable Log
location: class SmartLockActivity
Main.java:105: error: cannot find symbol
Log.d(TAG, "STATUS: RESOLVING");
^
symbol: variable Log
location: class SmartLockActivity
Main.java:109: error: package IntentSender does not exist
} catch (IntentSender.SendIntentException e) {
^
Main.java:110: error: cannot find symbol
Log.e(TAG, "STATUS: Failed to send resolution.", e);
^
symbol: variable Log
location: class SmartLockActivity
Main.java:118: error: cannot find symbol
super.onActivityResult(requestCode, resultCode, data);
^
symbol: variable super
location: class SmartLockActivity
Main.java:119: error: cannot find symbol
Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" +
^
symbol: variable Log
location: class SmartLockActivity
Main.java:122: error: cannot find symbol
if (resultCode == RESULT_OK) {
^
symbol: variable RESULT_OK
location: class SmartLockActivity
Main.java:123: error: cannot find symbol
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
^
symbol: class Credential
location: class SmartLockActivity
Main.java:123: error: cannot find symbol
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
^
symbol: variable Credential
location: class SmartLockActivity
Main.java:126: error: cannot find symbol
Log.e(TAG, "Credential Read: NOT OK");
^
symbol: variable Log
location: class SmartLockActivity
Main.java:130: error: cannot find symbol
Log.d(TAG, "Result code: " + resultCode);
^
symbol: variable Log
location: class SmartLockActivity
Main.java:131: error: cannot find symbol
if (resultCode == RESULT_OK) {
^
symbol: variable RESULT_OK
location: class SmartLockActivity
Main.java:132: error: cannot find symbol
Log.d(TAG, "Credential Save: OK");
^
symbol: variable Log
location: class SmartLockActivity
Main.java:134: error: cannot find symbol
Log.e(TAG, "Credential Save Failed");
^
symbol: variable Log
location: class SmartLockActivity
Main.java:145: error: cannot find symbol
CredentialRequest request = new CredentialRequest.Builder()
^
symbol: class CredentialRequest
location: class SmartLockActivity
Main.java:145: error: package CredentialRequest does not exist
CredentialRequest request = new CredentialRequest.Builder()
^
Main.java:150: error: cannot find symbol
new ResultCallback<CredentialRequestResult>() {
^
symbol: class ResultCallback
location: class SmartLockActivity
Main.java:150: error: cannot find symbol
new ResultCallback<CredentialRequestResult>() {
^
symbol: class CredentialRequestResult
location: class SmartLockActivity
Main.java:149: error: package Auth does not exist
Auth.CredentialsApi.request(mGoogleApiClient, request).setResultCallback(
^
Main.java:181: error: cannot find symbol
if (CodelabUtil.isValidCredential(credential)) {
^
symbol: variable CodelabUtil
location: class SmartLockActivity
Main.java:188: error: cannot find symbol
Log.d(TAG, "Retrieved credential invalid, so delete retrieved" +
^
symbol: variable Log
location: class SmartLockActivity
Main.java:190: error: cannot find symbol
Toast.makeText(this, "Retrieved credentials are invalid, so will be deleted.", Toast.LENGTH_LONG).show();
^
symbol: variable Toast
location: class SmartLockActivity
Main.java:190: error: cannot find symbol
Toast.makeText(this, "Retrieved credentials are invalid, so will be deleted.", Toast.LENGTH_LONG).show();
^
symbol: variable Toast
location: class SmartLockActivity
Main.java:200: error: cannot find symbol
credential).setResultCallback(new ResultCallback<Status>() {
^
symbol: class ResultCallback
location: class SmartLockActivity
Main.java:200: error: cannot find symbol
credential).setResultCallback(new ResultCallback<Status>() {
^
symbol: class Status
location: class SmartLockActivity
Main.java:199: error: package Auth does not exist
Auth.CredentialsApi.save(mGoogleApiClient,
^
Main.java:218: error: cannot find symbol
credential).setResultCallback(new ResultCallback<Status>() {
^
symbol: class ResultCallback
location: class SmartLockActivity
Main.java:218: error: cannot find symbol
credential).setResultCallback(new ResultCallback<Status>() {
^
symbol: class Status
location: class SmartLockActivity
Main.java:217: error: package Auth does not exist
Auth.CredentialsApi.delete(mGoogleApiClient,
^
74 errors
Standard output is empty