From 5f47be86b2c31c16e3be12b9ac19e72514cd2a2e Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 20 Feb 2012 19:07:40 -0800 Subject: [PATCH] Skeleton for fragment pager adapter --- .../adapter/TaskListFragmentPagerAdapter.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java new file mode 100644 index 000000000..9e51001a6 --- /dev/null +++ b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java @@ -0,0 +1,55 @@ +package com.todoroo.astrid.adapter; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; + +import com.todoroo.astrid.activity.TaskListFragment; +import com.todoroo.astrid.api.Filter; +import com.todoroo.astrid.api.FilterWithCustomIntent; + +public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter { + + private final Filter[] filters; + + public TaskListFragmentPagerAdapter(FragmentManager fm, Filter[] filters) { + super(fm); + this.filters = filters; + } + + @Override + public Fragment getItem(int position) { + return getFragmentForFilter(filters[position]); + } + + @Override + public int getCount() { + return filters.length; + } + + private Fragment getFragmentForFilter(Filter filter) { + if (filter instanceof FilterWithCustomIntent) { + try { + Class component = Class.forName(((FilterWithCustomIntent) filter).customTaskList.getClassName()); + Constructor constructor = component.getConstructor(Boolean.class, Filter.class); + return (Fragment) constructor.newInstance(true, filter); + } catch (NoSuchMethodException e) { + return new TaskListFragment(); + } catch (InvocationTargetException e) { + return new TaskListFragment(); + } catch (ClassNotFoundException e) { + return new TaskListFragment(); + } catch (IllegalAccessException e) { + return new TaskListFragment(); + } catch (InstantiationException e) { + return new TaskListFragment(); + } + } else { + return new TaskListFragment(); + } + } + +}