From 1e9c2b40c6813da35145cf8cc9076ee24817e20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E6=AD=8C?= Date: Tue, 8 Feb 2022 14:48:57 +0800 Subject: [PATCH] fix some style theme loading&apply issues --- cmake/common_functions.cmake | 2 +- scripts/po2json.py | 97 +++ src/gui/core/assets.cc | 14 +- src/gui/drawables/drawable.cc | 11 +- src/gui/res/mipmap/bottom_bar.png | Bin 0 -> 2426 bytes src/gui/res/values/ID.xml | 38 +- src/gui/res/values/styles.xml | 498 ++++++++++++ src/gui/res/values/themes.xml | 890 ++++++++++++++++++++++ src/gui/res/values/themes_holo.xml | 1143 ++++++++++++++++++++++++++++ src/gui/widget/textview.cc | 7 +- 10 files changed, 2661 insertions(+), 39 deletions(-) create mode 100755 scripts/po2json.py create mode 100755 src/gui/res/mipmap/bottom_bar.png create mode 100755 src/gui/res/values/themes.xml create mode 100755 src/gui/res/values/themes_holo.xml diff --git a/cmake/common_functions.cmake b/cmake/common_functions.cmake index c67b6fb1..a287657e 100755 --- a/cmake/common_functions.cmake +++ b/cmake/common_functions.cmake @@ -2,7 +2,7 @@ function(CreatePAK project ResourceDIR PakPath rhpath) add_custom_target(${project}_Resource COMMAND ${CMAKE_SOURCE_DIR}/scripts/idgen.py ${ResourceDIR} ${rhpath} - COMMAND zip -r -0 ${PakPath} ./ + COMMAND zip -r -D -0 ${PakPath} ./ WORKING_DIRECTORY ${ResourceDIR} COMMENT "Pckage Assets from ${ResourceDIR} to:${PakPath}") add_dependencies(${project} ${project}_Resource) diff --git a/scripts/po2json.py b/scripts/po2json.py new file mode 100755 index 00000000..06088553 --- /dev/null +++ b/scripts/po2json.py @@ -0,0 +1,97 @@ +#/usr/bin/env python +#coding=utf8 +#created by zhhou +import polib +import requests +import random +import json +from hashlib import md5 +import time +import xlrd #excel read +import xlwt #excel write +import sys, getopt + +appid = '20210610000859637' #Your APPID +secretKey = '7smZUeByLt4BJd5HqBMR' #Your SECURITY KEY +fromLang='en' +url='http://api.fanyi.baidu.com/api/trans/vip/translate' +headers = {'Content-Type': 'application/x-www-form-urlencoded'} +payload = {'appid': appid, 'from': 'en'} + +def make_md5(s, encoding='utf-8'): + return md5(s.encode(encoding)).hexdigest() + +def potranslate(pofile,tolan,sheet): + dict={} + payload['to']=tolan + salt = random.randint(32768, 65536) + payload['salt']=salt + r= requests.post(url,params=payload,headers=headers) + po = polib.pofile(pofile) #'/home/houzh/Miniwin/out-x86/src/apps/ntvplus/ntvplus.po') + i=1 + sheet.protect = True + sheet.password='NgLHello321;' + editable = xlwt.easyxf("protection: cell_locked false;") + read_only = xlwt.easyxf("") + sheet.write(0,0,'string id',read_only) + sheet.write(0,1,'string context',read_only) + for entry in po: + #print entry.msgid, entry.msgstr + q=entry.msgid + payload['q']=q + sign = make_md5(appid + q + str(salt) + secretKey) + payload['sign']=sign + r=requests.post(url,params=payload,headers=headers) + result = r.json() + rstrain= result['trans_result'] + sheet.write(i,0,q,read_only) + if len(rstrain)>0 : + dict[q]=rstrain[0]['dst'] + sheet.write(i,1,dict[q],editable) + print(q+' ==> '+dict[q]) + i=i+1 + #print dict + time.sleep(1) #base version can call 1 per second(1QPS),advance version 10 QPS. change che sleep time to match diffrent version + js=json.dumps(dict) + return dict + +#for language code,pls refto: https://api.fanyi.baidu.com/product/113 +tolans=['pt'] #,'th','bul','fin','fra','ru','zh'] + +def po2json(pofile,tolans): + xls = xlwt.Workbook(); + for lan in tolans : + sheet = xls.add_sheet(lan,cell_overwrite_ok=True) + sheet.col(0).width=256*50 + sheet.col(1).width=256*80 + print("************Translate to "+lan+"**************") + dict=potranslate(pofile,lan,sheet) + fp=open('strings-'+lan+'.json','w') + data=json.dumps(dict,indent=4) #,encoding="utf-8") + fp.write(data) + fp.close() + xls.save(sys.argv[1]+'.xls') + del xls + +def xls2json(fname): ##convert xml.sheet to json string resource + xls=xlrd.open_workbook(fname) + for sheet in xls.sheets(): + print(sheet.name) + strdict={} + for i in range(sheet.nrows): + strid=sheet.cell_value(i,0).encode('utf-8') + strtxt=sheet.cell_value(i,1).encode('utf-8') + print strid+'-->'+strtxt + strdict[strid]=strtxt + js=json.dumps(strdict,indent=4) + fjs=open('strings-'+sheet.name+'.json','w') + fjs.write(js) + fjs.close() + del xls + +if __name__== "__main__": + fname=sys.argv[1] + if fname.endswith('po') : + po2json(fname,tolans) + else: + xls2json(fname) diff --git a/src/gui/core/assets.cc b/src/gui/core/assets.cc index fb7bdd1a..1f0f9109 100755 --- a/src/gui/core/assets.cc +++ b/src/gui/core/assets.cc @@ -303,13 +303,14 @@ Drawable* Assets::getDrawable(const std::string&fullresid){ } int Assets::getColor(const std::string&refid){ + std::string name; auto it = mColors.find(refid); if(it!=mColors.end()) return it->second; - else { - std::string name,pkg; - parseResource(refid,&name,&pkg); - return getColor(pkg+":"+name); + else if(refid.find("color")==std::string::npos){//refid is defined as an color reference + parseResource(refid,&name,nullptr); + name=mTheme.getString(name); + return getColor(name); } } @@ -330,8 +331,9 @@ ColorStateList* Assets::getColorStateList(const std::string&fullresid){ ZipInputStream zs(zfile); return ColorStateList::fromStream(this,zs,resname); }else if(!fullresid.empty()){ - std::ifstream fs(fullresid); - return ColorStateList::fromStream(this,fs,resname); + const int color=getColor(fullresid); + LOGV("%s==%x",fullresid.c_str(),color); + return ColorStateList::valueOf(color); } return nullptr; } diff --git a/src/gui/drawables/drawable.cc b/src/gui/drawables/drawable.cc index 62aecbe4..843e7894 100755 --- a/src/gui/drawables/drawable.cc +++ b/src/gui/drawables/drawable.cc @@ -288,20 +288,11 @@ Drawable*Drawable::createItemDrawable(Context*ctx,const AttributeSet&atts){ resname=atts.getString("drawable"); if(resname.empty()) return nullptr; - std::vectorhorz,vert; if(resname.find("xml")!=std::string::npos){ return Drawable::inflate(ctx,resname); } - std::unique_ptris=ctx->getInputStream(resname); - if(is!=nullptr&&is->good()) - img=ImageSurface::create_from_stream(*is); - if(img==nullptr) - return nullptr; - else if(TextUtils::endWith(resname,"9.png")) - return new NinePatchDrawable(img); - else - return new BitmapDrawable(img); + return ctx->getDrawable(resname); } static std::mapdrawableParsers={ diff --git a/src/gui/res/mipmap/bottom_bar.png b/src/gui/res/mipmap/bottom_bar.png new file mode 100755 index 0000000000000000000000000000000000000000..1fdb0781551a4bfd2128e22a7b5c81afaba648f4 GIT binary patch literal 2426 zcmV-=35E8FP)br(ibPT*C41}{ss)!ri{ukU#filzr=S1*bWl6H^Ud7? zv(Wx_9wzE~CvJC@A);BkxXaaD1GCUC*URrG>b|(~Qef^HOz&=XJ!A|Xfu~UTAl&)> zd>cl3w=fDF#58F!^6i;MZHiUKEHsWS693fb0L`Wl{Pp+s^5qhklqRY8$j>-e0X%~y zdO$SX6U~Fr-`;LXr>Cy{Edg{l{WiRn1Jq|DnW>+iz$8vl^?6bKa=$`{R%+h1A3~)`?GVgVvtPs2f(SnUnL&BqQA6s8(a*vc%z%VM?Ig088Io6 zXRR1a3<>Vs;`W;(-8t%BhU;EC0T zb3!Q$vsrrSB@3q$#S2(SNa*RvD&{7BSxrnS@PIj#_oo**7!xX)3Eu$)|<`gM)#y^b)2M#S2_WL{4KvV*28&c6$9|c(7N8+$N2ocoQzBX)%f4 z?Z&HRbYtP%t3|IS{N)WAC!prTp<(bbFqdA;oPPZK!&$Rt?U=2z5LmNz@C7`~&%}%| z#+XAf9lVWZj4{R>f$4yniihOdPdn7(R`s*wX=eg$i znuuYN(ZWL#3I;x^B#fP-#fhN~&q}jgnLk9%cVkXFm($Des4^MGa+A@PyWS;WPrhy} ziD`T_Sn$?-f6ykM6833IcxPf}Mobq;eysMd6=JZlJt~!r7?ea3Qq?pma0Qf>h zuqR(PmIQg+lU7VFacI%LT9E*T4OT(beh+s^kvuES-5LqmJW7FfNfmK2h9FG-BzR0W z^h^c@R+%P>;3XQy^4{aQB{L1GR{{eE%Zwf~k{|DqGyt~l<>}o5?;%@oO5nj@6kQPNO@M(2bFDZmIiAEjF~HAo zDVZHmD+JSDijy{0r+wvG@l=WuvL=6+F1k_LU&BMK>D_ie51^li-Oq#UFQN1FR(^ga z<}U@UU>Vd(T;!4fqlhPm5qk%n=9hwc=#xu0z`~^jVUQ#vjU%57C&3&;{a}~kiK8bM z(_&^+m;wS}oEv!pgc;0JE6*rJVoP)W^!oiZdFw*Ff97;6zWoNift5Av^8@V*G@?c; z^-h1?j5%;RZk3RBtHqhJHR8zu4?0q$R;wr_m!<_=956F3mFXy*70{r#w0*7 z1~i!X!oZ70L0`?69N{q;EEWoIB8o^bNc-0!@{OKQB8$Lj1yhj&KA9=zlF7ByQ3Bna zUjKO&e`DLIQKS2y(U%$Wg91!q5|iv(^0)(Avu5p>ZTUjK`Wxpp>YQ^J)~36H-4>@# z_kFcCoA(Wpd4t66z!UBGG`tc7VJ^Wa*fR*RJ{tAl+& z31K-#NMPpsA|!<697fR&7>(o-Mew4-~Rqa9InefTpNFP$}}alFZD%Ou5pdMWmQ`S-^;17iL`XS zT50iTr@6-_`QLEui12r=>CvIO!%$ttQLKElnB^v?z|v=h@-1TrmnO#-iXx*6vRsM^NG(25+yaU^_cx%=U+WL3?*$!*gtX1vFAo*28ee5b-`JqKA~Q#IJ8Pf zqI!>FiYjo{PaIiE z75@}7q4p_sUP8dHf53PrES%tYs3+SBC@Y|War!!;}9ux9PZ`@nt`8#QY5h;;sa;2qQH0s7Zsf*f9+s*<;B#hW?ytjvk_Lnv2|a4;VFspE zd=OHJRwt3teBQy?=TIyM6eHqCHONC&i?9)BPcMJI9Oa35v4lu{a?Lid`R|LGSHV03vMtxTDvond z%SuPjxat#&h!H7l)>OhNj@J<#A*3t#JL(iTc?WjumpZo!>HhD)>jkRqSc-=e z)<g!jl-8^rxQz?=djIdyj4@_a#%ObTdimoe sg!tkvVP(gE+9kVGf63Y!?SBCV02{`iZ^YH^b^rhX07*qoM6N<$f+w$~zW@LL literal 0 HcmV?d00001 diff --git a/src/gui/res/values/ID.xml b/src/gui/res/values/ID.xml index f87df7d5..82693a30 100755 --- a/src/gui/res/values/ID.xml +++ b/src/gui/res/values/ID.xml @@ -2,30 +2,30 @@ 0x000003e8 0x000003e9 - 0x000003ea - 0x000003eb - 0x000003ec - 0x000003ed - 0x000003ee - 0x000003ef - 0x000003f0 - 0x000003f1 - 0x000003f2 - 0x000003f3 - 0x000003f4 - 0x000003f5 + 0x000003ea + 0x000003eb + 0x000003ec + 0x000003ed + 0x000003ee + 0x000003ef + 0x000003f0 + 0x000003f1 + 0x000003f2 + 0x000003f3 + 0x000003f4 + 0x000003f5 0x000003f6 - 0x000003f7 - 0x000003f8 + 0x000003f7 + 0x000003f8 0x000003f9 - 0x000003fa - 0x000003fb + 0x000003fa + 0x000003fb 0x000003fc 0x000003fd 0x000003fe - 0x000003ff - 0x00000400 - 0x00000401 + 0x000003ff + 0x00000400 + 0x00000401 0x00000402 0x00000403 0x00000404 diff --git a/src/gui/res/values/styles.xml b/src/gui/res/values/styles.xml index ce9e256c..893e71de 100755 --- a/src/gui/res/values/styles.xml +++ b/src/gui/res/values/styles.xml @@ -32,6 +32,493 @@ false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gui/res/values/themes.xml b/src/gui/res/values/themes.xml new file mode 100755 index 00000000..383ae5d5 --- /dev/null +++ b/src/gui/res/values/themes.xml @@ -0,0 +1,890 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gui/res/values/themes_holo.xml b/src/gui/res/values/themes_holo.xml new file mode 100755 index 00000000..8f73479e --- /dev/null +++ b/src/gui/res/values/themes_holo.xml @@ -0,0 +1,1143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gui/widget/textview.cc b/src/gui/widget/textview.cc index 36055fc4..a010843d 100755 --- a/src/gui/widget/textview.cc +++ b/src/gui/widget/textview.cc @@ -233,7 +233,8 @@ TextAppearanceAttributes::TextAppearanceAttributes(){ void TextAppearanceAttributes::readTextAppearance(Context*ctx,const AttributeSet&att){ const std::string ta=att.getString("textAppearance"); const AttributeSet atts=ctx->obtainStyledAttributes(ta); - mTextColorHighlight = atts.getColor("textColorHighlight",mTextColorHighlight); + + mTextColorHighlight = ctx->getColor(atts.getString("textColorHighlight")); mTextColor = ctx->getColorStateList(atts.getString("textColor")); mTextColorHint = ctx->getColorStateList(atts.getString("textColorHint")); mTextColorLink = ctx->getColorStateList(atts.getString("textColorLink")); @@ -255,9 +256,9 @@ TextView::TextView(Context*ctx,const AttributeSet& attrs) Drawable* left =ctx->getDrawable(attrs,"drawableLeft"); Drawable*right =ctx->getDrawable(attrs,"drawableRight"); - Drawable* top =ctx->getDrawable(attrs,"drawableTop"); + Drawable* top =ctx->getDrawable(attrs,"drawableTop"); Drawable*bottom=ctx->getDrawable(attrs,"drawableBottom"); - Drawable* start=ctx->getDrawable(attrs,"drawableStart"); + Drawable*start =ctx->getDrawable(attrs,"drawableStart"); Drawable* end =ctx->getDrawable(attrs,"drawableEnd"); setCompoundDrawablesWithIntrinsicBounds(left,top,right,bottom);