fork(3) download
  1. package com.tokopedia.session.register.activity;
  2.  
  3. import android.content.Intent;
  4. import android.content.IntentSender;
  5. import android.os.Bundle;
  6. import android.support.annotation.NonNull;
  7. import android.support.annotation.Nullable;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.util.Log;
  10. import android.widget.Toast;
  11.  
  12. import com.google.android.gms.auth.api.Auth;
  13. import com.google.android.gms.auth.api.credentials.Credential;
  14. import com.google.android.gms.auth.api.credentials.CredentialRequest;
  15. import com.google.android.gms.auth.api.credentials.CredentialRequestResult;
  16. import com.google.android.gms.common.ConnectionResult;
  17. import com.google.android.gms.common.api.CommonStatusCodes;
  18. import com.google.android.gms.common.api.GoogleApiClient;
  19. import com.google.android.gms.common.api.ResultCallback;
  20. import com.google.android.gms.common.api.Status;
  21. import com.tokopedia.session.R;
  22.  
  23. public class SmartLockActivity extends AppCompatActivity implements
  24. GoogleApiClient.ConnectionCallbacks,
  25. GoogleApiClient.OnConnectionFailedListener {
  26.  
  27. private static final String TAG = "MainActivity";
  28. private static final int RC_SAVE = 1;
  29. private static final int RC_READ = 3;
  30. private static final String IS_RESOLVING = "is_resolving";
  31. private static final String IS_REQUESTING = "is_requesting";
  32.  
  33. // Add mGoogleApiClient and mIsResolving fields here.
  34. private boolean mIsResolving;
  35. private boolean mIsRequesting;
  36.  
  37. private GoogleApiClient mGoogleApiClient;
  38.  
  39. @Override
  40. protected void onCreate(Bundle savedInstanceState) {
  41. super.onCreate(savedInstanceState);
  42. setContentView(R.layout.activity_simple_fragment);
  43.  
  44. mGoogleApiClient = new GoogleApiClient.Builder(this)
  45. .addConnectionCallbacks(this)
  46. .enableAutoManage(this, 0, this)
  47. .addApi(Auth.CREDENTIALS_API)
  48. .build();
  49.  
  50. if (savedInstanceState != null) {
  51. mIsResolving = savedInstanceState.getBoolean(IS_RESOLVING);
  52. mIsRequesting = savedInstanceState.getBoolean(IS_REQUESTING);
  53. }
  54. }
  55.  
  56. @Override
  57. public void onSaveInstanceState(Bundle savedInstanceState) {
  58. // Save the user's current sign in state
  59. savedInstanceState.putBoolean(IS_RESOLVING, mIsResolving);
  60. savedInstanceState.putBoolean(IS_REQUESTING, mIsRequesting);
  61.  
  62. // Always call the superclass so it can save the view hierarchy state
  63. super.onSaveInstanceState(savedInstanceState);
  64. }
  65.  
  66. /**
  67.   * Start the Content Activity and finish this one.
  68.   */
  69. protected void goToContent() {
  70. // startActivity(new Intent(this, ContentActivity.class));
  71. // finish();
  72. }
  73.  
  74. @Override
  75. public void onConnected(@Nullable Bundle bundle) {
  76. // Request Credentials once connected. If credentials are retrieved
  77. // the user will either be automatically signed in or will be
  78. // presented with credential options to be used by the application
  79. // for sign in.
  80. requestCredentials();
  81.  
  82. }
  83.  
  84. @Override
  85. public void onConnectionSuspended(int i) {
  86.  
  87. }
  88.  
  89. @Override
  90. public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
  91.  
  92. }
  93.  
  94. private void resolveResult(Status status, int requestCode) {
  95. // We don't want to fire multiple resolutions at once since that
  96. // can result in stacked dialogs after rotation or another
  97. // similar event.
  98. if (mIsResolving) {
  99. Log.w(TAG, "resolveResult: already resolving.");
  100. return;
  101. }
  102.  
  103. Log.d(TAG, "Resolving: " + status);
  104. if (status.hasResolution()) {
  105. Log.d(TAG, "STATUS: RESOLVING");
  106. try {
  107. status.startResolutionForResult(this, requestCode);
  108. mIsResolving = true;
  109. } catch (IntentSender.SendIntentException e) {
  110. Log.e(TAG, "STATUS: Failed to send resolution.", e);
  111. }
  112. } else {
  113. goToContent();
  114. }
  115. }
  116.  
  117. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  118. super.onActivityResult(requestCode, resultCode, data);
  119. Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" +
  120. data);
  121. if (requestCode == RC_READ) {
  122. if (resultCode == RESULT_OK) {
  123. Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
  124. processRetrievedCredential(credential);
  125. } else {
  126. Log.e(TAG, "Credential Read: NOT OK");
  127. // setSignInEnabled(true);
  128. }
  129. } else if (requestCode == RC_SAVE) {
  130. Log.d(TAG, "Result code: " + resultCode);
  131. if (resultCode == RESULT_OK) {
  132. Log.d(TAG, "Credential Save: OK");
  133. } else {
  134. Log.e(TAG, "Credential Save Failed");
  135. }
  136. goToContent();
  137. }
  138. mIsResolving = false;
  139. }
  140.  
  141. private void requestCredentials() {
  142. // setSignInEnabled(false);
  143. mIsRequesting = true;
  144.  
  145. CredentialRequest request = new CredentialRequest.Builder()
  146. .setSupportsPasswordLogin(true)
  147. .build();
  148.  
  149. Auth.CredentialsApi.request(mGoogleApiClient, request).setResultCallback(
  150. new ResultCallback<CredentialRequestResult>() {
  151. @Override
  152. public void onResult(CredentialRequestResult credentialRequestResult) {
  153. mIsRequesting = false;
  154. Status status = credentialRequestResult.getStatus();
  155. if (credentialRequestResult.getStatus().isSuccess()) {
  156. // Successfully read the credential without any user interaction, this
  157. // means there was only a single credential and the user has auto
  158. // sign-in enabled.
  159. Credential credential = credentialRequestResult.getCredential();
  160. processRetrievedCredential(credential);
  161. } else if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
  162. // This is most likely the case where the user has multiple saved
  163. // credentials and needs to pick one.
  164. resolveResult(status, RC_READ);
  165. } else if (status.getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) {
  166. // This is most likely the case where the user does not currently
  167. // have any saved credentials and thus needs to provide a username
  168. // and password to sign in.
  169. Log.d(TAG, "Sign in required");
  170. // setSignInEnabled(true);
  171. } else {
  172. Log.w(TAG, "Unrecognized status code: " + status.getStatusCode());
  173. // setSignInEnabled(true);
  174. }
  175. }
  176. }
  177. );
  178. }
  179.  
  180. private void processRetrievedCredential(Credential credential) {
  181. if (CodelabUtil.isValidCredential(credential)) {
  182. goToContent();
  183. } else {
  184. // This is likely due to the credential being changed outside of
  185. // Smart Lock,
  186. // ie: away from Android or Chrome. The credential should be deleted
  187. // and the user allowed to enter a valid credential.
  188. Log.d(TAG, "Retrieved credential invalid, so delete retrieved" +
  189. " credential.");
  190. Toast.makeText(this, "Retrieved credentials are invalid, so will be deleted.", Toast.LENGTH_LONG).show();
  191. deleteCredential(credential);
  192. requestCredentials();
  193. // setSignInEnabled(false);
  194. }
  195. }
  196.  
  197. public void saveCredential(Credential credential) {
  198. // Credential is valid so save it.
  199. Auth.CredentialsApi.save(mGoogleApiClient,
  200. credential).setResultCallback(new ResultCallback<Status>() {
  201. @Override
  202. public void onResult(Status status) {
  203. if (status.isSuccess()) {
  204. Log.d(TAG, "Credential saved");
  205. goToContent();
  206. } else {
  207. Log.d(TAG, "Attempt to save credential failed " +
  208. status.getStatusMessage() + " " +
  209. status.getStatusCode());
  210. resolveResult(status, RC_SAVE);
  211. }
  212. }
  213. });
  214. }
  215.  
  216. private void deleteCredential(Credential credential) {
  217. Auth.CredentialsApi.delete(mGoogleApiClient,
  218. credential).setResultCallback(new ResultCallback<Status>() {
  219. @Override
  220. public void onResult(Status status) {
  221. if (status.isSuccess()) {
  222. Log.d(TAG, "Credential successfully deleted.");
  223. } else {
  224. // This may be due to the credential not existing, possibly
  225. // already deleted via another device/app.
  226. Log.d(TAG, "Credential not deleted successfully.");
  227. }
  228. }
  229. });
  230. }
  231. }
  232.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty