Пример #1
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_sample);
   result = (TextView) findViewById(R.id.result);
   findViewById(R.id.single).setOnClickListener(this);
   findViewById(R.id.multi).setOnClickListener(this);
   findViewById(R.id.overlay).setOnClickListener(this);
   permissionHelper = PermissionHelper.getInstance(this);
 }
Пример #2
0
  // Twitter
  //    private static Twitter twitter;
  //    private static RequestToken requestToken;
  @SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    LogInActivityDialog = new ProgressDialog(LoginActivity.this);
    LogInActivityDialog.setCancelable(false);
    layoutCantConnect = (LinearLayout) findViewById(R.id.layoutCantConnect);
    LogInActivityDialog.setMessage("Please wait...");
    etEmail = (EditText) findViewById(R.id.etEmail);
    etPassword = (EditText) findViewById(R.id.etPassword);
    btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLogin.setOnClickListener(this);
    btnTryAgain = (TypedfacedButton) findViewById(R.id.btnTryAgain);
    if (AppConstant.isAndroid6()) {
      permissionHelper = PermissionHelper.getInstance(this);
    }
    btnTryAgain.setOnClickListener(this);
    //        btnSignIn = (SignInButton) findViewById(R.id.gmail_login_button);
    btnSignIn = (Button) findViewById(R.id.gmail_login_button);
    txtBottomSignup = (TextView) findViewById(R.id.txtBottomSignup);
    txtfrgtPassword = (TextView) findViewById(R.id.txtfrgtPassword);
    txtBottomSignup.setOnClickListener(this);
    txtfrgtPassword.setOnClickListener(this);
    // Button click listeners
    btnSignIn.setOnClickListener(this);

    if (AppConstant.isAndroid5()) {
      btnLogin.setBackground(getDrawable(R.drawable.ripple_accent_round_corner));
    }
    etPassword.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            try {
              if (actionId == EditorInfo.IME_ACTION_DONE) {
                try {
                  logIn(1, v);
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
            return false;
          }
        });

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

    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance()
        .registerCallback(
            callbackManager,
            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) {
                            loginId = Profile.getCurrentProfile().getId();
                            loginName = Profile.getCurrentProfile().getName();
                            loginEmail = object.optString("email");
                            loginImageUrl =
                                Profile.getCurrentProfile()
                                    .getProfilePictureUri(200, 200)
                                    .toString();
                            if (AppConstant.isNetworkAvailable(LoginActivity.this)) {
                              loginType = 2;
                              new LoginTask(loginId, loginName, loginEmail, loginImageUrl, 2)
                                  .execute();
                            } else {
                              AppConstant.showNetworkError(LoginActivity.this);
                            }

                            /*  Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                            intent.putExtra("name", Profile.getCurrentProfile().getName());
                            intent.putExtra("image", Profile.getCurrentProfile().getId());
                            startActivity(intent);
                            overridePendingTransition(R.anim.start_activity, R.anim.close_activity);
                            finish();*/

                            //                                Log.v("Email", "Resp : " + email);
                            Log.d(
                                "Facebook",
                                Profile.getCurrentProfile().getName()
                                    + "\n"
                                    + Profile.getCurrentProfile().getId()
                                    + "\n"
                                    + Profile.getCurrentProfile().getProfilePictureUri(200, 200));
                          }
                        });
                Bundle parameters = new Bundle();
                parameters.putString("fields", "id,name,email,gender, birthday");
                request.setParameters(parameters);
                request.executeAsync();
              }

              @Override
              public void onCancel() {}

              @Override
              public void onError(FacebookException e) {}
            });

    // Initializing google plus api client
    mGoogleApiClient =
        new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();
  }