Exemplo n.º 1
0
  /** * Fetching user's information name, email, profile pic * */
  private void getProfileInformation() {
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        String personName = currentPerson.getDisplayName();
        String personPhotoUrl = currentPerson.getImage().getUrl();
        String personGooglePlusProfile = currentPerson.getUrl();
        String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
        Log.e(
            TAG,
            "Name: "
                + personName
                + ", plusProfile: "
                + personGooglePlusProfile
                + ", email: "
                + email
                + ", Image: "
                + personPhotoUrl);

        Toast.makeText(
                getApplicationContext(),
                "Signed In as:" + currentPerson.getDisplayName(),
                Toast.LENGTH_LONG)
            .show();
        if (!sharedPref.contains("UID")) {
          int Applicationid = getUID();
          saveSharedint("UID", Applicationid);
        }

        long DS = getDataValue(context);
        long DC = getFolderSize() + DS;
        String DataS = l2bytes(DS, false);
        String DataC = l2bytes(DC, false);

        long hours = CommonUtils.totaltime / 3600;
        long minutes = (CommonUtils.totaltime % 3600) / 60;
        long seconds = (long) ((CommonUtils.totaltime % 3600) % 60);

        txtDatasent.setText("Data Sent :" + DataS);
        txtDatasent.setAnimation(null);

      } else {
        Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG)
            .show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  private void updateUI(boolean isSignedIn) {
    if (isSignedIn) {
      Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
      if (currentPerson != null) {
        // Show signed-in user's name
        String name = currentPerson.getDisplayName();
        mStatus.setText(getString(R.string.signed_in_fmt, name));

        // Show users' email address (which requires GET_ACCOUNTS permission)
        if (checkAccountsPermission()) {
          String currentAccount = Plus.AccountApi.getAccountName(mGoogleApiClient);
          ((TextView) recViewLogin.findViewById(R.id.email)).setText(currentAccount);
        }
      } else {
        // If getCurrentPerson returns null there is generally some error with the
        // configuration of the application (invalid Client ID, Plus API not enabled, etc).
        Log.w(TAG, getString(R.string.error_null_person));
        mStatus.setText(getString(R.string.signed_in_err));
      }

      // Set button visibility
      recViewLogin.findViewById(R.id.sign_in_button).setVisibility(View.GONE);
      recViewLogin.findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
    } else {
      // Show signed-out message and clear email field
      mStatus.setText(R.string.signed_out);
      ((TextView) recViewLogin.findViewById(R.id.email)).setText("");

      // Set button visibility
      recViewLogin.findViewById(R.id.sign_in_button).setEnabled(true);
      recViewLogin.findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
      recViewLogin.findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
    }
  }
  /** Fetching user's information name, email, profile pic */
  private void getProfileInformation() {
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        personName = currentPerson.getDisplayName();
        String personPhotoUrl = currentPerson.getImage().getUrl();
        String personGooglePlusProfile = currentPerson.getUrl();
        email = Plus.AccountApi.getAccountName(mGoogleApiClient);

        Log.e(
            TAG,
            "Name: "
                + personName
                + ", plusProfile: "
                + personGooglePlusProfile
                + ", email: "
                + email
                + ", Image: "
                + personPhotoUrl);

      } else {
        Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG)
            .show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  @Override
  public void onConnected(Bundle bundle) {
    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
      Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
      String personName = currentPerson.getDisplayName();
      String personPhoto = currentPerson.getImage().getUrl();
      String firstName = currentPerson.getName().getGivenName();
      String lastName = currentPerson.getName().getFamilyName();
      String personGooglePlusProfile = currentPerson.getUrl();
      String date = currentPerson.getBirthday();
      if (date == null) {
        date = "";
      }
      int gender = currentPerson.getGender();
      String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

      Intent mIntent = new Intent(getActivity(), LoginUserDetails.class);
      mIntent.putExtra("login_method", "google");
      mIntent.putExtra("email", email);
      mIntent.putExtra("first_name", firstName);
      mIntent.putExtra("gender", gender);
      mIntent.putExtra("last_name", lastName);
      mIntent.putExtra("photo", personPhoto);

      mixpanel.track("Login - Google");
      startActivity(mIntent);
    } else {
      Toast.makeText(getContext(), "You do not have a google+ account", Toast.LENGTH_SHORT).show();
      showSocialLoginDialog();
    }

    Log.d(TAG, "onConnected:" + bundle);
    mShouldResolve = false;
  }
Exemplo n.º 5
0
  private void setGResult() {
    Person signedInUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

    if (signedInUser != null) {
      if (signedInUser.hasDisplayName()) {
        guname = signedInUser.getDisplayName();
      }

      guemail = Plus.AccountApi.getAccountName(mGoogleApiClient);

      // Toast.makeText(getApplicationContext(),guemail,Toast.LENGTH_LONG).show();
      if (signedInUser.hasImage()) {
        String[] profileparts = signedInUser.getImage().getUrl().split("\\?");
        guserProfilePicUrl = profileparts[0];
      }
      if (signedInUser.hasBirthday()) {
        bday = signedInUser.getBirthday();
        Toast.makeText(getApplicationContext(), bday, Toast.LENGTH_LONG).show();
      }
      if (signedInUser.hasGender()) {
        gender = String.valueOf(signedInUser.getGender());
        Toast.makeText(getApplicationContext(), gender, Toast.LENGTH_LONG).show();
      }
      pref = getApplicationContext().getSharedPreferences("unid", MODE_APPEND);
      SharedPreferences.Editor editor = pref.edit();
      editor.putString("unid", guemail);
      editor.commit();

      new Makerqust().execute();
    }
  }
Exemplo n.º 6
0
  public void checkuser() {

    Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
    String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
    String personName = currentPerson.getDisplayName();

    try {

      long timeInMillis = System.currentTimeMillis();

      final String PhoneModel = android.os.Build.MODEL;
      JSONObject userData = new JSONObject();
      userData.put("phoneModel", PhoneModel);
      userData.put("username", personName);
      userData.put("email", email);
      Log.d(TAG, userData.toString());
      String response = CommonFunctions.sendRequestToServer(userData.toString(), "login");
      if (response.contains("SUCCESS") || response.contains("ALREADY")) {
        Log.d("testing", response);
        String userid = response.subSequence(13, 17).toString();
        // Log.d("testing", userid);
        saveSharedString("USERID", userid);
        // initialsetup();
        // SensingController.unregisterAlarm(getApplicationContext());
      }

    } catch (Exception e) {
      Log.e(TAG, e.toString());
    }
  }
Exemplo n.º 7
0
  private void getProfileInformation() {
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

        Log.e("GetInfo", currentPerson.toString());

        Gplus_name = currentPerson.getDisplayName();
        Gplus_image = currentPerson.getImage().getUrl();
        Gplus_email = Plus.AccountApi.getAccountName(mGoogleApiClient);
        Gplus_id = currentPerson.getId();
        Log.e("GetInfoID", Gplus_id);

        if (Gplus_id != null) {

          context.runOnUiThread(
              new Runnable() {
                @Override
                public void run() {

                  login_type = "gplus";
                  GlobalClaass.savePrefrencesfor(context, PreferenceConnector.Gplus_ID, Gplus_id);

                  CallFacebookLogin(login_type, Gplus_id, Gplus_email);
                }
              });
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 8
0
  // Called asynchronously -- result of loadPeople() call
  @Override
  public void onResult(People.LoadPeopleResult loadPeopleResult) {
    LOGD(TAG, "onPeopleLoaded, status=" + loadPeopleResult.getStatus().toString());
    if (loadPeopleResult.getStatus().isSuccess()) {
      PersonBuffer personBuffer = loadPeopleResult.getPersonBuffer();
      if (personBuffer != null && personBuffer.getCount() > 0) {
        LOGD(TAG, "Got plus profile for account " + mAccountName);
        Person currentUser = personBuffer.get(0);
        personBuffer.close();

        // Record profile ID, image URL and name
        LOGD(TAG, "Saving plus profile ID: " + currentUser.getId());
        AccountUtils.setPlusProfileId(mAppContext, mAccountName, currentUser.getId());
        String imageUrl = currentUser.getImage().getUrl();
        if (imageUrl != null) {
          imageUrl =
              Uri.parse(imageUrl).buildUpon().appendQueryParameter("sz", "256").build().toString();
        }
        LOGD(TAG, "Saving plus image URL: " + imageUrl);
        AccountUtils.setPlusImageUrl(mAppContext, mAccountName, imageUrl);
        LOGD(TAG, "Saving plus display name: " + currentUser.getDisplayName());
        AccountUtils.setPlusName(mAppContext, mAccountName, currentUser.getDisplayName());
        Person.Cover cover = currentUser.getCover();
        if (cover != null) {
          Person.Cover.CoverPhoto coverPhoto = cover.getCoverPhoto();
          if (coverPhoto != null) {
            LOGD(TAG, "Saving plus cover URL: " + coverPhoto.getUrl());
            AccountUtils.setPlusCoverUrl(mAppContext, mAccountName, coverPhoto.getUrl());
          }
        } else {
          LOGD(TAG, "Profile has no cover.");
        }

        Callbacks callbacks;
        if (null != (callbacks = mCallbacksRef.get())) {
          callbacks.onPlusInfoLoaded(mAccountName);
        }
      } else {
        LOGE(TAG, "Plus response was empty! Failed to load profile.");
      }
    } else {
      LOGE(
          TAG,
          "Failed to load plus proflie, error " + loadPeopleResult.getStatus().getStatusCode());
    }
  }
  /**
   * onConnected is called when our Activity successfully connects to Google Play services.
   * onConnected indicates that an account was selected on the device, that the selected account has
   * granted any requested permissions to our app and that we were able to establish a service
   * connection to Google Play services.
   */
  @Override
  public void onConnected(Bundle connectionHint) {
    final Person user = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

    // The new cordova permission API's are available since Cordova-Android 5,
    // so if you're using API level 23 and want to deploy to Android 6,
    // make sure you're building with Cordova-Android 5 or higher.
    // .. it was either this or adding an Android Support library.
    try {
      Method hasPermissionMethod = cordova.getClass().getMethod("hasPermission", String.class);
      if (hasPermissionMethod != null) {
        if (!(Boolean) hasPermissionMethod.invoke(cordova, Manifest.permission.GET_ACCOUNTS)) {
          Method requestPermissionMethod =
              cordova
                  .getClass()
                  .getMethod("requestPermission", CordovaPlugin.class, int.class, String.class);
          requestPermissionMethod.invoke(
              cordova, this, REQUEST_GET_ACCOUNTS, Manifest.permission.GET_ACCOUNTS);
        }
      }
    } catch (Exception ignore) {
    }

    this.email = Plus.AccountApi.getAccountName(mGoogleApiClient);
    this.result = new JSONObject();

    try {
      result.put("email", email);
      // in case there was no internet connection, this may be null
      if (user != null) {
        result.put("userId", user.getId());
        result.put("displayName", user.getDisplayName());
        result.put("gender", getGender(user.getGender()));
        if (user.getImage() != null) {
          result.put("imageUrl", user.getImage().getUrl());
        }
        if (user.getName() != null) {
          result.put("givenName", user.getName().getGivenName());
          result.put("middleName", user.getName().getMiddleName());
          result.put("familyName", user.getName().getFamilyName());
          if (user.hasAgeRange()) {
            if (user.getAgeRange().hasMin()) {
              result.put("ageRangeMin", user.getAgeRange().getMin());
            }
            if (user.getAgeRange().hasMax()) {
              result.put("ageRangeMax", user.getAgeRange().getMax());
            }
          }
          if (user.hasBirthday()) {
            result.put("birthday", user.getBirthday());
          }
        }
      }
      resolveToken(email, result);
    } catch (JSONException e) {
      savedCallbackContext.error("result parsing trouble, error: " + e.getMessage());
    }
  }
Exemplo n.º 10
0
  private void setUserDetails() {
    if (mGoogleApiClient.isConnected()
        && Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
      Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
      String personName = currentPerson.getDisplayName();
      Person.Image personPhoto = currentPerson.getImage();
      User user = TrailBookState.getCurrentUser();
      if (personPhoto != null) user.profilePhotoUrl = personPhoto.getUrl();

      user.userName = personName;
      TrailBookState.getInstance().setUser(user);
    }
  }
Exemplo n.º 11
0
  // Implements ConnectionCallbacks
  @Override
  public void onConnected(Bundle arg0) {
    // TODO Auto-generated method stub
    Person user = mPlusClient.getCurrentPerson();

    // show The Image
    new DownloadImageTask(imageView).execute(user.getImage().getUrl());

    textViewName.setText(user.getDisplayName());
    textViewUrl.setText(user.getUrl());
    textViewBday.setText(user.getBirthday());
    textViewEmail.setText(user.getEmails() != null ? user.getEmails().get(0).getValue() : "");
    textViewGender.setText(user.getGender() == 0 ? "Male" : "Female");

    buttonSignIn.setVisibility(View.GONE);
    relativeLayout.setVisibility(View.VISIBLE);

    mPlusClient.loadPeople(this, Person.Collection.VISIBLE);
  }
Exemplo n.º 12
0
  @Override
  public void onConnected(Bundle bundle) {
    if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
      BrewSharedPrefs.setIsUserLoggedIn(true);
      Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
      BrewSharedPrefs.setFullName(currentPerson.getDisplayName());
      String personPhoto = currentPerson.getImage().getUrl();

      try {
        URL url = new URL(personPhoto);
        personPhoto = personPhoto.replace(url.getQuery(), "");
      } catch (MalformedURLException e) {
        e.printStackTrace();
      }

      BrewSharedPrefs.setGoolgePlusProfileUrl(currentPerson.getUrl());
      BrewSharedPrefs.setUserProfileImageUrl(personPhoto);
      BrewSharedPrefs.setEmailAddress(Plus.AccountApi.getAccountName(mGoogleApiClient));
      PlusAccountSetup();
    }
  }
Exemplo n.º 13
0
  public void getProfileInformation() {
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        String personName = currentPerson.getDisplayName();
        String personPhotoUrl = currentPerson.getImage().getUrl();
        String personGooglePlusProfile = currentPerson.getUrl();
        String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

        Log.e(
            TAG,
            "Name: "
                + personName
                + ", plusProfile: "
                + personGooglePlusProfile
                + ", email: "
                + email
                + ", Image: "
                + personPhotoUrl);

        profileName.setText(personName);
        profileEmail.setText(email);

        // by default the profile url gives 50x50 px image only
        // we can replace the value with whatever dimension we want by
        // replacing sz=X
        personPhotoUrl =
            personPhotoUrl.substring(0, personPhotoUrl.length() - 2) + PROFILE_PIC_SIZE;

        new LoadProfileImage(imgProfilePic).execute(personPhotoUrl);

      } else {
        Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG)
            .show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 14
0
  /** Fetching user's information name, email, profile picture */
  private void getGGProfileInformation() {
    Log.e(tag, "getGGProfileInformation");
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        String personGooglePlusProfile = currentPerson.getUrl();

        Log.e(tag, currentPerson.toString());

        String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
        String id = currentPerson.getId();
        String name = new String(currentPerson.getDisplayName().getBytes("UTF-8"), "UTF-8");
        String birthday = "";
        if (currentPerson.getBirthday() != null) {
          birthday = currentPerson.getBirthday();
        }
        String gender = currentPerson.getGender() == 1 ? "men" : "women";
        String avatar = currentPerson.getImage().getUrl();
        Log.e(
            tag,
            "Name: "
                + name
                + ", plusProfile: "
                + personGooglePlusProfile
                + ", email: "
                + email
                + ", Image: "
                + avatar
                + ", birthday: "
                + birthday);

        new GGLoginTask().execute(name, email, avatar, gender, birthday, id);
      } else {
        Log.e(tag, "Person information is null");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 15
0
  public Person getCurrentPerson() {

    if (!isConnected()) {
      return null;
    }

    Person person = null;
    String id = "";
    String name = "";
    int gender = Person.GENDER_UNCLASSIFIED;
    String email = "";
    String profileImageLink = "";

    try {

      com.google.android.gms.plus.model.people.Person currentPerson =
          Plus.PeopleApi.getCurrentPerson(getClient());
      id = currentPerson.getId();
      name = currentPerson.getDisplayName();
      gender = currentPerson.getGender();
      email = Plus.AccountApi.getAccountName(getClient());
      profileImageLink = currentPerson.getImage().getUrl();

      if (id == null) id = "";
      if (name == null) name = "";
      if (email == null) email = "";
      if (profileImageLink == null) profileImageLink = "";

      person = new Person(id, name, gender, email, profileImageLink);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return person;
  }
Exemplo n.º 16
0
  /** Fetching user's information name, email, profile pic */
  private void getProfileInformation() {
    try {
      if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
        Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
        // Log.d("getAboutMe", currentPerson.getAboutMe());
        // Log.d("getBirthday", currentPerson.getBirthday());
        // Log.d("getBraggingRights",
        // currentPerson.getBraggingRights());
        // Log.d("getCurrentLocation",
        // currentPerson.getCurrentLocation());
        // Log.d("getDisplayName", currentPerson.getDisplayName());
        // Log.d("getId", currentPerson.getId());
        // Log.d("getLanguage", currentPerson.getLanguage());
        // Log.d("getNickname", currentPerson.getNickname());
        // Log.d("getTagline", currentPerson.getTagline());
        // Log.d("getUrl", currentPerson.getUrl());
        // Log.d("getAgeRange", "" + currentPerson.getAgeRange());
        // Log.d("getCircledByCount",
        // "" + currentPerson.getCircledByCount());
        // Log.d("getCover", "" + currentPerson.getCover());
        // Log.d("getUrls", "" + currentPerson.getUrls());
        // Log.d("getPlacesLived", "" + currentPerson.getPlacesLived());
        // Log.d("getOrganizations", "" +
        // currentPerson.getOrganizations());
        // Log.d("getName", "" + currentPerson.getName());
        // Log.d("getGender", "" + currentPerson.getGender());
        //                Toast.makeText(LoginActivity.this, currentPerson.getDisplayName(),
        // Toast.LENGTH_LONG).show();
        loginName = currentPerson.getDisplayName();
        loginId = currentPerson.getId();
        loginImageUrl = currentPerson.getImage().getUrl();

        loginEmail = Plus.AccountApi.getAccountName(mGoogleApiClient);

        if (AppConstant.isNetworkAvailable(LoginActivity.this)) {
          loginType = 3;
          new LoginTask(loginId, loginName, loginEmail, loginImageUrl, 3).execute();
        } else {
          AppConstant.showNetworkError(LoginActivity.this);
        }

        /*
          Log.e(TAG, "Name: " + personName + ", plusProfile: "
                  + personGooglePlusProfile + ", email: " + email
                  + ", Image: " + personPhotoUrl);

          // by default the profile url gives 50x50 px image only
          // we can replace the value with whatever dimension we want by
          // replacing sz=X
        /* personPhotoUrl = personPhotoUrl.substring(0,
                  personPhotoUrl.length() - 2)
                  + PROFILE_PIC_SIZE;*/
        // email = "";
        //                if (email.equals("")) {
        //                    AppConstant
        //                            .singleButtonAlertDialog(
        //                                    LoginActivity.this,
        //                                    "Error",
        //                                    "Unable to find Email Address from Google Plus.So
        // please register with us  to use this application.");
        //
        //                } else {
        //                    new LoginTask(LoginActivity.this, true, false, personName,
        //                            email, id, personPhotoUrl, dob,
        //                            shouldShowMainActivity, "").execute();
        //                }
      } else {
        Toast.makeText(getApplicationContext(), "Person information is null", Toast.LENGTH_LONG)
            .show();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (null != dialog) {
        if (dialog.isShowing()) {
          dialog.dismiss();
        }
      }
    }
  }
 @Override
 public void OnGSignInComplete(Person mPerson, String emailAddress, String error) {
   progressBar.setVisibility(View.GONE);
   if (mPerson != null) gplusName.setText(mPerson.getDisplayName());
   if (emailAddress != null) gplusEmail.setText(emailAddress);
 }