fix a tablayout's crash

This commit is contained in:
houzh 2023-09-09 11:34:25 +08:00
parent 7788624c06
commit 9035e37d66
7 changed files with 39 additions and 14 deletions

View File

@ -5,6 +5,7 @@
#include <cdlog.h>
#include <string.h>
#include <textutils.h>
#include <core/windowmanager.h>
using namespace Cairo;
namespace cdroid {
@ -237,6 +238,29 @@ Drawable*Drawable::getCurrent() {
return this;
}
int Drawable::resolveOpacity(int op1,int op2){
if (op1 == op2) {
return op1;
}
if (op1 == PixelFormat::UNKNOWN || op2 == PixelFormat::UNKNOWN) {
return PixelFormat::UNKNOWN;
}
if (op1 == PixelFormat::TRANSLUCENT || op2 == PixelFormat::TRANSLUCENT) {
return PixelFormat::TRANSLUCENT;
}
if (op1 == PixelFormat::TRANSPARENT || op2 == PixelFormat::TRANSPARENT) {
return PixelFormat::TRANSPARENT;
}
return PixelFormat::OPAQUE;
}
int Drawable::resolveDensity(int parentDensity){
DisplayMetrics metrics;
WindowManager::getInstance().getDefaultDisplay().getMetrics(metrics);
const int densityDpi = /*r == null ? parentDensity :*/metrics.densityDpi;
return densityDpi == 0 ? DisplayMetrics::DENSITY_DEFAULT : densityDpi;
}
float Drawable::scaleFromDensity(float pixels, int sourceDensity, int targetDensity) {
return pixels * targetDensity / sourceDensity;
}

View File

@ -137,6 +137,7 @@ public:
virtual void draw(Canvas&ctx)=0;
static int resolveOpacity(int op1,int op2);
static int resolveDensity(int parentDensity);
static float scaleFromDensity(float pixels, int sourceDensity, int targetDensity);
static int scaleFromDensity(int pixels, int sourceDensity, int targetDensity, bool isSize);
static Drawable*createWrappedDrawable(Context* ctx,const AttributeSet&atts);

View File

@ -38,7 +38,7 @@ public:
DrawableContainer::DrawableContainerState::DrawableContainerState(const DrawableContainerState*orig,DrawableContainer*own){
mOwner = own;
mDensity = 160;//Drawable.resolveDensity(res, orig != null ? orig.mDensity : 0);
mDensity = Drawable::resolveDensity(orig? orig->mDensity : 0);
mVariablePadding = false;
mConstantSize = false;
mCheckedConstantState = true;

View File

@ -81,7 +81,7 @@ GradientDrawable::GradientState::GradientState(const GradientState& orig) {
mAttrCorners = orig.mAttrCorners;
mAttrPadding = orig.mAttrPadding;
mDensity = orig.mDensity;// Drawable::resolveDensity(/*res,*/orig.mDensity);
mDensity = Drawable::resolveDensity(/*res,*/orig.mDensity);
if (orig.mDensity != mDensity) {
applyDensityScaling(orig.mDensity, mDensity);
}
@ -834,13 +834,13 @@ void GradientDrawable::draw(Canvas&canvas) {
break;
case OVAL:
canvas.save();
rad =std::min(mRect.width,mRect.height)/2.f;
canvas.translate(mRect.left + mRect.width/2.f ,mRect.top+mRect.height/2.f);
canvas.scale(float(mRect.width)/mRect.height,1.f);
rad = mRect.height/2.f;
canvas.translate(mRect.left + mRect.width/2.f ,mRect.top+mRect.height/2.f);
canvas.scale(float(mRect.width)/mRect.height,1.f);
LOGV("%p size=%.fx%.f radius=%f strokewidth=%d",this,mRect.width,mRect.height,(float)st->mRadius,st->mStrokeWidth);
canvas.move_to(mRect.left+mRect.width/2.f +rad,mRect.top+mRect.height/2.f);
canvas.arc(0,0,rad,0,M_PI*2.f*(getUseLevel()?(float)getLevel()/10000.f:1));
#endif
if(mFillPaint)canvas.set_source(mFillPaint);
if (haveStroke) {
if(mFillPaint)canvas.fill_preserve();

View File

@ -87,7 +87,7 @@ LayerDrawable::LayerState::LayerState(){
}
LayerDrawable::LayerState::LayerState(const LayerState*orig,LayerDrawable*owner):LayerState(){
//mDensity = Drawable::resolveDensity( orig != nullptr ? orig->mDensity : 0);
mDensity = Drawable::resolveDensity( orig ? orig->mDensity : 0);
if (orig == nullptr) return;
mChangingConfigurations = orig->mChangingConfigurations;

View File

@ -40,7 +40,7 @@ int RippleDrawable::RippleState::getChangingConfigurations()const{
RippleDrawable::RippleDrawable(std::shared_ptr<RippleState> state) {
mState.reset(new RippleState(state.get(), this));
mLayerState = mState;
mDensity = 160;//Drawable::resolveDensity(res, mState.mDensity);
mDensity = Drawable::resolveDensity(mState->mDensity);
mRipple = nullptr;
mBackground = nullptr;
mRippleActive = false;

View File

@ -233,12 +233,12 @@ void TabLayout::removeAllTabs(){
removeTabViewAt(i);
}
/*for (Iterator<Tab> i = mTabs.iterator(); i.hasNext();) {
Tab tab = i.next();
i.remove();
tab.reset();
//sTabPool.release(tab);
}*/
while (!mTabs.empty()){
auto it= mTabs.begin();
Tab* tab = (*it);
delete tab;
mTabs.erase(it);
}
mSelectedTab = nullptr;
}