From 44d1043ecbb2b5c7d99789137ed18162140edca7 Mon Sep 17 00:00:00 2001 From: houzh Date: Wed, 13 Dec 2023 15:01:00 +0800 Subject: [PATCH] ViewConfiguration can loading params from @style/view_Configuration --- src/gui/core/attributeset.cc | 2 +- src/gui/core/layout.cc | 4 ++-- src/gui/res/values/styles.xml | 15 +++++++++++++++ src/gui/view/viewconfiguration.cc | 30 ++++++++++++++++++------------ src/gui/view/viewconfiguration.h | 1 + 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/gui/core/attributeset.cc b/src/gui/core/attributeset.cc index 55473c1f..c90dcb30 100755 --- a/src/gui/core/attributeset.cc +++ b/src/gui/core/attributeset.cc @@ -80,7 +80,7 @@ bool AttributeSet::add(const std::string&key,const std::string&value){ auto itr = mAttrs.find(key); std::string ks = key; size_t pos =ks.find(' '); - if(pos!=std::string::npos)ks=ks.substr(pos+1); + if(pos!=std::string::npos)ks = ks.substr(pos+1); if(itr == mAttrs.end()) mAttrs.insert({(std::string)ks,normalize(mPackage,value)}); else diff --git a/src/gui/core/layout.cc b/src/gui/core/layout.cc index 449ed53d..18480679 100644 --- a/src/gui/core/layout.cc +++ b/src/gui/core/layout.cc @@ -610,8 +610,8 @@ void Layout::drawText(Canvas&canvas,int firstLine,int lastLine){ case ALIGN_OPPOSITE: case ALIGN_RIGHT : x = mWidth - lw ; break; } - LOGV("line[%d](%d,%d) layoutWidth=%d [%s](%d).width=%d fontsize=%.f alignment=%x abearing=%f", - lineNum,x,y,mWidth,TextUtils::unicode2utf8(line).c_str(),line.size(),lw,mFontSize,mAlignment,te.x_bearing); + LOGV("line[%d/%d](%d,%d) layoutWidth=%d [%s](%d).width=%d fontsize=%.f alignment=%x abearing=%f", + lineNum,mLineCount,x,y,mWidth,TextUtils::unicode2utf8(line).c_str(),line.size(),lw,mFontSize,mAlignment,te.x_bearing); canvas.move_to(x - te.x_bearing,y); canvas.show_text(processBidi(line)); if(mCaretPos>=lineStart&&mCaretPos1dip @mipmap/bottom_bar + diff --git a/src/gui/view/viewconfiguration.cc b/src/gui/view/viewconfiguration.cc index 0c6af660..3d6823fd 100644 --- a/src/gui/view/viewconfiguration.cc +++ b/src/gui/view/viewconfiguration.cc @@ -9,6 +9,7 @@ namespace cdroid{ ViewConfiguration*ViewConfiguration::mInst=nullptr; ViewConfiguration::ViewConfiguration(){ mEdgeSlop = EDGE_SLOP; + mIsScreenRound = false; mFadingEdgeLength = FADING_EDGE_LENGTH; mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY; mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY; @@ -36,6 +37,9 @@ ViewConfiguration::ViewConfiguration(Context* context):ViewConfiguration(){ AttributeSet atts(context,""); WindowManager::getInstance().getDefaultDisplay().getMetrics(metrics); const float sizeAndDensity = metrics.density; + atts = context->obtainStyledAttributes("@style/view_Configuration"); + if(atts.size()==0) + atts = context->obtainStyledAttributes("cdroid:style/view_Configuration"); mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f); mFadingEdgeLength = int(sizeAndDensity*FADING_EDGE_LENGTH + 0.5f); @@ -46,31 +50,33 @@ ViewConfiguration::ViewConfiguration(Context* context):ViewConfiguration(){ mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f); if(atts.size()){ - mScrollbarSize = atts.getDimensionPixelSize("config_scrollbarSize"); - mFadingMarqueeEnabled = atts.getBoolean("config_ui_enableFadingMarquee"); - mTouchSlop = atts.getDimensionPixelSize("config_viewConfigurationTouchSlop"); - mHoverSlop = atts.getDimensionPixelSize("config_viewConfigurationHoverSlop"); - mMinScrollbarTouchTarget = atts.getDimensionPixelSize("config_minScrollbarTouchTarget"); + mIsScreenRound = atts.getBoolean("config_isScreenRound",false); + mScrollbarSize = atts.getDimensionPixelSize("config_scrollbarSize",mScrollbarSize); + mFadingMarqueeEnabled = atts.getBoolean("config_ui_enableFadingMarquee",mFadingMarqueeEnabled); + mTouchSlop = atts.getDimensionPixelSize("config_viewConfigurationTouchSlop",mTouchSlop); + mHoverSlop = atts.getDimensionPixelSize("config_viewConfigurationHoverSlop",mHoverSlop); + mMinScrollbarTouchTarget = atts.getDimensionPixelSize("config_minScrollbarTouchTarget",mMinScrollbarTouchTarget); + mGlobalActionsKeyTimeout = atts.getInt("config_globalActionsKeyTimeout",mGlobalActionsKeyTimeout); } mPagingTouchSlop = mTouchSlop * 2; mDoubleTapTouchSlop = mTouchSlop; if(atts.size()){ - mMinimumFlingVelocity = atts.getDimensionPixelSize("config_viewMinFlingVelocity"); - mMaximumFlingVelocity = atts.getDimensionPixelSize("config_viewMaxFlingVelocity"); - mHorizontalScrollFactor = atts.getDimensionPixelSize("config_horizontalScrollFactor"); - mVerticalScrollFactor = atts.getDimensionPixelSize("config_verticalScrollFactor"); + mMinimumFlingVelocity = atts.getDimensionPixelSize("config_viewMinFlingVelocity",mMinimumFlingVelocity); + mMaximumFlingVelocity = atts.getDimensionPixelSize("config_viewMaxFlingVelocity",mMaximumFlingVelocity); + mHorizontalScrollFactor = atts.getDimensionPixelSize("config_horizontalScrollFactor",mHorizontalScrollFactor); + mVerticalScrollFactor = atts.getDimensionPixelSize("config_verticalScrollFactor",mVerticalScrollFactor); } } ViewConfiguration& ViewConfiguration::get(Context*context){ - if(mInst==nullptr) - mInst=new ViewConfiguration(context); + if(mInst == nullptr) + mInst = new ViewConfiguration(context); return *mInst; } bool ViewConfiguration::isScreenRound(){ - return false; + return mInst && mInst->mIsScreenRound; } int ViewConfiguration::getThumbLength(int size, int thickness, int extent, int range) { diff --git a/src/gui/view/viewconfiguration.h b/src/gui/view/viewconfiguration.h index c3081e25..b99d1e59 100644 --- a/src/gui/view/viewconfiguration.h +++ b/src/gui/view/viewconfiguration.h @@ -188,6 +188,7 @@ private: bool mShowMenuShortcutsWhenKeyboardPresent; bool sHasPermanentMenuKey; bool sHasPermanentMenuKeySet; + bool mIsScreenRound; static ViewConfiguration*mInst; ViewConfiguration(Context*context); public: