add viewpropertyanimator,move some base components to view

This commit is contained in:
侯歌 2022-03-11 17:14:46 +08:00
parent 9f1f1bc299
commit 2dd90ae8c6
249 changed files with 1123 additions and 329 deletions

View File

@ -14,7 +14,7 @@ set(CMAKE_INSTALL_DATAROOTDIR ${CMAKE_BINARY_DIR}/data)
set(CMAKE_INSTALL_DATADIR ${CMAKE_BINARY_DIR}/data CACHE PATH "General install location")
set(CMAKE_INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/lib)
if (EXISTS "${CMAKE_SOURCE_DIR}/src/gui/widget/view.h" )
if (EXISTS "${CMAKE_SOURCE_DIR}/src/gui/view/view.h" )
set(DEPS_DIR ${CMAKE_BINARY_DIR})
else()
set(DEPS_DIR ${CMAKE_SOURCE_DIR}/deps)

View File

@ -6,7 +6,7 @@ option( LUA_BINDINGS "UI Lua script bindings" OFF)
option( GUI_STATIC "UI is static link" ON)
aux_source_directory(core SRCS_GUICORE)
aux_source_directory(views SRCS_VIEWS)
aux_source_directory(view SRCS_VIEWS)
aux_source_directory(widget SRCS_WIDGET)
aux_source_directory(drawables SRCS_DRAWABLES)
aux_source_directory(cairomm SRCS_CAIROMM)
@ -21,7 +21,7 @@ message("UI Lua script bindings is ${LUA_BINDINGS} guistatic=${GUI_STATIC}")
include_directories(
./ ./private
./core
./views
./view
./cairomm
./core/svg ./luabinding
${CMAKE_BINARY_DIR}/include
@ -76,7 +76,7 @@ target_link_libraries(gui_static pixman-1 png jpeg cairo_static unibreak zip js
install (TARGETS gui DESTINATION lib)
install (TARGETS gui_static DESTINATION lib)
install (DIRECTORY ${PROJECT_SOURCE_DIR} DESTINATION include/ FILES_MATCHING PATTERN "*.h"
PATTERN "views" EXCLUDE
PATTERN "view" EXCLUDE
PATTERN "core" EXCLUDE)
install (FILES ${LOOPERHEADERS} DESTINATION include/looper)

View File

@ -1,6 +1,5 @@
#include <animation/animationhandler.h>
#include <animation/objectanimator.h>
#include <core/choreographer.h>
#include <core/systemclock.h>
namespace cdroid{

View File

@ -1,8 +1,9 @@
#ifndef __ANIMATION_HANDLER__
#define __ANIMATION_HANDLER__
#include <core/choreographer.h>
#include <core/looper.h>
#include <map>
#include <core/looper.h>
#include <view/choreographer.h>
namespace cdroid{
class ObjectAnimator;
class AnimationHandler:EventHandler{

View File

@ -15,28 +15,32 @@ typedef struct{
AttributeSet attr;
}ANIMDATA;
typedef struct{
Context*context;
std::string package;
int index;
ANIMDATA data[8];
}ANIMPARSERDATA;
static void startAnimation(void *userData, const XML_Char *xname, const XML_Char **satts){
void** parseParams=(void**)userData;
int*index=(int*)parseParams[0];
ANIMDATA*ads=(ANIMDATA*)parseParams[1];
Context*c=(Context*)parseParams[2];
AttributeSet attrs;
ANIMPARSERDATA*pd=(ANIMPARSERDATA*)userData;
AttributeSet attrs(pd->context,pd->package);
std::string name=xname;
Animation*anim=nullptr;
attrs.set(satts);
if (0==name.compare("set")) {
anim = new AnimationSet(c, attrs);
anim = new AnimationSet(pd->context, attrs);
//createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);
} else if (0==name.compare("alpha")) {
anim = new AlphaAnimation(c, attrs);
anim = new AlphaAnimation(pd->context, attrs);
} else if (0==name.compare("scale")) {
anim = new ScaleAnimation(c, attrs);
anim = new ScaleAnimation(pd->context, attrs);
} else if (0==name.compare("rotate")) {
anim = new RotateAnimation(c, attrs);
anim = new RotateAnimation(pd->context, attrs);
} else if (0==name.compare("translate")) {
anim = new TranslateAnimation(c, attrs);
anim = new TranslateAnimation(pd->context, attrs);
} else if (0==name.compare("cliprect")) {
anim = new ClipRectAnimation(c, attrs);
anim = new ClipRectAnimation(pd->context, attrs);
} else {
LOGE("Unknown animation name: %s" ,xname);
}
@ -49,15 +53,14 @@ Animation* AnimationUtils::loadAnimation(Context* context,const std::string&resi
int rdlen;
char buf[256];
int index=0;
ANIMDATA ads[8];
ANIMPARSERDATA pd;
void*parseParams[2];
parseParams[0]=&index;
parseParams[1]=(void*)ads;
parseParams[2]=context;
pd.index = 0;
pd.context = context;
XML_Parser parser=XML_ParserCreate(nullptr);
XML_SetElementHandler(parser, startAnimation, endAnimation);
XML_SetUserData(parser,(void*)parseParams);
std::unique_ptr<std::istream>stream=context->getInputStream(resid);
XML_SetUserData(parser,(void*)&pd);
std::unique_ptr<std::istream>stream=context->getInputStream(resid,&pd.package);
do {
stream->read(buf,sizeof(buf));
rdlen=stream->gcount();

View File

@ -1,5 +1,5 @@
#include <stdlib.h>
#include <widget/viewgroup.h>
#include <view/viewgroup.h>
#include <animation/gridlayoutanimationcontroller.h>
namespace cdroid{

View File

@ -1,5 +1,5 @@
#include <stdlib.h>
#include <widget/viewgroup.h>
#include <view/viewgroup.h>
#include <animation/animationutils.h>
#include <animation/layoutanimationcontroller.h>

View File

@ -1,4 +1,5 @@
#pragma once
#ifndef __LAYOUT_ANIMATION_CONTROLLER_H__
#define __LAYOUT_ANIMATION_CONTROLLER_H__
#include <animation/animation.h>
namespace cdroid{
@ -50,3 +51,4 @@ public:
};
}//endof namespace
#endif //__LAYOUT_ANIMATION_CONTROLLER_H__

View File

@ -1,5 +1,5 @@
#include <animation/layouttransition.h>
#include <widget/viewgroup.h>
#include <view/viewgroup.h>
#include <animation/objectanimator.h>
namespace cdroid{

View File

@ -2,7 +2,7 @@
#define __LAYOUT_TRANSITION_H__
#include <map>
#include <functional>
#include <widget/view.h>
#include <view/view.h>
#include <animation/animator.h>
namespace cdroid{

View File

@ -0,0 +1,126 @@
#include <animation/statelistanimator.h>
namespace cdroid{
StateListAnimator::StateListAnimator(){
mAnimationListener.onAnimationEnd=[this](Animator& animator,bool){
if (mRunningAnimator == &animator) {
mRunningAnimator = nullptr;
}
};
}
void StateListAnimator::addState(const std::vector<int>&specs, ValueAnimator* animator){
Tuple tuple =Tuple(specs, animator);
animator->addListener(mAnimationListener);
mTuples.push_back(tuple);
mChangingConfigurations |= animator->getChangingConfigurations();
}
void StateListAnimator::setState(const std::vector<int>&state){
Tuple* match = nullptr;
const int count = mTuples.size();
for (int i = 0; i < count; i++) {
Tuple& tuple = mTuples.at(i);
if (StateSet::stateSetMatches(tuple.mSpecs, state)) {
match = &tuple;
break;
}
}
if (match == mLastMatch) {
return;
}
if (mLastMatch != nullptr) {
cancel();
}
mLastMatch = match;
if (match != nullptr) {
start(match);
}
}
Animator* StateListAnimator::getRunningAnimator() {
return mRunningAnimator;
}
View* StateListAnimator::getTarget(){
return mView;
}
void StateListAnimator::setTarget(View* view) {
View* current = getTarget();
if (current == view) {
return;
}
if (current != nullptr) {
clearTarget();
}
if (view != nullptr) {
mView = view;
}
}
void StateListAnimator::clearTarget() {
const int size = mTuples.size();
for (int i = 0; i < size; i++) {
mTuples.at(i).mAnimator->setTarget(nullptr);
}
mView = nullptr;
mLastMatch = nullptr;
mRunningAnimator = nullptr;
}
void StateListAnimator::start(Tuple* match) {
mRunningAnimator = match->mAnimator;
mRunningAnimator->start();
}
void StateListAnimator::cancel() {
if (mRunningAnimator != nullptr) {
mRunningAnimator->cancel();
mRunningAnimator = nullptr;
}
}
void StateListAnimator::jumpToCurrentState(){
if (mRunningAnimator != nullptr) {
mRunningAnimator->end();
mRunningAnimator = nullptr;
}
}
int StateListAnimator::getChangingConfigurations()const{
return mChangingConfigurations;
}
void StateListAnimator::setChangingConfigurations(int configs) {
mChangingConfigurations = configs;
}
void StateListAnimator::appendChangingConfigurations(int configs) {
mChangingConfigurations |= configs;
}
std::shared_ptr<ConstantState<StateListAnimator*>>StateListAnimator::createConstantState(){
return mConstantState;
}
/////////////////////////////////////////////////////////////////
StateListAnimator::StateListAnimatorConstantState::StateListAnimatorConstantState(StateListAnimator* animator) {
mAnimator = animator;
mAnimator->mConstantState = shared_from_this();
mChangingConf = mAnimator->getChangingConfigurations();
}
int StateListAnimator::StateListAnimatorConstantState::getChangingConfigurations()const{
return mChangingConf;
}
StateListAnimator* StateListAnimator::StateListAnimatorConstantState::newInstance() {
StateListAnimator* clone = nullptr;//mAnimatorclone();
clone->mConstantState = shared_from_this();
return clone;
}
}

View File

@ -0,0 +1,53 @@
#ifndef __STATELIST_ANIMATOR_H__
#define __STATELIST_ANIMATOR_H__
#include <animation/valueanimator.h>
namespace cdroid{
class StateListAnimator{
protected:
class Tuple {
public:
std::vector<int>mSpecs;
ValueAnimator* mAnimator;
Tuple(const std::vector<int>&specs, ValueAnimator* animator) {
mSpecs = specs;
mAnimator = animator;
}
};
private:
class StateListAnimatorConstantState: public std::enable_shared_from_this<StateListAnimatorConstantState>,public ConstantState<StateListAnimator*>{
protected:
int mChangingConf;
StateListAnimator*mAnimator;
public:
StateListAnimatorConstantState(StateListAnimator*animator);
int getChangingConfigurations()const;
StateListAnimator*newInstance()override;
};
private:
std::vector<Tuple>mTuples;
Tuple* mLastMatch;
Animator*mRunningAnimator;
class View*mView;
std::shared_ptr<StateListAnimatorConstantState> mConstantState;
ValueAnimator::AnimatorListener mAnimationListener;
int mChangingConfigurations;
void clearTarget();
void start(Tuple* match);
void cancel();
public:
StateListAnimator();
void addState(const std::vector<int>&specs, ValueAnimator* animator);
void setState(const std::vector<int>&state);
Animator* getRunningAnimator();
View* getTarget();
void setTarget(View* view);
void jumpToCurrentState();
int getChangingConfigurations()const;
void setChangingConfigurations(int configs);
void appendChangingConfigurations(int configs);
std::shared_ptr<ConstantState<StateListAnimator*>>createConstantState();
};
}//endof namespace
#endif//__STATELIST_ANIMATOR_H__

View File

@ -1,6 +1,5 @@
#include <app/alertcontroller.h>
#include <app/alertdialog.h>
#include <widget/layoutinflater.h>
#include <widget/R.h>
namespace cdroid{

View File

@ -1,6 +1,6 @@
#ifndef __DIALOG_INTERFACE_H__
#define __DIALOG_INTERFACE_H__
#include <widget/view.h>
#include <view/view.h>
namespace cdroid{
class DialogInterface{

View File

@ -1,6 +1,6 @@
#include <cdtypes.h>
#include <widget/viewgroup.h>
#include <views/viewoverlay.h>
#include <view/viewgroup.h>
#include <view/viewoverlay.h>
#include <widget/viewpager.h>
#include <widget/simplemonthview.h>
#include <widget/linearlayout.h>
@ -37,7 +37,7 @@
#include <widget/horizontalscrollview.h>
#include <widget/progressbar.h>
#include <widget/cdwindow.h>
#include <views/toastwindow.h>
#include <view/toastwindow.h>
#include <core/app.h>
#include <widget/seekbar.h>
using namespace cdroid;

0
src/gui/core/app.cc Executable file → Normal file
View File

0
src/gui/core/app.h Executable file → Normal file
View File

5
src/gui/core/assets.cc Executable file → Normal file
View File

@ -285,10 +285,7 @@ Drawable* Assets::getDrawable(const std::string&fullresid){
resname = mTheme.getString(resname.substr(5));
d=getDrawable(resname);
}else if(TextUtils::endWith(resname,".9.png")){
size_t pos = fullresid.find(".");
const std::string ext=(pos==std::string::npos?".9.png":"");
d=new NinePatchDrawable(this,fullresid+ext);
LOGD("%s load =%p",fullresid.c_str(),d);
d=new NinePatchDrawable(this,fullresid);
}else if (TextUtils::endWith(resname,".png")||TextUtils::endWith(resname,".jpg")){
d=new BitmapDrawable(this,fullresid);
}

0
src/gui/core/assets.h Executable file → Normal file
View File

1
src/gui/core/attributeset.cc Executable file → Normal file
View File

@ -1,7 +1,6 @@
#include <attributeset.h>
#include <widget/linearlayout.h>
#include <color.h>
#include <gravity.h>
#include <string.h>
#include <vector>
#include <cdlog.h>

0
src/gui/core/attributeset.h Executable file → Normal file
View File

0
src/gui/core/calendar.cc Executable file → Normal file
View File

0
src/gui/core/callbackbase.h Executable file → Normal file
View File

2
src/gui/core/canvas.cc Executable file → Normal file
View File

@ -8,7 +8,7 @@
#include <wordbreak.h>
#include <linebreak.h>
#include <textutils.h>
#include <gravity.h>
#include <view/gravity.h>
#include <windowmanager.h>
#include <cdgraph.h>
using namespace std;

0
src/gui/core/canvas.h Executable file → Normal file
View File

0
src/gui/core/color.cc Executable file → Normal file
View File

0
src/gui/core/color.h Executable file → Normal file
View File

0
src/gui/core/context.h Executable file → Normal file
View File

0
src/gui/core/displaymetrics.cc Executable file → Normal file
View File

0
src/gui/core/displaymetrics.h Executable file → Normal file
View File

0
src/gui/core/eventcodes.h Executable file → Normal file
View File

0
src/gui/core/graphdevice.cc Executable file → Normal file
View File

0
src/gui/core/graphdevice.h Executable file → Normal file
View File

0
src/gui/core/inputdevice.cc Executable file → Normal file
View File

0
src/gui/core/inputdevice.h Executable file → Normal file
View File

0
src/gui/core/inputeventlabels.h Executable file → Normal file
View File

0
src/gui/core/inputeventsource.cc Executable file → Normal file
View File

0
src/gui/core/inputeventsource.h Executable file → Normal file
View File

0
src/gui/core/inputmethod.cc Executable file → Normal file
View File

0
src/gui/core/inputmethodmanager.cc Executable file → Normal file
View File

0
src/gui/core/inputmethodmanager.h Executable file → Normal file
View File

0
src/gui/core/insets.cc Executable file → Normal file
View File

0
src/gui/core/insets.h Executable file → Normal file
View File

0
src/gui/core/iostreams.cc Executable file → Normal file
View File

0
src/gui/core/keyboard.cc Executable file → Normal file
View File

0
src/gui/core/keyboard.h Executable file → Normal file
View File

2
src/gui/core/layout.cc Executable file → Normal file
View File

@ -1,5 +1,5 @@
#include <layout.h>
#include <gravity.h>
#include <view/gravity.h>
#include <wordbreak.h>
#include <linebreak.h>
#include <fribidi.h>

0
src/gui/core/layout.h Executable file → Normal file
View File

0
src/gui/core/looper.cc Executable file → Normal file
View File

0
src/gui/core/looper.h Executable file → Normal file
View File

0
src/gui/core/mathutils.h Executable file → Normal file
View File

0
src/gui/core/path.cc Executable file → Normal file
View File

0
src/gui/core/path.h Executable file → Normal file
View File

0
src/gui/core/rect.h Executable file → Normal file
View File

0
src/gui/core/scheduler.cc Executable file → Normal file
View File

0
src/gui/core/scheduler.h Executable file → Normal file
View File

0
src/gui/core/scroller.cc Executable file → Normal file
View File

0
src/gui/core/scroller.h Executable file → Normal file
View File

0
src/gui/core/setproctitle.cc Executable file → Normal file
View File

View File

@ -1,5 +1,5 @@
#include <core/soundeffect.h>
#include <widget/view.h>
#include <view/view.h>
namespace cdroid{
int SoundEffectConstants::getContantForFocusDirection(int direction) {
switch (direction) {

0
src/gui/core/sparsearray.h Executable file → Normal file
View File

0
src/gui/core/systemclock.cc Executable file → Normal file
View File

0
src/gui/core/systemclock.h Executable file → Normal file
View File

0
src/gui/core/textutils.cc Executable file → Normal file
View File

0
src/gui/core/textutils.h Executable file → Normal file
View File

0
src/gui/core/typedvalue.cc Executable file → Normal file
View File

0
src/gui/core/typedvalue.h Executable file → Normal file
View File

0
src/gui/core/uievents.cc Executable file → Normal file
View File

0
src/gui/core/uievents.h Executable file → Normal file
View File

1
src/gui/core/uieventsource.cc Executable file → Normal file
View File

@ -2,7 +2,6 @@
#include <windowmanager.h>
#include <cdlog.h>
#include <systemclock.h>
#include <widget/view.h>
#include <list>

2
src/gui/core/uieventsource.h Executable file → Normal file
View File

@ -3,7 +3,7 @@
#include <core/looper.h>
#include <list>
#include <unordered_set>
#include <widget/view.h>
#include <view/view.h>
namespace cdroid{
class UIEventSource:public EventHandler{

0
src/gui/core/variant.h Executable file → Normal file
View File

0
src/gui/core/windowmanager.cc Executable file → Normal file
View File

0
src/gui/core/ziparchive.cc Executable file → Normal file
View File

View File

@ -1,5 +1,4 @@
#include <drawables/bitmapdrawable.h>
#include <gravity.h>
#include <fstream>
#include <app.h>
#include <cdlog.h>

View File

@ -1,8 +1,6 @@
#include <drawables/clipdrawable.h>
#include <gravity.h>
#include <cdlog.h>
namespace cdroid{
#define MAX_LEVEL 10000

View File

@ -1,7 +1,6 @@
#include <color.h>
#include <drawables.h>
#include <expat.h>
#include <gravity.h>
#include <fstream>
#include <cdlog.h>
#include <string.h>

View File

@ -6,7 +6,7 @@
#include <drawables/colorfilters.h>
#include <core/attributeset.h>
#include <core/context.h>
#include <core/gravity.h>
#include <view/gravity.h>
#include <core/insets.h>
#include <vector>

View File

@ -1,5 +1,4 @@
#include <drawables/drawablecontainer.h>
#include <gravity.h>
#include <cdlog.h>
namespace cdroid{

View File

@ -1,7 +1,5 @@
#include <drawables/layerdrawable.h>
#include <drawables/ninepatchdrawable.h>
#include <gravity.h>
#include <cdlog.h>
#include <limits.h>

View File

@ -1,7 +1,7 @@
#include <drawables/ninepatchdrawable.h>
#include <gravity.h>
#include <fstream>
#include <cdlog.h>
namespace cdroid{
//https://github.com/soramimi/QtNinePatch/blob/master/NinePatch.cpp

View File

@ -1,5 +1,5 @@
#include <drawables/scaledrawable.h>
#include <gravity.h>
namespace cdroid{
#define MAX_LEVEL 10000

View File

@ -1,19 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:cdroid="http://schemas.android.com/apk/res/android">
<item cdroid:state_pressed="false"
cdroid:state_enabled="true"
cdroid:state_focused="false"
cdroid:drawable="@mipmap/numberpicker_input_normal" />
<item cdroid:state_pressed="true"
cdroid:state_enabled="true"
cdroid:drawable="@mipmap/numberpicker_input_pressed" />
<item cdroid:state_pressed="false"
cdroid:state_enabled="true" cdroid:state_focused="false"
cdroid:drawable="@mipmap/numberpicker_down_normal" />
<item cdroid:state_pressed="true" cdroid:state_enabled="true"
cdroid:drawable="@mipmap/numberpicker_down_pressed" />
<item cdroid:state_pressed="false"
cdroid:state_enabled="true" cdroid:state_focused="true"
cdroid:drawable="@mipmap/numberpicker_down_selected" />
cdroid:state_enabled="true"
cdroid:state_focused="true"
cdroid:drawable="@mipmap/numberpicker_input_selected" />
<item cdroid:state_pressed="false"
cdroid:state_enabled="false" cdroid:state_focused="false"
cdroid:drawable="@mipmap/numberpicker_down_disabled" />
cdroid:state_enabled="false"
cdroid:state_focused="false"
cdroid:drawable="@mipmap/numberpicker_input_disabled" />
<item cdroid:state_pressed="false"
cdroid:state_enabled="false" cdroid:state_focused="true"
cdroid:drawable="@mipmap/numberpicker_down_disabled_focused" />
cdroid:state_enabled="false"
cdroid:state_focused="true"
cdroid:drawable="@mipmap/numberpicker_input_normal" />
</selector>

View File

@ -1,4 +1,4 @@
#include <choreographer.h>
#include <view/choreographer.h>
#include <systemclock.h>
#include <cdlog.h>

View File

View File

@ -1,5 +1,6 @@
#include <focusfinder.h>
#include <viewconfiguration.h>
#include <view/focusfinder.h>
#include <view/viewconfiguration.h>
namespace cdroid {
FocusFinder*FocusFinder::mInst=nullptr;

View File

@ -1,6 +1,6 @@
#ifndef __FOCUS_FINDER_H__
#define __FOCUS_FINDER_H__
#include <widget/viewgroup.h>
#include <view/viewgroup.h>
namespace cdroid{
class FocusFinder{

3
src/gui/core/gravity.cc → src/gui/view/gravity.cc Executable file → Normal file
View File

@ -1,5 +1,4 @@
#include <gravity.h>
#include <widget/view.h>
#include <view/view.h>
#include <iostream>
#include <sstream>
#include <cdlog.h>

0
src/gui/core/gravity.h → src/gui/view/gravity.h Executable file → Normal file
View File

View File

@ -1,5 +1,5 @@
#include <widget/layoutinflater.h>
#include <widget/viewgroup.h>
#include <view/layoutinflater.h>
#include <view/viewgroup.h>
#include <cdroid.h>
#include <expat.h>
#include <cdlog.h>

View File

@ -3,6 +3,7 @@
#include <core/attributeset.h>
#include <core/attributeset.h>
#include <core/context.h>
namespace cdroid{
class View;
class ViewGroup;

View File

@ -1,5 +1,5 @@
#include <widget/layoutparams.h>
#include <widget/viewgroup.h>
#include <view/layoutparams.h>
#include <view/viewgroup.h>
#include <cdlog.h>
namespace cdroid{

View File

2
src/gui/views/menu.cc → src/gui/view/menu.cc Executable file → Normal file
View File

@ -1,4 +1,4 @@
#include <menu.h>
#include <view/menu.h>
namespace cdroid{
MenuItem::MenuItem(){

2
src/gui/views/menu.h → src/gui/view/menu.h Executable file → Normal file
View File

@ -1,7 +1,7 @@
#ifndef __MENU_H__
#define __MENU_H__
#include <string>
#include <widget/view.h>
#include <view/view.h>
namespace cdroid{

View File

@ -1,4 +1,4 @@
#include <widget/rendernode.h>
#include <view/rendernode.h>
namespace cdroid{
RenderNode::RenderNode(){

View File

View File

@ -1,4 +1,4 @@
#include <toastwindow.h>
#include <view/toastwindow.h>
#include <cdroid.h>
#include <cdlog.h>

View File

View File

@ -1,4 +1,4 @@
#include <velocitytracker.h>
#include <view/velocitytracker.h>
#include <math.h>
#include <string.h>
#include <cdtypes.h>

Some files were not shown because too many files have changed in this diff Show More