mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-29 18:59:14 +08:00
fix assets::getArray
This commit is contained in:
parent
2a3695f1c9
commit
aa2c1bd866
@ -1,3 +1,11 @@
|
|||||||
<strings lang="zh_CN">
|
<resources lang="zh_CN">
|
||||||
<string name="weathertips">weathertips</string>
|
<string name="weathertips">weathertips</string>
|
||||||
</strings>
|
<string-array name="cleverwash">
|
||||||
|
<item>10分钟</item>
|
||||||
|
<item>20分钟</item>
|
||||||
|
<item>30分钟</item>
|
||||||
|
<item>40分钟</item>
|
||||||
|
<item>50分钟</item>
|
||||||
|
<item>60分钟</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
||||||
|
@ -14,8 +14,7 @@ OptionPicker::OptionPicker(Context*ctx,const AttributeSet&attr):RelativeLayout(c
|
|||||||
mNumberPicker = (NumberPicker*)findViewById(w9::R::id::numpicker);
|
mNumberPicker = (NumberPicker*)findViewById(w9::R::id::numpicker);
|
||||||
mNumberPicker->setVisibility(View::GONE);
|
mNumberPicker->setVisibility(View::GONE);
|
||||||
mNumberPicker->setMinValue(0);
|
mNumberPicker->setMinValue(0);
|
||||||
mNumberPicker->setMaxValue(10);
|
mNumberPicker->setMaxValue(5);
|
||||||
mNumberPicker->setSelector(5,-1);
|
|
||||||
mText1=(TextView*)findViewById(w9::R::id::text1);
|
mText1=(TextView*)findViewById(w9::R::id::text1);
|
||||||
mText2=(TextView*)findViewById(w9::R::id::text2);
|
mText2=(TextView*)findViewById(w9::R::id::text2);
|
||||||
mText1->setText(attr.getString("text1"));
|
mText1->setText(attr.getString("text1"));
|
||||||
@ -54,9 +53,10 @@ void OptionPicker::setOnValueChangedListener(NumberPicker::OnValueChangeListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OptionPicker::setValuedName(const std::vector<int>&values,const std::vector<std::string>&names){
|
void OptionPicker::setValuedName(const std::vector<int>&values,const std::vector<std::string>&names){
|
||||||
|
const int count=std::max(values.size(),names.size());
|
||||||
mValues=values;
|
mValues=values;
|
||||||
mNumberPicker->setMinValue(0);
|
mNumberPicker->setMinValue(0);
|
||||||
mNumberPicker->setMaxValue(values.size());
|
mNumberPicker->setMaxValue(count-1);
|
||||||
mNumberPicker->setDisplayedValues(names);
|
mNumberPicker->setDisplayedValues(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,11 @@ WashOptionsWindow::WashOptionsWindow(int options):Window(0,0,-1,-1){
|
|||||||
|
|
||||||
void WashOptionsWindow::onOptionClick(View&v){
|
void WashOptionsWindow::onOptionClick(View&v){
|
||||||
ViewGroup*vg=v.getParent();
|
ViewGroup*vg=v.getParent();
|
||||||
|
std::vector<int>values;
|
||||||
|
std::vector<std::string>array;
|
||||||
|
getContext()->getArray("w9:array/cleverwash",array);
|
||||||
|
LOGD("array.size=%d",array.size());
|
||||||
|
dynamic_cast<OptionPicker&>(v).setValuedName(values,array);
|
||||||
for(int i=0;i<vg->getChildCount();i++){
|
for(int i=0;i<vg->getChildCount();i++){
|
||||||
OptionPicker*op=dynamic_cast<OptionPicker*>(vg->getChildAt(i));
|
OptionPicker*op=dynamic_cast<OptionPicker*>(vg->getChildAt(i));
|
||||||
op->showOptions(op==&v);
|
op->showOptions(op==&v);
|
||||||
|
@ -131,7 +131,7 @@ class IDGenerater(object):
|
|||||||
def strings2XML(self,filename):
|
def strings2XML(self,filename):
|
||||||
print self.Handler.strings
|
print self.Handler.strings
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
dom=parseString('<?xml version="1.0" encoding="utf-8"?>\n<strings lang="zh_CN"></strings>')
|
dom=parseString('<?xml version="1.0" encoding="utf-8"?>\n<resources lang="zh_CN"></resources>')
|
||||||
else:
|
else:
|
||||||
dom=parse(filename)
|
dom=parse(filename)
|
||||||
root = dom.documentElement
|
root = dom.documentElement
|
||||||
|
@ -107,26 +107,27 @@ void Assets::parseItem(const std::string&package,const std::vector<std::string>&
|
|||||||
it->second.add(atts[1].getString("name"),normalizedValue);
|
it->second.add(atts[1].getString("name"),normalizedValue);
|
||||||
}else if(tag0.compare("array")==0){
|
}else if(tag0.compare("array")==0){
|
||||||
const std::string name=atts[0].getString("name");
|
const std::string name=atts[0].getString("name");
|
||||||
auto it=mArraies.find(name);
|
const std::string key=package+":array/"+name;
|
||||||
|
auto it=mArraies.find(key);
|
||||||
if(it==mArraies.end()){
|
if(it==mArraies.end()){
|
||||||
it=mArraies.insert(it,std::pair<const std::string,std::vector<std::string>>(name,std::vector<std::string>()));
|
it=mArraies.insert(it,std::pair<const std::string,std::vector<std::string>>(key,std::vector<std::string>()));
|
||||||
LOGD("array:%s",name.c_str());
|
LOGV("array:%s",key.c_str());
|
||||||
}
|
}
|
||||||
it->second.push_back(value);
|
it->second.push_back(value);
|
||||||
}else if(tags[0].compare("string-array")==0){
|
}else if(tags[0].compare("string-array")==0){
|
||||||
const std::string name=atts[0].getString("name");
|
const std::string name=atts[0].getString("name");
|
||||||
const std::string key=package+":string/"+name;
|
const std::string key=package+":array/"+name;
|
||||||
auto it=mArraies.find(name);
|
auto it=mArraies.find(key);
|
||||||
if(it==mArraies.end()){
|
if(it==mArraies.end()){
|
||||||
it=mArraies.insert(it,std::pair<const std::string,std::vector<std::string>>(name,std::vector<std::string>()));
|
it=mArraies.insert(it,std::pair<const std::string,std::vector<std::string>>(key,std::vector<std::string>()));
|
||||||
LOGD("string-array:%s",name.c_str());
|
LOGV("string-array:%s",key.c_str());
|
||||||
}
|
}
|
||||||
it->second.push_back(value);
|
it->second.push_back(value);
|
||||||
}else if(tags[1].compare("string")==0){
|
}else if(tags[1].compare("string")==0){
|
||||||
const std::string name=atts[1].getString("name");
|
const std::string name=atts[1].getString("name");
|
||||||
const std::string key=package+":string/"+name;
|
const std::string key=package+":string/"+name;
|
||||||
mStrings[key]=value;
|
mStrings[key]=value;
|
||||||
LOGD("%s=%s",key.c_str(),value.c_str());
|
LOGV("%s=%s",key.c_str(),value.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +149,7 @@ int Assets::addResource(const std::string&path,const std::string&name){
|
|||||||
pak->forEachEntry([this,package,&count](const std::string&res){
|
pak->forEachEntry([this,package,&count](const std::string&res){
|
||||||
count++;
|
count++;
|
||||||
if((res.size()>7)&&TextUtils::startWith(res,"values")){
|
if((res.size()>7)&&TextUtils::startWith(res,"values")){
|
||||||
LOGD("LoadKeyValues from:%s ...",res.c_str());
|
LOGV("LoadKeyValues from:%s ...",res.c_str());
|
||||||
const std::string resid=package+":"+res;
|
const std::string resid=package+":"+res;
|
||||||
loadKeyValues(resid,std::bind(&Assets::parseItem,this,package,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3));
|
loadKeyValues(resid,std::bind(&Assets::parseItem,this,package,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3));
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<strings lang="zh_CN">
|
<resources lang="zh_CN">
|
||||||
<string name="number_picker_increment_button">number_picker_increment_button</string>
|
<string name="number_picker_increment_button">number_picker_increment_button</string>
|
||||||
<string name="number_picker_decrement_button">number_picker_decrement_button</string>
|
<string name="number_picker_decrement_button">number_picker_decrement_button</string>
|
||||||
<string name="row1">row1</string>
|
<string name="row1">row1</string>
|
||||||
<string name="row2">row2</string>
|
<string name="row2">row2</string>
|
||||||
<string name="row3">row3</string>
|
<string name="row3">row3</string>
|
||||||
<string name="row4">row4</string>
|
<string name="row4">row4</string>
|
||||||
</strings>
|
</resources>
|
||||||
|
24
tests/gui/assets_tests.cc
Executable file
24
tests/gui/assets_tests.cc
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <cdroid.h>
|
||||||
|
#include <ngl_os.h>
|
||||||
|
|
||||||
|
using namespace cdroid;
|
||||||
|
|
||||||
|
class ASSETS:public testing::Test{
|
||||||
|
|
||||||
|
public :
|
||||||
|
virtual void SetUp(){
|
||||||
|
}
|
||||||
|
virtual void TearDown(){
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TEST_F(ASSETS,arrsy){
|
||||||
|
App app(0,NULL);
|
||||||
|
std::vector<std::string>array;
|
||||||
|
app.getArray("cdroid:array/resolver_target_actions_unpin",array);
|
||||||
|
for(auto a:array)printf("%s\r\n",a.c_str());
|
||||||
|
ASSERT_TRUE(array.size()>0);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user