Search in sources :

Example 16 with LoginResult

use of com.facebook.login.LoginResult in project FirebaseAuth-Android by jirawatee.

the class FacebookLoginActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_facebook);
    mImageView = findViewById(R.id.logo);
    mTextViewProfile = findViewById(R.id.profile);
    findViewById(R.id.button_facebook_signout).setOnClickListener(this);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            updateUI(user);
        }
    };
    // Initialize Facebook Login button
    mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = findViewById(R.id.button_facebook_login);
    loginButton.setReadPermissions("email", "public_profile");
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
            updateUI(null);
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            updateUI(null);
        }
    });
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) LoginButton(com.facebook.login.widget.LoginButton) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 17 with LoginResult

use of com.facebook.login.LoginResult in project EC2018App by Manan-YMCA.

the class ProfileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    callbackManager = CallbackManager.Factory.create();
    userDetails = new UserDetails();
    userDetails.setmFbId("null");
    tvName = (TextView) findViewById(R.id.tv_name);
    tvMail = (TextView) findViewById(R.id.tv_email);
    tvCollege = (TextView) findViewById(R.id.tv_college);
    tvPhone = (TextView) findViewById(R.id.tv_phone);
    final String EMAIL = "email";
    backbutton = findViewById(R.id.pr_back_button);
    SharedPreferences prefs = getSharedPreferences(getResources().getString(R.string.sharedPrefName), MODE_PRIVATE);
    phoneNumber = prefs.getString("Phone", null);
    if (phoneNumber == null) {
    }
    ivBar = (ProgressBar) findViewById(R.id.pb_profile_image);
    detailsBar = (ProgressBar) findViewById(R.id.pb_user_profile);
    ivBar.setVisibility(View.VISIBLE);
    detailsBar.setVisibility(View.VISIBLE);
    mAuth = FirebaseAuth.getInstance();
    textView1 = (TextView) findViewById(R.id.tv6);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    profilePictureFrame = (RelativeLayout) findViewById(R.id.profile_picture_layout);
    profilePicture = (ImageView) findViewById(R.id.profile_pic);
    loginButton.setReadPermissions(Arrays.asList(EMAIL));
    // If you are using in a fragment, call loginButton.setFragment(this);
    // Callback registration
    backbutton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            ivBar.setVisibility(View.VISIBLE);
            if (Profile.getCurrentProfile() == null) {
                mProfileTracker = new ProfileTracker() {

                    @Override
                    protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
                        mProfileTracker.stopTracking();
                    }
                };
            } else {
                Profile profile = Profile.getCurrentProfile();
            }
            userDetails.setmFbId(loginResult.getAccessToken().getUserId());
            registerUser(userDetails);
            profilePicture.setImageBitmap(null);
            checkStatus();
            handleFirebaseLogin(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
        }

        @Override
        public void onError(FacebookException exception) {
        }
    });
    // Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.dashboard_image);
    // Bitmap resized = Bitmap.createScaledBitmap(largeIcon, 100, 100, true);
    // GetRoundedImage getRoundedImage = new GetRoundedImage();
    // Bitmap conv_bm = getRoundedImage.getRoundedShape(resized);
    // BitmapDrawable background = new BitmapDrawable(conv_bm);
    // profilePicture.setBackground(background);
    final LayoutInflater factory = LayoutInflater.from(this);
    ImageView editButton = (ImageView) findViewById(R.id.edit_button);
    editButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            input1 = new EditText(ProfileActivity.this);
            input2 = new EditText(ProfileActivity.this);
            input3 = new EditText(ProfileActivity.this);
            flag = false;
            final AlertDialog.Builder alert = new AlertDialog.Builder(ProfileActivity.this);
            final LinearLayout layout = new LinearLayout(ProfileActivity.this);
            layout.setOrientation(LinearLayout.VERTICAL);
            layout.removeAllViews();
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            layoutParams.setMargins(30, 0, 30, 0);
            final TextView tv_name = new TextView(ProfileActivity.this);
            tv_name.setLayoutParams(layoutParams);
            tv_name.setText("Name");
            input1.setLayoutParams(layoutParams);
            final TextView tv_email = new TextView(ProfileActivity.this);
            tv_email.setText("Email");
            tv_email.setLayoutParams(layoutParams);
            input2.setLayoutParams(layoutParams);
            final TextView tv_college = new TextView(ProfileActivity.this);
            tv_college.setText("College Name");
            input1.setText(userDetails.getmName());
            input3.setText(userDetails.getmCollege());
            input2.setText(userDetails.getEmail());
            tv_college.setLayoutParams(layoutParams);
            input3.setLayoutParams(layoutParams);
            layout.addView(tv_name);
            layout.addView(input1);
            layout.addView(tv_email);
            layout.addView(input2);
            layout.addView(tv_college);
            layout.addView(input3);
            alert.setIcon(R.drawable.vector_pencil_black).setTitle("Edit Profile").setView(layout).setPositiveButton("Save", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    /* User clicked OK so do some stuff */
                    boolean checker = checkDetails();
                    if (checker) {
                        detailsBar.setVisibility(View.VISIBLE);
                        userDetails.setmName(input1.getText().toString());
                        userDetails.setEmail(input2.getText().toString());
                        userDetails.setmCollege(input3.getText().toString());
                        tvName.setText("");
                        tvCollege.setText("");
                        tvMail.setText("");
                        tvPhone.setText("");
                        registerUser(userDetails);
                        layout.removeAllViews();
                    } else {
                        MDToast.makeText(ProfileActivity.this, "Invalid Credentials", Toast.LENGTH_SHORT, MDToast.TYPE_ERROR).show();
                    }
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    /*
     * User clicked cancel so do some stuff
     */
                    layout.removeAllViews();
                }
            });
            alert.show();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) LoginResult(com.facebook.login.LoginResult) Profile(com.facebook.Profile) UserDetails(com.manan.dev.ec2018app.Models.UserDetails) ProfileTracker(com.facebook.ProfileTracker) FacebookException(com.facebook.FacebookException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) LinearLayout(android.widget.LinearLayout)

Example 18 with LoginResult

use of com.facebook.login.LoginResult in project EC2018App by Manan-YMCA.

the class QuestionFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_question, container, false);
    if (mContext == null) {
        mContext = getActivity();
    }
    mAuth = FirebaseAuth.getInstance();
    bar = (ProgressBar) view.findViewById(R.id.pb_question);
    bar.getIndeterminateDrawable().setColorFilter(mContext.getResources().getColor(R.color.pb_xunbao), android.graphics.PorterDuff.Mode.MULTIPLY);
    barImage = (ProgressBar) view.findViewById(R.id.pb_image);
    barImage.getIndeterminateDrawable().setColorFilter(mContext.getResources().getColor(R.color.pb_xunbao), android.graphics.PorterDuff.Mode.MULTIPLY);
    bar.setVisibility(View.VISIBLE);
    barImage.setVisibility(View.GONE);
    loginButton = (LoginButton) view.findViewById(R.id.login_button);
    loginText = (TextView) view.findViewById(R.id.tv_log_in);
    loginText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent in = new Intent(mContext, LoginActivity.class);
            in.putExtra("parent", "xunbao");
            startActivity(in);
        }
    });
    final String EMAIL = "email";
    callbackManager = CallbackManager.Factory.create();
    loginButton.setReadPermissions(Arrays.asList(EMAIL));
    loginButton.setFragment(this);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = loginResult.getAccessToken();
            FragmentFbLogin.fbLoginButton activity = (FragmentFbLogin.fbLoginButton) mContext;
            handleFacebookAccessToken(loginResult.getAccessToken());
            activity.fbStatus(true, accessToken.getUserId());
            Toast.makeText(mContext, "Facebook Login Done!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast.makeText(mContext, "Facebook login cancelled!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(FacebookException exception) {
        }
    });
    queURL = mContext.getResources().getString(R.string.xunbao_get_question_api);
    ansURL = mContext.getResources().getString(R.string.xunbao_check_answer_api);
    statusURL = mContext.getResources().getString(R.string.xunbao_status);
    queLayout = view.findViewById(R.id.question_layout);
    level = view.findViewById(R.id.tv_question_number);
    question = view.findViewById(R.id.tv_question_text);
    xunbaoimg = view.findViewById(R.id.iv_xunbao_question_image);
    ans = view.findViewById(R.id.et_xunbao_answer);
    submit = view.findViewById(R.id.ll_submit);
    contestEnd = view.findViewById(R.id.contest_ends);
    refreshButton = view.findViewById(R.id.refresh_button);
    refreshText = view.findViewById(R.id.refresh_text);
    queLayout.setVisibility(View.GONE);
    contestEnd.setVisibility(View.GONE);
    refreshButton.setVisibility(View.GONE);
    refreshText.setVisibility(View.GONE);
    loginButton.setVisibility(View.GONE);
    loginText.setVisibility(View.GONE);
    queue = Volley.newRequestQueue(mContext);
    refreshButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            reload();
        }
    });
    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            bar.setVisibility(View.VISIBLE);
            // progressBar.show();
            submitAnswer();
        }
    });
    return view;
}
Also used : FragmentFbLogin(com.manan.dev.ec2018app.Fragments.FragmentFbLogin) LoginActivity(com.manan.dev.ec2018app.LoginActivity) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 19 with LoginResult

use of com.facebook.login.LoginResult in project quickstart-android by firebase.

the class FacebookLoginFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setProgressBar(mBinding.progressBar);
    // Views
    mBinding.buttonFacebookSignout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            signOut();
        }
    });
    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    // Initialize Facebook Login button
    mCallbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = mBinding.buttonFacebookLogin;
    loginButton.setPermissions("email", "public_profile");
    loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "facebook:onSuccess:" + loginResult);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "facebook:onCancel");
            updateUI(null);
        }

        @Override
        public void onError(FacebookException error) {
            Log.d(TAG, "facebook:onError", error);
            updateUI(null);
        }
    });
}
Also used : FacebookException(com.facebook.FacebookException) LoginResult(com.facebook.login.LoginResult) View(android.view.View) LoginButton(com.facebook.login.widget.LoginButton)

Example 20 with LoginResult

use of com.facebook.login.LoginResult in project ServiceStack.Java by ServiceStack.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Twitter(new TwitterAuthConfig(getString(R.string.twitter_key), getString(R.string.twitter_secret))));
    setContentView(R.layout.login);
    Toolbar toolbar = (Toolbar) findViewById(R.id.loginToolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    txtStatus = (TextView) findViewById(R.id.txtStatus);
    UiHelpers.setStatus(txtStatus, "");
    // see this max value coming back here, we animale towards that value
    animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 500);
    animation.setRepeatMode(ValueAnimator.REVERSE);
    animation.setRepeatCount(100);
    animation.setDuration(1500);
    animation.setInterpolator(new FastOutLinearInInterpolator());
    LoginActivity activity = this;
    ImageButton btnTwitter = (ImageButton) findViewById(R.id.btnTwitter);
    twitterAuth = new TwitterAuthClient();
    btnTwitter.setOnClickListener(view -> {
        startProgressBar();
        twitterAuth.authorize(activity, new Callback<TwitterSession>() {

            @Override
            public void success(Result<TwitterSession> result) {
                UiHelpers.setStatus(txtStatus, "Local twitter sign-in successful, signing into server...");
                TwitterSession session = result.data;
                App.get().getServiceClient().postAsync(new dtos.Authenticate().setProvider("twitter").setAccessToken(session.getAuthToken().token).setAccessTokenSecret(session.getAuthToken().secret).setRememberMe(true), r -> {
                    UiHelpers.setStatus(txtStatus, "Server twitter sign-in successful, opening chat...");
                    App.get().saveTwitterAccessToken(session.getAuthToken());
                    Intent intent = new Intent(activity, MainActivity.class);
                    stopProgressBar();
                    startActivity(intent);
                }, error -> {
                    UiHelpers.setStatusError(txtStatus, "Server twitter sign-in failed", error);
                    stopProgressBar();
                });
            }

            @Override
            public void failure(TwitterException exception) {
                exception.printStackTrace();
                stopProgressBar();
            }
        });
    });
    facebookCallback = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(facebookCallback, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            UiHelpers.setStatus(txtStatus, "Local facebook sign-in successful, signing into server...");
            App.get().getServiceClient().postAsync(new dtos.Authenticate().setProvider("facebook").setAccessToken(loginResult.getAccessToken().getToken()).setRememberMe(true), r -> {
                UiHelpers.setStatus(txtStatus, "Server facebook sign-in successful, opening chat...");
                Intent intent = new Intent(activity, MainActivity.class);
                stopProgressBar();
                startActivity(intent);
            }, error -> {
                UiHelpers.setStatusError(txtStatus, "Server facebook sign-in failed", error);
                stopProgressBar();
            });
        }

        @Override
        public void onCancel() {
            stopProgressBar();
        }

        @Override
        public void onError(FacebookException exception) {
            Log.e(exception);
            stopProgressBar();
        }
    });
    ImageButton btnFacebook = (ImageButton) findViewById(R.id.btnFacebook);
    btnFacebook.setOnClickListener(view -> {
        startProgressBar();
        LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
    });
    ImageButton btnAnon = (ImageButton) findViewById(R.id.btnAnon);
    btnAnon.setOnClickListener(view -> {
        UiHelpers.setStatus(txtStatus, "Opening chat as guest...");
        startGuestChatActivity(App.get().getServiceClient());
    });
    dtos.Authenticate authDto = App.get().getSavedAccessToken();
    if (authDto != null) {
        UiHelpers.setStatus(txtStatus, "Signing in with saved " + authDto.getProvider() + " AccessToken...");
        App.get().getServiceClient().postAsync(authDto, r -> {
            Intent intent = new Intent(activity, MainActivity.class);
            stopProgressBar();
            startActivity(intent);
        }, error -> {
            UiHelpers.setStatusError(txtStatus, "Error logging into " + authDto.getProvider() + " using Saved AccessToken", error);
            stopProgressBar();
        });
    }
}
Also used : Result(com.twitter.sdk.android.core.Result) ImageButton(android.widget.ImageButton) Text(org.w3c.dom.Text) Arrays(java.util.Arrays) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) Intent(android.content.Intent) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) TwitterException(com.twitter.sdk.android.core.TwitterException) View(android.view.View) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException) ObjectAnimator(android.animation.ObjectAnimator) LoginResult(com.facebook.login.LoginResult) AppCompatActivity(android.support.v7.app.AppCompatActivity) FacebookCallback(com.facebook.FacebookCallback) CallbackManager(com.facebook.CallbackManager) LoginManager(com.facebook.login.LoginManager) TwitterAuthClient(com.twitter.sdk.android.core.identity.TwitterAuthClient) TextView(android.widget.TextView) Callback(com.twitter.sdk.android.core.Callback) AndroidServiceClient(net.servicestack.android.AndroidServiceClient) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) Toolbar(android.support.v7.widget.Toolbar) Fabric(io.fabric.sdk.android.Fabric) Log(net.servicestack.client.Log) ValueAnimator(android.animation.ValueAnimator) TwitterSession(com.twitter.sdk.android.core.TwitterSession) TwitterSession(com.twitter.sdk.android.core.TwitterSession) LoginResult(com.facebook.login.LoginResult) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator) Twitter(com.twitter.sdk.android.Twitter) TwitterAuthConfig(com.twitter.sdk.android.core.TwitterAuthConfig) Intent(android.content.Intent) TwitterAuthClient(com.twitter.sdk.android.core.identity.TwitterAuthClient) ImageButton(android.widget.ImageButton) FacebookException(com.facebook.FacebookException) TwitterException(com.twitter.sdk.android.core.TwitterException) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

LoginResult (com.facebook.login.LoginResult)25 FacebookException (com.facebook.FacebookException)22 View (android.view.View)12 TextView (android.widget.TextView)10 AccessToken (com.facebook.AccessToken)9 Intent (android.content.Intent)7 FacebookCallback (com.facebook.FacebookCallback)7 LoginButton (com.facebook.login.widget.LoginButton)7 CallbackManager (com.facebook.CallbackManager)6 LoginManager (com.facebook.login.LoginManager)6 ArrayList (java.util.ArrayList)6 Profile (com.facebook.Profile)5 Bundle (android.os.Bundle)4 Activity (android.app.Activity)3 Toolbar (android.support.v7.widget.Toolbar)3 ImageView (android.widget.ImageView)3 ProfileTracker (com.facebook.ProfileTracker)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ObjectAnimator (android.animation.ObjectAnimator)2