Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import com.actionbarsherlock.app.ActionBar;
- import com.actionbarsherlock.app.SherlockActivity;
- import com.dzinesunlimited.sociallyyou.BaseRequestListener;
- import com.dzinesunlimited.sociallyyou.R;
- import com.dzinesunlimited.sociallyyou.UsersProfile;
- import com.dzinesunlimited.sociallyyou.Utility;
- import com.facebook.sdk.FacebookError;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.graphics.PixelFormat;
- import android.os.Bundle;
- import android.os.StrictMode;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.EditText;
- import android.widget.GridView;
- import android.widget.Toast;
- public class TagFriends extends SherlockActivity {
- ProgressDialog dialog;
- protected String graph_or_fql;
- private JSONArray JAFriends;
- JSONObject json_data;
- protected JSONArray jsonArray;
- TagFriendsAdapter adapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
- setProgressBarIndeterminateVisibility(true);
- setContentView(R.layout.tag_friends_list);
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- ActionBar actionBar = getSupportActionBar();
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setDisplayShowHomeEnabled(true);
- actionBar.setDisplayShowTitleEnabled(true);
- actionBar.setTitle("Friends List");
- // Hide the On-screen Keyboard when loading the activity
- hideKeyboard();
- ArrayList<Friends> listOfFriends = getFriends();
- final GridView grid = (GridView) findViewById(R.id.gridFriends);
- adapter = new TagFriendsAdapter(this, listOfFriends);
- grid.setAdapter(adapter);
- setProgressBarIndeterminateVisibility(false);
- EditText filterText = (EditText) findViewById(R.id.editFilterList);
- filterText.addTextChangedListener(filterTextWatcher);
- }
- private TextWatcher filterTextWatcher = new TextWatcher() {
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- adapter.getFilter().filter(s.toString().toLowerCase());
- adapter.notifyDataSetChanged();
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count,
- int after) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- };
- private ArrayList<Friends> getFriends() {
- ArrayList<Friends> results = new ArrayList<TagFriends.Friends>();
- Friends friends = new Friends();
- try {
- // MAKE THE CALL TO THE FQL TABLE
- graph_or_fql = "fql";
- String query = "select name, uid, pic_big from user where uid in (select uid2 from friend where uid1=me()) order by name";
- Bundle params = new Bundle();
- params.putString("method", "fql.query");
- params.putString("query", query);
- String response = Utility.mFacebook.request(params);
- // Log.e("response", response);
- JAFriends = new JSONArray(response);
- // Log.e("JAFriends", JAFriends.toString());
- for (int i = 0; i < JAFriends.length(); i++) {
- json_data = JAFriends.getJSONObject(i);
- // Log.d("json_data", json_data.toString());
- friends = new Friends();
- if (json_data.has("uid")) {
- String getFriendID = json_data.getString("uid");
- friends.setID(getFriendID);
- // Log.d("ID", friends.getID());
- } else {
- String getFriendID = null;
- // Log.d("ID", getFriendID);
- }
- if (json_data.has("name")) {
- String getFriendName = json_data.getString("name");
- friends.setName(getFriendName);
- // Log.e("NAME", friends.getName());
- } else {
- String getFriendName = null;
- // Log.e("NAME", getFriendName);
- }
- if (json_data.has("pic_big")) {
- String getFriendPhoto = json_data.getString("pic_big");
- friends.setPicture(getFriendPhoto);
- // Log.e("COVER", friends.getPicture());
- } else {
- String getFriendPhoto = null;
- // Log.e("COVER", getFriendPhoto);
- }
- results.add(friends);
- }
- // Utility.mAsyncRunner.request(null, params, new GetFriendsForTagging());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return results;
- }
- class Friends {
- private String userID = "";
- private String userName = "";
- private String userPicture = "";
- // USER ID
- public void setID(String userID) {
- this.userID = userID;
- }
- public String getID() {
- return userID;
- }
- // USER NAME
- public void setName(String userName) {
- this.userName = userName;
- }
- public String getName() {
- return userName;
- }
- // USER PICTURE
- public void setPicture(String userPicture) {
- this.userPicture = userPicture;
- }
- public String getPicture() {
- return userPicture;
- }
- }
- public class ProfileListener extends BaseRequestListener {
- private String userID;
- private String userName;
- private String userProfilePicture;
- private String userRelationshipStatus;
- private String userSignificantOtherName;
- private String userSignificantOtherID;
- private String userSignificantOtherPic;
- private String userBirthDay;
- private String userGender;
- private String userLanguages;
- private String userLink;
- private String userEmail;
- private String userWebsite;
- private String userBio;
- private StringBuilder langBuilder;
- @Override
- public void onComplete(final String response, final Object state) {
- // Log.e("PROFILE DATA", response);
- try {
- JSONObject jsonObject = new JSONObject(response);
- if (jsonObject.has("id")) {
- userID = jsonObject.getString("id");
- // Log.v("ID", userID);
- } else {
- userID = null;
- // Log.v("ID", userID);
- }
- if (jsonObject.has("name")) {
- userName = jsonObject.getString("name");
- // Log.v("NAME", userName);
- } else {
- userName = null;
- // Log.v("NAME", userName);
- }
- userProfilePicture = "https://graph.facebook.com/"+ userID
- + "/picture?type=large" + "&access_token=" + Utility.mFacebook.getAccessToken();
- // Log.v("PROFILE PICTURE", userProfilePicture);
- if (jsonObject.has("relationship_status")) {
- userRelationshipStatus = jsonObject.getString("relationship_status");
- // Log.v("RELATIONSHIP STATUS", userRelationshipStatus);
- if (jsonObject.has("significant_other")) {
- JSONObject joSignificantOther = jsonObject.optJSONObject("significant_other");
- userSignificantOtherName = joSignificantOther.getString("name");
- userSignificantOtherID = joSignificantOther.getString("id");
- userSignificantOtherPic = "https://graph.facebook.com/"+ userSignificantOtherID
- + "/picture?type=square" + "&access_token=" + Utility.mFacebook.getAccessToken();
- // Log.v("SIGNIFICANT OTHER NAME", userSignificantOtherName);
- // Log.v("SIGNIFICANT OTHER ID", userSignificantOtherID);
- // Log.v("SIGNIFICANT OTHER PICTURE", userSignificantOtherPic);
- } else {
- userSignificantOtherName = null;
- userSignificantOtherID = null;
- userSignificantOtherPic = null;
- // Log.v("SIGNIFICANT OTHER NAME", userSignificantOtherName);
- // Log.v("SIGNIFICANT OTHER ID", userSignificantOtherID);
- // Log.v("SIGNIFICANT OTHER PICTURE", userSignificantOtherPic);
- }
- } else {
- userRelationshipStatus = null;
- // Log.v("RELATIONSHIP STATUS", userRelationshipStatus);
- }
- if (jsonObject.has("birthday")) {
- userBirthDay = jsonObject.getString("birthday");
- // Log.v("BIRTHDAY", userBirthDay);
- } else {
- userBirthDay = null;
- // Log.v("BIRTHDAY", userBirthDay);
- }
- if (jsonObject.has("gender")) {
- userGender = jsonObject.getString("gender");
- // Log.v("GENDER", userGender);
- } else {
- userGender = null;
- // Log.v("GENDER", userGender);
- }
- if (jsonObject.has("languages")) {
- JSONArray jaLang = jsonObject.getJSONArray("languages");
- langBuilder = new StringBuilder();
- for(int i = 0; i < jaLang.length(); i ++) {
- JSONObject json_data = jaLang.getJSONObject(i);
- langBuilder.append((json_data.getString("name")) + (" ") );
- }
- userLanguages = langBuilder.toString();
- // Log.v("LANGUAGES", userLanguages);
- } else {
- userLanguages = null;
- // Log.v("LANGUAGES", userLanguages);
- }
- if (jsonObject.has("link")) {
- userLink = jsonObject.getString("link");
- // Log.v("LINK", userLink);
- } else {
- userLink = null;
- // Log.v("LINK", userLink);
- }
- if (jsonObject.has("email")) {
- userEmail = jsonObject.getString("email");
- // Log.v("EMAIL", userEmail);
- } else {
- userEmail = null;
- // Log.v("EMAIL", userEmail);
- }
- if (jsonObject.has("website")) {
- userWebsite = jsonObject.getString("website");
- // Log.v("WEBSITE", userWebsite);
- // } else {
- userWebsite = null;
- // Log.v("WEBSITE", userWebsite);
- }
- if (jsonObject.has("bio")) {
- userBio = jsonObject.getString("bio");
- // Log.v("BIO", userBio);
- } else {
- userBio = null;
- // Log.v("BIO", userBio);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- Intent myIntent = new Intent(getApplicationContext(), UsersProfile.class);
- myIntent.putExtra("USER_ID", userID);
- myIntent.putExtra("USER_NAME", userName);
- myIntent.putExtra("USER_PROFILE_PICTURE", userProfilePicture);
- myIntent.putExtra("USER_RELATIONSHIP_STATUS", userRelationshipStatus);
- myIntent.putExtra("USER_SIGNIFICANT_OTHER_NAME", userSignificantOtherName);
- myIntent.putExtra("USER_SIGNIFICANT_OTHER_ID", userSignificantOtherID);
- myIntent.putExtra("USER_SIGNIFICANT_OTHER_PROFILE_PICTURE", userSignificantOtherPic);
- myIntent.putExtra("USER_BIRTHDAY", userBirthDay);
- myIntent.putExtra("USER_GENDER", userGender);
- myIntent.putExtra("USER_LANGUAGES", userLanguages);
- myIntent.putExtra("USER_LINK", userLink);
- myIntent.putExtra("USER_EMAIL", userEmail);
- myIntent.putExtra("USER_WEBSITE", userWebsite);
- myIntent.putExtra("USER_BIO", userBio);
- dialog.dismiss();
- startActivity(myIntent);
- }
- public void onFacebookError(FacebookError error) {
- dialog.dismiss();
- Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),
- Toast.LENGTH_SHORT).show();
- }
- }
- private void hideKeyboard() {
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
- }
- @Override
- public void onAttachedToWindow() {
- super.onAttachedToWindow();
- Window window = getWindow();
- window.setFormat(PixelFormat.RGBA_8888);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement