mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-05 21:58:44 +08:00
modify inputeventsource for onKeyMultiple suuport
This commit is contained in:
parent
983ff58e5a
commit
90cbf9f4f4
@ -10,43 +10,45 @@ long AnimationUtils::currentAnimationTimeMillis(){
|
||||
return SystemClock::uptimeMillis();
|
||||
}
|
||||
|
||||
typedef struct{
|
||||
Animation*anim;
|
||||
AttributeSet attr;
|
||||
}ANIMDATA;
|
||||
|
||||
typedef struct{
|
||||
Context*context;
|
||||
std::string package;
|
||||
int index;
|
||||
ANIMDATA data[8];
|
||||
Animation*animation;
|
||||
std::vector<Animation*>animations;
|
||||
}ANIMPARSERDATA;
|
||||
|
||||
static void startAnimation(void *userData, const XML_Char *xname, const XML_Char **satts){
|
||||
ANIMPARSERDATA*pd=(ANIMPARSERDATA*)userData;
|
||||
ANIMPARSERDATA*pd = (ANIMPARSERDATA*)userData;
|
||||
AttributeSet attrs(pd->context,pd->package);
|
||||
std::string name=xname;
|
||||
Animation*anim=nullptr;
|
||||
std::string name = xname;
|
||||
attrs.set(satts);
|
||||
if (0==name.compare("set")) {
|
||||
anim = new AnimationSet(pd->context, attrs);
|
||||
pd->animation= new AnimationSet(pd->context, attrs);
|
||||
//createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);
|
||||
} else if (0==name.compare("alpha")) {
|
||||
anim = new AlphaAnimation(pd->context, attrs);
|
||||
pd->animation = new AlphaAnimation(pd->context, attrs);
|
||||
} else if (0==name.compare("scale")) {
|
||||
anim = new ScaleAnimation(pd->context, attrs);
|
||||
pd->animation = new ScaleAnimation(pd->context, attrs);
|
||||
} else if (0==name.compare("rotate")) {
|
||||
anim = new RotateAnimation(pd->context, attrs);
|
||||
pd->animation = new RotateAnimation(pd->context, attrs);
|
||||
} else if (0==name.compare("translate")) {
|
||||
anim = new TranslateAnimation(pd->context, attrs);
|
||||
pd->animation = new TranslateAnimation(pd->context, attrs);
|
||||
} else if (0==name.compare("cliprect")) {
|
||||
anim = new ClipRectAnimation(pd->context, attrs);
|
||||
pd->animation = new ClipRectAnimation(pd->context, attrs);
|
||||
} else {
|
||||
LOGE("Unknown animation name: %s" ,xname);
|
||||
}
|
||||
pd->animations.push_back(pd->animation);
|
||||
}
|
||||
|
||||
static void endAnimation(void *userData, const XML_Char *name){
|
||||
ANIMPARSERDATA*pd = (ANIMPARSERDATA*)userData;
|
||||
Animation*last = pd->animations.back();
|
||||
pd->animations.pop_back();
|
||||
if( pd->animations.size()){
|
||||
AnimationSet*aset=(AnimationSet*)pd->animations.back();
|
||||
aset->addAnimation(last);
|
||||
}
|
||||
}
|
||||
|
||||
Animation* AnimationUtils::loadAnimation(Context* context,const std::string&resid){
|
||||
@ -55,39 +57,63 @@ Animation* AnimationUtils::loadAnimation(Context* context,const std::string&resi
|
||||
int index=0;
|
||||
ANIMPARSERDATA pd;
|
||||
void*parseParams[2];
|
||||
pd.index = 0;
|
||||
pd.context = context;
|
||||
XML_Parser parser=XML_ParserCreate(nullptr);
|
||||
XML_Parser parser = XML_ParserCreate(nullptr);
|
||||
XML_SetElementHandler(parser, startAnimation, endAnimation);
|
||||
XML_SetUserData(parser,(void*)&pd);
|
||||
std::unique_ptr<std::istream>stream=context->getInputStream(resid,&pd.package);
|
||||
std::unique_ptr<std::istream> stream = context->getInputStream(resid,&pd.package);
|
||||
do {
|
||||
stream->read(buf,sizeof(buf));
|
||||
rdlen=stream->gcount();
|
||||
rdlen = stream->gcount();
|
||||
if (XML_Parse(parser, buf,rdlen,!rdlen) == XML_STATUS_ERROR) {
|
||||
const char*es=XML_ErrorString(XML_GetErrorCode(parser));
|
||||
const char*es = XML_ErrorString(XML_GetErrorCode(parser));
|
||||
LOGE("%s at %s:line %ld",es, resid.c_str(),XML_GetCurrentLineNumber(parser));
|
||||
XML_ParserFree(parser);
|
||||
break;
|
||||
}
|
||||
} while(rdlen);
|
||||
XML_ParserFree(parser);
|
||||
return nullptr;
|
||||
return pd.animation;
|
||||
}
|
||||
|
||||
typedef struct{
|
||||
Context*context;
|
||||
LayoutAnimationController*controller;
|
||||
std::string package;
|
||||
}LACDATA;
|
||||
|
||||
static void startAnimationController(void *userData, const XML_Char *xname, const XML_Char **satts){
|
||||
LACDATA*pd =(LACDATA*)userData;
|
||||
AttributeSet attrs(pd->context,pd->package);
|
||||
if(strcmp(xname,"layoutAnimation")==0){
|
||||
pd->controller= new LayoutAnimationController(pd->context, attrs);
|
||||
}else if(strcmp(xname,"gridLayoutAnimation")==0){
|
||||
pd->controller= new GridLayoutAnimationController(pd->context, attrs);
|
||||
}else{
|
||||
FATAL("unknown layout animation name %s",xname);
|
||||
}
|
||||
}
|
||||
|
||||
LayoutAnimationController* AnimationUtils::loadLayoutAnimation(Context* context,const std::string&resid){
|
||||
return nullptr;
|
||||
LACDATA data;
|
||||
XML_Parser parser = XML_ParserCreate(nullptr);
|
||||
data.context = context;
|
||||
XML_SetElementHandler(parser, startAnimationController, nullptr);
|
||||
XML_SetUserData(parser,&data);
|
||||
std::unique_ptr<std::istream> stream = context->getInputStream(resid,&data.package);
|
||||
|
||||
return data.controller;
|
||||
}
|
||||
|
||||
Animation* AnimationUtils::makeInAnimation(Context* c, bool fromLeft){
|
||||
Animation*a=loadAnimation(c,fromLeft?"cdroid:anim/slide_in_left.xml":"cdroid:anim/slide_in_right.xml");
|
||||
Animation*a = loadAnimation(c,fromLeft?"cdroid:anim/slide_in_left.xml":"cdroid:anim/slide_in_right.xml");
|
||||
a->setInterpolator(new DecelerateInterpolator());
|
||||
a->setStartTime(currentAnimationTimeMillis());
|
||||
return a;
|
||||
}
|
||||
|
||||
Animation* AnimationUtils::makeOutAnimation(Context* c, bool toRight){
|
||||
Animation*a=loadAnimation(c,toRight?"cdroid:anim/slide_out_right.xml":"cdroid:anim/slide_out_left.xml");
|
||||
Animation*a = loadAnimation(c,toRight?"cdroid:anim/slide_out_right.xml":"cdroid:anim/slide_out_left.xml");
|
||||
a->setInterpolator(new AccelerateInterpolator());
|
||||
a->setStartTime(currentAnimationTimeMillis());
|
||||
return a;
|
||||
@ -101,9 +127,9 @@ Animation* AnimationUtils::makeInChildBottomAnimation(Context* c){
|
||||
}
|
||||
|
||||
static void startPolator(void *userData, const XML_Char *xname, const XML_Char **satts){
|
||||
Interpolator**interpolator=(Interpolator**)userData;
|
||||
Interpolator**interpolator = (Interpolator**)userData;
|
||||
AttributeSet attrs;
|
||||
std::string name=xname;
|
||||
std::string name = xname;
|
||||
Context*ctx;
|
||||
attrs.set(satts);
|
||||
if (0==name.compare("linearInterpolator")) {
|
||||
@ -134,14 +160,14 @@ static void startPolator(void *userData, const XML_Char *xname, const XML_Char *
|
||||
Interpolator* AnimationUtils::loadInterpolator(Context* context,const std::string&resid){
|
||||
int rdlen;
|
||||
char buf[256];
|
||||
Interpolator*interpolator=nullptr;
|
||||
XML_Parser parser=XML_ParserCreate(nullptr);
|
||||
Interpolator*interpolator = nullptr;
|
||||
XML_Parser parser = XML_ParserCreate(nullptr);
|
||||
XML_SetElementHandler(parser, startPolator,nullptr);
|
||||
XML_SetUserData(parser,&interpolator);
|
||||
std::unique_ptr<std::istream>stream=context->getInputStream(resid);
|
||||
std::unique_ptr<std::istream> stream = context->getInputStream(resid);
|
||||
do{
|
||||
stream->read(buf,sizeof(buf));
|
||||
rdlen=stream->gcount();
|
||||
rdlen = stream->gcount();
|
||||
if (XML_Parse(parser, buf,rdlen,!rdlen) == XML_STATUS_ERROR) {
|
||||
const char*es=XML_ErrorString(XML_GetErrorCode(parser));
|
||||
LOGE("%s at %s:line %ld",es, resid.c_str(),XML_GetCurrentLineNumber(parser));
|
||||
|
@ -38,14 +38,18 @@ static void startElement(void *userData, const XML_Char *name, const XML_Char **
|
||||
}else{
|
||||
LOGE("Unknown animator name:%s",name);
|
||||
}
|
||||
if(pd->animators.empty())
|
||||
pd->result = anim;
|
||||
pd->result = anim;
|
||||
pd->animators.push_back(anim);
|
||||
}
|
||||
|
||||
static void endElement(void *userData, const XML_Char *name){
|
||||
ParseData*pd =(ParseData*)userData;
|
||||
|
||||
Animator*anim=pd->animators.back();
|
||||
pd->animators.pop_back();
|
||||
if(pd->animators.size()){
|
||||
AnimatorSet*aset=(AnimatorSet*)pd->animators.back();
|
||||
//aset->addAnimator(anim);
|
||||
}
|
||||
}
|
||||
|
||||
Animator* AnimatorInflater::createAnimatorFromXml(Context*ctx,const std::string&resid){
|
||||
|
@ -8,8 +8,17 @@ GridLayoutAnimationController::GridLayoutAnimationController(Context* context,co
|
||||
:LayoutAnimationController(context,attrs){
|
||||
mColumnDelay = attrs.getFloat("columnDelay");
|
||||
mRowDelay = attrs.getFloat("rowDelay");
|
||||
mDirection = attrs.getInt("direction");
|
||||
mDirectionPriority = attrs.getInt("directionPriority");
|
||||
mDirection = attrs.getInt("direction",std::map<const std::string,int>{
|
||||
{"left_to_right",(int)DIRECTION_LEFT_TO_RIGHT},
|
||||
{"right_to_left",(int)DIRECTION_RIGHT_TO_LEFT},
|
||||
{"top_to_bottom",(int)DIRECTION_TOP_TO_BOTTOM},
|
||||
{"bottom_to_top",(int)DIRECTION_BOTTOM_TO_TOP}
|
||||
}, DIRECTION_LEFT_TO_RIGHT | DIRECTION_TOP_TO_BOTTOM);
|
||||
mDirectionPriority = attrs.getInt("directionPriority",std::map<const std::string,int>{
|
||||
{"none",(int)PRIORITY_NONE},
|
||||
{"column",(int)PRIORITY_COLUMN},
|
||||
{"row", (int)PRIORITY_ROW}
|
||||
},PRIORITY_NONE);
|
||||
}
|
||||
|
||||
GridLayoutAnimationController::GridLayoutAnimationController(Animation* animation)
|
||||
|
@ -7,12 +7,15 @@ namespace cdroid{
|
||||
|
||||
LayoutAnimationController::LayoutAnimationController(Context* context, const AttributeSet& attrs){
|
||||
mDelay = attrs.getFloat("delay");
|
||||
mOrder = attrs.getInt("animationOrder",ORDER_NORMAL);
|
||||
mOrder = attrs.getInt("animationOrder",std::map<const std::string,int>{
|
||||
{"normal" ,(int)ORDER_NORMAL},
|
||||
{"reverse",(int)ORDER_REVERSE},
|
||||
{"random" ,(int)ORDER_RANDOM}
|
||||
},ORDER_NORMAL);
|
||||
std::string resource = attrs.getString("animation");
|
||||
mAnimation = nullptr;
|
||||
mInterpolator = nullptr;
|
||||
mMaxDelay = LONG_MIN;
|
||||
mOrder =0;
|
||||
setAnimation(context,resource);
|
||||
resource = attrs.getString("interpolator");
|
||||
setInterpolator(context,resource);
|
||||
@ -99,7 +102,7 @@ Animation* LayoutAnimationController::getAnimationForView(View* view){
|
||||
}
|
||||
|
||||
bool LayoutAnimationController::isDone()const{
|
||||
return SystemClock::uptimeMillis()>//AnimationUtils.currentAnimationTimeMillis() >
|
||||
return AnimationUtils::currentAnimationTimeMillis() >
|
||||
mAnimation->getStartTime() + mMaxDelay + mDuration;
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,10 @@ TranslateAnimation::TranslateAnimation(const TranslateAnimation&o):Animation(o){
|
||||
|
||||
TranslateAnimation::TranslateAnimation(Context* context,const AttributeSet& attrs)
|
||||
:Animation(context,attrs){
|
||||
mFromXValue=getPivotType(attrs.getString("toXDelta"),mFromXType);
|
||||
mFromYValue=getPivotType(attrs.getString("toYDelta"),mFromYType);
|
||||
mToXValue=getPivotType(attrs.getString("toYDelta"),mToXType);
|
||||
mToYValue=getPivotType(attrs.getString("toYDelta"),mToYType);
|
||||
mFromXValue = getPivotType(attrs.getString("toXDelta"),mFromXType);
|
||||
mFromYValue = getPivotType(attrs.getString("toYDelta"),mFromYType);
|
||||
mToXValue = getPivotType(attrs.getString("toYDelta"),mToXType);
|
||||
mToYValue = getPivotType(attrs.getString("toYDelta"),mToYType);
|
||||
}
|
||||
|
||||
TranslateAnimation::TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <cdtypes.h>
|
||||
#include <gui_features.h>
|
||||
//#include <porting/cdtypes.h>
|
||||
#include <gui/gui_features.h>
|
||||
#include <view/viewgroup.h>
|
||||
#include <view/viewoverlay.h>
|
||||
#include <widget/viewpager.h>
|
||||
|
@ -35,6 +35,10 @@ Canvas::~Canvas(){
|
||||
GFXDestroySurface(mHandle);
|
||||
}
|
||||
|
||||
void*Canvas::getHandler()const{
|
||||
return mHandle;
|
||||
}
|
||||
|
||||
void Canvas::set_color(UINT color){
|
||||
set_color((color>>16)&0xFF,(color>>8)&0xFF,color&0xFF,(color>>24));
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ public:
|
||||
Canvas(const Cairo::RefPtr<Cairo::Surface>&target);
|
||||
Canvas(unsigned int width,unsigned int height);
|
||||
~Canvas();
|
||||
void*getHandler()const;
|
||||
void get_text_size(const std::string&txt,int*w,int*h);
|
||||
void draw_text(const Rect&rect,const std::string&text,int text_alignment=0);
|
||||
void set_color(uint8_t r,uint8_t g, uint8_t b,uint8_t a=255);
|
||||
|
@ -88,13 +88,13 @@ std::shared_ptr<InputDevice>InputEventSource::getdevice(int fd){
|
||||
dev.reset(new MouseDevice(fd));
|
||||
dev->setEventConsumeListener([&](const InputEvent&e){
|
||||
MotionEvent*mt=MotionEvent::obtain((MotionEvent&)e);
|
||||
mInputEvents.push(mt);
|
||||
mMotionEvents.push(mt);
|
||||
});
|
||||
}else if(tmpdev.getClasses()&(INPUT_DEVICE_CLASS_KEYBOARD)){
|
||||
dev.reset(new KeyDevice(fd));
|
||||
dev->setEventConsumeListener([&](const InputEvent&e){
|
||||
KeyEvent*key=KeyEvent::obtain((KeyEvent&)e);
|
||||
mInputEvents.push(key);
|
||||
mKeyEvents.push_back(key);
|
||||
});
|
||||
}
|
||||
mDevices.emplace(fd,dev);
|
||||
@ -114,11 +114,11 @@ int InputEventSource::checkEvents(){
|
||||
mIsScreenSaveActived = true;
|
||||
}
|
||||
process();
|
||||
if(mInputEvents.size() && mIsScreenSaveActived && mScreenSaver){
|
||||
if(mMotionEvents.size() && mIsScreenSaveActived && mScreenSaver){
|
||||
mScreenSaver(false);
|
||||
mLastInputEventTime = now;
|
||||
}
|
||||
return mInputEvents.size()>0;
|
||||
return mMotionEvents.size()+mKeyEvents.size();
|
||||
}
|
||||
|
||||
void InputEventSource::closeScreenSaver(){
|
||||
@ -131,9 +131,50 @@ bool InputEventSource::isScreenSaverActived()const{
|
||||
|
||||
int InputEventSource::handleEvents(){
|
||||
std::lock_guard<std::mutex> lock(mtxEvents);
|
||||
if(mInputEvents.size()==0)return false;
|
||||
while(mInputEvents.size()){
|
||||
InputEvent* e = mInputEvents.front();
|
||||
int ret = mKeyEvents.size() + mMotionEvents.size();
|
||||
while(mKeyEvents.size()){
|
||||
int lastDev = -1,lastKey = -1;
|
||||
int numDown = 0 ,numUp = 0;
|
||||
for(KeyEvent*e:mKeyEvents){
|
||||
const int dev = e->getDeviceId();
|
||||
const int key = e->getKeyCode();
|
||||
const int act = e->getAction();
|
||||
LOGV("dev=%d key=%d act=%d %d",dev,key,act,mKeyEvents.size());
|
||||
if( (lastKey !=-1) || (lastKey==key) ){
|
||||
numDown+= (act==KeyEvent::ACTION_DOWN);
|
||||
numUp += (act==KeyEvent::ACTION_UP);
|
||||
lastKey = dev; lastKey = key;
|
||||
}else{
|
||||
numDown = numUp =0;
|
||||
lastKey = -1; lastDev = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if((numDown>1)&&(numUp>1)){
|
||||
int repeat = std::min(numDown,numUp);
|
||||
KeyEvent*e = mKeyEvents.front();
|
||||
KeyEvent*kMulti = KeyEvent::obtain(e->getDownTime(),e->getEventTime(),KeyEvent::ACTION_MULTIPLE,
|
||||
e->getKeyCode(),repeat,e->getMetaState(),e->getDeviceId(),
|
||||
e->getScanCode(),e->getFlags(),e->getSource());
|
||||
LOGD("key %d repeat %d",e->getKeyCode(),repeat);
|
||||
WindowManager::getInstance().processEvent(*kMulti);
|
||||
kMulti->recycle();
|
||||
repeat<<=1;
|
||||
for(int i=0;i<repeat;i++){
|
||||
e = mKeyEvents.front();
|
||||
e->recycle();
|
||||
mKeyEvents.erase(mKeyEvents.begin());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
KeyEvent*e1 = mKeyEvents.front();
|
||||
WindowManager::getInstance().processEvent(*e1);
|
||||
e1->recycle();
|
||||
LOGV("key %d repeat=%d/%d",e1->getKeyCode(),numDown,numUp);
|
||||
mKeyEvents.erase(mKeyEvents.begin());
|
||||
}
|
||||
while(mMotionEvents.size()){
|
||||
MotionEvent* e = mMotionEvents.front();
|
||||
WindowManager::getInstance().processEvent(*e);
|
||||
if((!mIsPlayback)&& frecord.is_open() && dynamic_cast<KeyEvent*>(e) ){
|
||||
nsecs_t eventTime=SystemClock::uptimeMillis();
|
||||
@ -144,9 +185,9 @@ int InputEventSource::handleEvents(){
|
||||
mLastPlaybackEventTime = eventTime;
|
||||
}
|
||||
e->recycle();
|
||||
mInputEvents.pop();
|
||||
mMotionEvents.pop();
|
||||
}
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int InputEventSource::process(){
|
||||
@ -167,8 +208,12 @@ int InputEventSource::process(){
|
||||
|
||||
int InputEventSource::pushEvent(InputEvent*evt){
|
||||
std::lock_guard<std::mutex> lock(mtxEvents);
|
||||
mInputEvents.push(evt);
|
||||
return mInputEvents.size();
|
||||
if(evt->getType()==InputEvent::EVENT_TYPE_MOTION){
|
||||
mMotionEvents.push((MotionEvent*)evt);
|
||||
}else if(evt->getType()==InputEvent::EVENT_TYPE_KEY){
|
||||
mKeyEvents.push_back((KeyEvent*)evt);
|
||||
}
|
||||
return mMotionEvents.size() + mKeyEvents.size();
|
||||
}
|
||||
|
||||
void InputEventSource::playback(const std::string&fname){
|
||||
@ -202,7 +247,7 @@ void InputEventSource::playback(const std::string&fname){
|
||||
int keycode = KeyEvent::getKeyCodeFromLabel(word.c_str());
|
||||
KeyEvent*key= KeyEvent::obtain(evttime,evttime,action,keycode,1,0/*metastate*/,
|
||||
0/*deviceid*/,keycode/*scancode*/,0/*flags*/,0/*source*/);
|
||||
mInputEvents.push(key);
|
||||
mKeyEvents.push_back(key);
|
||||
}
|
||||
if(in.gcount() == 0){
|
||||
in.close();
|
||||
|
@ -25,7 +25,8 @@ private:
|
||||
nsecs_t mLastPlaybackEventTime;/*for event record and playback*/
|
||||
nsecs_t mLastInputEventTime;/*for screensaver*/
|
||||
std::ofstream frecord;
|
||||
std::queue<InputEvent*>mInputEvents;
|
||||
std::queue<MotionEvent*>mMotionEvents;
|
||||
std::vector<KeyEvent*>mKeyEvents;
|
||||
std::queue<INPUTEVENT> mRawEvents;
|
||||
std::unordered_map<int,std::shared_ptr<InputDevice>>mDevices;
|
||||
std::shared_ptr<InputDevice>getdevice(int fd);
|
||||
|
@ -3,34 +3,47 @@
|
||||
#include <cdlog.h>
|
||||
#include <gui/gui_features.h>
|
||||
#include <image-decoders/imagedecoder.h>
|
||||
#include <porting/cdgraph.h>
|
||||
namespace cdroid{
|
||||
|
||||
AnimatedImageDrawable::AnimatedImageDrawable():Drawable(){
|
||||
mAnimatedImageState = std::make_shared<AnimatedImageState>();
|
||||
mHandler = nullptr;
|
||||
mStarting = false;
|
||||
mIntrinsicWidth = 0;
|
||||
mIntrinsicHeight= 0;
|
||||
mCurrentFrame= 0;
|
||||
mRepeatCount = REPEAT_UNDEFINED;
|
||||
#define ENEBLE_DMABLIT 0
|
||||
AnimatedImageDrawable::AnimatedImageDrawable()
|
||||
:AnimatedImageDrawable(std::make_shared<AnimatedImageState>()){
|
||||
}
|
||||
|
||||
AnimatedImageDrawable::AnimatedImageDrawable(std::shared_ptr<AnimatedImageState> state){
|
||||
AnimatedImageDrawable::AnimatedImageDrawable(std::shared_ptr<AnimatedImageState> state)
|
||||
:Drawable(){
|
||||
mStarting = 0;
|
||||
mIntrinsicWidth = mIntrinsicHeight =0;
|
||||
mAnimatedImageState =state;
|
||||
mHandler = nullptr;
|
||||
mRepeatCount = REPEAT_UNDEFINED;
|
||||
mIntrinsicWidth = mIntrinsicHeight = 0;
|
||||
mAnimatedImageState = state;
|
||||
mCurrentFrame= 0;
|
||||
mImageHandler = nullptr;
|
||||
}
|
||||
|
||||
AnimatedImageDrawable::AnimatedImageDrawable(cdroid::Context*ctx,const std::string&res)
|
||||
:AnimatedImageDrawable(){
|
||||
uint8_t*buffer;
|
||||
uint32_t pitch;
|
||||
LOGD("decoder=%p res=%s",mAnimatedImageState->mDecoder,res.c_str());
|
||||
ImageDecoder*decoder = ImageDecoder::create(ctx,res);
|
||||
mAnimatedImageState->mDecoder = decoder;
|
||||
#if ENABLE(DMABLIT)
|
||||
GFXCreateSurface(0,&mImageHandler,decoder->getWidth(),decoder->getHeight(),0,0);
|
||||
GFXLockSurface(mImageHandler,(void**)&buffer,&pitch);
|
||||
mAnimatedImageState->mImage = Cairo::ImageSurface::create(buffer,Cairo::Surface::Format::ARGB32,decoder->getWidth(),decoder->getHeight(),pitch);
|
||||
#else
|
||||
mAnimatedImageState->mImage = Cairo::ImageSurface::create(Cairo::Surface::Format::ARGB32,decoder->getWidth(),decoder->getHeight());
|
||||
#endif
|
||||
LOGI("image %dx%dx%d hwsurface.buffer=%p",decoder->getWidth(),decoder->getHeight(),pitch,buffer);
|
||||
mAnimatedImageState->mFrameCount = decoder->getFrameCount();
|
||||
}
|
||||
|
||||
AnimatedImageDrawable::~AnimatedImageDrawable(){
|
||||
if(mImageHandler){
|
||||
GFXDestroySurface(mImageHandler);
|
||||
mImageHandler = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Drawable::ConstantState>AnimatedImageDrawable::getConstantState(){
|
||||
@ -95,7 +108,7 @@ void AnimatedImageDrawable::draw(Canvas& canvas){
|
||||
mRunnable = [this](){
|
||||
invalidateSelf();
|
||||
mCurrentFrame=(mCurrentFrame+1)%mAnimatedImageState->mFrameCount;
|
||||
};
|
||||
};
|
||||
}
|
||||
scheduleSelf(mRunnable, nextDelay + SystemClock::uptimeMillis());
|
||||
} else if (nextDelay<=0){// == FINISHED) {
|
||||
@ -104,9 +117,18 @@ void AnimatedImageDrawable::draw(Canvas& canvas){
|
||||
}
|
||||
}
|
||||
image->mark_dirty();
|
||||
canvas.set_source(image,mBounds.left,mBounds.top);
|
||||
canvas.rectangle(mBounds.left,mBounds.top,mBounds.width,mBounds.height);
|
||||
canvas.fill();
|
||||
void*handler = canvas.getHandler();
|
||||
if((mImageHandler==nullptr)||(handler==nullptr)){
|
||||
canvas.set_source(image,mBounds.left,mBounds.top);
|
||||
canvas.set_operator(Cairo::Context::Operator::SOURCE);
|
||||
canvas.rectangle(mBounds.left,mBounds.top,mBounds.width,mBounds.height);
|
||||
canvas.fill();
|
||||
}else{
|
||||
#if ENABLE(DMABLIT)
|
||||
Rect rd={0,0,mBounds.width,mBounds.height};
|
||||
GFXBlit(handler,(const GFXRect*)&rd,mImageHandler,nullptr,0);
|
||||
#endif
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ private:
|
||||
Runnable mRunnable;
|
||||
ColorFilter* mColorFilter;
|
||||
std::vector<Animatable2::AnimationCallback> mAnimationCallbacks;
|
||||
int loadGIF(std::istream&);
|
||||
Handler* getHandler();
|
||||
void* mImageHandler;
|
||||
void postOnAnimationStart();
|
||||
void postOnAnimationEnd();
|
||||
AnimatedImageDrawable(std::shared_ptr<AnimatedImageState> state);
|
||||
|
@ -160,7 +160,7 @@ void NumberPicker::setWheelItemCount(int count) {
|
||||
}
|
||||
|
||||
void NumberPicker::initView(){
|
||||
ViewConfiguration&config=ViewConfiguration::get(mContext);
|
||||
ViewConfiguration&config= ViewConfiguration::get(mContext);
|
||||
mDisplayedDrawableCount = 0;
|
||||
mDisplayedDrawableSize = 0;
|
||||
mSelectedText = nullptr;
|
||||
@ -177,16 +177,17 @@ void NumberPicker::initView(){
|
||||
mDividerColor =DEFAULT_DIVIDER_COLOR;
|
||||
mWheelMiddleItemIndex = 0;
|
||||
mDividerDrawable = nullptr;
|
||||
mDividerLength =2;
|
||||
mDividerLength = 2;
|
||||
mDividerThickness =2;
|
||||
mBottomSelectionDividerBottom = 0;
|
||||
mDividerType = SIDE_LINES;
|
||||
mLastHandledDownDpadKeyCode =-1;
|
||||
mLastHandledDownDpadKeyCode = -1;
|
||||
mWrapSelectorWheel= false;
|
||||
mWrapSelectorWheelPreferred =true;
|
||||
mWrapSelectorWheelPreferred = true;
|
||||
mSelectionDividerHeight = UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT;
|
||||
mPreviousScrollerY =0;
|
||||
mCurrentScrollOffset =0;
|
||||
mInitialScrollOffset =0;
|
||||
mPreviousScrollerY = 0;
|
||||
mCurrentScrollOffset = 0;
|
||||
mInitialScrollOffset = 0;
|
||||
mLongPressUpdateInterval = DEFAULT_LONG_PRESS_UPDATE_INTERVAL;
|
||||
mMinHeight = SIZE_UNSPECIFIED;
|
||||
mMaxHeight = SIZE_UNSPECIFIED;
|
||||
@ -196,7 +197,7 @@ void NumberPicker::initView(){
|
||||
mMinValue = 0;
|
||||
mMaxValue = 0;
|
||||
mSelectorTextGapHeight = 0;
|
||||
mSelectorElementSize =0;
|
||||
mSelectorElementSize = 0;
|
||||
mSelectionDividersDistance =UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE;
|
||||
mVelocityTracker = nullptr;
|
||||
|
||||
@ -206,7 +207,7 @@ void NumberPicker::initView(){
|
||||
mFlingScroller = new Scroller(getContext(), nullptr, true);
|
||||
mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));
|
||||
mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);
|
||||
mHideWheelUntilFocused=false;
|
||||
mHideWheelUntilFocused = false;
|
||||
mWheelItemCount = DEFAULT_WHEEL_ITEM_COUNT;
|
||||
mRealWheelItemCount= DEFAULT_WHEEL_ITEM_COUNT;
|
||||
mSelectorIndices.resize(mWheelItemCount);
|
||||
|
@ -62,13 +62,13 @@ void ViewAnimator::showOnly(int childIndex, bool animate) {
|
||||
if (i == childIndex) {
|
||||
LOGV("set %d Visible",i);
|
||||
if (animate && mInAnimation != nullptr) {
|
||||
child->startAnimation(mInAnimation);
|
||||
child->startAnimation(mInAnimation->clone());
|
||||
}
|
||||
child->setVisibility(View::VISIBLE);
|
||||
mFirstTime = false;
|
||||
} else {
|
||||
if (animate && mOutAnimation != nullptr && child->getVisibility() == View::VISIBLE) {
|
||||
child->startAnimation(mOutAnimation);
|
||||
child->startAnimation(mOutAnimation->clone());
|
||||
} else if (child->getAnimation() == mInAnimation){
|
||||
child->clearAnimation();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user