modify ImageView::setImageResource

This commit is contained in:
houzh 2023-12-14 11:35:07 +08:00
parent 46e04cce07
commit 59d4a9bb6c
3 changed files with 21 additions and 9 deletions

View File

@ -8,14 +8,14 @@ int main(int argc,const char*argv[]){
Window*w=new Window(0,0,-1,-1);
w->setId(1);
Drawable*d=nullptr;
StateListDrawable*sd;
StateListDrawable*sld;
CompoundButton*chk;
LOGD("test LOGF %d",__LINE__);
LOG(DEBUG)<<"Test Stream(DEBUG)";
#if 10
Button *btn=new Button("Button",120,60);
d=ctx->getDrawable("cdroid:drawable/btn_default.xml");
sd=dynamic_cast<StateListDrawable*>(d);
sld=dynamic_cast<StateListDrawable*>(d);
w->setBackgroundColor(0xFF101112);
btn->setOnTouchListener([](View&v,MotionEvent&e){
const bool down=e.getAction()==MotionEvent::ACTION_DOWN;
@ -25,7 +25,8 @@ int main(int argc,const char*argv[]){
v.setScaleY(down?0.8f:1.f);
return false;
});
LOGD("%p statecount=%d",sd,sd->getStateCount());
LOGD("%p statecount=%d",sld,sld->getStateCount());
btn->setBackground(d);
btn->setBackgroundTintList(ctx->getColorStateList("cdroid:color/textview"));
btn->setTextAlignment(View::TEXT_ALIGNMENT_CENTER);
@ -33,19 +34,30 @@ int main(int argc,const char*argv[]){
btn->setOnLongClickListener([](View&v)->bool{LOGD(" Button LongClicked ");return true;});
w->addView(btn).setId(100).setPos(50,60);
ShapeDrawable*sd=new ShapeDrawable();
sd->setShape(new ArcShape(0,360));
sd->getShape()->setGradientColors({0x20FFFFFF,0xFFFFFFFF,0x00FFFFFF});//setSolidColor(0x800000FF);
RippleDrawable*rp=new RippleDrawable(ColorStateList::valueOf(0x80222222),
new ColorDrawable(0x8000FF00),sd);
btn=new Button("RippleButton",300,64);
btn->setMinimumHeight(64);
btn->setBackground(rp);
btn->setClickable(true);
w->addView(btn).setId(101).setPos(200,60);
btn=new ToggleButton(120,40);
d=ctx->getDrawable("cdroid:drawable/btn_toggle_bg.xml");
btn->setBackground(d);
btn->setTextColor(ctx->getColorStateList("cdroid:color/textview"));
((ToggleButton*)btn)->setTextOn("ON");
((ToggleButton*)btn)->setTextOff("Off");
w->addView(btn).setId(101).setPos(200,70).setClickable(true);
w->addView(btn).setId(101).setPos(200,150).setClickable(true);
chk=new CheckBox("CheckME",200,60);
d=ctx->getDrawable("cdroid:drawable/btn_check.xml");
chk->setButtonDrawable(d);
chk->setChecked(true);
w->addView(chk).setPos(350,60);
w->addView(chk).setPos(350,150);
/*AnalogClock*clk=new AnalogClock(300,300);
d=ctx->getDrawable("cdroid:drawable/analog.xml");
@ -59,7 +71,7 @@ int main(int argc,const char*argv[]){
Drawable*dr=ctx->getDrawable("cdroid:drawable/btn_radio.xml");
chk->setButtonDrawable(dr);
chk->setChecked(true);
w->addView(chk).setPos(600,60);
w->addView(chk).setPos(600,150);
EditText*edt=new EditText("Edit Me!",200,60);
d=ctx->getDrawable("cdroid:drawable/edit_text.xml");//editbox_background.xml");

View File

@ -44,8 +44,8 @@ void RippleForeground::onTargetRadiusChanged(float targetRadius){
}
void RippleForeground::drawSoftware(Canvas& c,float origAlpha) {
int alpha = (int) (origAlpha * mOpacity + 0.5f);
float radius = getCurrentRadius();
const int alpha = (int) (origAlpha * mOpacity + 0.5f);
const float radius = getCurrentRadius();
if (alpha > 0 && radius > 0) {
const float x = getCurrentX();
const float y = getCurrentY();

View File

@ -534,9 +534,9 @@ void ImageView::setImageResource(const std::string& resId) {
const int oldWidth = mDrawableWidth;
const int oldHeight = mDrawableHeight;
if(mResource==resId) return;
updateDrawable(nullptr);
mResource = resId;
//mUri = nullptr;
resolveUri();
if (oldWidth != mDrawableWidth || oldHeight != mDrawableHeight) {