ViewConfiguration can loading params from @style/view_Configuration

This commit is contained in:
houzh 2023-12-13 15:01:00 +08:00
parent 382b17fbdb
commit 44d1043ecb
5 changed files with 37 additions and 15 deletions

View File

@ -80,7 +80,7 @@ bool AttributeSet::add(const std::string&key,const std::string&value){
auto itr = mAttrs.find(key); auto itr = mAttrs.find(key);
std::string ks = key; std::string ks = key;
size_t pos =ks.find(' '); 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()) if(itr == mAttrs.end())
mAttrs.insert({(std::string)ks,normalize(mPackage,value)}); mAttrs.insert({(std::string)ks,normalize(mPackage,value)});
else else

View File

@ -610,8 +610,8 @@ void Layout::drawText(Canvas&canvas,int firstLine,int lastLine){
case ALIGN_OPPOSITE: case ALIGN_OPPOSITE:
case ALIGN_RIGHT : x = mWidth - lw ; break; case ALIGN_RIGHT : x = mWidth - lw ; break;
} }
LOGV("line[%d](%d,%d) layoutWidth=%d [%s](%d).width=%d fontsize=%.f alignment=%x abearing=%f", LOGV("line[%d/%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); 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.move_to(x - te.x_bearing,y);
canvas.show_text(processBidi(line)); canvas.show_text(processBidi(line));
if(mCaretPos>=lineStart&&mCaretPos<lineEnd){ if(mCaretPos>=lineStart&&mCaretPos<lineEnd){

View File

@ -718,4 +718,19 @@
<item name="paddingBottom">1dip</item> <item name="paddingBottom">1dip</item>
<item name="background">@mipmap/bottom_bar</item> <item name="background">@mipmap/bottom_bar</item>
</style> </style>
<style name="view_Configuration">
<item name="config_scrollbarSize">4dip</item>
<item name="config_isScreenRound">false</item>
<item name="config_ui_enableFadingMarquee">true</item>
<item name="config_viewConfigurationTouchSlop">8dp</item>
<item name="config_viewConfigurationHoverSlop">8dp</item>
<item name="config_minScrollbarTouchTarget">48dp</item>
<item name="config_viewMinFlingVelocity">50dp</item>
<item name="config_viewMaxFlingVelocity">8000dp</item>
<item name="config_horizontalScrollFactor">64dp</item>
<item name="config_verticalScrollFactor">64dp</item>
<item name="config_globalActionsKeyTimeout">500</item>
<item name="config_horizontalScrollFactor">64</item>
<item name="config_verticalScrollFactor">64</item>
</style>
</resources> </resources>

View File

@ -9,6 +9,7 @@ namespace cdroid{
ViewConfiguration*ViewConfiguration::mInst=nullptr; ViewConfiguration*ViewConfiguration::mInst=nullptr;
ViewConfiguration::ViewConfiguration(){ ViewConfiguration::ViewConfiguration(){
mEdgeSlop = EDGE_SLOP; mEdgeSlop = EDGE_SLOP;
mIsScreenRound = false;
mFadingEdgeLength = FADING_EDGE_LENGTH; mFadingEdgeLength = FADING_EDGE_LENGTH;
mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY; mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY; mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
@ -36,6 +37,9 @@ ViewConfiguration::ViewConfiguration(Context* context):ViewConfiguration(){
AttributeSet atts(context,""); AttributeSet atts(context,"");
WindowManager::getInstance().getDefaultDisplay().getMetrics(metrics); WindowManager::getInstance().getDefaultDisplay().getMetrics(metrics);
const float sizeAndDensity = metrics.density; 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); mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f);
mFadingEdgeLength = int(sizeAndDensity*FADING_EDGE_LENGTH + 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); mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);
if(atts.size()){ if(atts.size()){
mScrollbarSize = atts.getDimensionPixelSize("config_scrollbarSize"); mIsScreenRound = atts.getBoolean("config_isScreenRound",false);
mFadingMarqueeEnabled = atts.getBoolean("config_ui_enableFadingMarquee"); mScrollbarSize = atts.getDimensionPixelSize("config_scrollbarSize",mScrollbarSize);
mTouchSlop = atts.getDimensionPixelSize("config_viewConfigurationTouchSlop"); mFadingMarqueeEnabled = atts.getBoolean("config_ui_enableFadingMarquee",mFadingMarqueeEnabled);
mHoverSlop = atts.getDimensionPixelSize("config_viewConfigurationHoverSlop"); mTouchSlop = atts.getDimensionPixelSize("config_viewConfigurationTouchSlop",mTouchSlop);
mMinScrollbarTouchTarget = atts.getDimensionPixelSize("config_minScrollbarTouchTarget"); mHoverSlop = atts.getDimensionPixelSize("config_viewConfigurationHoverSlop",mHoverSlop);
mMinScrollbarTouchTarget = atts.getDimensionPixelSize("config_minScrollbarTouchTarget",mMinScrollbarTouchTarget);
mGlobalActionsKeyTimeout = atts.getInt("config_globalActionsKeyTimeout",mGlobalActionsKeyTimeout);
} }
mPagingTouchSlop = mTouchSlop * 2; mPagingTouchSlop = mTouchSlop * 2;
mDoubleTapTouchSlop = mTouchSlop; mDoubleTapTouchSlop = mTouchSlop;
if(atts.size()){ if(atts.size()){
mMinimumFlingVelocity = atts.getDimensionPixelSize("config_viewMinFlingVelocity"); mMinimumFlingVelocity = atts.getDimensionPixelSize("config_viewMinFlingVelocity",mMinimumFlingVelocity);
mMaximumFlingVelocity = atts.getDimensionPixelSize("config_viewMaxFlingVelocity"); mMaximumFlingVelocity = atts.getDimensionPixelSize("config_viewMaxFlingVelocity",mMaximumFlingVelocity);
mHorizontalScrollFactor = atts.getDimensionPixelSize("config_horizontalScrollFactor"); mHorizontalScrollFactor = atts.getDimensionPixelSize("config_horizontalScrollFactor",mHorizontalScrollFactor);
mVerticalScrollFactor = atts.getDimensionPixelSize("config_verticalScrollFactor"); mVerticalScrollFactor = atts.getDimensionPixelSize("config_verticalScrollFactor",mVerticalScrollFactor);
} }
} }
ViewConfiguration& ViewConfiguration::get(Context*context){ ViewConfiguration& ViewConfiguration::get(Context*context){
if(mInst==nullptr) if(mInst == nullptr)
mInst=new ViewConfiguration(context); mInst = new ViewConfiguration(context);
return *mInst; return *mInst;
} }
bool ViewConfiguration::isScreenRound(){ bool ViewConfiguration::isScreenRound(){
return false; return mInst && mInst->mIsScreenRound;
} }
int ViewConfiguration::getThumbLength(int size, int thickness, int extent, int range) { int ViewConfiguration::getThumbLength(int size, int thickness, int extent, int range) {

View File

@ -188,6 +188,7 @@ private:
bool mShowMenuShortcutsWhenKeyboardPresent; bool mShowMenuShortcutsWhenKeyboardPresent;
bool sHasPermanentMenuKey; bool sHasPermanentMenuKey;
bool sHasPermanentMenuKeySet; bool sHasPermanentMenuKeySet;
bool mIsScreenRound;
static ViewConfiguration*mInst; static ViewConfiguration*mInst;
ViewConfiguration(Context*context); ViewConfiguration(Context*context);
public: public: