Exemple #1
1
  private void displayFriendCount() {
    Collection<GraphUser> selectedFriends = HushApp.getSelectedUsers();

    if (selectedFriends == null || selectedFriends.size() == 0) {
      return;
    }
    numFriendsSelected = selectedFriends.size();

    Chatter chatter;
    final ArrayList<String> fbChatterIds = new ArrayList<String>();
    Collection<GraphUser> selection = HushApp.getSelectedUsers();
    for (GraphUser user : selection) {
      chatter = new Chatter(user.getId(), user.getName());
      fbChatterIds.add(user.getId());
      chatter.saveToParse();
      chat.addChatter(chatter);
    }

    // Send a push notification
    chat.saveToParseWithPush(
        this,
        HushPushNotifReceiver.PushType.NEW_CHAT.toString(),
        getString(R.string.new_chat_push_notif_message),
        fbChatterIds);
  }
  /** Build user's info to display on the screen */
  private String buildUserInfoDisplay(GraphUser user) {
    StringBuilder userInfo = new StringBuilder("");

    /** (name) - no special permissions required */
    userInfo.append(String.format("Name: %s\n", user.getName()));

    /** (birthday) - requires user_birthday permission */
    userInfo.append(String.format("Birthday: %s\n", user.getBirthday()));

    /** (location) - requires user_location permission */
    GraphPlace location = user.getLocation();
    if (location != null) {
      userInfo.append(String.format("Location: %s\n", location.getProperty("name")));
    }

    /** (locale) - no special permissions required */
    userInfo.append(String.format("Locale: %s\n", user.getProperty("locale")));

    /** (languages) - requires user_likes permission. */
    JSONArray languages = (JSONArray) user.getProperty("languages");
    if (languages != null && languages.length() > 0) {
      ArrayList<String> languageNames = new ArrayList<String>();
      for (int i = 0; i < languages.length(); i++) {
        JSONObject language = languages.optJSONObject(i);
        languageNames.add(language.optString("name"));
      }
      userInfo.append(String.format("Languages: %s\n", languageNames.toString()));
    }
    return userInfo.toString();
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;

    if (convertView == null) {
      LayoutInflater inflater =
          (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      vi = inflater.inflate(R.layout.item_invitados_list, null);
    }

    GraphUser item = items.get(position);

    ProfilePictureView foto = (ProfilePictureView) vi.findViewById(R.id.fotoPerfil);
    foto.setProfileId(item.getId());

    TextView nombre = (TextView) vi.findViewById(R.id.nombrePerfil);
    nombre.setText(item.getName());

    ImageButton eliminar = (ImageButton) vi.findViewById(R.id.eliminarInvitado);
    // Usamos el SETTAG y despues el GETTAG para saber que botón ha sido pulsado de todos los items
    // que son visibles, y así poder saber que item borrar.
    eliminar.setTag(position);
    eliminar.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (view.getTag() instanceof Integer) {
              deleteItem(((Integer) view.getTag()));
              notifyDataSetChanged();
            }
          }
        });

    return vi;
  }
  private void updateUI() {
    if (!isAdded()) {
      return;
    }
    if (isSessionOpen()) {
      connectedStateLabel.setTextColor(
          getResources().getColor(R.color.com_facebook_usersettingsfragment_connected_text_color));
      connectedStateLabel.setShadowLayer(
          1f,
          0f,
          -1f,
          getResources()
              .getColor(R.color.com_facebook_usersettingsfragment_connected_shadow_color));

      if (user != null) {
        ImageRequest request = getImageRequest();
        if (request != null) {
          URI requestUrl = request.getImageUri();
          // Do we already have the right picture? If so, leave it alone.
          if (!requestUrl.equals(connectedStateLabel.getTag())) {
            if (user.getId().equals(userProfilePicID)) {
              connectedStateLabel.setCompoundDrawables(null, userProfilePic, null, null);
              connectedStateLabel.setTag(requestUrl);
            } else {
              ImageDownloader.downloadAsync(request);
            }
          }
        }
        connectedStateLabel.setText(user.getName());
      } else {
        connectedStateLabel.setText(
            getResources().getString(R.string.com_facebook_usersettingsfragment_logged_in));
        Drawable noProfilePic =
            getResources().getDrawable(R.drawable.com_facebook_profile_default_icon);
        noProfilePic.setBounds(
            0,
            0,
            getResources()
                .getDimensionPixelSize(
                    R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
            getResources()
                .getDimensionPixelSize(
                    R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
        connectedStateLabel.setCompoundDrawables(null, noProfilePic, null, null);
      }
    } else {
      int textColor =
          getResources()
              .getColor(R.color.com_facebook_usersettingsfragment_not_connected_text_color);
      connectedStateLabel.setTextColor(textColor);
      connectedStateLabel.setShadowLayer(0f, 0f, 0f, textColor);
      connectedStateLabel.setText(
          getResources().getString(R.string.com_facebook_usersettingsfragment_not_logged_in));
      connectedStateLabel.setCompoundDrawables(null, null, null, null);
      connectedStateLabel.setTag(null);
    }
  }
  private ImageRequest getImageRequest() {
    ImageRequest request = null;
    try {
      ImageRequest.Builder requestBuilder =
          new ImageRequest.Builder(
              getActivity(),
              ImageRequest.getProfilePictureUrl(
                  user.getId(),
                  getResources()
                      .getDimensionPixelSize(
                          AirFacebookExtension.context.getResourceId(
                              "dimen.com_facebook_usersettingsfragment_profile_picture_width")),
                  getResources()
                      .getDimensionPixelSize(
                          AirFacebookExtension.context.getResourceId(
                              "dimen.com_facebook_usersettingsfragment_profile_picture_height"))));

      request =
          requestBuilder
              .setCallerTag(this)
              .setCallback(
                  new ImageRequest.Callback() {
                    @Override
                    public void onCompleted(ImageResponse response) {
                      processImageResponse(user.getId(), response);
                    }
                  })
              .build();
    } catch (MalformedURLException e) {
    }
    return request;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initHeader();

    findViewById(R.id.registerfacebooktwitter_btn1).setOnClickListener(this);
    findViewById(R.id.registerfacebooktwitter_btn1_twwiter).setOnClickListener(this);
    // TextView textView =
    // (TextView)findViewById(R.id.registerfacebooktwitter_btn1);
    if (user == null) {
      setText(R.id.registerfacebooktwitter_edt1, name);
      findViewById(R.id.registerfacebooktwitter_btn1).setVisibility(View.GONE);
      // textView.setBackgroundResource(R.drawable.diablog_register_button_twitter);

      // textView.setTextAppearance(getContext(),
      // R.style.v3_button_twitter);
      // textView.setText(R.string.v3_register_twwiter);
    } else {
      setText(R.id.registerfacebooktwitter_edt1, user.getName());
      findViewById(R.id.registerfacebooktwitter_btn1_twwiter).setVisibility(View.GONE);
      // textView.setBackgroundResource(R.drawable.diablog_register_button_facebook);
      // textView.setTextAppearance(getContext(),
      // R.style.v3_button_facebook);
      // textView.setText(R.string.v3_register_facebook);
    }

    openPopActivity(findViewById(R.id.forgotpassword_m_main));
  }
 @Override
 public void onCompleted(GraphUser me, Response response) {
   assertNotNull(me);
   assertEquals(session.getTestUserId(), me.getId());
   RequestTests.validateMeResponse(session, response);
   onCompleted(response);
 }
  private void updateUI() {
    Session session = Session.getActiveSession();
    boolean enableButtons = (session != null && session.isOpened());

    postStatusUpdateButton.setEnabled(enableButtons);
    postPhotoButton.setEnabled(enableButtons);
    pickFriendsButton.setEnabled(enableButtons);
    pickPlaceButton.setEnabled(enableButtons);

    if (enableButtons && user != null) {
      profilePictureView.setProfileId(user.getId());
      greeting.setText("Greetings " + user.getFirstName());
    } else {
      profilePictureView.setProfileId(null);
      greeting.setText(null);
    }
  }
  private void updateUI() {
    Session session = Session.getActiveSession();
    boolean enableButtons = (session != null && session.isOpened());

    // postStatusUpdateButton.setEnabled(enableButtons
    // || canPresentShareDialog);
    // postPhotoButton.setEnabled(enableButtons
    // || canPresentShareDialogWithPhotos);
    // pickFriendsButton.setEnabled(enableButtons);
    // pickPlaceButton.setEnabled(enableButtons);
    //
    if (enableButtons && user != null) {
      System.out.println("userid" + user.getId());
      System.out.println("First name" + user.getFirstName());
      System.out.println("email" + user.getProperty("email").toString());
      System.out.println("Birthday:" + user.getBirthday());
      System.out.println("GENDER" + user.getBirthday());
      System.out.println("Location:" + user.getLocation());

      System.out.println("JSON:" + user.getInnerJSONObject());

    } else {
      System.out.println("Userinfo is null");
    }
  }
 /** Update user's profile info */
 private void updateUI() {
   if (mUser != null) {
     mUserInfo.setText(buildUserInfoDisplay(mUser));
     mProfilePictureView.setProfileId(mUser.getId());
   } else {
     mUserInfo.setText(null);
     mProfilePictureView.setProfileId(null);
   }
 }
 public void syncFbFriends(View v) {
   ArrayList<Contact> contacts = (ArrayList) MainActivity.db.dbGetAllContacts();
   GraphObjectList<GraphUser> fbFriends = FbLoginFragment.fbObjectList;
   URL url = null;
   for (GraphUser usr : fbFriends) {
     for (Contact contData : contacts) {
       if (contData.getFirstName() == usr.getFirstName()) {
         if (contData.getLastName() == usr.getLastName()) {
           //                        try {
           //                            url = new URL("http://graph.facebook.com/" + "");
           //                        } catch (MalformedURLException){
           //
           //                        }
         }
       }
     }
   }
 }
    private byte[] getByteArray(ArrayList<GraphUser> users) {
      // convert the list of GraphUsers to a list of String
      // where each element is the JSON representation of the
      // GraphUser so it can be stored in a Bundle
      ArrayList<String> usersAsString = new ArrayList<String>(users.size());

      for (GraphUser user : users) {
        usersAsString.add(user.getInnerJSONObject().toString());
      }
      try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        new ObjectOutputStream(outputStream).writeObject(usersAsString);
        return outputStream.toByteArray();
      } catch (IOException e) {
        Log.e(TAG, "Unable to serialize users.", e);
      }
      return null;
    }
  private void onFriendPickerDone(FriendPickerFragment fragment) {
    FragmentManager fm = getSupportFragmentManager();
    fm.popBackStack();

    String results = "";

    Collection<GraphUser> selection = fragment.getSelection();
    if (selection != null && selection.size() > 0) {
      ArrayList<String> names = new ArrayList<String>();
      for (GraphUser user : selection) {
        names.add(user.getName());
      }
      results = TextUtils.join(", ", names);
    } else {
      results = "no friends";
    }

    showAlert("rar", results);
  }
 @Override
 public void onCompleted(GraphUser user, Response response) {
   // TODO Auto-generated method stub
   view.dismissLoading();
   if (user == null) {
     view.showError(response.getError().getErrorMessage());
   } else {
     l.d("facebook login result : " + user.getInnerJSONObject().toString());
     SNSLoginData data = app().getUserConfig().loginData;
     data.nickName = user.getLastName() + user.getFirstName();
     data.sns = EXTRA_AUTO_LOGIN_FACEBOOK;
     data.snsHome = user.getLink();
     data.userId = (String) user.getProperty("email");
     try {
       data.profileImage =
           ImageRequest.getProfilePictureUrl(
                   user.getId(),
                   FacebookModel.PROFILE_IMAGE_SIZE,
                   FacebookModel.PROFILE_IMAGE_SIZE)
               .toString();
     } catch (MalformedURLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     prefModel.setAutoLogin(true);
     prefModel.setAutoLoginAction(EXTRA_AUTO_LOGIN_FACEBOOK);
     loginModel.loginSNS(data);
   }
 }
 @JavascriptInterface
 public String getUserId() {
   if (userInfo == null) return null;
   return userInfo.getId();
 }
  @Override
  public void onClick(View v) {
    String name = getTextStr(R.id.registerfacebooktwitter_edt1);
    final String email = getTextStr(R.id.registerfacebooktwitter_edt2);
    final String password = getTextStr(R.id.registerfacebooktwitter_edt3);
    String repassword = getTextStr(R.id.registerfacebooktwitter_edt3);

    String message = null;

    if (ByUtils.isBlank(name)) {
      message = getContext().getResources().getString(R.string.error_message_input_name);
    }

    if (ByUtils.isBlank(email)) {
      message = getContext().getResources().getString(R.string.error_message_input_email);
    }

    if (ByUtils.isBlank(password)) {
      message = getContext().getResources().getString(R.string.error_message_input_password);
    }

    if (!password.equals(repassword)) {
      message =
          getContext().getResources().getString(R.string.error_message_check_passwordandrepassword);
    }

    if (message != null) {
      CommonAndroid.showDialog(getContext(), message, null);
      return;
    }

    Map<String, String> sendData = new HashMap<String, String>();
    if (user != null) {
      sendData.put("type", "2");
      sendData.put("id", user.getId());
    } else {
      sendData.put("type", "1");
      sendData.put("id", id);
    }

    sendData.put("user", name);
    sendData.put("email", email);
    sendData.put("name", name);
    sendData.put("password", password);
    sendData.put("repassword", repassword);

    APICaller apiCaller = new APICaller(getContext());
    ICallbackAPI callbackAPI =
        new ICallbackAPI() {

          @Override
          public void onSuccess(String response) {
            try {
              JSONObject jsonObject = new JSONObject(response);
              if (jsonObject.getString("status").equals("1")) {
                AccountDB accountDB = new AccountDB(getContext());
                accountDB.save("email", email);
                accountDB.save("password", password);
                accountDB.save(response);
                GcmBroadcastReceiver.register(getContext());
                clickListener.onClick(null, 0);
                dismiss();
              } else {
                CommonAndroid.showDialog(getContext(), jsonObject.getString("message"), null);
              }
            } catch (Exception e) {
              CommonAndroid.showDialog(
                  getContext(),
                  getContext().getResources().getString(R.string.error_message_register_fail),
                  null);
            }
          }

          @Override
          public void onError(String message) {
            CommonAndroid.showDialog(
                getContext(),
                getContext().getResources().getString(R.string.error_message_register_fail),
                null);
          }
        };
    apiCaller.callApi("/user/register", true, callbackAPI, sendData);
  }