Guest User

Untitled

a guest
Mar 23rd, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 KB | None | 0 0
  1. package ru.podgorny.carcall;
  2.  
  3. import android.accounts.Account;
  4. import android.content.Intent;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.TextView;
  10.  
  11. import com.google.android.gms.auth.api.signin.GoogleSignIn;
  12. import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
  13. import com.google.android.gms.auth.api.signin.GoogleSignInClient;
  14. import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
  15. import com.google.android.gms.common.SignInButton;
  16. import com.google.android.gms.common.api.ApiException;
  17. import com.google.android.gms.tasks.Task;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20.  
  21. SignInButton signInButton;
  22. public static final int RC_SIGN_IN = 07;
  23. public static final String TAG = "MainActivity";
  24. TextView tw1;
  25. TextView tw2;
  26.  
  27.  
  28. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
  29. .requestEmail()
  30. .requestProfile()
  31. .build();
  32.  
  33. GoogleSignInClient mGSC = GoogleSignIn.getClient(this, gso);
  34.  
  35.  
  36. @Override
  37. protected void onCreate (Bundle savedInstanceState){
  38. super.onCreate(savedInstanceState);
  39. setContentView(R.layout.activity_main);
  40. findViews();
  41.  
  42.  
  43. }
  44.  
  45. private void findViews() {
  46. signInButton = findViewById(R.id.idButtonGoogle);
  47. tw1 = findViewById(R.id.textView1);
  48. tw1 = findViewById(R.id.textView2);
  49.  
  50.  
  51. }
  52.  
  53. public void onClick(View v) {
  54. switch (v.getId()) {
  55. case R.id.idButtonGoogle:
  56. signIn();
  57. break;
  58. }
  59. }
  60.  
  61. private void signIn() {
  62.  
  63. Intent signInIntent = mGSC.getSignInIntent();
  64. startActivityForResult(signInIntent, RC_SIGN_IN);
  65.  
  66. }
  67.  
  68. @Override
  69. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  70. super.onActivityResult(requestCode, resultCode, data);
  71.  
  72. // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
  73. if (requestCode == RC_SIGN_IN) {
  74. // The Task returned from this call is always completed, no need to attach
  75. // a listener.
  76. Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
  77. handleSignInResult(task);
  78. }
  79. }
  80.  
  81. private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
  82. try {
  83. GoogleSignInAccount account = completedTask.getResult(ApiException.class);
  84.  
  85.  
  86. updateUI(account);
  87. } catch (ApiException e) {
  88.  
  89. Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
  90. updateUI(null);
  91. }
  92. }
  93.  
  94. private void updateUI(GoogleSignInAccount account) {
  95. tw1.setText("OK");
  96. tw2.setText("Name: " + account.getGivenName() + ", Family name: " + account.getFamilyName() + ", Email: " + account.getEmail() + " image: " +
  97. account.getPhotoUrl());
  98.  
  99. }
  100.  
  101.  
  102. }
  103.  
  104. <?xml version="1.0" encoding="utf-8"?>
  105. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  106. xmlns:app="http://schemas.android.com/apk/res-auto"
  107. xmlns:tools="http://schemas.android.com/tools"
  108. android:layout_width="match_parent"
  109. android:layout_height="match_parent"
  110. tools:context="ru.podgorny.carcall.MainActivity"
  111. >
  112.  
  113. <com.google.android.gms.common.SignInButton
  114. android:id="@+id/idButtonGoogle"
  115. android:layout_width="wrap_content"
  116. android:layout_height="wrap_content"
  117. android:foregroundGravity="top"
  118. android:onClick="onClick"
  119.  
  120.  
  121. app:layout_constraintBottom_toBottomOf="parent"
  122. app:layout_constraintLeft_toLeftOf="parent"
  123. app:layout_constraintRight_toRightOf="parent"
  124. app:layout_constraintTop_toTopOf="parent" />
  125.  
  126. <TextView
  127. android:id="@+id/textView1"
  128. android:layout_width="wrap_content"
  129. android:layout_height="wrap_content"
  130. android:layout_marginTop="8dp"
  131. android:text="TextView"
  132. app:layout_constraintLeft_toLeftOf="parent"
  133. app:layout_constraintRight_toRightOf="parent"
  134. app:layout_constraintTop_toBottomOf="@+id/idButtonGoogle" />
  135.  
  136. <TextView
  137. android:id="@+id/textView2"
  138. android:layout_width="wrap_content"
  139. android:layout_height="wrap_content"
  140. android:layout_marginTop="8dp"
  141. android:text="TextView"
  142. app:layout_constraintLeft_toLeftOf="parent"
  143. app:layout_constraintRight_toRightOf="parent"
  144. app:layout_constraintTop_toBottomOf="@+id/textView1" />
  145.  
  146.  
  147. </android.support.constraint.ConstraintLayout>
  148.  
  149. <?xml version="1.0" encoding="utf-8"?>
  150. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  151. package="ru.podgorny.carcall">
  152.  
  153. <application
  154. android:allowBackup="true"
  155. android:icon="@mipmap/ic_launcher"
  156. android:label="@string/app_name"
  157. android:roundIcon="@mipmap/ic_launcher_round"
  158. android:supportsRtl="true"
  159. android:theme="@style/AppTheme">
  160. <activity android:name=".MainActivity">
  161. <intent-filter>
  162. <action android:name="android.intent.action.MAIN" />
  163.  
  164. <category android:name="android.intent.category.LAUNCHER" />
  165. </intent-filter>
  166. </activity>
  167. </application>
  168.  
  169. </manifest>
  170.  
  171. 03-23 08:35:32.774 5682-5682/? E/libprocessgroup: failed to make and chown /acct/uid_10060: Read-only file system
  172. 03-23 08:35:32.774 5682-5682/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
  173. 03-23 08:35:32.775 5682-5682/? I/art: Not late-enabling -Xcheck:jni (already on)
  174. 03-23 08:35:33.180 5682-5682/ru.podgorny.carcall I/InstantRun: starting instant run server: is main process
  175. 03-23 08:35:33.746 5682-5682/ru.podgorny.carcall D/AndroidRuntime: Shutting down VM
  176. 03-23 08:35:33.753 5682-5682/ru.podgorny.carcall E/AndroidRuntime: FATAL EXCEPTION: main
  177. Process: ru.podgorny.carcall, PID: 5682
  178. java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ru.podgorny.carcall/ru.podgorny.carcall.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
  179. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
  180. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
  181. at android.app.ActivityThread.access$800(ActivityThread.java:151)
  182. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
  183. at android.os.Handler.dispatchMessage(Handler.java:102)
  184. at android.os.Looper.loop(Looper.java:135)
  185. at android.app.ActivityThread.main(ActivityThread.java:5254)
  186. at java.lang.reflect.Method.invoke(Native Method)
  187. at java.lang.reflect.Method.invoke(Method.java:372)
  188. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  189. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  190. Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
  191. at android.content.ContextWrapper.getMainLooper(ContextWrapper.java:101)
  192. at com.google.android.gms.common.api.GoogleApi.<init>(Unknown Source)
  193. at com.google.android.gms.auth.api.signin.GoogleSignInClient.<init>(Unknown Source)
  194. at com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(Unknown Source)
  195. at ru.podgorny.carcall.MainActivity.<init>(MainActivity.java:35)
  196. at java.lang.reflect.Constructor.newInstance(Native Method)
  197. at java.lang.Class.newInstance(Class.java:1606)
  198. at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
  199. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
  200. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
  201. at android.app.ActivityThread.access$800(ActivityThread.java:151) 
  202. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
  203. at android.os.Handler.dispatchMessage(Handler.java:102) 
  204. at android.os.Looper.loop(Looper.java:135) 
  205. at android.app.ActivityThread.main(ActivityThread.java:5254) 
  206. at java.lang.reflect.Method.invoke(Native Method) 
  207. at java.lang.reflect.Method.invoke(Method.java:372) 
  208. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
  209. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
  210. 03-23 08:35:33.827 5682-5695/ru.podgorny.carcall I/art: Background sticky concurrent mark sweep GC freed 2567(255KB) AllocSpace objects, 0(0B) LOS objects, 30% free, 773KB/1117KB, paused 18.376ms total 73.744ms
Add Comment
Please, Sign In to add comment