mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-02 04:07:42 +08:00
layoutinflater add defaultStyle support.
This commit is contained in:
parent
1e9c2b40c6
commit
38b836827a
@ -178,7 +178,7 @@ ZIPArchive*Assets::getResource(const std::string&fullResId,std::string*relativeR
|
||||
guessExtension(pak,resname);
|
||||
if(relativeResid) *relativeResid=resname;
|
||||
}
|
||||
LOGV_IF(resname.size(),"resource for [%s::%s:%s] is%s found",package.c_str(),fullResId.c_str(),resname.c_str(),(pak?"":" not"));
|
||||
LOGV_IF(pak==nullptr&&resname.size(),"resource for [%s] is%s found",fullResId.c_str(),(pak?"":" not"));
|
||||
return pak;
|
||||
}
|
||||
|
||||
|
@ -111,9 +111,11 @@ void GraphDevice::composeSurfaces(){
|
||||
WindowManager::getInstance().enumWindows([&wSurfaces,&wBounds,&wins](Window*w)->bool{
|
||||
if(w->getVisibility()!=View::VISIBLE||w->mVisibleRgn->empty()==false){
|
||||
Rect rcw=w->getBound();
|
||||
wSurfaces.push_back(w->mAttachInfo->mCanvas);
|
||||
wBounds.push_back(rcw);
|
||||
wins.push_back(w);
|
||||
if(w->mAttachInfo->mCanvas){
|
||||
wSurfaces.push_back(w->mAttachInfo->mCanvas);
|
||||
wBounds.push_back(rcw);
|
||||
wins.push_back(w);
|
||||
}
|
||||
}return true;
|
||||
});
|
||||
primaryContext->set_operator(Cairo::Context::Operator::SOURCE);
|
||||
|
@ -16,24 +16,36 @@ LayoutInflater*LayoutInflater::from(Context*context){
|
||||
return new LayoutInflater(context);
|
||||
}
|
||||
|
||||
LayoutInflater::INFLATERMAPPER& LayoutInflater::getInflaterMap(){
|
||||
static LayoutInflater::INFLATERMAPPER mFlateMapper;
|
||||
return mFlateMapper;
|
||||
}
|
||||
|
||||
LayoutInflater::STYLEMAPPER& LayoutInflater::getStyleMap(){
|
||||
static LayoutInflater::STYLEMAPPER mDefaultStyle;
|
||||
return mDefaultStyle;
|
||||
}
|
||||
|
||||
const std::string LayoutInflater::getDefaultStyle(const std::string&name)const{
|
||||
LayoutInflater::STYLEMAPPER& maps=getStyleMap();
|
||||
auto it=maps.find(name);
|
||||
return it==maps.end()?std::string():it->second;
|
||||
}
|
||||
|
||||
LayoutInflater::ViewInflater LayoutInflater::getInflater(const std::string&name){
|
||||
std::map<const std::string,ViewInflater>&maps=LayoutInflater::getMap();
|
||||
const size_t pt = name.rfind('.');
|
||||
LayoutInflater::INFLATERMAPPER &maps =getInflaterMap();
|
||||
const std::string sname=(pt!=std::string::npos)?name.substr(pt+1):name;
|
||||
auto it=maps.find(sname);
|
||||
return (it!=maps.end())?it->second:nullptr;
|
||||
}
|
||||
|
||||
std::map<const std::string,LayoutInflater::ViewInflater>&LayoutInflater::getMap(){
|
||||
static std::map<const std::string,LayoutInflater::ViewInflater> maps;
|
||||
return maps;
|
||||
}
|
||||
|
||||
bool LayoutInflater::registInflater(const std::string&name,LayoutInflater::ViewInflater inflater){
|
||||
std::map<const std::string,ViewInflater>&maps=LayoutInflater::getMap();
|
||||
bool LayoutInflater::registInflater(const std::string&name,const std::string&defstyle,LayoutInflater::ViewInflater inflater){
|
||||
LayoutInflater::INFLATERMAPPER&maps =getInflaterMap();
|
||||
if(maps.find(name)!=maps.end())
|
||||
return false;
|
||||
maps.insert(std::map<const std::string,LayoutInflater::ViewInflater>::value_type(name,inflater));
|
||||
maps.insert(INFLATERMAPPER::value_type(name,inflater));
|
||||
getStyleMap().insert(std::pair<const std::string,const std::string>(name,defstyle));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -72,7 +84,9 @@ static void startElement(void *userData, const XML_Char *name, const XML_Char **
|
||||
LOGE("Unknown Parser for %s",name);
|
||||
return;
|
||||
}
|
||||
const std::string stname=atts.getString("style");
|
||||
std::string stname=atts.getString("style");
|
||||
if(stname.empty())
|
||||
stname=LayoutInflater::from(pd->ctx)->getDefaultStyle(name);
|
||||
if(!stname.empty()){
|
||||
AttributeSet style=pd->ctx->obtainStyledAttributes(stname);
|
||||
atts.inherit(style);
|
||||
|
@ -12,25 +12,30 @@ public:
|
||||
private:
|
||||
Context*mContext;
|
||||
LayoutInflater(Context*ctx);
|
||||
static std::map<const std::string,ViewInflater>&getMap();
|
||||
typedef std::map<const std::string,ViewInflater>INFLATERMAPPER;
|
||||
typedef std::map<const std::string,const std::string>STYLEMAPPER;
|
||||
static INFLATERMAPPER& getInflaterMap();
|
||||
static STYLEMAPPER& getStyleMap();
|
||||
protected:
|
||||
View* inflate(std::istream&stream,ViewGroup*root,bool attachToRoot);
|
||||
public:
|
||||
static LayoutInflater*from(Context*context);
|
||||
static ViewInflater getInflater(const std::string&);
|
||||
static bool registInflater(const std::string&name,ViewInflater fun);
|
||||
static bool registInflater(const std::string&name,const std::string&,ViewInflater fun);
|
||||
const std::string getDefaultStyle(const std::string&name)const;
|
||||
View* inflate(const std::string&resource,ViewGroup* root, bool attachToRoot=true);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class InflaterRegister{
|
||||
public:
|
||||
InflaterRegister(const std::string&name){
|
||||
LayoutInflater::registInflater(name,[](Context*ctx,const AttributeSet&attr)->View*{return new T(ctx,attr);});
|
||||
InflaterRegister(const std::string&name,const std::string&defstyle){
|
||||
LayoutInflater::registInflater(name,defstyle,[](Context*ctx,const AttributeSet&attr)->View*{return new T(ctx,attr);});
|
||||
}
|
||||
};
|
||||
|
||||
#define DECLARE_WIDGET(T) static InflaterRegister<T> widget_inflater_##T(#T);
|
||||
#define DECLARE_WIDGET2(T,name) static InflaterRegister<T> widget_inflater_##T_##name(#name);
|
||||
#define DECLARE_WIDGET(T) static InflaterRegister<T> widget_inflater_##T(#T,"");
|
||||
#define DECLARE_WIDGET2(T,style) static InflaterRegister<T> widget_inflater_##T(#T,style);
|
||||
#define DECLARE_WIDGET3(T,name,style) static InflaterRegister<T> widget_inflater_##name(#name,style);
|
||||
}//endof namespace
|
||||
#endif
|
||||
|
@ -766,7 +766,8 @@ int TabLayout::getTabMaxWidth() {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
static InflaterRegister<TabLayout::TabItem> widget_inflater_tabitem("TabItem");
|
||||
DECLARE_WIDGET3(TabLayout::TabItem,TabItem,"")
|
||||
|
||||
TabLayout::TabItem::TabItem():View(0,0){
|
||||
mIcon=nullptr;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
namespace cdroid {
|
||||
|
||||
DECLARE_WIDGET(TextView)
|
||||
DECLARE_WIDGET2(TextView,"cdroid:style/textViewStyle")
|
||||
|
||||
class Drawables{
|
||||
public:
|
||||
@ -275,6 +275,7 @@ TextView::TextView(Context*ctx,const AttributeSet& attrs)
|
||||
if(attrs.hasAttribute("textAppearance")){
|
||||
TextAppearanceAttributes attributes;
|
||||
attributes.readTextAppearance(ctx,attrs);
|
||||
applyTextAppearance(&attributes);
|
||||
}
|
||||
|
||||
setMarqueeRepeatLimit(attrs.getInt("marqueeRepeatLimit",mMarqueeRepeatLimit));
|
||||
|
@ -300,7 +300,7 @@ void View::initView(){
|
||||
mID = NO_ID;
|
||||
mAutofillViewId =NO_ID;
|
||||
mAccessibilityViewId=NO_ID;
|
||||
mDrawingCacheBackgroundColor =0xFF000000;
|
||||
mDrawingCacheBackgroundColor =0;
|
||||
mContext = nullptr;
|
||||
mParent = nullptr;
|
||||
mAttachInfo = nullptr;
|
||||
@ -2635,9 +2635,9 @@ bool View::draw(Canvas&canvas,ViewGroup*parent,long drawingTime){
|
||||
}
|
||||
} else if (cache != nullptr) {
|
||||
mPrivateFlags &= ~PFLAG_DIRTY_MASK;
|
||||
cache->flush();
|
||||
canvas.save();
|
||||
canvas.reset_clip();
|
||||
cache->flush();
|
||||
canvas.set_source(cache,0,0);
|
||||
if(alpha<1)canvas.paint_with_alpha(alpha);
|
||||
else canvas.paint();
|
||||
|
Loading…
Reference in New Issue
Block a user