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);
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

View File

@ -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&&mCaretPos<lineEnd){

View File

@ -718,4 +718,19 @@
<item name="paddingBottom">1dip</item>
<item name="background">@mipmap/bottom_bar</item>
</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>

View File

@ -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) {

View File

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