add RecyclerView::SavedState

This commit is contained in:
侯歌 2024-06-28 10:12:35 +08:00
parent c57256f4f0
commit 5df3a226d7
6 changed files with 49 additions and 64 deletions

View File

@ -573,7 +573,7 @@ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value
slot = mTrack2Slot.indexOfKey(mProp.id);
#else
slot = mProp.id;
if( (mProp.id==-1) && ((mDeviceClasses&INPUT_DEVICE_CLASS_TOUCH_MT)==0) )
if( (mProp.id==-1) && ((mCorrectedDeviceClasses&INPUT_DEVICE_CLASS_TOUCH_MT)==0) )
mProp.id = 0;
#endif
slot = slot>=0?slot:0;

View File

@ -576,19 +576,13 @@ void Layout::relayout(bool force){
static const std::string processBidi(const std::wstring&logstr){
#ifdef ENABLE_FRIBIDI
size_t wsize=logstr.length()+1;
FriBidiCharType base_dir=FRIBIDI_TYPE_ON;
FriBidiChar * visstr= new FriBidiChar[wsize] ;
FriBidiLevel* level = new FriBidiLevel[wsize];
FriBidiStrIndex *posLV= new FriBidiStrIndex[wsize];
FriBidiStrIndex *posVL= new FriBidiStrIndex[wsize];
const size_t wsize = logstr.length()+1;
FriBidiCharType base_dir = FRIBIDI_TYPE_ON;
FriBidiChar * visstr = new FriBidiChar[wsize] ;
fribidi_log2vis((const FriBidiChar*)logstr.c_str(),logstr.length(),&base_dir,visstr,posLV,posVL,level);
fribidi_log2vis((const FriBidiChar*)logstr.c_str(),logstr.length(),&base_dir,visstr,nullptr,nullptr,nullptr);
std::wstring biditxt((const wchar_t*)visstr,wsize-1);
delete [] visstr;
delete [] posLV;
delete [] posVL;
delete [] level;
return TextUtils::unicode2utf8(biditxt);
#else
return TextUtils::unicode2utf8(logstr);
@ -621,7 +615,7 @@ void Layout::drawText(Canvas&canvas,int firstLine,int lastLine){
line.size(),lw,int(te.x_advance));
canvas.move_to(x,y);
canvas.show_text(processBidi(line));
if(mCaretPos>=lineStart&&mCaretPos<lineEnd){
if( (mCaretPos>=lineStart) && (mCaretPos<lineEnd) ){
measureSize(line.substr(0,mCaretPos-lineStart),te,nullptr);
mCaretRect.left= x + te.x_advance;
mCaretRect.top = lineNum * mLineHeight;

View File

@ -17,6 +17,7 @@ LinearLayoutManager::LinearLayoutManager(Context* context,int orientation,bool r
mStackFromEnd = false;
mShouldReverseLayout = false;
mRecycleChildrenOnDetach = true;
mInitialPrefetchItemCount = 2;
mAnchorInfo = new AnchorInfo();
mLayoutChunkResult = new LayoutChunkResult();
setOrientation(orientation);
@ -98,6 +99,7 @@ Parcelable* LinearLayoutManager::onSaveInstanceState() {
}
return state;
}
void LinearLayoutManager::onRestoreInstanceState(Parcelable& state) {
if (dynamic_cast<SavedState*>(&state)) {
mPendingSavedState = (SavedState*)&state;

View File

@ -26,8 +26,8 @@ private:
bool mStackFromEnd = false;
bool mSmoothScrollbarEnabled = true;
bool mRecycleChildrenOnDetach;
LayoutChunkResult* mLayoutChunkResult;// = new LayoutChunkResult();
int mInitialPrefetchItemCount = 2;
LayoutChunkResult* mLayoutChunkResult;;
int mInitialPrefetchItemCount;
int mReusableIntPair[2];
private:
void resolveShouldLayoutReverse();

View File

@ -124,6 +124,7 @@ RecyclerView::~RecyclerView(){
delete mBottomGlow;
delete mEdgeEffectFactory;
delete mScrollingChildHelper;
delete mPendingSavedState;
delete (ViewInfoStore::ProcessCallback*)mViewInfoProcessCallback;
}
@ -145,6 +146,7 @@ void RecyclerView::initRecyclerView(){
mViewFlinger = new ViewFlinger(this);
mItemAnimator= nullptr;
mRecycler = new Recycler(this);
mPendingSavedState = nullptr;
mObserver = new RecyclerViewDataObserver(this);
mLeftGlow = mTopGlow = nullptr;
mRightGlow = mBottomGlow = nullptr;
@ -616,34 +618,28 @@ RecyclerView::OnFlingListener RecyclerView::getOnFlingListener() {
}
Parcelable* RecyclerView::onSaveInstanceState() {
#if 0
SavedState* state = new SavedState(super.onSaveInstanceState());;
SavedState* state = new SavedState(ViewGroup::onSaveInstanceState());
if (mPendingSavedState != nullptr) {
state->copyFrom(mPendingSavedState);
state->copyFrom(*mPendingSavedState);
} else if (mLayout != nullptr) {
state->mLayoutState = mLayout->onSaveInstanceState();
} else {
state->mLayoutState = nullptr;
}
return state;
#else
return nullptr;
#endif
}
void RecyclerView::onRestoreInstanceState(Parcelable& state) {
#if 0
if (!(dynamic_cast<SavedState*>(&state)) {
ViewGroup::onRestoreInstanceState(state);
if (dynamic_cast<SavedState*>(&state)==nullptr) {
ViewGroup::onRestoreInstanceState(state);
return;
}
mPendingSavedState = (SavedState*)& state;
ViewGroup::onRestoreInstanceState(mPendingSavedState.getSuperState());
if (mLayout != null && mPendingSavedState.mLayoutState != null) {
mLayout->onRestoreInstanceState(mPendingSavedState.mLayoutState);
ViewGroup::onRestoreInstanceState(*mPendingSavedState->getSuperState());
if (mLayout != nullptr && mPendingSavedState->mLayoutState != nullptr) {
mLayout->onRestoreInstanceState(*mPendingSavedState->mLayoutState);
}
#endif
}
void RecyclerView::dispatchSaveInstanceState(SparseArray<Parcelable*>& container) {
@ -6801,47 +6797,25 @@ void RecyclerView::SmoothScroller::Action::update(int dx,int dy,int duration,Int
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#if 0
public static class SavedState extends AbsSavedState {
/** called by CREATOR */
RecyclerView::SavedState::SavedState(Parcel& in):AbsSavedState(in){
//super(in, loader);
//mLayoutState = in.readParcelable(loader != null ? loader : LayoutManager.class.getClassLoader());
}
Parcelable mLayoutState;
/**Called by onSaveInstanceState */
RecyclerView::SavedState::SavedState(Parcelable* superState):AbsSavedState(superState){
}
/** called by CREATOR */
SavedState(Parcel in, ClassLoader loader) {
super(in, loader);
mLayoutState = in.readParcelable(
loader != null ? loader : LayoutManager.class.getClassLoader());
}
void RecyclerView::SavedState::writeToParcel(Parcel& dest, int flags) {
AbsSavedState::writeToParcel(dest, flags);
//dest.writeParcelable(mLayoutState, 0);
}
/**Called by onSaveInstanceState */
SavedState(Parcelable superState) {
super(superState);
}
void RecyclerView::SavedState::copyFrom(SavedState& other) {
mLayoutState = other.mLayoutState;
}
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeParcelable(mLayoutState, 0);
}
void copyFrom(SavedState other) {
mLayoutState = other.mLayoutState;
}
public static final Creator<SavedState> CREATOR = new ClassLoaderCreator<SavedState>() {
public SavedState createFromParcel(Parcel in, ClassLoader loader) {
return new SavedState(in, loader);
}
public SavedState createFromParcel(Parcel in) {
return new SavedState(in, null);
}
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
}
#endif
bool RecyclerView::AdapterDataObservable::hasObservers() const{
return !mObservers.empty();

View File

@ -25,6 +25,7 @@ public:
class ViewHolder;
class Recycler;
class State;
class SavedState;
class LayoutManager;
class AdapterDataObservable;
class RecycledViewPool;
@ -448,6 +449,7 @@ public:
private:
RecyclerViewDataObserver* mObserver;
Recycler* mRecycler;
SavedState* mPendingSavedState;
AdapterHelper* mAdapterHelper;
ChildHelper* mChildHelper;
ViewInfoStore* mViewInfoStore;
@ -811,6 +813,7 @@ public:
int getViewLayoutPosition();
int getViewAdapterPosition();
};
class RecyclerView::EdgeEffectFactory {
public:
friend RecyclerView;
@ -1088,6 +1091,18 @@ public:
void notifyItemRangeRemoved(int positionStart, int itemCount);
void notifyItemMoved(int fromPosition, int toPosition);
};
class RecyclerView::SavedState:public AbsSavedState{
protected:
Parcelable*mLayoutState;
friend RecyclerView;
public:
SavedState(Parcel&in);
SavedState(Parcelable*superState);
void writeToParcel(Parcel&dest,int flags)override;
void copyFrom(SavedState&other);
};
class RecyclerView::State{
protected:
friend RecyclerView;