com.commonsware.cwac.pager.PageDescriptor Java Examples

The following examples show how to use com.commonsware.cwac.pager.PageDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 6 votes vote down vote up
public void insert(PageDescriptor desc, int position) {
  validatePageDescriptor(desc);

  positionDelta.clear();

  for (int i=position; i < entries.size(); i++) {
    Fragment f=getExistingFragment(i);

    if (f != null) {
      positionDelta.put(f, i + 1);
    }
  }

  entries.add(position, new PageEntry(desc));
  notifyDataSetChanged();
}
 
Example #2
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public ArrayPagerAdapter(FragmentManager fragmentManager,
                         List<PageDescriptor> descriptors,
                         RetentionStrategy retentionStrategy) {
    this.fm = fragmentManager;
    this.entries = new ArrayList<PageEntry>();

    for (PageDescriptor desc : descriptors) {
        validatePageDescriptor(desc);

        entries.add(new PageEntry(desc));
    }

    this.retentionStrategy = retentionStrategy;

    if (this.retentionStrategy == null) {
        this.retentionStrategy = KEEP;
    }
}
 
Example #3
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 6 votes vote down vote up
public ArrayPagerAdapter(FragmentManager fragmentManager,
                         List<PageDescriptor> descriptors,
                         RetentionStrategy retentionStrategy) {
  this.fm=fragmentManager;
  this.entries=new ArrayList<PageEntry>();

  for (PageDescriptor desc : descriptors) {
    validatePageDescriptor(desc);

    entries.add(new PageEntry(desc));
  }

  this.retentionStrategy=retentionStrategy;

  if (this.retentionStrategy == null) {
    this.retentionStrategy=KEEP;
  }
}
 
Example #4
Source File: MenuActivity.java    From utexas-utilities with Apache License 2.0 6 votes vote down vote up
private void initialisePaging(String restId) {
        ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
        int pagesDisplayed = getResources().getInteger(R.integer.menu_num_visible_pages);
        List<PageDescriptor> pages = new ArrayList<>();
        pages.add(new MenuPageDescriptor("Breakfast", restId));
        pages.add(new MenuPageDescriptor("Lunch", restId));
        pages.add(new MenuPageDescriptor("Dinner", restId));
        mPagerAdapter = new MenuPagerAdapter(getSupportFragmentManager(), pages);
        mPagerAdapter.setPagesDisplayed(pagesDisplayed);

        pager.setAdapter(mPagerAdapter);
        // TODO: reimplement selectAll hack with design support library
//        if (pagesDisplayed > 1) {
//            tabIndicator.setSelectAll(true);
//        }
        ((TabLayout) findViewById(R.id.tabs)).setupWithViewPager(pager);
        float elevationPx = getResources().getDimensionPixelSize(R.dimen.actionbar_elevation);
        ViewCompat.setElevation(findViewById(R.id.tabs), elevationPx);
        ViewCompat.setElevation(findViewById(R.id.open_times), elevationPx);

        pager.setOffscreenPageLimit(2);
        pager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.pager_margin));
    }
 
Example #5
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void insert(PageDescriptor desc, int position) {
    validatePageDescriptor(desc);

    positionDelta.clear();

    for (int i = position; i < entries.size(); i++) {
        Fragment f = getExistingFragment(i);

        if (f != null) {
            positionDelta.put(f, i + 1);
        }
    }

    entries.add(position, new PageEntry(desc));
    notifyDataSetChanged();
}
 
Example #6
Source File: BalanceActivity.java    From utexas-utilities with Apache License 2.0 6 votes vote down vote up
private void initialisePaging() {
        List<PageDescriptor> pages = new ArrayList<>();
        pages.add(new TransactionsPageDescriptor("Dine In", TransactionType.Dinein,
                TRANSACTIONS_URL));
        pages.add(new TransactionsPageDescriptor("Bevo Bucks", TransactionType.Bevo,
                TRANSACTIONS_URL));
        mPagerAdapter = new TransactionsPagerAdapter(getSupportFragmentManager(), pages, this);
        mPagerAdapter.setPagesDisplayed(pagesDisplayed);

        pager.setAdapter(this.mPagerAdapter);
        pager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.pager_margin));
        // TODO: reimplement selectAll hack with design support library
//        if (pagesDisplayed > 1) {
//            tabIndicator.setSelectAll(true);
//        }
        ((TabLayout) findViewById(R.id.tabs)).setupWithViewPager(pager);
        float elevationPx = getResources().getDimensionPixelSize(R.dimen.actionbar_elevation);
        ViewCompat.setElevation(findViewById(R.id.tabs), elevationPx);

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        pager.setCurrentItem(Integer.parseInt(sp.getString("default_balance_tab", "0")));
    }
 
Example #7
Source File: ScheduleActivity.java    From utexas-utilities with Apache License 2.0 6 votes vote down vote up
private void initialisePaging() {
        List<PageDescriptor> pages = new ArrayList<>();
        pages.add(new SimplePageDescriptor("Exam Schedule", "Exam Schedule"));
        pages.add(new CourseSchedulePageDescriptor(true, "Current Schedule",
                DEFAULT_COURSE_SCHEDULE_URL));
        mPagerAdapter = new SchedulePagerAdapter(getSupportFragmentManager(), pages, this);
        pager.setPageMargin(2);
        pager.setOffscreenPageLimit(2);
        pager.setAdapter(mPagerAdapter);
        pager.addOnPageChangeListener(this);
        pager.setCurrentItem(1, false);

//        titleIndicator.setOnPageChangeListener(this);
//        ((PagerTabStrip) findViewById(R.id.titles)).no
        PagerTabStrip titleIndicator = (PagerTabStrip) findViewById(R.id.tabs);
        ViewCompat.setElevation(titleIndicator, getResources().getDimensionPixelSize(R.dimen.actionbar_elevation));
    }
 
Example #8
Source File: BottomPageAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected Fragment createFragment(PageDescriptor desc) {
    if (desc.getFragmentTag().equals(MessageFragment.TAG)) {
        return MessageFragment.newInstance();
    } else if (desc.getFragmentTag().equals(DiagnosticFragment.TAG)) {
        return DiagnosticFragment.newInstance();
    }
    return null;
}
 
Example #9
Source File: MainActivity.java    From cwac-pager with Apache License 2.0 5 votes vote down vote up
private ArrayPagerAdapter<EditorFragment> buildAdapter() {
  ArrayList<PageDescriptor> pages=new ArrayList<PageDescriptor>();

  for (int i=0; i < 10; i++) {
    pages.add(new SimplePageDescriptor(buildTag(i), buildTitle(i)));
  }

  return(new SamplePagerAdapter(getSupportFragmentManager(), pages));
}
 
Example #10
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 5 votes vote down vote up
private void validatePageDescriptor(PageDescriptor desc) {
  for (PageEntry entry : entries) {
    if (desc.getFragmentTag().equals(entry.getDescriptor()
                                          .getFragmentTag())) {
      throw new IllegalArgumentException(
                                         "PageDescriptor tag not unique: "
                                             + desc.getFragmentTag());
    }
  }
}
 
Example #11
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 5 votes vote down vote up
public void move(int oldPosition, int newPosition) {
  if (oldPosition != newPosition) {
    PageDescriptor desc=getPageDescriptor(oldPosition);

    remove(oldPosition);
    insert(desc, newPosition);
  }
}
 
Example #12
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 5 votes vote down vote up
public void add(PageDescriptor desc) {
  validatePageDescriptor(desc);

  positionDelta.clear();
  entries.add(new PageEntry(desc));
  notifyDataSetChanged();
}
 
Example #13
Source File: MainActivity.java    From cwac-pager with Apache License 2.0 5 votes vote down vote up
private ArrayPagerAdapter<EditorFragment> buildAdapter() {
  ArrayList<PageDescriptor> pages=new ArrayList<PageDescriptor>();

  for (int i=0; i < 10; i++) {
    pages.add(new SimplePageDescriptor(buildTag(i), buildTitle(i)));
  }

  return(new SamplePagerAdapter(getFragmentManager(), pages));
}
 
Example #14
Source File: ScheduleActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
@Override
protected ScheduleFragment createFragment(PageDescriptor pageDescriptor) {
    if (pageDescriptor instanceof CourseSchedulePageDescriptor) {
        CourseSchedulePageDescriptor coursePage =
                (CourseSchedulePageDescriptor) pageDescriptor;
        return CourseScheduleFragment.newInstance(coursePage.isCurrentSemester(),
                coursePage.getUrl());
    } else {
        return ExamScheduleFragment.newInstance();
    }
}
 
Example #15
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private void validatePageDescriptor(PageDescriptor desc) {
    for (PageEntry entry : entries) {
        if (desc.getFragmentTag().equals(entry.getDescriptor()
                .getFragmentTag())) {
            throw new IllegalArgumentException(
                    "PageDescriptor tag not unique: "
                            + desc.getFragmentTag());
        }
    }
}
 
Example #16
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void move(int oldPosition, int newPosition) {
    if (oldPosition != newPosition) {
        PageDescriptor desc = getPageDescriptor(oldPosition);

        remove(oldPosition);
        insert(desc, newPosition);
    }
}
 
Example #17
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void add(PageDescriptor desc) {
    validatePageDescriptor(desc);

    positionDelta.clear();
    entries.add(new PageEntry(desc));
    notifyDataSetChanged();
}
 
Example #18
Source File: ProjectManagerActivity.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState != null) {
        this.mProjectFile = (JavaProjectFolder) savedInstanceState.getSerializable(KEY_PROJECT_FILE);
    } else {
        this.mProjectFile = ProjectManager.getLastProject(this);
    }
    bindView();
    setupToolbar();
    setupFileView(savedInstanceState);
    setupEditor();
    FragmentManager fm = getSupportFragmentManager();

    List<PageDescriptor> pageDescriptors = new ArrayList<>();
    pageDescriptors.add(new SimplePageDescriptor(MessageFragment.TAG, "Message"));
    pageDescriptors.add(new SimplePageDescriptor(DiagnosticFragment.TAG, "Diagnostic"));
    BottomPageAdapter bottomAdapter = new BottomPageAdapter(fm, pageDescriptors);

    mBottomPage = findViewById(R.id.bottom_page);
    mBottomPage.setAdapter(bottomAdapter);
    mBottomPage.setOffscreenPageLimit(bottomAdapter.getCount());

    mMessagePresenter = new MessagePresenter(this, bottomAdapter);
    mDiagnosticPresenter = new DiagnosticPresenter(this, bottomAdapter, mPagePresenter);

    TabLayout bottomTab = findViewById(R.id.bottom_tab);
    bottomTab.setupWithViewPager(mBottomPage);

    //create project if need
    createProjectIfNeed();
}
 
Example #19
Source File: MainActivity.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
@Override
protected EditorFragment createFragment(PageDescriptor desc) {
  return(EditorFragment.newInstance(desc.getTitle()));
}
 
Example #20
Source File: MainActivity.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
@Override
protected EditorFragment createFragment(PageDescriptor desc) {
  return(EditorFragment.newInstance(desc.getTitle()));
}
 
Example #21
Source File: MainActivity.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
public SamplePagerAdapter(FragmentManager fragmentManager,
                          ArrayList<PageDescriptor> descriptors) {
  super(fragmentManager, descriptors);
}
 
Example #22
Source File: BottomPageAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public BottomPageAdapter(FragmentManager fragmentManager, List<PageDescriptor> descriptors) {
    super(fragmentManager, descriptors);
}
 
Example #23
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
PageDescriptor getDescriptor() {
  return(descriptor);
}
 
Example #24
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
PageEntry(PageDescriptor descriptor) {
  this.descriptor=descriptor;
}
 
Example #25
Source File: EditorPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@NonNull
protected EditorFragment createFragment(@NonNull PageDescriptor pageDescriptor) {
    return EditorFragment.newInstance(pageDescriptor.getFragmentTag());
}
 
Example #26
Source File: EditorPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public EditorPagerAdapter(@NonNull FragmentManager fragmentManager,
                          @NonNull List<PageDescriptor> descriptors) {
    super(fragmentManager, descriptors);
    this.MAX_PAGE = 5;
}
 
Example #27
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public ArrayPagerAdapter(FragmentManager fragmentManager,
                         List<PageDescriptor> descriptors) {
    this(fragmentManager, descriptors, null);
}
 
Example #28
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
public PageDescriptor getPageDescriptor(int position) {
  return(entries.get(position).getDescriptor());
}
 
Example #29
Source File: ArrayPagerAdapter.java    From cwac-pager with Apache License 2.0 4 votes vote down vote up
public ArrayPagerAdapter(FragmentManager fragmentManager,
                         List<PageDescriptor> descriptors) {
  this(fragmentManager, descriptors, null);
}
 
Example #30
Source File: ArrayPagerAdapter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
PageDescriptor getDescriptor() {
    return (descriptor);
}