Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProfiloFragment extends Fragment {
- View rootView;
- private static final int RC_SIGN_IN = 9001;
- String str_email;
- String str_foto;
- String str_id ;
- String str_firstname;
- String str_lastname;
- String str_photo;
- String locale;
- String tipoLogin;
- String str_pass;
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- private GoogleApiClient mGoogleApiClient;
- private static final String TAG = "SignInActivity";
- TwitterLoginButton loginTW;
- TwitterSession session;
- int a;
- String password;
- JSONParser jsonParser = new JSONParser();
- private ProgressDialog dialog;
- private static String register_user = "https://www.crazylex.com/v105/login.php";
- // Creating Facebook CallbackManager Value
- public static CallbackManager callbackmanager;
- @Nullable
- @Override
- public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
- TwitterAuthConfig authConfig = new TwitterAuthConfig("fKqzTc5H8P3E7aswE2NNCommv", "iifLdpVOghIqk9TSv8lTCR639bh6CM4yZYNuvNYhR3kpSm8lww");
- Fabric.with(getActivity(), new TwitterCore(authConfig));
- rootView = inflater.inflate(R.layout.profilo_fragment, container, false);
- getActivity().setTitle(getResources().getString(R.string.PROFILE));
- setHasOptionsMenu(true);
- Button loginBt = (Button) rootView.findViewById(R.id.loginButton);
- ImageButton loginFbBt = (ImageButton) rootView.findViewById(R.id.facebookLogin);
- Button registrazioneBt = (Button) rootView.findViewById(R.id.registrazioneBtn);
- Button recuperaPass = (Button) rootView.findViewById(R.id.recuperaPass);
- ImageButton loginGoogle = (ImageButton) rootView.findViewById(R.id.loginGoogle);
- locale = getActivity().getBaseContext().getResources().getConfiguration().locale.getCountry();
- Locale obj = new Locale("", locale);
- locale = obj.getDisplayCountry();
- Button terminiecondizioni = (Button) rootView.findViewById(R.id.terminiecondizioniProfilo);
- terminiecondizioni.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent myIntent = new Intent(getActivity().getBaseContext(), InfoActivity.class);
- startActivity(myIntent);
- }
- });
- loginGoogle.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
- .requestEmail()
- .requestProfile()
- .build();
- mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
- .enableAutoManage(getActivity(), null)
- .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
- .build();
- signIn();
- }
- });
- loginBt.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- tipoLogin = "login";
- LinearLayout layout = new LinearLayout(getContext());
- layout.setOrientation(LinearLayout.VERTICAL);
- final EditText inputE = new EditText(getActivity());
- final EditText inputP = new EditText(getActivity());
- inputE.setHint("Email");
- inputP.setHint("Password");
- layout.addView(inputE);
- layout.addView(inputP);
- AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
- alertDialog.setTitle("Login");
- alertDialog.setMessage(getResources().getString(R.string.ENTER_LOGIN));
- alertDialog.setView(layout, 10, 0, 10, 0); // 10 spacing, left and right
- alertDialog.setButton("Login", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // Clicked
- str_email = inputE.getText().toString();
- str_pass = inputP.getText().toString();
- Networking n = new Networking();
- n.execute("https://www.crazylex.com/v105/login.php", Networking.NETWORK_STATE_REGISTER);
- }
- });
- alertDialog.show();
- }
- });
- registrazioneBt.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent i = new Intent(getActivity().getBaseContext(), Registrazione_Activity.class);
- startActivity(i);
- }
- });
- recuperaPass.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- tipoLogin = "recupera";
- final EditText input = new EditText(getActivity());
- input.setHint("Email");
- AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
- alertDialog.setTitle(getResources().getString(R.string.RECOVERPASSWORD_BUTTON));
- alertDialog.setMessage(getResources().getString(R.string.ENTER_EMAIL));
- alertDialog.setView(input, 10, 0, 10, 0); // 10 spacing, left and right
- alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // Clicked
- str_email = input.getText().toString();
- Networking n = new Networking();
- n.execute("https://www.crazylex.com/v105/user_password.php", Networking.NETWORK_STATE_REGISTER);
- }
- });
- alertDialog.show();
- }
- });
- loginFbBt.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- tipoLogin = "fb";
- onFblogin();
- }
- });
- loginTW = (TwitterLoginButton) rootView.findViewById(R.id.twitter_login_button);
- loginTW.setCallback(new LoginHandler());
- return rootView;
- }
- @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- Log.e("request",""+requestCode);
- // Result returned from launching the Intent from
- // GoogleSignInApi.getSignInIntent(...);
- if (requestCode == RC_SIGN_IN) {
- GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
- if (result.isSuccess()) {
- GoogleSignInAccount acct = result.getSignInAccount();
- // Get account information
- String mFullName = acct.getDisplayName();
- String[] items = mFullName.split(" ");
- str_firstname =items[0];
- str_lastname = items[1];
- str_photo = acct.getPhotoUrl().toString();
- str_email = acct.getEmail();
- Log.e("risultato", str_firstname+str_email + str_lastname + str_photo);
- tipoLogin = "Google";
- Networking n = new Networking();
- n.execute("https://www.crazylex.com/v105/loginGP.php", Networking.NETWORK_STATE_REGISTER);
- }
- }else{
- callbackmanager.onActivityResult(requestCode, resultCode, data);
- loginTW.onActivityResult(requestCode, resultCode, data);
- }
- }
- void getUserData() {
- Twitter.getApiClient(session).getAccountService()
- .verifyCredentials(true, false, new Callback<User>() {
- @Override
- public void failure(TwitterException e) {
- }
- @Override
- public void success(Result<User> userResult) {
- User user = userResult.data;
- String twitterImage = user.profileImageUrl;
- try {
- Log.e("imageurl", user.profileImageUrl);
- Log.e("name", user.name);
- //Log.d("email",user.email);
- Log.e("des", user.description);
- Log.e("followers ", String.valueOf(user.followersCount));
- Log.e("createdAt", user.createdAt);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- private class LoginHandler extends Callback<TwitterSession> {
- @Override
- public void success(Result<TwitterSession> twitterSessionResult) {
- String output = "Status: " +
- "Your login was successful " +
- twitterSessionResult.data.getUserName() +
- "\nAuth Token Received: " +
- twitterSessionResult.data.getAuthToken().token;
- Log.e("loginTWOK",output);
- }
- @Override
- public void failure(TwitterException e) {
- Log.e("loginTWFAIL","FAIL");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement