@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gplus); Intent i = getIntent(); name = i.getStringExtra("name"); phone = i.getStringExtra("phone"); vehicle = i.getStringExtra("vehicle"); regId = i.getStringExtra("regId"); lati = ((Variables) this.getApplication()).getamb_lati(); longi = ((Variables) this.getApplication()).getamb_longi(); btnSignIn = (SignInButton) findViewById(R.id.btn_sign_in); // Button click listeners btnSignIn.setOnClickListener(this); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); }
private void setListener() { buttonSignIn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!mPlusClient.isConnected() && connectionResult != null) { try { connectionResult.startResolutionForResult( GooglePlusActivity.this, REQUEST_CODE_RESOLVE_ERR); } catch (SendIntentException e) { connectionResult = null; mPlusClient.connect(); } } } }); buttonLogOut.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO: Toast.makeText(GooglePlusActivity.this, "TODO", Toast.LENGTH_SHORT).show(); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); setContentView(R.layout.activity_login); SignInButton button = (SignInButton) findViewById(R.id.google_login); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { pickUserAccount(); } }); callbackManager = CallbackManager.Factory.create(); fbButton = (LoginButton) findViewById(R.id.facebook_login); fbButton.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Log.d("LoginActivity", loginResult.getAccessToken().getToken()); mBoundService.sendJOIN("fb", loginResult.getAccessToken().getToken()); } @Override public void onCancel() {} @Override public void onError(FacebookException error) {} }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.glogin); btnSignIn = (SignInButton) findViewById(R.id.btn_sign_in); btnSignOut = (Button) findViewById(R.id.btn_sign_out); btnRevokeAccess = (Button) findViewById(R.id.btn_revoke_access); imgProfilePic = (ImageView) findViewById(R.id.imgProfilePic); txtName = (TextView) findViewById(R.id.txtName); txtEmail = (TextView) findViewById(R.id.txtEmail); llProfileLayout = (LinearLayout) findViewById(R.id.llProfile); // Button click listeners btnSignIn.setOnClickListener(this); btnSignOut.setOnClickListener(this); btnRevokeAccess.setOnClickListener(this); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // check if already logged in if (authManager.isSignedIn()) { startMainActivity(); return; } // setup sign in button signInButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { signInClicked = true; if (signInSuccessful) startMainActivity(); else if (signInConnectionResult != null) resolveSignInError(); // else do nothing and wait for callbacks } }); // restore state if (savedInstanceState != null) { authInProgress = savedInstanceState.getBoolean(STATE_AUTH_PENDING); signInSuccessful = savedInstanceState.getBoolean(STATE_SIGN_IN_SUCCESSFUL); signInClicked = savedInstanceState.getBoolean(STATE_SIGN_IN_CLICKED); signInConnectionResult = savedInstanceState.getParcelable(STATE_SIGN_IN_CONNECTION_RESULT); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mPlusClient = new PlusClient.Builder(this, this, this).build(); mSignInButton = (SignInButton) findViewById(R.id.b_sign_in); mSignInButton.setOnClickListener(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); // Find the Google+ sign in button. mPlusSignInButton = (SignInButton) findViewById(R.id.plus_sign_in_button); if (supportsGooglePlayServices()) { // Set a listener to connect the user when the G+ button is clicked. mPlusSignInButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { signIn(); } }); } else { // Don't offer G+ sign in if the app's version is too low to support Google Play // Services. mPlusSignInButton.setVisibility(View.GONE); return; } // Set up the login form. mEmailView = (AutoCompleteTextView) findViewById(R.id.email); populateAutoComplete(); mPasswordView = (EditText) findViewById(R.id.password); mPasswordView.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { if (id == R.id.login || id == EditorInfo.IME_NULL) { attemptLogin(); return true; } return false; } }); Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); mEmailSignInButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { attemptLogin(); } }); mLoginFormView = findViewById(R.id.login_form); mProgressView = findViewById(R.id.login_progress); mEmailLoginFormView = findViewById(R.id.email_login_form); mSignOutButtons = findViewById(R.id.plus_sign_out_buttons); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.gplus_signin); btnSignIn = (SignInButton) findViewById(R.id.btn_sign_in); btnSignOut = (Button) findViewById(R.id.btn_sign_out); btnStart = (Button) findViewById(R.id.btn_launch_app); btnOnTime = (Button) findViewById(R.id.btn_note_on_time); btnOffTime = (Button) findViewById(R.id.btn_note_off_time); btnEntryStn = (Button) findViewById(R.id.btn_entry_station); btnExitStn = (Button) findViewById(R.id.btn_exit_station); imgProfilePic = (ImageView) findViewById(R.id.imgProfilePic); txtName = (TextView) findViewById(R.id.txtName); txtFileUpload = (TextView) findViewById(R.id.txt_file_upload); txtDatasent = (TextView) findViewById(R.id.txtDatasent); imgAppName = (ImageView) findViewById(R.id.imgappname); imgAppIcon = (ImageView) findViewById(R.id.imgicon); context = getApplicationContext(); // Button click listeners btnStart.setOnClickListener(this); btnEntryStn.setOnClickListener(this); btnExitStn.setOnClickListener(this); btnOnTime.setOnClickListener(this); btnOffTime.setOnClickListener(this); btnSignIn.setOnClickListener(this); btnSignOut.setOnClickListener(this); sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); // Initializing google plus api client mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // opening file to record time of entry and exit logFile = new File(CommonUtils.getFilepath("TimeLog.txt")); try { timeBuf = new BufferedWriter(new FileWriter(logFile, true)); Log.i("File opened:", "Preparing to write data"); isBufferWriterOpen = true; } catch (IOException e) { e.printStackTrace(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mScope = new Scope(SHORTENER_SCOPE); mGoogleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(mScope) .requestEmail() .build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, mGoogleSignInOptions) .addScope(mScope) .build(); mGoogleApiClient.connect(); SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button); signInButton.setScopes(mGoogleSignInOptions.getScopeArray()); signInButton.setOnClickListener(this); findViewById(R.id.sign_out_button).setOnClickListener(this); mStatusTextView = (TextView) findViewById(R.id.status); findViewById(R.id.btn_shorten).setOnClickListener(this); findViewById(R.id.long_uri) .setOnKeyListener( new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { shorten(((EditText) findViewById(R.id.long_uri)).getText().toString()); return true; } return false; } }); mStatusTextView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); cm.setPrimaryClip(ClipData.newPlainText("", ((TextView) v).getText())); showClipboardSnackBar(((TextView) v).getText().toString()); return true; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); setContentView(R.layout.activity_login); callbackManager = CallbackManager.Factory.create(); googleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); LoginButton loginButton = (LoginButton) findViewById(R.id.activity_login_facebook); googleSignIn = (SignInButton) findViewById(R.id.activity_login_google); getToken = (Button) findViewById(R.id.activity_login_auth_token); loginButton.setReadPermissions("email"); facebookTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged( AccessToken oldAccessToken, AccessToken newAccessToken) { isFbLogin = true; Toast.makeText(LoginActivity.this, "Facebook Access Token", Toast.LENGTH_SHORT).show(); } }; facebookProfileTracker = new ProfileTracker() { @Override protected void onCurrentProfileChanged(Profile oldProfile, Profile newProfile) { isFbLogin = (!isFbLogin); Toast.makeText(LoginActivity.this, "Facebook Current Profile", Toast.LENGTH_SHORT) .show(); } }; facebookTokenTracker.startTracking(); facebookProfileTracker.startTracking(); googleSignIn.setOnClickListener(this); getToken.setOnClickListener(this); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mSignInButton = (SignInButton) findViewById(R.id.sign_in_button); mSignOutButton = (Button) findViewById(R.id.sign_out_button); mRevokeButton = (Button) findViewById(R.id.revoke_access_button); mStatus = (TextView) findViewById(R.id.sign_in_status); mSignInButton.setOnClickListener(this); mSignOutButton.setOnClickListener(this); mRevokeButton.setOnClickListener(this); if (savedInstanceState != null) { mSignInProgress = savedInstanceState.getInt(SAVED_PROGRESS, STATE_DEFAULT); } mGoogleApiClient = buildGoogleApiClient(); }
@Override protected void onStart() { super.onStart(); final LogInActivity logInActivity = this; userInfo = UserInfo.getInstance(); userList = UserInfo.getUserList(getApplicationContext()); // mProgDialog = new ProgressDialog(); LogInAutoCompleteAdapter autoCompleteAdapter = new LogInAutoCompleteAdapter(getApplicationContext(), R.layout.login_auto_fill, userList); loginBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!email.getText().toString().equals(" ") && !pw.getText().toString().equals(" ")) { mProgDialog = new ProgressDialog(LogInActivity.this); mProgDialog.setTitle("Sign In"); mProgDialog.setMessage("Signing In..."); mProgDialog.show(); // mProgDialog //= ProgressDialog.show(getBaseContext(),"Sign In", "Signing // In..,",true); // boolean authed = // userInfo.logInUser(email.getText().toString(),pw.getText().toString(),getApplicationContext(),logInActivity,mProgDialog); userInfo.setCredentials(email.getText().toString(), pw.getText().toString()); HerokuLogin hlogin = new HerokuLogin(); hlogin.execute(LogInActivity.this, mProgDialog, getBaseContext()); } } }); // Google Auth signInButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, RC_SIGN_IN); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.activity_login); btnSignIn = (SignInButton) findViewById(R.id.btn_sign_in); pDialog = new ProgressDialog(this); pDialog.setMessage("Please wait..."); pDialog.setCancelable(false); // Button click listeners btnSignIn.setOnClickListener(this); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(new Scope(Scopes.PROFILE)) .addScope(new Scope(Scopes.EMAIL)) .build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); isGoogleLogin = false; // Facebook Login Code FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); fbLoginButton = (LoginButton) findViewById(R.id.fb_login_button); fbLoginButton.setReadPermissions(Arrays.asList("email")); fbLoginButton.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { // bug in fb login /* AccessToken accessToken=loginResult.getAccessToken(); Profile profile=Profile.getCurrentProfile(); String userName=profile.getName(); String userEmail=profile.getId(); Uri userPhoto=profile.getProfilePictureUri(64,64); Preferences.putString(Preferences.USER_NAME,userName); Preferences.putString(Preferences.USER_EMAIL,userEmail); Preferences.putString(Preferences.USER_PHOTO,userPhoto.toString()); */ Toast.makeText(getApplicationContext(), "Successfull Login", Toast.LENGTH_SHORT).show(); } @Override public void onCancel() { Toast.makeText(getApplicationContext(), "Login Cancelled", Toast.LENGTH_SHORT).show(); } @Override public void onError(FacebookException error) { Toast.makeText(getApplicationContext(), "Login Error", Toast.LENGTH_SHORT).show(); } }); // Google Login Code gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestProfile() .build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); googleLoginButton = (SignInButton) findViewById(R.id.google_login_button); googleLoginButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { googleSignIn(); } }); }
public void showSocialLoginDialog() { smsPB.setVisibility(View.GONE); final MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) .customView(R.layout.smartdialog, false) .title("Sign Up") .titleGravity(GravityEnum.CENTER) .positiveText("SKIP") .cancelable(false) .callback( new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); dialog.dismiss(); mixpanel.track("Login - Skipped"); Intent mIntent = new Intent(getActivity(), LoginUserDetails.class); startActivity(mIntent); } }) .show(); View view = dialog.getCustomView(); callbackManager = CallbackManager.Factory.create(); LoginButton facebookBtn = (LoginButton) view.findViewById(R.id.smartDialogFacebook); facebookBtn.setFragment(this); facebookBtn.setReadPermissions(Arrays.asList("public_profile, email, user_birthday")); facebookBtn.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Log.d(TAG, "Facebook login success"); try { getUserFacebookDetails(loginResult); } catch (Exception e) { Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } @Override public void onCancel() { Log.d(TAG, "Facebook login cancel"); } @Override public void onError(FacebookException e) { Log.d(TAG, "Facebook login error"); Toast.makeText( getActivity(), "Couldn't login with facebook, try again" + e.getMessage(), Toast.LENGTH_SHORT) .show(); } }); SignInButton googleBtn = (SignInButton) view.findViewById(R.id.smartDialogGoogle); googleBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mGoogleApiClient.isConnected()) { Plus.AccountApi.clearDefaultAccount(mGoogleApiClient); mGoogleApiClient.disconnect(); } else { mShouldResolve = true; mGoogleApiClient.connect(); } } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); ButterKnife.bind(this); session = new SessionManager(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); LoginButton loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setReadPermissions(Arrays.asList("user_status", "email")); LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email")); LoginManager.getInstance().registerCallback(callbackManager, this); if (BuildConfig.DEBUG) { // we only want to show the logs in debug builds, for easier debugging Stormpath.setLogLevel(StormpathLogger.VERBOSE); } // initialise login button below _loginButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { login(); } }); // intialise Register link below _registerLink.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Start register activity Toast.makeText(getApplicationContext(), "Register is selected!", Toast.LENGTH_SHORT) .show(); Intent intent = new Intent(getApplicationContext(), RegisterActivity.class); startActivityForResult(intent, REQUEST_REGISTER); } }); _skiploginLink.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // Start register activity Toast.makeText(getApplicationContext(), "Skipping login!", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); } }); String serverClientId = getString(R.string.goog_app_id); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestScopes(new Scope(Scopes.EMAIL)) .requestServerAuthCode(serverClientId, false) .build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button); signInButton.setSize(SignInButton.SIZE_STANDARD); signInButton.setScopes(gso.getScopeArray()); signInButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.d("google click", "test "); signIn(); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { remplaceFont.replaceDefaultFont(this, "DEFAULT", "Exo-Medium.otf"); remplaceFont.replaceDefaultFont(this, "SANS", "Roboto-Light.ttf"); remplaceFont.replaceDefaultFont(this, "SERIF", "Roboto-Light.ttf"); super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(this); setContentView(R.layout.activity_inscription); firstName = (TextInputLayout) findViewById(R.id.layoutFirstName); lastName = (TextInputLayout) findViewById(R.id.layoutLastName); email = (TextInputLayout) findViewById(R.id.layoutEmail); emailConfirmed = (TextInputLayout) findViewById(R.id.layoutEmailConfirmed); password = (TextInputLayout) findViewById(R.id.layoutPassword); passwordConfirmed = (TextInputLayout) findViewById(R.id.layoutPasswordConfirmed); inscrptionButton = (ImageView) findViewById(R.id.inscrptionButton); progressBar = (ProgressBar) findViewById(R.id.ProgressBar); imageSuccess = (ImageView) findViewById(R.id.yes); imageEchec = (ImageView) findViewById(R.id.no); progressBar.setVisibility(View.GONE); imageSuccess.setVisibility(View.GONE); imageEchec.setVisibility(View.GONE); Retrofit retrofit = new Retrofit.Builder().baseUrl(GitHubService.baseUrl).build(); gitHubService = retrofit.create(GitHubService.class); if (Build.VERSION.SDK_INT >= 21) { Slide slide = new Slide(); slide.setDuration(400); getWindow().setEnterTransition(slide); getWindow() .setReturnTransition( TransitionInflater.from(this).inflateTransition(R.transition.shared_element_a)); } inscrptionButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String firstNameValue = firstName.getEditText().getText().toString(); String lastNameValue = lastName.getEditText().getText().toString(); String emailValue = email.getEditText().getText().toString(); String emailConfirmedValue = emailConfirmed.getEditText().getText().toString(); String passwordValue = password.getEditText().getText().toString(); String passwordConfirmedValue = passwordConfirmed.getEditText().getText().toString(); firstName.setErrorEnabled(false); firstName.requestFocus(); lastName.setErrorEnabled(false); lastName.requestFocus(); email.setErrorEnabled(false); email.requestFocus(); emailConfirmed.setErrorEnabled(false); emailConfirmed.requestFocus(); password.setErrorEnabled(false); password.requestFocus(); passwordConfirmed.setErrorEnabled(false); passwordConfirmed.requestFocus(); if (!validateInput(firstNameValue)) { firstName.setError("nom non valide !"); firstName.requestFocus(); // hideButton(); mdperreur(); } else if (!validateInput(lastNameValue)) { lastName.setError("prénom non valide !"); lastName.requestFocus(); mdperreur(); } else if (!validateEmail(emailValue)) { email.setError("Email non valide !"); email.requestFocus(); // hideButton(); mdperreur(); } else if (!validateEmail(emailConfirmedValue)) { emailConfirmed.setError("Email non valide !"); emailConfirmed.requestFocus(); // hideButton(); mdperreur(); } else if (!(emailValue.equals(emailConfirmedValue))) { email.setError("Les deux e-mails ne sont pas identiques"); emailConfirmed.setError("Les deux e-mails ne sont pas identiques"); emailConfirmed.requestFocus(); // hideButton(); mdperreur(); } else if (!validatePassword(passwordValue)) { password.setError("Mot de passe non valide !"); password.requestFocus(); // hideButton(); mdperreur(); } else if (!validateInput(passwordConfirmedValue)) { passwordConfirmed.setError("Mot de passe non valide !"); passwordConfirmed.requestFocus(); // hideButton(); mdperreur(); } else if (!(passwordValue.equals(passwordConfirmedValue))) { password.setError("Les deux mots de passe ne sont pas identiques"); passwordConfirmed.setError("Les deux mots de passe ne sont pas identiques"); passwordConfirmed.requestFocus(); // hideButton(); mdperreur(); } else { hideKeyboard(); doInscri(firstNameValue, lastNameValue, emailValue, passwordValue); } } }); // facebook login callbackManager = CallbackManager.Factory.create(); loginFacebook = (LoginButton) findViewById(R.id.login_button); loginManager = LoginManager.getInstance(); loginFacebook.setReadPermissions(readPermissions); loginFacebook.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { hideButton(); } }); loginFacebook.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { accessToken = AccessToken.getCurrentAccessToken(); // Log.d("user facebook",loginResult.toString()); GraphRequest request = GraphRequest.newMeRequest( loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject object, GraphResponse response) { Log.v("LoginActivity", response.toString()); try { User user = new User( object.get("id").toString(), object.get("email").toString(), object.get("name").toString()); AuthUtils.saveUser(InscriptionActivity.this, user); succ(); } catch (JSONException e) { e.printStackTrace(); } } }); Bundle parameters = new Bundle(); parameters.putString("fields", "id,name,email"); request.setParameters(parameters); request.executeAsync(); } @Override public void onCancel() { Toast.makeText(getBaseContext(), "cancel", Toast.LENGTH_SHORT).show(); } @Override public void onError(FacebookException error) { Toast.makeText(getBaseContext(), "error,retry again", Toast.LENGTH_SHORT).show(); error.printStackTrace(); mdperreur(); } }); // google+ login // [START configure_signin] // Configure sign-in to request the user's ID, email address, and basic // profile. ID and basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build(); // [START build_client] // Build a GoogleApiClient with access to the Google Sign-In API and the // options specified by gso. mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); signInButtonGoogle = (SignInButton) findViewById(R.id.sign_in_button); signInButtonGoogle.setSize(SignInButton.SIZE_STANDARD); signInButtonGoogle.setScopes(gso.getScopeArray()); signInButtonGoogle.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { progressBar.setVisibility(View.VISIBLE); Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(signInIntent, RC_SIGN_IN); hideButton(); } }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.v(LOG_TAG, "OnCreateView for LoginActivity Fragment"); View view = inflater.inflate(R.layout.fragment_landing, container, false); loginButtonFaceBook = (LoginButton) view.findViewById(R.id.login_button); signButton = (Button) view.findViewById(R.id.signup); loginButton = (Button) view.findViewById(R.id.login); loginButtonFaceBook.setReadPermissions("user_friends"); googleButton = (com.google.android.gms.common.SignInButton) view.findViewById(R.id.google); // If using in a fragment loginButtonFaceBook.setFragment(this); // Other app specific specialization callbackManager = CallbackManager.Factory.create(); // Callback registration signButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.v(LOG_TAG, "Signup button clicked, switching to SignUp fragment"); getActivity() .getSupportFragmentManager() .beginTransaction() .replace(R.id.frame_layout, new SignUpFragment()) .commit(); } }); loginButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.v(LOG_TAG, "Login button clicked, switching to SplatterLogin fragment"); getActivity() .getSupportFragmentManager() .beginTransaction() .replace(R.id.frame_layout, new SplatterLoginFragment()) .commit(); } }); googleButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Log.v(LOG_TAG, "Sign-in with Google clicked, switching to Google activity"); Intent intent = new Intent(getActivity(), GoogleActivity.class); getActivity().startActivity(intent); } }); loginButtonFaceBook.registerCallback( callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Log.i(LOG_TAG, "Sign-in with Facebook successful"); String username = loginResult.getAccessToken().getUserId(); HttpAgent.tokenValue = loginResult.getAccessToken().toString(); Log.v( LOG_TAG, String.format("Username %s, AccessToken %s", username, HttpAgent.tokenValue)); SharedPreferences sharedPref = getActivity() .getSharedPreferences( getString(R.string.preference_file), Context.MODE_PRIVATE); SharedPreferences.Editor prefEdit = sharedPref.edit(); prefEdit.putString( getString(R.string.login_method), getString(R.string.facebook_login)); prefEdit.putString(getString(R.string.key_username), username); prefEdit.putString(getString(R.string.access_token), HttpAgent.tokenValue); prefEdit.apply(); String k = JsonHandler.stringifyNormal(loginResult); getActivity() .getSupportFragmentManager() .beginTransaction() .replace(R.id.frame_layout, new SelectTagsFragment()) .commit(); } @Override public void onCancel() { Log.i(LOG_TAG, "Facebook login operation cancelled"); } @Override public void onError(FacebookException exception) { Log.e(LOG_TAG, "In Facebook Sign-in, got exception: ", exception); } }); return view; }