コード例 #1
0
  public void completeRegistrationFacebook(final UserDTO user) {
    CheckUserNameTask checkUserNameTask = new CheckUserNameTask();
    checkUserNameTask.setUser(user);
    checkUserNameTask.setContext(getApplicationContext());
    checkUserNameTask.execute();
    checkUserNameTask.setCheckUserNameTaskListener(
        new CheckUserNameTaskListener() {
          @Override
          public void onComplete(String result) {
            if (result != "") {
              if (result.equalsIgnoreCase("userNameExist")) {
                System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>> result" + result);
                userDto = new UserDTO(user.getUserName(), "", "", user.getNickName(), "", 0, "");
                session.createLoginSession(user.getUserName(), "", user.getNickName(), 0, "");

                // register GCM
                UserService userService = new UserService();
                userService.registerGCM(MainActivity.this);

                Intent matchList = new Intent(getApplicationContext(), MainContainerActivity.class);
                // Close all views before launching matchList
                matchList.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(matchList);
                // Close match list View
                finish();
              } else {
                session.addFacebookLoginSession(user.getUserName(), user.getNickName());
                session.addLoginType("facebook");
                Intent completeRegistration =
                    new Intent(getApplicationContext(), TwitterFacebookRegistration.class);
                // Close all views before launching matchList
                completeRegistration.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(completeRegistration);
                // Close match list View
                finish();
              }
            } else {
              // Error in registration
              Toast toast =
                  Toast.makeText(
                      MainActivity.this, "Error occured in registration", Toast.LENGTH_LONG);
              toast.setGravity(Gravity.CENTER, 0, 0);
              toast.show();
            }
          }
        });
  }
コード例 #2
0
  // complete registration twitter
  public void completeRegistration(final UserDTO user, final AccessToken accessToken) {
    CheckUserNameTask checkUserNameTask = new CheckUserNameTask();
    checkUserNameTask.setUser(user);
    checkUserNameTask.setContext(getApplicationContext());
    checkUserNameTask.execute();
    checkUserNameTask.setCheckUserNameTaskListener(
        new CheckUserNameTaskListener() {
          @Override
          public void onComplete(String result) {
            if (result != "") {
              if (result.equalsIgnoreCase("userNameExist")) {
                Editor e = mSharedPreferences.edit();
                // After getting access token, access token secret
                // store them in application preferences
                e.putString(PREF_KEY_OAUTH_TOKEN, accessToken.getToken());
                e.putString(PREF_KEY_OAUTH_SECRET, accessToken.getTokenSecret());
                // Store login status - true
                e.putBoolean(PREF_KEY_TWITTER_LOGIN, true);
                e.commit(); // save changes

                long userID = accessToken.getUserId();
                User user = null;
                try {
                  user = twitter.showUser(userID);
                } catch (TwitterException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
                }
                String nickname = user.getName();
                userDto = new UserDTO(String.valueOf(userID), "", "", nickname, "", 0, "");
                session.createLoginSession(String.valueOf(userID), "", nickname, 0, "");

                // register GCM
                UserService userService = new UserService();
                userService.registerGCM(MainActivity.this);

                Intent matchList = new Intent(getApplicationContext(), MainContainerActivity.class);
                // Close all views before launching matchList
                matchList.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(matchList);
                // Close match list View
                finish();
              } else {
                long userID = accessToken.getUserId();
                User user = null;
                try {
                  user = twitter.showUser(userID);
                } catch (TwitterException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
                }
                String nickname = user.getName();
                session.addTwitterLoginSession(String.valueOf(userID), nickname);
                session.addLoginType("twitter");
                Intent completeRegistration =
                    new Intent(getApplicationContext(), TwitterFacebookRegistration.class);
                // Close all views before launching matchList
                completeRegistration.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(completeRegistration);
                // Close match list View
                finish();
              }
            } else {
              // Error in registration
              Toast toast =
                  Toast.makeText(
                      MainActivity.this, "Error occured in registration", Toast.LENGTH_LONG);
              toast.setGravity(Gravity.CENTER, 0, 0);
              toast.show();
            }
          }
        });
  }