1

so i have a project where im implementing a google sign in, i followed this tutorial on how to do that, but when i did, all my XML files appear blank. i made changes to the original MainActivity.java and the activity_main.xml file. i woudl think that only the activity_main.xml would be affected, but all of my XML files appear blank. when i try to run the app, i get

"Error:Content is not allowed in prolog.

" and

"Execution failed for task '.app:builderInfoDebugLoader'"

this is my activity main where i implement the google sign in:

    package com.example.mayankthakur.personalprojecttrial2;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.auth.api.signin.SignInAccount;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
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 org.w3c.dom.Text;


public class MainActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {

    private LinearLayout prof_section;
    private Button SignOut;
    private SignInButton SignIn;
    private TextView Name,Email;
    private ImageView Prof_Picture;
    private Button continueBut;
    private static final int REQ_CODE = 9001;
    String name;
    Intent nameSave;
    private GoogleApiClient mGoogleApiClient;

    public static final String prefsName = "com.example.mayankthakur.personalprojecttrial2";


    private static final String TAG = "MainActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        prof_section = (LinearLayout) findViewById(R.id.prof_section);
        SignOut = (Button) findViewById(R.id.logoutBtn);
        SignIn = (SignInButton) findViewById(R.id.gSignIn);
        Name = (TextView) findViewById(R.id.nameSpace);
        Email = (TextView) findViewById(R.id.emailSpace);
        Prof_Picture = (ImageView) findViewById(R.id.profilePicture);
        continueBut = (Button) findViewById(R.id.button2);
        continueBut.setOnClickListener(this);
        SignOut.setOnClickListener(this);
        SignIn.setOnClickListener(this) ;
        prof_section.setVisibility(View.GONE);
        continueBut.setVisibility(View.GONE);

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();


    }


    @Override
    public void onClick (View v) {


        switch (v.getId()) {

            case R.id.gSignIn:
                signIn();

                break;

            case R.id.logoutBtn:
                signOut();

                break;


        /*// This is the shared preference
        SharedPreferences.Editor prefs = getSharedPreferences(prefsName, MODE_PRIVATE).edit();
        //adding a value to the preference
        prefs.putString("name", name);
        prefs.apply();
        nameSave = new Intent(MainActivity.this, Activity2.class);
        MainActivity.this.startActivity(nameSave);
        */
        }


    }
    @Override
    public void onConnectionFailed (@NonNull ConnectionResult connectionResult){

    }
    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, REQ_CODE );
    }
    private void signOut(){

        Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
            @Override
            public void onResult(@NonNull Status status) {
                updateUI(false);
            }
        });

    }
    private void handleReuslt(GoogleSignInResult result){

        if(result.isSuccess())
        {
            GoogleSignInAccount acct = result.getSignInAccount();
            String personName = acct.getDisplayName();
            String personEmail = acct.getEmail();
            String imgUrl = acct.getPhotoUrl().toString();
            String personId = acct.getId();
            Uri personPhoto = acct.getPhotoUrl();
            Name.setText(personName);
            Email.setText(personEmail);
            Glide.with(this).load(imgUrl).into(Prof_Picture);
            updateUI(true);
        }
        else
        {
            updateUI(false);
        }

    }
    private void updateUI(boolean isLogin){

        if(isLogin)
        {
            prof_section.setVisibility(View.VISIBLE);
            SignIn.setVisibility(View.GONE);

        }

        else
        {
            prof_section.setVisibility(View.GONE);
            SignIn.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == REQ_CODE)
        {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleReuslt(result);
        }
    }
}

this is my XML file where i added the buttons and stuff for the google sign in:\

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/activity_main"
    android:orientation="vertical"
    tools:context="com.example.mayankthakur.personalprojecttrial2.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/prof_section"
        android:layout_marginLeft="20dp"
        android:layout_marginTop = "50dp"
        android:weightSum="1">

        <ImageView
            android:id="@+id/profilePicture"
            android:layout_width="90dp"
            android:layout_height="100dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/photo"
            android:layout_weight="0.25" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="28dp"
            android:layout_marginTop="20dp">

            <TextView
                android:id="@+id/nameSpace"
                android:layout_width="166dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center_horizontal"
                android:text="Name Display"
                android:textSize="20dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/emailSpace"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="Email Display"
                android:textSize="14dp"
                android:textStyle="bold" />

            <Button
                android:id="@+id/logoutBtn"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Logout" />

        </LinearLayout>

    </LinearLayout>


    <com.google.android.gms.common.SignInButton
        android:id="@+id/gSignIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:layout_marginTop="60dp">


    </com.google.android.gms.common.SignInButton>

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Please Sign in in order to make use of all of the features of the app"
        android:textAlignment="center"
        android:textSize="20dp"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Continue"
        android:layout_marginRight="50dp"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="50dp"/>
</LinearLayout>

any help would be greatly appreciated, and if any of you require any more code please do ask

thanks in advance!

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
Mayank Thakur
  • 61
  • 1
  • 12

0 Answers0