0

In Contacts Tab, trying to fetch list of all Facebook Friends

In Month Tab, trying to fetch list of Facebook Friends those Birthdays in Current Month

In Week Tab, trying to fetch list of Facebook Friends those Birthdays in Current Week

I have written code for all and i am not getting any error while build and run my program, but i am not getting list of friends in any of the Tab.

Please let me know, where i am doing silly mistake...where i am missing..

TabSample.Java :-

public class TabSample extends TabActivity {

String response;

private static JSONArray jsonArray;
public static TabHost mTabHost;
private MyFacebook fb = MyFacebook.getInstance();
public static MyLocalDB db = null;
private BcReceiver bcr = null;
private BcReceiverAlarm bcra = null;
private PendingIntent mAlarmSender;
private boolean isAlarmSet;
private ProgressDialog busyDialog;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAlarmSender = PendingIntent.getService(TabSample.this, 0, new Intent(
            TabSample.this, BdRemService.class), 0);
    setContentView(R.layout.main);
    if (db == null) {
        db = new MyLocalDB(this);
        db.open();
    }
    if (!fb.isReady()) {
        Log.v(TAG, "TabSample- initiating facebook");
        fb.init(this);// after finishing, this will call loadContents itself
    } else {
        loadContents();
    }
    busyDialog = new ProgressDialog(this);
    busyDialog.setIndeterminate(true);
    busyDialog.setMessage("Refreshing");
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        return;
    }
    response = getIntent().getStringExtra("FRIENDS");
    try {
        jsonArray = new JSONArray(response);
    } catch (JSONException e) {
        FacebookUtility.displayMessageBox(this,
        this.getString(R.string.json_failed));
    }
    setTabs();

}
private void setTabs() {

    addTab("Contacts", com.chr.tatu.sample.friendslist.ContactTab.class);
    addTab("Month", com.chr.tatu.sample.friendslist.MonthTab.class);
    addTab("Week", com.chr.tatu.sample.friendslist.WeekTab.class);

}
private void setupTabHost() {
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();

}
private void setupTab(final View view, final String tag, Intent intent,
        int id) {
    View tabview = createTabView(mTabHost.getContext(), tag, id);
    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
    .setContent(intent);
    mTabHost.addTab(setContent);
}
private void addTab(String labelId, Class<?> c) {
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    intent.putExtra("FRIENDS", response);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
    View tabIndicator = LayoutInflater.from(this).inflate(
    R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
}
private static View createTabView(final Context context, final String text,
final int id) 
{
    View view = LayoutInflater.from(context).inflate(
    R.layout.tab_indicator, null);
    return view;
}
@Override
protected void onResume() {
if (bcr == null) {
    bcr = new BcReceiver();
    registerReceiver(bcr, new IntentFilter(MyUtils.BIRTHDAY_ALERT));
}
if (bcra == null) {
    bcra = new BcReceiverAlarm();
    registerReceiver(bcra, new IntentFilter(MyUtils.ALARM_RESET));
}
super.onResume();
}
public void loadContents() {
if (fb.getFriendsCount() > 0) {
    return;
}
fb.setMyFriends(db.getAllFriends());
if (fb.getFriendsCount() > 0) {
    notifyTabSample(Note.FRIENDLIST_CHANGED);
} else {
    fb.reLoadAllFriends();
}
// 4. initiate alarm
if (!isAlarmSet) {
    setAlarm(true);
}
}
private void setAlarm(boolean isON) {
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
if (isON) {
    am.setRepeating(AlarmManager.RTC_WAKEUP, MyUtils
            .getAlarmStartTimeAsLong(MyUtils.getAlarmHour(), MyUtils
                    .getAlarmMinute()), 24 * 60 * 60 * 1000,
            mAlarmSender);
    isAlarmSet = true;
    Log.v(TAG, "TabSample- alarm set");
} else {
    am.cancel(mAlarmSender);
    isAlarmSet = true;
    Log.v(TAG, "TabSample- alarm cancelled");
}
}
public void notifyTabSample(Note what) {
switch (what) {
case FRIENDLIST_RELOADED:
    db.syncFriends(fb.getMyFriends());
    sendBroadcast(new Intent(MyUtils.FRIENDLIST_CHANGED));
    break;
case FRIENDLIST_CHANGED:
    sendBroadcast(new Intent(MyUtils.FRIENDLIST_CHANGED));
    // setup timer
    break;
default:
    break;
}
}

ContactTab.Java :-

public class ContactTab extends ListActivity {
private MyFacebook fb = MyFacebook.getInstance();
private BcReceiver bcr = null;
private MyAdapter adapter;
private List<MyFriend> list;
private ProgressDialog busyDialog;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    busyDialog = new ProgressDialog(this);
    busyDialog.setIndeterminate(true);
    busyDialog.setMessage("Refreshing");
}

private void refreshList() {

    new Thread() {
        public void run() {
            list = fb.getAllFriends();
            Log.v(TAG, "contactstab- refresh called. " + list.size());
            adapter = new MyAdapter(ContactTab.this, list);
            handler.sendEmptyMessage(0);
        }
    }.start();
}

@Override
protected void onResume() {
    if (bcr == null) {
        bcr = new BcReceiver();
        registerReceiver(bcr, new IntentFilter(MyUtils.FRIENDLIST_CHANGED));
    }
    refreshList();
    super.onResume();
}

@Override

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    MyFriend friend = (MyFriend) this.getListAdapter().getItem(position);

    Intent intent = new Intent(ContactTab.this, PersonalGreeting.class);
    intent.putExtra("fbID", friend.getFbID());
    intent.putExtra("name", friend.getName());
    intent.putExtra("pic", friend.getPic());
    startActivity(intent);
}

public boolean onCreateOptionsMenu(Menu menu) {
    new MenuInflater(getApplication()).inflate(R.layout.menu, menu);
    return (super.onPrepareOptionsMenu(menu));
}

public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;
    switch (item.getItemId()) {
    case R.id.globalGreeting:
        intent = new Intent(ContactTab.this, com.chr.tatu.sample.friendslist.GlobalGreeting.class);
        startActivity(intent);
        break;
    case R.id.Settings:
        intent = new Intent(ContactTab.this, com.chr.tatu.sample.friendslist.Settings.class);
        startActivity(intent);
    }
    return (super.onOptionsItemSelected(item));
}

public class BcReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        runOnUiThread(new Runnable() {
            public void run() {
                refreshList();
            }
        });
    }
}

private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        setListAdapter(adapter);
        //busyDialog.dismiss();
    }
};
   }

MonthTab.Java :-

public class MonthTab extends ListActivity {
private MyFacebook fb = MyFacebook.getInstance();
private BcReceiver bcr = null;
private MyAdapter adapter;
private List<MyFriend> list;
private ProgressDialog busyDialog;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    busyDialog = new ProgressDialog(this);
    busyDialog.setIndeterminate(true);
    busyDialog.setMessage("Please wait ...");
    busyDialog.show();
    refreshList();
}

private void refreshList() {
    // list = fb.getFilteredFriends(Filter.MONTH);
    list = fb.getFilteredFriends(Filter.MONTH);
    adapter = new MyAdapter(MonthTab.this, list);
    setListAdapter(adapter);
    busyDialog.dismiss();
}

@Override
protected void onResume() {
    if (bcr == null) {
        bcr = new BcReceiver();
        registerReceiver(bcr, new IntentFilter(MyUtils.FRIENDLIST_CHANGED));
    }
    super.onResume();
}

@Override
@SuppressWarnings("unchecked")
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    MyFriend friend = (MyFriend) this.getListAdapter().getItem(position);

    Intent intent = new Intent(MonthTab.this, PersonalGreeting.class);
    intent.putExtra("fbID", friend.getFbID());
    intent.putExtra("name", friend.getName());
    startActivity(intent);
}

public boolean onCreateOptionsMenu(Menu menu) {
    new MenuInflater(getApplication()).inflate(R.layout.menu, menu);
    return (super.onPrepareOptionsMenu(menu));
}

public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;
    switch (item.getItemId()) {
    case R.id.globalGreeting:
        intent = new Intent(MonthTab.this, GlobalGreeting.class);
        startActivity(intent);
        break;
    case R.id.Settings:
        intent = new Intent(MonthTab.this, Settings.class);
        startActivity(intent);
    }
    return (super.onOptionsItemSelected(item));
}

public class BcReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        runOnUiThread(new Runnable() {
            public void run() {
                refreshList();
            }
        });
    }
}
   }
Liza
  • 227
  • 2
  • 16
  • 1
    have you got any exception or error in your logcat?if any,please post it for a better view of your question. – AndroidLearner Jan 21 '13 at 06:23
  • @AndroidLearner no i did not get any error, it is the main reason i am not able to understand the problem.... – Liza Jan 21 '13 at 06:53
  • Have you set INTERNET Permissions in your manifest file? – AndroidLearner Jan 21 '13 at 06:55
  • @AndroidLearner friend i have made 4 tabs, in 3 out of 4 i am not getting ListView in Tabs, but in 1st tab i am getting data, but these three tabs belongs to another sample which i have included in my existing project, if i will run same sample code which i have downloaded then i am getting data in that also but like i said i am using two different programs in one therefore only i am getting some minor problem but don't know what??? – Liza Jan 21 '13 at 07:03
  • @AndroidLearner see this question: http://stackoverflow.com/questions/14373862/current-month-facebook-friends-birthdays-in-android i did not get any solution to get Current Month Facebook Friends Birthdays that's why only i have inserted another sample code in my existing one.. – Liza Jan 21 '13 at 07:11
  • That means are you adding `FRIENDS` tab dynamically in your layout? – AndroidLearner Jan 21 '13 at 07:14
  • try without adding `FRIENDS` tab and see what happens :) – AndroidLearner Jan 21 '13 at 07:25
  • @Liza deleted your yahoo mail id...??? – Wolverine Jan 21 '13 at 11:35

0 Answers0