Ejemplo n.º 1
0
  @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);
    FacebookSdk.sdkInitialize(getApplicationContext());
    Firebase.setAndroidContext(this);
    setContentView(R.layout.activity_main);
    ref = new Firebase("https://amber-fire-4138.firebaseio.com");

    callbackManager = CallbackManager.Factory.create();
    setContentView(R.layout.activity_main);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            onFacebookAccessTokenChange(loginResult.getAccessToken());
            // App code
          }

          @Override
          public void onCancel() {
            // App code
          }

          @Override
          public void onError(FacebookException exception) {
            // App code
          }
        });
  }
Ejemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    callbackManager = CallbackManager.Factory.create();

    setContentView(R.layout.activity_main);
    info = (TextView) findViewById(R.id.info);
    loginButton = (LoginButton) findViewById(R.id.login_button);

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            info.setText(
                "User ID: "
                    + loginResult.getAccessToken().getUserId()
                    + "\n"
                    + "Auth Token: "
                    + loginResult.getAccessToken().getToken());
          }

          @Override
          public void onCancel() {
            info.setText("Login attempt canceled.");
          }

          @Override
          public void onError(FacebookException error) {
            info.setText("Login attempt failed.");
          }
        });
  }
Ejemplo n.º 4
0
  public void onResume() {
    super.onResume();

    // Load layout
    btnLogin = (LoginButton) findViewById(R.id.btnLogin);

    // Check if user is already logged in to Facebook with this app
    if (FacebookController.getInstance(this).isLoggedIn()) {
      writeProfileToPrefs(Profile.getCurrentProfile());
      onLoginSuccessful();
    }

    callbackManager = CallbackManager.Factory.create();
    btnLogin.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            writeProfileToPrefs(Profile.getCurrentProfile());
            onLoginSuccessful();
          }

          @Override
          public void onCancel() {
            Toast.makeText(LoginActivity.this, R.string.login_cancelled, Toast.LENGTH_LONG).show();
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(LoginActivity.this, R.string.login_failed, Toast.LENGTH_LONG).show();
          }
        });
  }
  public void initialize(LoginButton fbLoginBtn, CallbackManager callbackManager) {

    // Setting permissions for fetching facebook content and performing facebook actions (eg:
    // posting on facebook)
    List<String> facebookPermissions =
        Arrays.asList(
            "user_photos", "email", "user_birthday", "user_friends", "read_custom_friendlists");
    fbLoginBtn.setReadPermissions(facebookPermissions);

    // Callback registration
    fbLoginBtn.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Toast.makeText(context, "Success", Toast.LENGTH_LONG).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(context, "Failed", Toast.LENGTH_LONG).show();
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this);
    setContentView(R.layout.activity_log_in);

    // setViewObject();
    // setListner();

    callbackManager = CallbackManager.Factory.create();
    // LoginButtonはFacebookSDKに含まれたButtonウィジェットの拡張ウィジェット。
    loginButton = (LoginButton) findViewById(R.id.login_btn_facebook);
    // APIから取得したいユーザー情報の種類を指定し、パーミッションを許可する。
    List<String> permissionNeeds =
        Arrays.asList("user_photos", "email", "user_birthday", "public_profile");
    loginButton.setReadPermissions(permissionNeeds);

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            System.out.println("");
            GraphRequest request =
                GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject object, GraphResponse response) {
                        // API連携に成功し、ログイン状態になったら、下記のようなゲッター関数により、ユーザー情報を取得することが出来る。
                        try {
                          String id = object.getString("id");
                          String name = object.getString("name");
                          String email = object.getString("email");
                          String gender = object.getString("gender");
                          String birthday = object.getString("birthday");
                          System.out.println(name);
                        } catch (JSONException e) {
                          e.printStackTrace();
                        }
                      }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,gender, birthday");
            request.setParameters(parameters);
            request.executeAsync();
          }

          @Override
          public void onCancel() {
            System.out.println("onCancel");
          }

          @Override
          public void onError(FacebookException exception) {
            Log.v("LoginActivity", exception.toString());
          }
        });
  }
Ejemplo n.º 7
0
 @Override
 public void onViewCreated(View view, Bundle savedInstanceState) {
   super.onViewCreated(view, savedInstanceState);
   LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
   loginButton.setReadPermissions("user_friends");
   loginButton.setFragment(this);
   loginButton.registerCallback(mCallbackManager, mCallback);
 }
  public void signInWithFaceButton(LoginButton loginButton) {
    List<String> permissionNeeds = Arrays.asList("email", "user_about_me");
    loginButton.setReadPermissions(permissionNeeds);
    loginButton.registerCallback(
        mCallbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {

            GraphRequest request =
                GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject object, GraphResponse response) {
                        Log.v("TAG", "JSON: " + object);
                        try {
                          String id = object.getString("id");
                          String foto =
                              "https://graph.facebook.com/" + id + "/picture?height=120&width=120";
                          String nome = object.getString("name");
                          String email = object.getString("email");
                          if (mFaceCallback != null) {
                            mFaceCallback.getInfoFace(id, nome, email, foto);
                          } else {
                            throw new IllegalArgumentException(
                                "interface InfoLoginFaceCallback is null");
                          }
                        } catch (JSONException e) {
                          e.printStackTrace();
                        }
                      }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,picture.width(120).height(120)");
            request.setParameters(parameters);
            request.executeAsync();
          }

          @Override
          public void onCancel() {
            if (mFaceCallback != null) {
              mFaceCallback.cancelLoginFace();
            } else {
              throw new IllegalArgumentException("interface InfoLoginFaceCallback is null");
            }
          }

          @Override
          public void onError(FacebookException error) {
            if (mFaceCallback != null) {
              mFaceCallback.erroLoginFace(error);
            } else {
              throw new IllegalArgumentException("interface InfoLoginFaceCallback is null");
            }
          }
        });
  }
Ejemplo n.º 9
0
  // what happens when the view is created
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // find fb login button by id and assign it to variable
    LoginButton login_button = (LoginButton) view.findViewById(R.id.login_button);
    login_button.setFragment(this); // set login button as a fragment

    login_button.registerCallback(callBackManager, callback); // register callback to button
  }
Ejemplo n.º 10
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    btnConnectWithFacebook = (LoginButton) getActivity().findViewById(R.id.btnConnectWithFacebok);
    btnConnectWithFacebook.setTypeface(
        FontManager.setFont(getActivity(), FontManager.Font.OpenSansSemiBold));

    btnConnectWithFacebook.setReadPermissions(Arrays.asList("public_profile, email"));
    btnConnectWithFacebook.setFragment(this);
    btnConnectWithFacebook.registerCallback(callbackManager, callback);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_log_in);

    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Log.d("debug", loginResult.getAccessToken().getToken());
            AccessToken accessToken = loginResult.getAccessToken();

            GraphRequest.newMeRequest(
                    accessToken,
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                        Log.d("debug", "me request: " + jsonObject.toString());
                      }
                    })
                .executeAsync();

            GraphRequest.newGraphPathRequest(
                    accessToken,
                    "/me?fields=feed",
                    new GraphRequest.Callback() {
                      @Override
                      public void onCompleted(GraphResponse graphResponse) {
                        String response = graphResponse.getRawResponse();
                        Log.d("debug", "graph path request: " + response);
                      }
                    })
                .executeAsync();
          }

          @Override
          public void onCancel() {}

          @Override
          public void onError(FacebookException e) {
            e.printStackTrace();
          }
        });
  }
Ejemplo n.º 12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // initializing facebook sdk
    FacebookSdk.sdkInitialize(getApplicationContext());

    // setting layout
    setContentView(R.layout.activity_login);

    // binding id's to view
    ButterKnife.bind(this);

    // facebook login button
    fbLoginButton.setReadPermissions("user_friends", "public_profile");

    // initializing callback function
    callbackManager = CallbackManager.Factory.create();

    // Callback registration
    fbLoginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            // App code
            //                getUserDetail();
            //                Intent goToNavigation = new Intent(LoginActivity.this,
            // NavigationDrawerActivity.class);
          }

          @Override
          public void onCancel() {
            Snackbar.make(
                    fbLoginButton,
                    "Can not login using Facebook, Please try logging again or Enter application without logging in",
                    Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }

          @Override
          public void onError(FacebookException exception) {
            Snackbar.make(fbLoginButton, "Some Error occurred! Login again", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });
  }
Ejemplo n.º 13
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // mTextDisplayed = (TextView) view.findViewById(R.id.text_details);

    // Create facebook button and initialize permissions.
    fbLoginButton = (LoginButton) view.findViewById(R.id.login_button);
    fbLoginButton.setPublishPermissions("publish_actions");
    fbLoginButton.setFragment(this);
    fbLoginButton.registerCallback(mCallbackManager, facebookCallback);

    // Creating loginButton and setting the callback.
    twitterLoginButton = (TwitterLoginButton) view.findViewById(R.id.twitter_login_button);
    twitterLoginButton.setCallback(twitterSessionCallback);
  }
Ejemplo n.º 14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(this.getApplicationContext());
    requestWindowFeature(Window.FEATURE_NO_TITLE); // hide title
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN); // hide top bar
    setContentView(R.layout.highscorescreen);

    btn_back = (Button) findViewById(R.id.btn_back);
    btn_back.setOnClickListener(this);

    theScore = getSharedPreferences("thePref", Context.MODE_PRIVATE);
    theText = (TextView) findViewById(R.id.textView);
    theText.setText("" + theScore.getInt("HighScore", 0));

    callbackManager = CallbackManager.Factory.create();

    List<String> PERMISSIONS = Arrays.asList("publish_actions");

    loginBtn = (LoginButton) findViewById(R.id.fb_login_button);
    loginManager = LoginManager.getInstance();
    loginManager.logInWithPublishPermissions(this, PERMISSIONS);

    loginBtn.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {

          @Override
          public void onSuccess(LoginResult loginResult) {

            sharePhotoToFacebook();
          }

          @Override
          public void onCancel() {
            userName.setText("Login attempt canceled.");
          }

          @Override
          public void onError(FacebookException e) {
            userName.setText("Login attempt failed.");
          }
        });
  }
Ejemplo n.º 15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
    mClient.connect();

    Intent sIntent = new Intent(this, BeeplePaperService.class);
    startService(sIntent);

    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_main);

    final Button btn = (Button) findViewById(R.id.mButt);

    btn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent mIntent = new Intent(Intent.ACTION_SEND);
            sendBroadcast(mIntent);
          }
        });

    callbackManager = CallbackManager.Factory.create();
    Log.d(TAG, "Building login button for FB");
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("user_friends");
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Log.d(TAG, "Getting access token");
          }

          @Override
          public void onCancel() {
            Log.d(TAG, "Login Cancelled");
          }

          @Override
          public void onError(FacebookException exception) {
            Log.e(TAG, exception.toString());
          }
        });
  }
Ejemplo n.º 16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Iniciar Parse
    Parse.initialize(
        this,
        getResources().getString(R.string.parseId),
        getResources().getString(R.string.parseKey));
    localRepository = new ParseLocalRepository();
    camareroRepository = new ParseCamareroRepository();
    cocinaRepository = new ParseCocinaRepository();
    extraRepository = new ParseExtraRepository();

    // iniciar Facebook
    FacebookSdk.sdkInitialize(getApplicationContext());

    // Hay que cargar la api de facebook antes de ejecutar el setContextView para que importe el
    // boton estilo facebook
    setContentView(R.layout.activity_main);

    callbackManager = CallbackManager.Factory.create();

    loginButton = (LoginButton) findViewById(R.id.login_button);

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            user = new Usuario(loginResult.getAccessToken().getUserId());

            AccessToken accessToken = loginResult.getAccessToken();
            profile = Profile.getCurrentProfile();
          }

          @Override
          public void onCancel() {
            Toast.makeText(getBaseContext(), "Inicio de sesion cancelado", Toast.LENGTH_SHORT)
                .show();
          }

          @Override
          public void onError(FacebookException e) {
            Toast.makeText(getBaseContext(), "Inicio de sesion fallido", Toast.LENGTH_SHORT).show();
          }
        });
  }
Ejemplo n.º 17
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    loginButton = (LoginButton) view.findViewById(R.id.ivfb);
    tvUser = (TextView) getView().findViewById(R.id.tvUser);
    etEmail = (EditText) getView().findViewById(R.id.etEmail);
    etUser = (EditText) getView().findViewById(R.id.etUser);
    etPhone = (EditText) getView().findViewById(R.id.etPhone);
    etPass = (EditText) getView().findViewById(R.id.etPass);
    bLogin = (Button) view.findViewById(R.id.bLogin);
    bReg = (Button) view.findViewById(R.id.bReg);
    ivgp = (ImageView) view.findViewById(R.id.ivgp);

    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
    loginButton.registerCallback(callbackManager, callback);
  }
Ejemplo n.º 18
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    callbackManager = CallbackManager.Factory.create();

    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile");

    // Callback registration
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            updateDatabase();
            // jump to another activity
            Intent showPosts = new Intent(LoginActivity.this, PostActivity.class);
            startActivity(showPosts);
          }

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

          @Override
          public void onError(FacebookException exception) {
            showAlert();
          }

          private void showAlert() {
            new AlertDialog.Builder(LoginActivity.this)
                .setTitle(R.string.cancelled)
                .setMessage(R.string.login_failed)
                .setPositiveButton(R.string.ok, null)
                .show();
          }
        });

    LoginManager.getInstance()
        .logInWithReadPermissions(this, Collections.singletonList("public_profile"));
  }
Ejemplo n.º 19
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    setContentView(R.layout.activity_main);

    callbackManager = CallbackManager.Factory.create();

    final LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile", "email", "user_friends");

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {

          @Override
          public void onSuccess(LoginResult loginResult) {

            Intent intent = new Intent(MainActivity.this, HomeActivity.class);
            startActivity(intent);

            System.out.print("Logged in");
          }

          @Override
          public void onCancel() {
            // App code
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(
                    MainActivity.this, "Error al realizar Login Facebook", Toast.LENGTH_SHORT)
                .show();
            Log.i("Error", "Error");
          }
        });

    // printHashKey();

  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.splash, container, false);

    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) view.findViewById(R.id.login_button);
    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Toast.makeText(getActivity(), "Login successful", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(getActivity(), "Login canceled", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onError(FacebookException exception) {
            Toast.makeText(getActivity(), "Login error", Toast.LENGTH_SHORT).show();
          }
        });

    skipLoginButton = (TextView) view.findViewById(R.id.skip_login_button);
    skipLoginButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (skipLoginCallback != null) {
              skipLoginCallback.onSkipLoginPressed();
            }
          }
        });

    return view;
  }
Ejemplo n.º 21
0
  @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
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // for finding key hash of dev environment
    // Log.i(TAG, printKeyHash(this));
    pref = getSharedPreferences(Constants.SHARED_PREFERENCE, Context.MODE_PRIVATE);
    // initializing facebook sdk
    FacebookSdk.sdkInitialize(this.getApplicationContext());

    // setting the layout
    setContentView(R.layout.activity_login);

    Button clickButton = (Button) findViewById(R.id.inst);
    final TypedValue typedValue = new TypedValue();
    clickButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            String mssg =
                "1. Login with facebook.\n"
                    + "2. This app will work only if other users are also on the same wifi network."
                    + "3. Select discover tab for seeing people around"
                    + "4. Select Match tab for seeing all your matches and chat with them by tapping on matches"
                    + "5. view your profile and preferences from action overflow"
                    + "6. logout by clicking logout button in action overflow";
            AlertDialog.Builder myAlert = new AlertDialog.Builder(LoginActivity.this);

            myAlert
                .setMessage(mssg)
                .setNeutralButton(
                    "Continue..",
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                      }
                    })
                .setTitle("!Instructions For You!")
                .setIcon(typedValue.resourceId)
                .create();
            myAlert.show();
          }
        });
    if (android.os.Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    // System.setProperty("http.keepAlive", "false");

    // login button reference
    loginButton = (LoginButton) findViewById(R.id.login_button);

    // registering callback manager
    callbackManager = CallbackManager.Factory.create();
    loginButton.registerCallback(callbackManager, loginCallback());

    // setting permissions of login button
    loginButton.setReadPermissions(
        "user_photos", "user_about_me", "user_birthday", "user_location", "user_posts");

    WifiManager wifi_manager = (WifiManager) this.getSystemService(this.WIFI_SERVICE);
    if (!wifi_manager.isWifiEnabled()) {
      Toast.makeText(this, "enable your wifi", Toast.LENGTH_SHORT).show();
      AppServer.getInstance(this).killServer();
      NSDHelper.getInstance(this).tearDown();
      MessageClientHelper.getInstance(this).terminateMessageClient();
      // LoginManager.getInstance().logOut();
      finish();

    } else {

      // getting current access token
      accessToken = AccessToken.getCurrentAccessToken();

      //
      if (accessToken != null && accessToken.isExpired()) {
        LoginManager.getInstance()
            .logInWithReadPermissions(
                this,
                Arrays.asList(
                    "user_photos",
                    "user_about_me",
                    "user_birthday",
                    "user_location",
                    "user_posts"));
      } else if (accessToken != null && !accessToken.isExpired()) {
        // getPermanentToken();
        requestProfileInfo();
        // enterMainApp();
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mLM = LoginManager.getInstance();

    login = (LoginButton) findViewById(R.id.btn_login);
    callbackManager = CallbackManager.Factory.create();
    login.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {

          @Override
          public void onSuccess(LoginResult result) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            Toast.makeText(
                    MainActivity.this, "login success : " + token.getUserId(), Toast.LENGTH_SHORT)
                .show();
          }

          @Override
          public void onError(FacebookException error) {
            Toast.makeText(MainActivity.this, "login error", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(MainActivity.this, "login cancel", Toast.LENGTH_SHORT).show();
          }
        });

    btnLogin = (Button) findViewById(R.id.btn_login2);
    AccessToken token = AccessToken.getCurrentAccessToken();
    if (token == null) {
      btnLogin.setText("login");
    } else {
      btnLogin.setText("logout");
    }

    btnLogin.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token == null) {
              mLM.logInWithReadPermissions(MainActivity.this, null);
            } else {
              mLM.logOut();
            }
          }
        });

    Button btn = (Button) findViewById(R.id.btn_post);
    btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token != null) {
              if (token.getPermissions().contains("publish_actions")) {
                sendPost();
                return;
              }
            }
            state = ActionState.POST;
            mLM.logInWithPublishPermissions(MainActivity.this, Arrays.asList("publish_actions"));
          }
        });

    btn = (Button) findViewById(R.id.btn_home);
    btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            AccessToken token = AccessToken.getCurrentAccessToken();
            if (token != null) {
              if (token.getPermissions().contains("user_posts")) {
                readPost();
                return;
              }
            }
            state = ActionState.READ;
            mLM.logInWithReadPermissions(MainActivity.this, Arrays.asList("user_posts"));
          }
        });
    tracker =
        new AccessTokenTracker() {

          @Override
          protected void onCurrentAccessTokenChanged(
              AccessToken oldAccessToken, AccessToken currentAccessToken) {
            if (currentAccessToken != null) {
              btnLogin.setText("logout");
            } else {
              btnLogin.setText("login");
            }
          }
        };
  }
Ejemplo n.º 24
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    mCallbackManager = CallbackManager.Factory.create();

    getSupportActionBar().hide();

    if (mata_sessao) {
      LoginManager.getInstance().logOut();
    }

    final EditText etEmail = (EditText) findViewById(R.id.etEmail);
    final EditText etSenha = (EditText) findViewById(R.id.etSenha);
    etEmail.requestFocus();

    Button btEntrar = (Button) findViewById(R.id.btEntrar);

    btEntrar.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
            map.add("email", String.valueOf(etEmail.getText().toString()));
            map.add("senha", String.valueOf(etSenha.getText().toString()));

            Usuario usuario = new Usuario();
            Webservice ws = new Webservice();
            new HttpLogin(ws.login(), map, Usuario.class, "").execute();
          }
        });

    TextView tvCadastrar = (TextView) findViewById(R.id.tvCadastrar);

    tvCadastrar.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            Intent tela1 = new Intent(Login.this, Cadastro.class);
            startActivity(tela1);
          }
        });

    ProfileTracker profileTracker =
        new ProfileTracker() {
          @Override
          protected void onCurrentProfileChanged(Profile profile, Profile newProfile) {}
        };

    LoginButton FBLoginButton = (LoginButton) findViewById(R.id.fb_login_button);
    FBLoginButton.registerCallback(mCallbackManager, mCallBack);

    if (AccessToken.getCurrentAccessToken() != null) {
      GraphRequest request2 =
          GraphRequest.newMeRequest(
              AccessToken.getCurrentAccessToken(),
              new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
                  try {
                    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
                    map.add("email", jsonObject.getString("email"));
                    map.add("senha", jsonObject.getString("id"));

                    new HttpLoginFB((new Webservice()).login(), map, Usuario.class, "").execute();

                  } catch (JSONException e) {
                    e.printStackTrace();
                  }
                }
              });
      Bundle params2 = new Bundle();
      params2.putString("fields", "id,name,email");
      request2.setParameters(params2);
      request2.executeAsync();
    }
  }
Ejemplo n.º 25
0
  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();
            }
          }
        });
  }
Ejemplo n.º 26
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initFacebook();
    setContentView(R.layout.activity_main);

    sp = this.getSharedPreferences("Accounts", Context.MODE_PRIVATE);
    tv_name = (TextView) findViewById(R.id.tv_name);
    profilePictureView = (ProfilePictureView) findViewById(R.id.proflie_picture);
    profilePictureView.setCropped(true);
    profilePictureView.setPresetSize(ProfilePictureView.NORMAL);

    // setting profile from storage;
    String id = sp.getString("fb_id", "");
    String name = sp.getString("fb_name", "");
    profilePictureView.setProfileId(id);
    tv_name.setText(name);

    fbLoginButton = (LoginButton) findViewById(R.id.fb_login_button);
    fbShareButton = (ShareButton) findViewById(R.id.fb_share_button);
    if (id != "") {
      fbShareButton.setEnabled(true);
    }

    fbShareButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (ShareDialog.canShow(ShareLinkContent.class)) {
              ShareLinkContent linkContent =
                  new ShareLinkContent.Builder()
                      .setContentTitle("I am the king")
                      .setContentDescription("No doubt")
                      .setImageUrl(
                          Uri.parse(
                              "http://vignette2.wikia.nocookie.net/genealogy/images/2/28/King_Henry_I_from_NPG.jpg/revision/latest?cb=20090610170605"))
                      .setContentUrl(Uri.parse("http://stackoverflow.com/"))
                      .build();

              // Mode.FEED:Shared link with this account
              // Mode.NATIVE:Shared link with the account that you have logged in the facebook app
              // So, if your app ask for login, you use Mode.FEED to share link
              // In general, you use Mode.AUTOMATIC
              shareDialog.show(linkContent, ShareDialog.Mode.FEED);
            }
          }
        });

    shareDialog.registerCallback(
        callbackManager,
        new FacebookCallback<Sharer.Result>() {

          @Override
          public void onSuccess(Sharer.Result result) {
            Log.d(TAG, "success");
          }

          @Override
          public void onError(FacebookException error) {
            Log.d(TAG, "error");
          }

          @Override
          public void onCancel() {
            Log.d(TAG, "cancel");
          }
        });
    fbLoginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            String id = loginResult.getAccessToken().getUserId();
            profilePictureView.setProfileId(id);
            fbShareButton.setEnabled(true);
            SharedPreferences.Editor editor = sp.edit();
            editor.putString("fb_id", id);
            editor.commit();
            getMoreInformation(loginResult);

            Log.d(TAG, "Facebook Login Successful!");
            Log.d(TAG, "Logged in user Details : ");
            Log.d(TAG, "--------------------------");
            Log.d(TAG, "User ID  : " + id);
            Log.d(TAG, "Authentication Token : " + loginResult.getAccessToken().getToken());
            Toast.makeText(MainActivity.this, "Login Successful!", Toast.LENGTH_LONG).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(MainActivity.this, "Login cancelled by user!", Toast.LENGTH_LONG).show();
            Log.d(TAG, "Facebook Login failed!!");
          }

          @Override
          public void onError(FacebookException e) {
            Toast.makeText(MainActivity.this, "Login unsuccessful!", Toast.LENGTH_LONG).show();
            Log.d(TAG, "Facebook Login failed!!");
          }
        });

    fbLoginButton.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Log.d(TAG, "beforeTextChanged");
          }

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Log.d(TAG, "onTextChanged");
          }

          @Override
          public void afterTextChanged(Editable s) {
            // Log.d(TAG, "afterTextChanged");
            if (AccessToken.getCurrentAccessToken() == null) {
              clearFbData();
            }
          }
        });
  }
Ejemplo n.º 27
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (LoginService.getInstance().validateCurrentSession()
        || FacebookHelper.getInstance().login() != null) {
      finish();
      return;
    }

    FacebookHelper.getInstance().logout();
    setContentView(R.layout.activity_login);
    // 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);

    callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.facebook_signin_button);

    loginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            ProfileTracker profileTracker =
                new ProfileTracker() {
                  @Override
                  protected void onCurrentProfileChanged(
                      Profile oldProfile, Profile currentProfile) {
                    this.stopTracking();
                    Profile.setCurrentProfile(currentProfile);
                    FacebookHelper.getInstance().login();
                    finish();
                  }
                };

            if (Profile.getCurrentProfile() != null) {
              FacebookHelper.getInstance().login();
              finish();
            } else {
              showProgress(true);
              profileTracker.startTracking();
            }
          }

          @Override
          public void onCancel() {
            Log.i("FB", "Cancel");
          }

          @Override
          public void onError(FacebookException error) {
            //                Toast.makeText(getApplicationContext(), "Error : " + error.toString(),
            // Toast.LENGTH_LONG).show();
            Log.e("FB", "Error " + error.toString());
          }
        });
  }
Ejemplo n.º 28
0
  @Override
  public void initSignInButton(View button) {
    final LoginButton loginButton = (LoginButton) button;
    loginButton.setReadPermissions(READ_PERMISSIONS_PUBLIC_PROFILE);

    mFacebookCallback = CallbackManager.Factory.create();

    loginButton.registerCallback(
        mFacebookCallback,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            final AccessToken accessToken = loginResult.getAccessToken();

            final GraphRequest request =
                GraphRequest.newMeRequest(
                    accessToken,
                    new GraphRequest.GraphJSONObjectCallback() {
                      @Override
                      public void onCompleted(JSONObject object, GraphResponse response) {

                        final String id;
                        final String name;
                        try {
                          id = object.getString("id");
                          name = object.getString("name");
                        } catch (JSONException e) {
                          e.printStackTrace();
                          return;
                        }

                        final User user =
                            new User(
                                UserVerifierApp.AccountType.FACEBOOK,
                                id,
                                name,
                                accessToken.getToken());

                        mEventBus
                            .obtainMessage(LoginActivity.EVENT_ATTACH_USER, user)
                            .sendToTarget();
                      }
                    });

            final Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name");
            request.setParameters(parameters);
            request.executeAsync();
          }

          @Override
          public void onCancel() {
            mEventBus
                .obtainMessage(
                    LoginActivity.EVENT_ERROR, mActivity.getString(R.string.facebook_cancelled))
                .sendToTarget();
          }

          @Override
          public void onError(FacebookException exception) {
            mEventBus
                .obtainMessage(
                    LoginActivity.EVENT_ERROR,
                    mActivity.getString(R.string.facebook_error, exception.getMessage()))
                .sendToTarget();
          }
        });
  }
Ejemplo n.º 29
0
  @SuppressLint("NewApi")
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();

    // You need this method to be used only once to configure
    // your key hash in your App Console at
    // developers.facebook.com/apps

    getFbKeyHash("com.jaze.hello_world");

    setContentView(R.layout.activity_login);
    if (Build.VERSION.SDK_INT > 9) {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
    }

    init();

    Button log = (Button) findViewById(R.id.btn_log);
    log.bringToFront();
    log.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Boolean is_netConnetion = glbFunc.isInternetOn(LoginActivity.this, true);
            // .isConnectingToInternet(LoginActivity.this);
            if (glbFunc.isInternetOn(getApplicationContext(), false) == false) {
              new AlertDialog.Builder(LoginActivity.this)
                  .setTitle(R.string.app_name)
                  .setMessage(R.string.Server_not_reachable)
                  .setNeutralButton(R.string.OK_btn, null)
                  .setInverseBackgroundForced(true)
                  .show();

            } else {
              if (username.getText().toString().matches("")
                  && pass.getText().toString().matches("")) {
                new AlertDialog.Builder(LoginActivity.this)
                    .setTitle(R.string.app_name)
                    .setMessage(R.string.All_field_blank)
                    .setNeutralButton(R.string.OK_btn, null)
                    .setInverseBackgroundForced(true)
                    .show();

              } else {
                progressDialog =
                    new ProgressDialog(LoginActivity.this, R.style.AppTheme_Dark_Dialog);
                progressDialog.setIndeterminate(true);
                progressDialog.setMessage("Authenticating...");
                progressDialog.show();
                String Server_url = "http://www.thumpi.com/jazeit_api/api_user/login";
                new LongOperation().execute(Server_url);

                // http://www.thumpi.com/jazeit_api/api_user/[email protected]&password=q1w2e3r4
                /* if ( glbFunc.isInternetOn(getApplicationContext(), false) == true ) {
                    String names = username.getText().toString();
                    String appide = pass.getText().toString();
                    String _url = Server_url + "?email=" + names + "&password="******"Updating Server ..";
                    glbAsyn.PARAM_ShowDowloadDialog = false ;
                    glbAsyn.PARAM_PrefKey = "storedAddress";
                    glbAsyn.PARAM_PostHandler =	"SAVE_PREF";
                    glbAsyn.execute(_url);
                    glbAsyn = null;
                }*/
              }
            }
          }
        });
    fbLoginButton = (LoginButton) findViewById(R.id.fb_login_button);

    fbLoginButton.registerCallback(
        callbackManager,
        new FacebookCallback<LoginResult>() {
          @Override
          public void onSuccess(LoginResult loginResult) {
            Intent intent = new Intent(LoginActivity.this, Search_catagory.class);
            startActivity(intent);
            System.out.println("Facebook Login Successful!");
            System.out.println("Logged in user Details : ");
            System.out.println("--------------------------");
            System.out.println("User ID  : " + loginResult.getAccessToken().getUserId());
            Log.d("User Id ", "" + loginResult.getAccessToken().getUserId());
            Log.d("User name", "" + loginResult.getAccessToken().getApplicationId());
            prefs = getSharedPreferences(prefName, MODE_PRIVATE);
            SharedPreferences.Editor editor = prefs.edit();

            // ---save the values in the EditText view to preferences---
            editor.putString("FBUser_id", loginResult.getAccessToken().getUserId());
            editor.putString("FBAccessToken", loginResult.getAccessToken().getToken());

            editor.commit();
            System.out.println("Authentication Token : " + loginResult.getAccessToken().getToken());
            Log.d("Authentication : ", "" + loginResult.getAccessToken().getToken());
            Toast.makeText(LoginActivity.this, "Login Successful!", Toast.LENGTH_LONG).show();
          }

          @Override
          public void onCancel() {
            Toast.makeText(LoginActivity.this, "Login cancelled by user!", Toast.LENGTH_LONG)
                .show();
            System.out.println("Facebook Login failed!!");
          }

          @Override
          public void onError(FacebookException e) {
            Toast.makeText(LoginActivity.this, "Login unsuccessful!", Toast.LENGTH_LONG).show();
            System.out.println("Facebook Login failed!!");
          }
        });

    btnfb.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            final String urlFb = "fb://page/";
            Intent intent1 = new Intent(Intent.ACTION_VIEW);
            intent1.setData(Uri.parse(urlFb));

            final PackageManager packageManager = getPackageManager();
            List<ResolveInfo> list =
                packageManager.queryIntentActivities(intent1, PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() == 0) {
              final String urlBrowser = "https://www.facebook.com/pages/";
              intent1.setData(Uri.parse(urlBrowser));
            }
            overridePendingTransition(0, 0);
            startActivity(intent1);
          }
        });
    btntwit.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {

            String tweetUrl =
                String.format(
                    "https://twitter.com/intent/tweet?text=%s&url=%s",
                    urlEncode("Tweet text"), urlEncode("https://www.google.fi/"));
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tweetUrl));

            // Narrow down to official Twitter app, if available:
            List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
            for (ResolveInfo info : matches) {
              if (info.activityInfo.packageName.toLowerCase().startsWith("com.twitter")) {
                intent.setPackage(info.activityInfo.packageName);
              }
            }

            startActivity(intent);
          }
        });
    findViewById(R.id.btn_signup)
        .setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(intent);
              }
            });
    findViewById(R.id.btn_forgotpass)
        .setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this, Forgot_Password_Activity.class);
                startActivity(intent);
              }
            });
  }
  @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;
  }