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;
  }
  @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));
  }
  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 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);
  }