mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-01 19:58:14 +08:00
modify toast impl ,working now
This commit is contained in:
parent
0da5eadd45
commit
1a75b821c5
@ -218,7 +218,7 @@ if ( __name__ == "__main__"):
|
||||
fidxml = sys.argv[2]+"/values/ID.xml"
|
||||
isIDSame = os.path.exists(fidxml) and filecmp.cmp(ftempids,fidxml)
|
||||
msg = "not changed "
|
||||
if not isIDSame:#True if same,otherwise False
|
||||
if not isIDSame or not os.path.exists(sys.argv[3]):#True if same,otherwise False
|
||||
#content is changed,we must copy ftempids to fidxml(sys.argv[2]+"/values/ID.xml)
|
||||
shutil.copyfile(ftempids,fidxml)
|
||||
idgen.dict2RH(sys.argv[3])
|
||||
|
@ -166,7 +166,7 @@ AlertDialog::Builder& AlertDialog::Builder::setOnKeyListener(DialogInterface::On
|
||||
|
||||
AlertDialog::Builder& AlertDialog::Builder::setItems(const std::string& itemsId,OnClickListener listener){
|
||||
P->mContext->getArray(itemsId,P->mItems);
|
||||
//P->mItems=P->Context.getResources().getTextArray(itemsId);
|
||||
P->mContext->getArray(itemsId,P->mItems);
|
||||
P->mOnClickListener = listener;
|
||||
return *this;
|
||||
}
|
||||
@ -185,7 +185,6 @@ AlertDialog::Builder& AlertDialog::Builder::setAdapter(ListAdapter* adapter,Dial
|
||||
|
||||
AlertDialog::Builder& AlertDialog::Builder::setMultiChoiceItems(const std::string&itemsId,
|
||||
const std::vector<bool>& checkedItems,DialogInterface::OnMultiChoiceClickListener listener){
|
||||
//P.mItems = P.mContext.getResources().getTextArray(itemsId);
|
||||
P->mContext->getArray(itemsId,P->mItems);
|
||||
P->mOnCheckboxClickListener = listener;
|
||||
P->mCheckedItems = checkedItems;
|
||||
@ -204,7 +203,6 @@ AlertDialog::Builder& AlertDialog::Builder::setMultiChoiceItems(const std::vecto
|
||||
|
||||
AlertDialog::Builder& AlertDialog::Builder::setSingleChoiceItems(const std::string&itemsId,
|
||||
int checkedItem, DialogInterface::OnClickListener listener){
|
||||
//P.mItems = P.mContext.getResources().getTextArray(itemsId);
|
||||
P->mContext->getArray(itemsId,P->mItems);
|
||||
P->mOnClickListener = listener;
|
||||
P->mCheckedItem = checkedItem;
|
||||
|
@ -50,10 +50,11 @@ void Dialog::show(){
|
||||
LOGD("size=%dx%d margin=%d,%d",pt.x,pt.y,horzMargin,vertMargin);
|
||||
int widthSpec = MeasureSpec::makeMeasureSpec(pt.x-horzMargin,MeasureSpec::EXACTLY);
|
||||
int heightSpec = MeasureSpec::makeMeasureSpec(pt.y-vertMargin,MeasureSpec::AT_MOST);
|
||||
|
||||
|
||||
widthSpec = frm->getChildMeasureSpec(widthSpec ,0,lp->width);
|
||||
heightSpec = frm->getChildMeasureSpec(heightSpec,0,lp->height);
|
||||
frm->measure(widthSpec,heightSpec);
|
||||
LOGD("spec=%x/%x measured=%dx%d",widthSpec,heightSpec,frm->getMeasuredWidth(),frm->getMeasuredHeight());
|
||||
mWindow->setSize(frm->getMeasuredWidth()+horzMargin,frm->getMeasuredHeight()+vertMargin);
|
||||
LOGD("size=%dx%d %d,%d",frm->getMeasuredWidth(),frm->getMeasuredHeight(),mWindow->getWidth(),mWindow->getHeight());
|
||||
frm->layout(lp->leftMargin,lp->topMargin,mWindow->getWidth()-horzMargin, mWindow->getHeight()-vertMargin);
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include <widget/horizontalscrollview.h>
|
||||
#include <widget/progressbar.h>
|
||||
#include <widget/cdwindow.h>
|
||||
#include <view/toastwindow.h>
|
||||
#include <widget/toast.h>
|
||||
#include <core/app.h>
|
||||
#include <widget/seekbar.h>
|
||||
using namespace cdroid;
|
||||
|
@ -1,66 +0,0 @@
|
||||
#include <view/toastwindow.h>
|
||||
#include <cdroid.h>
|
||||
#include <cdlog.h>
|
||||
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
std::vector<Window*>ToastWindow::toasts_;
|
||||
|
||||
ToastWindow::ToastWindow(int w,int h):Window(0,0,w,h,TYPE_TOAST){
|
||||
timeout_=-1;
|
||||
time_elapsed=0;
|
||||
setFocusable(false);
|
||||
//sendMessage((DWORD)WM_TIMER,(DWORD)TIMER_ID,0,500);
|
||||
toasts_.push_back(this);
|
||||
}
|
||||
|
||||
ToastWindow::~ToastWindow(){
|
||||
toasts_.erase(std::find(toasts_.begin(),toasts_.end(),this));
|
||||
}
|
||||
|
||||
/*bool ToastWindow::onMessage(DWORD msg,DWORD wp,ULONG lp){
|
||||
if(msg==WM_TIMER && wp==TIMER_ID){
|
||||
time_elapsed+=500;
|
||||
if(time_elapsed>=timeout_){
|
||||
sendMessage(WM_DESTROY,0,0);
|
||||
time_elapsed=0;
|
||||
}
|
||||
sendMessage(msg,wp,lp,500);
|
||||
return true;
|
||||
}
|
||||
return Window::onMessage(msg,wp,lp);
|
||||
}*/
|
||||
|
||||
bool ToastWindow::onKeyUp(int keyCode,KeyEvent&evt){
|
||||
time_elapsed=0;
|
||||
return Window::onKeyUp(keyCode,evt);
|
||||
}
|
||||
|
||||
ToastWindow*ToastWindow::makeWindow(OnCreateContentListener oncreate,UINT timeout){
|
||||
ToastWindow*w=nullptr;
|
||||
if(oncreate){
|
||||
w=oncreate();
|
||||
w->timeout_=timeout;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
ToastWindow*ToastWindow::makeText(const std::string&txt,UINT timeout){
|
||||
int sw,sh,tw,th;
|
||||
GraphDevice::getInstance().getScreenSize(sw,sh);
|
||||
GraphDevice::getInstance().getPrimaryContext()->set_font_size(20);
|
||||
GraphDevice::getInstance().getPrimaryContext()->get_text_size(txt,&tw,&th);
|
||||
tw+=th*4;th+=th;
|
||||
return makeWindow([&]()->ToastWindow*{
|
||||
ToastWindow*w=new ToastWindow(tw,th);
|
||||
TextView*tv=new TextView(txt,tw,th);
|
||||
tv->setTextSize(20);
|
||||
tv->setSingleLine(false);
|
||||
w->addView(tv);
|
||||
w->setPos((sw-tw)/2,(sh-th)/2);
|
||||
return w;
|
||||
},timeout);
|
||||
}
|
||||
}//namespace
|
||||
|
@ -1,30 +0,0 @@
|
||||
#ifndef __TOAST_WINDOW_H__
|
||||
#define __TOAST_WINDOW_H__
|
||||
#include <widget/cdwindow.h>
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
class ToastWindow:public Window{
|
||||
enum{
|
||||
LENGTH_SHORT=2000,
|
||||
LENGTH_LONG=4000
|
||||
};
|
||||
DECLARE_UIEVENT(ToastWindow*,OnCreateContentListener);
|
||||
public:
|
||||
ToastWindow(int w,int h);
|
||||
~ToastWindow();
|
||||
virtual bool onKeyUp(int,KeyEvent&event)override;
|
||||
static ToastWindow*makeWindow(OnCreateContentListener oncreate,UINT timeout=LENGTH_SHORT);
|
||||
static ToastWindow*makeText(const std::string&txt,UINT timeout=LENGTH_SHORT);
|
||||
private:
|
||||
const static int TIMER_ID=0x1000;
|
||||
static std::vector<Window*>toasts_;
|
||||
DWORD timeout_;
|
||||
DWORD time_elapsed;
|
||||
DISALLOW_COPY_AND_ASSIGN(ToastWindow);
|
||||
};
|
||||
typedef ToastWindow Toast;
|
||||
|
||||
}//namespace
|
||||
|
||||
#endif
|
@ -6494,11 +6494,11 @@ void View::setMeasuredDimensionRaw(int measuredWidth, int measuredHeight) {
|
||||
}
|
||||
|
||||
void View::setMeasuredDimension(int measuredWidth, int measuredHeight){
|
||||
bool optical = isLayoutModeOptical(this);
|
||||
const bool optical = isLayoutModeOptical(this);
|
||||
if (optical != isLayoutModeOptical(mParent)) {
|
||||
Insets insets = getOpticalInsets();
|
||||
int opticalWidth = insets.left + insets.right;
|
||||
int opticalHeight = insets.top + insets.bottom;
|
||||
const int opticalWidth = insets.left + insets.right;
|
||||
const int opticalHeight = insets.top + insets.bottom;
|
||||
|
||||
measuredWidth += optical ? opticalWidth : -opticalWidth;
|
||||
measuredHeight += optical ? opticalHeight : -opticalHeight;
|
||||
|
@ -330,15 +330,14 @@ bool HorizontalScrollView::onInterceptTouchEvent(MotionEvent& ev){
|
||||
* being flinged. */
|
||||
mIsBeingDragged = !mScroller->isFinished()||!mEdgeGlowLeft->isFinished()
|
||||
||!mEdgeGlowRight->isFinished();
|
||||
if(shouldDisplayEdgeEffects()){
|
||||
if(shouldDisplayEdgeEffects()){
|
||||
if (!mEdgeGlowLeft->isFinished()) {
|
||||
mEdgeGlowLeft->onPullDistance(0.f, 1.f - ev.getY() / getHeight());
|
||||
}
|
||||
if (!mEdgeGlowRight->isFinished()) {
|
||||
mEdgeGlowRight->onPullDistance(0.f, ev.getY() / getHeight());
|
||||
}
|
||||
}
|
||||
LOGD("mIsBeingDragged=%d edgefinished=%d/%d",mIsBeingDragged,mEdgeGlowLeft->isFinished(),mEdgeGlowRight->isFinished());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,39 +1,106 @@
|
||||
#include <widget/toast.h>
|
||||
#include <widget/textview.h>
|
||||
#include <widget/R.h>
|
||||
#include <core/app.h>
|
||||
#include <core/windowmanager.h>
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
class ToastWindow:public Window{
|
||||
private:
|
||||
int mDuration;
|
||||
int mTimeElapsed;
|
||||
Runnable mTimer;
|
||||
Toast* mToast;
|
||||
public:
|
||||
ToastWindow(Toast*t,int w,int h);
|
||||
~ToastWindow();
|
||||
void timeElapsed();
|
||||
void setDuration(int dur);
|
||||
};
|
||||
|
||||
ToastWindow::ToastWindow(Toast*toast,int w,int h):Window(0,0,w,h){
|
||||
mDuration = INT_MAX;
|
||||
mTimeElapsed = 100;
|
||||
mToast = toast;
|
||||
mTimer = std::bind(&ToastWindow::timeElapsed,this);
|
||||
postDelayed(mTimer,100);
|
||||
}
|
||||
|
||||
ToastWindow::~ToastWindow(){
|
||||
LOGD("Window=%p mToast=%p",this,mToast);
|
||||
delete mToast;
|
||||
}
|
||||
|
||||
void ToastWindow::timeElapsed(){
|
||||
if(mTimeElapsed <mDuration){
|
||||
postDelayed(mTimer,500);
|
||||
mTimeElapsed += 500;
|
||||
return;
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
void ToastWindow::setDuration(int dur){
|
||||
mDuration = dur;
|
||||
}
|
||||
|
||||
Toast::Toast(Context*context){
|
||||
mContext = context;
|
||||
mX = mY = 0;
|
||||
if(context == nullptr)
|
||||
mContext= &App::getInstance();
|
||||
mX = mY = 0;
|
||||
mGravity = Gravity::NO_GRAVITY;
|
||||
mWindow = nullptr;
|
||||
mWindow = nullptr;
|
||||
}
|
||||
|
||||
void Toast::show(){
|
||||
ViewGroup* frame = dynamic_cast<ViewGroup*>(mNextView);
|
||||
MarginLayoutParams*lp=(MarginLayoutParams*)frame->getLayoutParams();
|
||||
const int horzMargin = lp->leftMargin+ lp->rightMargin;
|
||||
const int vertMargin = lp->topMargin + lp->bottomMargin;
|
||||
Point pt;
|
||||
WindowManager::getInstance().getDefaultDisplay().getSize(pt);
|
||||
LOGD("size=%dx%d margin=%d,%d",pt.x,pt.y,horzMargin,vertMargin);
|
||||
int widthSpec = MeasureSpec::makeMeasureSpec(pt.x-horzMargin,MeasureSpec::EXACTLY);
|
||||
int heightSpec = MeasureSpec::makeMeasureSpec(pt.y-vertMargin,MeasureSpec::AT_MOST);
|
||||
LOGD("spec=%x/%x lpsize=%d/%d",widthSpec,heightSpec,lp->width,lp->height);
|
||||
widthSpec = frame->getChildMeasureSpec(widthSpec ,0,lp->width);
|
||||
heightSpec = frame->getChildMeasureSpec(heightSpec,0,lp->height);
|
||||
frame->measure(widthSpec,heightSpec);
|
||||
LOGD("size=%dx%d window=%p duration=%d",frame->getMeasuredWidth(),frame->getMeasuredHeight(),mDuration);
|
||||
ToastWindow*w = new ToastWindow(this,frame->getMeasuredWidth(),frame->getMeasuredHeight());
|
||||
mWindow = w;
|
||||
mWindow->addView(mNextView);
|
||||
mWindow->requestLayout();
|
||||
w->setDuration(mDuration);
|
||||
}
|
||||
|
||||
void Toast::cancel(){
|
||||
if(mWindow)mWindow->close();
|
||||
mWindow = nullptr;
|
||||
}
|
||||
|
||||
void Toast::setView(View*view){
|
||||
Toast& Toast::setView(View*view){
|
||||
mNextView = view;
|
||||
return *this;
|
||||
}
|
||||
|
||||
View*Toast::getView()const{
|
||||
return mNextView;
|
||||
}
|
||||
|
||||
void Toast::setDuration(int duration){
|
||||
Toast& Toast::setDuration(int duration){
|
||||
mDuration = duration;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Toast::getDuration()const{
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
void Toast::setMargin(int horizontalMargin,int verticalMargin){
|
||||
Toast& Toast::setMargin(int horizontalMargin,int verticalMargin){
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Toast::getHorizontalMargin()const{
|
||||
@ -44,10 +111,11 @@ int Toast::getVerticalMargin()const{
|
||||
return mVerticalMargin;
|
||||
}
|
||||
|
||||
void Toast::setGravity(int gravity,int xoffset,int yoffset){
|
||||
Toast& Toast::setGravity(int gravity,int xoffset,int yoffset){
|
||||
mGravity =gravity;
|
||||
mX = xoffset;
|
||||
mY = yoffset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Toast::getGravity()const{
|
||||
@ -63,23 +131,24 @@ int Toast::getYOffset()const{
|
||||
}
|
||||
|
||||
Toast*Toast::makeText(Context*context,const std::string&text,int duration){
|
||||
Toast*result = new Toast(context);
|
||||
LayoutInflater*inflater=LayoutInflater::from(context);
|
||||
Toast* result = new Toast(context);
|
||||
LayoutInflater*inflater=LayoutInflater::from(result->mContext);
|
||||
View*v = inflater->inflate("cdroid:layout/transient_notification",nullptr);
|
||||
TextView*tv= (TextView*)v->findViewById(cdroid::R::id::message);
|
||||
TextView*tv = (TextView*)v->findViewById(cdroid::R::id::message);
|
||||
tv->setText(text);
|
||||
result->mNextView=v;
|
||||
result->mDuration =duration;
|
||||
result->mNextView = v;
|
||||
result->mDuration = duration;
|
||||
return result;
|
||||
}
|
||||
|
||||
void Toast::setText(const std::string&text){
|
||||
TextView*tv=nullptr;
|
||||
if(mNextView)
|
||||
tv=(TextView*)mNextView->findViewById(cdroid::R::id::message);
|
||||
if(tv==nullptr)
|
||||
throw("This Toast was not created by Toast::makeText");
|
||||
tv->setText(text);
|
||||
Toast& Toast::setText(const std::string&text){
|
||||
TextView* tv = nullptr;
|
||||
if(mNextView){
|
||||
tv = (TextView*)mNextView->findViewById(cdroid::R::id::message);
|
||||
if(tv)tv->setText(text);
|
||||
}
|
||||
LOGE_IF(tv==nullptr,"This Toast was not created by Toast::makeText");
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,27 +17,25 @@ protected:
|
||||
int mDuration;
|
||||
View*mNextView;
|
||||
public:
|
||||
enum{
|
||||
LENGTH_SHORT,
|
||||
LENGTH_LONG
|
||||
};
|
||||
static constexpr int LENGTH_SHORT= 2000;
|
||||
static constexpr int LENGTH_LONG = 4000;
|
||||
public:
|
||||
Toast(Context*context);
|
||||
void show();
|
||||
void cancel();
|
||||
void setView(View*);
|
||||
Toast& setView(View*);
|
||||
View*getView()const;
|
||||
void setDuration(int duration);
|
||||
Toast& setDuration(int duration);
|
||||
int getDuration()const;
|
||||
void setMargin(int horizontalMargin,int verticalMargin);
|
||||
Toast& setMargin(int horizontalMargin,int verticalMargin);
|
||||
int getHorizontalMargin()const;
|
||||
int getVerticalMargin()const;
|
||||
void setGravity(int gravity,int xoffset,int yoffset);
|
||||
Toast& setGravity(int gravity,int xoffset,int yoffset);
|
||||
int getGravity()const;
|
||||
int getXOffset()const;
|
||||
int getYOffset()const;
|
||||
static Toast*makeText(Context*,const std::string&text,int duration);
|
||||
void setText(const std::string&);
|
||||
Toast& setText(const std::string&);
|
||||
static Toast*makeText(Context*,const std::string&text,int duration= LENGTH_SHORT);
|
||||
};
|
||||
}//endof namespace
|
||||
|
||||
|
@ -21,7 +21,7 @@ static void onClick(View&v){
|
||||
std::string txt="You clicked:";
|
||||
txt+=((TextView&)v).getText();
|
||||
txt+=" id:"+std::to_string(v.getId());
|
||||
Toast::makeText(txt,2000)->setPos(200,v.getId()*20);
|
||||
Toast::makeText(v.getContext(),txt,2000);
|
||||
}
|
||||
|
||||
TEST_F(WIDGET,View){
|
||||
@ -58,7 +58,7 @@ TEST_F(WIDGET,Button){
|
||||
std::string txt="You clicked:";
|
||||
txt+=((TextView&)v).getText();
|
||||
txt+=" id:"+std::to_string(v.getId());
|
||||
Toast::makeText(txt,2000)->setPos(200,v.getId()*20);
|
||||
Toast::makeText(v.getContext(),txt,2000);
|
||||
});
|
||||
//btn2->setOnClickListener(click);//it click listener is not set ,view's parent will recv WM_CLICK message
|
||||
layout->addView(btn1);
|
||||
|
@ -213,22 +213,11 @@ TEST_F(WINDOW,TOAST){
|
||||
int cnt=sizeof(texts)/sizeof(texts[0]);
|
||||
for(int i=0;i<8;i++){
|
||||
printf("toast text:%s\r\n",texts[i%cnt]);
|
||||
Toast::makeText(std::string(texts[i%cnt]),600+200*i)->setPos(i*80,i*40);
|
||||
Toast::makeText(w1->getContext(),std::string(texts[i%cnt]),600+200*i);
|
||||
}
|
||||
app.exec();
|
||||
}
|
||||
|
||||
static ToastWindow*createCustomToast(const std::string&txt,int w,int h,int timeout){
|
||||
return Toast::makeWindow([&]()->ToastWindow*{
|
||||
ToastWindow*win=new ToastWindow(500,100);
|
||||
TextView*tv=new TextView(txt,w-20,h-20);
|
||||
tv->setTextSize(20);
|
||||
tv->setSingleLine(false);
|
||||
win->addView(tv).setPos(10,10);
|
||||
return win;
|
||||
},timeout);
|
||||
}
|
||||
|
||||
TEST_F(WINDOW,TOAST_MAKEWINDOW){
|
||||
App app;
|
||||
int index=0;
|
||||
@ -237,7 +226,7 @@ TEST_F(WINDOW,TOAST_MAKEWINDOW){
|
||||
"Innovation in China","Innovation by Shenzhen"};
|
||||
int cnt=sizeof(texts)/sizeof(texts[0]);
|
||||
for(int i=0;i<cnt;i++){
|
||||
createCustomToast(texts[i],300,80,10000-i*1000)->setPos(i*50,i*50);
|
||||
//createCustomToast(texts[i],300,80,10000-i*1000)->setPos(i*50,i*50);
|
||||
}
|
||||
/*TimerFD *tfd=new TimerFD(800,false);
|
||||
app.addEventSource(tfd,[&](EventSource&s)->bool{
|
||||
@ -248,37 +237,6 @@ TEST_F(WINDOW,TOAST_MAKEWINDOW){
|
||||
app.exec();
|
||||
}
|
||||
|
||||
class PopWindow{
|
||||
protected:
|
||||
ToastWindow*mt;
|
||||
static PopWindow*mInst;
|
||||
friend class MyToast;
|
||||
PopWindow(){mt=nullptr;}
|
||||
public:
|
||||
static PopWindow*getInstance(){
|
||||
if(mInst==nullptr)
|
||||
mInst=new PopWindow();
|
||||
return mInst;
|
||||
}
|
||||
void pop(){
|
||||
mt=Toast::makeText("Test Message",2000);
|
||||
}
|
||||
void hide(){
|
||||
if(mt)
|
||||
mt->close();
|
||||
mt=nullptr;
|
||||
}
|
||||
};
|
||||
PopWindow*PopWindow::mInst=nullptr;
|
||||
|
||||
class MyToast:public Toast{
|
||||
public:
|
||||
MyToast(int w,int h):Toast(w,h){}
|
||||
~MyToast(){
|
||||
PopWindow::getInstance()->mt=nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(WINDOW,TOAST_SINGLE){
|
||||
App app;
|
||||
int index=0;
|
||||
|
Loading…
Reference in New Issue
Block a user