2022-01-18 16:21:54 +08:00
|
|
|
#include <cdroid.h>
|
2021-06-24 10:12:55 +08:00
|
|
|
#include <widget/simplemonthview.h>
|
2021-09-27 15:14:59 +08:00
|
|
|
#include <widget/pagetransformers.h>
|
2021-08-27 09:58:02 +08:00
|
|
|
static int mPageCount=5;
|
2021-06-24 10:12:55 +08:00
|
|
|
class MyPageAdapter:public PagerAdapter{
|
|
|
|
public:
|
2022-01-21 18:29:06 +08:00
|
|
|
int getCount(){return 8;}
|
2021-06-24 10:12:55 +08:00
|
|
|
bool isViewFromObject(View* view, void*object) { return view==object;}
|
|
|
|
void* instantiateItem(ViewGroup* container, int position) {
|
2022-01-21 18:29:06 +08:00
|
|
|
if(position<getCount()/2){
|
|
|
|
SimpleMonthView*sm=new SimpleMonthView(100,100);
|
|
|
|
sm->setMonthParams(23,Calendar::MAY+position,2021,-1,1,31);
|
|
|
|
container->addView(sm);
|
|
|
|
return sm;
|
|
|
|
}else{
|
|
|
|
View*sm=new View(100,100);
|
|
|
|
sm->setBackground(new ColorDrawable(0xFF000000|(0xFF<<((position%3)*8))));
|
|
|
|
container->addView(sm);
|
|
|
|
return sm;
|
|
|
|
}
|
2021-06-24 10:12:55 +08:00
|
|
|
}
|
|
|
|
void destroyItem(ViewGroup* container, int position,void* object){
|
|
|
|
container->removeView((View*)object);
|
2022-03-22 16:50:31 +08:00
|
|
|
delete (View*)object;
|
2021-06-24 10:12:55 +08:00
|
|
|
}
|
2023-04-27 09:38:42 +08:00
|
|
|
float getPageWidth(int position){return 0.2.f;}//if returned calue <1 OffscreenPageLimit must be larger to workfine
|
2021-06-24 10:12:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc,const char*argv[]){
|
|
|
|
App app(argc,argv);
|
2023-03-26 18:56:30 +08:00
|
|
|
Window*w=new Window(0,0,-1,-1);
|
2021-06-24 10:12:55 +08:00
|
|
|
HorizontalScrollView* hs=new HorizontalScrollView(800,400);
|
2021-08-26 14:46:02 +08:00
|
|
|
LinearLayout*layout=new LinearLayout(400,100);
|
2022-02-22 17:28:27 +08:00
|
|
|
ColorStateList*cl =app.getColorStateList("cdroid::color/textview");
|
2021-08-26 14:46:02 +08:00
|
|
|
layout->setId(10);
|
|
|
|
hs->addView(layout);
|
2021-06-24 10:12:55 +08:00
|
|
|
hs->setOverScrollMode(View::OVER_SCROLL_ALWAYS);
|
|
|
|
w->addView(hs).setId(1);
|
|
|
|
|
2021-08-27 09:58:02 +08:00
|
|
|
if(argc>1)mPageCount=std::max(5L,std::strtol(argv[1],nullptr,10));
|
2021-06-24 10:12:55 +08:00
|
|
|
for(int i=0;i<16;i++){
|
|
|
|
Button*btn=new Button("Hello Button"+std::to_string(i),150,30);
|
|
|
|
btn->setPadding(5,5,5,5);
|
|
|
|
btn->setTextColor(cl);
|
|
|
|
btn->setTextSize(30);
|
|
|
|
btn->setBackgroundColor(0xFF000000|i*20<<8|i*8);
|
|
|
|
btn->setId(100+i);
|
|
|
|
btn->setTextAlignment(View::TEXT_ALIGNMENT_CENTER);
|
2021-08-26 14:46:02 +08:00
|
|
|
layout->addView(btn,new LinearLayout::LayoutParams(800,LayoutParams::WRAP_CONTENT));
|
2021-06-24 10:12:55 +08:00
|
|
|
}
|
2021-08-26 14:46:02 +08:00
|
|
|
ViewPager*pager=new ViewPager(800,560);
|
2021-06-24 10:12:55 +08:00
|
|
|
MyPageAdapter*gpAdapter=new MyPageAdapter();
|
2022-01-21 18:29:06 +08:00
|
|
|
pager->setOffscreenPageLimit(8);
|
2021-08-26 14:46:02 +08:00
|
|
|
pager->setAdapter(gpAdapter);
|
2021-09-07 16:57:48 +08:00
|
|
|
ViewPager::OnPageChangeListener listener;
|
2021-06-24 10:12:55 +08:00
|
|
|
listener.onPageSelected=[&](int position){
|
|
|
|
//hs->
|
|
|
|
};
|
|
|
|
listener.onPageScrolled=[&](int position, float positionOffset, int positionOffsetPixels){
|
2021-08-26 14:46:02 +08:00
|
|
|
hs->scrollTo(position*pager->getWidth()+positionOffsetPixels,0);
|
2021-06-24 10:12:55 +08:00
|
|
|
};
|
2021-09-07 11:53:09 +08:00
|
|
|
pager->addOnPageChangeListener(listener);
|
2021-08-26 14:46:02 +08:00
|
|
|
pager->setOverScrollMode(View::OVER_SCROLL_ALWAYS);
|
|
|
|
w->addView(pager).setPos(0,40);
|
2021-06-24 10:12:55 +08:00
|
|
|
gpAdapter->notifyDataSetChanged();
|
2021-08-26 14:46:02 +08:00
|
|
|
pager->setCurrentItem(0);
|
2021-06-24 10:12:55 +08:00
|
|
|
w->requestLayout();
|
2021-09-08 18:28:34 +08:00
|
|
|
if(argc>1)
|
2021-09-27 15:14:59 +08:00
|
|
|
pager->setPageTransformer(true,new RotateUpTransformer());
|
2021-09-08 18:28:34 +08:00
|
|
|
|
2021-06-24 10:12:55 +08:00
|
|
|
app.exec();
|
|
|
|
}
|