add filterable

This commit is contained in:
houzh 2023-08-04 17:32:34 +08:00
parent 10e8994d10
commit 0856ec50be
7 changed files with 213 additions and 31 deletions

View File

@ -9,6 +9,7 @@ TOOLCHAINS["SIGMA"]=$HOME/cdroid/cmake/ssd202-mtitoolchain.cmake
TOOLCHAINS["ALI3528"]=$HOME/cdroid/cmake/ali3528-mtitoolchain.cmake
TOOLCHAINS["RISCVD211"]=$HOME/cdroid/cmake/riscv64-d211-toolchain.cmake
TOOLCHAINS["R818"]=$HOME/cdroid/cmake/aarch64-toolchain.cmake
declare -A DEPLIBS #key/value dict,key is platform,value is deplibs dir in vcpkg,key must be uppercase
DEPLIBS["X64"]=$HOME/vcpkg/installed/x64-linux-dynamic
DEPLIBS["SIGMA"]=$HOME/vcpkg/installed/arm-linux-dynamic

View File

@ -1,18 +0,0 @@
if [ $# -gt 0 ]
then
mkdir -p out-ssd202r
pushd out-ssd202r
TYPE=Release
else
mkdir -p out-ssd202
pushd out-ssd202
TYPE=Debug
fi
export PKG_CONFIG_PATH=$HOME/vcpkg/installed/arm-linux-dynamic/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$HOME/vcpkg/installed/arm-linux-dynamic/lib/pkgconfig
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/ssd202-mtitoolchain.cmake \
-DCMAKE_INSTALL_PREFIX=./ \
-DCDROID_CHIPSET="sigma" \
-DCMAKE_BUILD_TYPE=${TYPE} \
..
popd

View File

@ -2,6 +2,7 @@
#include <widget/checkable.h>
#include <widget/recyclebin.h>
#include <widget/fastscroller.h>
#include <widget/edittext.h>
#include <cdtypes.h>
#include <cdlog.h>
@ -31,6 +32,7 @@ void AbsListView::initAbsListView(const AttributeSet&atts) {
mPositionScroller= nullptr;
mFastScroll = nullptr;
mPopup = nullptr;
mTextFilter = nullptr;
mStackFromBottom = false;
mIsChildViewEnabled =false;
mFiltered = false;
@ -702,8 +704,138 @@ void AbsListView::requestLayoutIfNecessary() {
}
}
bool AbsListView::acceptFilter() const {
Filterable*filter = dynamic_cast<Filterable*>(mAdapter);
return mTextFilterEnabled && filter && filter->getFilter() != nullptr;
}
void AbsListView::createTextFilter(bool animateEntrance) {
/*if (mPopup == nullptr) {
PopupWindow* p = new PopupWindow(getContext());
p->setFocusable(false);
p->setTouchable(false);
p->setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
p->setContentView(getTextFilterInput());
p->setWidth(LayoutParams.WRAP_CONTENT);
p->setHeight(LayoutParams.WRAP_CONTENT);
p->setBackgroundDrawable(null);
mPopup = p;
//getViewTreeObserver().addOnGlobalLayoutListener(this);
mGlobalLayoutListenerAddedFilter = true;
}
if (animateEntrance) {
mPopup->setAnimationStyle(com.android.internal.R.style.Animation_TypingFilter);
} else {
mPopup->setAnimationStyle(com.android.internal.R.style.Animation_TypingFilterRestore);
}*/
}
EditText* AbsListView::getTextFilterInput() {
if (mTextFilter == nullptr) {
LayoutInflater* layoutInflater = LayoutInflater::from(getContext());
mTextFilter = (EditText*) layoutInflater->inflate("cdroid:layout/typing_filter", nullptr);
// For some reason setting this as the "real" input type changes
// the text view in some way that it doesn't work, and I don't
// want to figure out why this is.
//mTextFilter->setRawInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_FILTER);
//mTextFilter->setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
//mTextFilter->addTextChangedListener(this);
}
return mTextFilter;
}
bool AbsListView::isTextFilterEnabled() const{
return mTextFilterEnabled;
}
void AbsListView::setTextFilterEnabled(bool textFilterEnabled) {
mTextFilterEnabled = textFilterEnabled;
}
void AbsListView::setFilterText(const std::string& filterText){
// TODO: Should we check for acceptFilter()?
if (mTextFilterEnabled && !filterText.empty()){//TextUtils.isEmpty(filterText)) {
createTextFilter(false);
// This is going to call our listener onTextChanged, but we might not
// be ready to bring up a window yet
mTextFilter->setText(filterText);
//mTextFilter->setSelection(filterText.length());
if (dynamic_cast<Filterable*>(mAdapter)) {
// if mPopup is non-null, then onTextChanged will do the filtering
if (mPopup == nullptr) {
Filter* f = ((Filterable*) mAdapter)->getFilter();
f->filter(filterText);
}
// Set filtered to true so we will display the filter window when our main
// window is ready
mFiltered = true;
mDataSetObserver->clearSavedState();
}
}
}
void AbsListView::clearTextFilter() {
if (mFiltered) {
getTextFilterInput()->setText("");
mFiltered = false;
if (mPopup && mPopup->isShowing()) {
dismissPopup();
}
}
}
bool AbsListView::hasTextFilter() const{
return mFiltered;
}
const std::string AbsListView::getTextFilter()const{
if (mTextFilterEnabled && mTextFilter) {
return mTextFilter->getText();
}
return std::string();
}
void AbsListView::beforeTextChanged(const std::string& s, int start, int count, int after){
}
void AbsListView::onTextChanged(const std::string& s, int start, int before, int count){
if (isTextFilterEnabled()) {
createTextFilter(true);
const int length = s.length();
const bool showing = mPopup->isShowing();
if (!showing && length > 0) {
// Show the filter popup if necessary
showPopup();
mFiltered = true;
} else if (showing && length == 0) {
// Remove the filter popup if the user has cleared all text
dismissPopup();
mFiltered = false;
}
if (dynamic_cast<Filterable*>(mAdapter)){
Filter* f = ((Filterable*)mAdapter)->getFilter();
// Filter should not be null when we reach this part
if (f != nullptr) {
f->filter(s, this);//todo EditText must impl FilterListener
} else {
FATAL("You cannot call onTextChanged with a non filterable adapter");
}
}
}
}
//void AbsListView::afterTextChanged(Editable s) {}
void AbsListView::onFilterComplete(int count) {
if (mSelectedPosition < 0 && count > 0) {
mResurrectToPosition = INVALID_POSITION;
resurrectSelection();
}
}
void AbsListView::setDrawSelectorOnTop(bool onTop) {
mDrawSelectorOnTop=onTop;
mDrawSelectorOnTop = onTop;
}
Drawable*AbsListView::getSelector() {
@ -1735,12 +1867,11 @@ void AbsListView::jumpDrawablesToCurrentState() {
void AbsListView::onAttachedToWindow() {
AdapterView::onAttachedToWindow();
/*ViewTreeObserver treeObserver = getViewTreeObserver();
treeObserver.addOnTouchModeChangeListener(this);
if (mTextFilterEnabled && mPopup != null && !mGlobalLayoutListenerAddedFilter) {
treeObserver.addOnGlobalLayoutListener(this);
}*/
//ViewTreeObserver* treeObserver = getViewTreeObserver();
//treeObserver->addOnTouchModeChangeListener(this);
if (mTextFilterEnabled && mPopup && !mGlobalLayoutListenerAddedFilter) {
//treeObserver->addOnGlobalLayoutListener(this);
}
if (mAdapter && mDataSetObserver==nullptr) {
mDataSetObserver = new AdapterDataSetObserver(this);
mAdapter->registerDataSetObserver(mDataSetObserver);
@ -1763,12 +1894,12 @@ void AbsListView::onDetachedFromWindow() {
// Detach any view left in the scrap heap
mRecycler->clear();
/*ViewTreeObserver treeObserver = getViewTreeObserver();
treeObserver.removeOnTouchModeChangeListener(this);
//ViewTreeObserver treeObserver = getViewTreeObserver();
//treeObserver.removeOnTouchModeChangeListener(this);
if (mTextFilterEnabled && mPopup != nullptr) {
treeObserver.removeOnGlobalLayoutListener(this);
//treeObserver.removeOnGlobalLayoutListener(this);
mGlobalLayoutListenerAddedFilter = false;
}*/
}
if (mAdapter && mDataSetObserver) {
mAdapter->unregisterDataSetObserver(mDataSetObserver);

View File

@ -6,12 +6,13 @@
#include <widget/overscroller.h>
#include <widget/edgeeffect.h>
#include <widget/popupwindow.h>
#include <widget/filterable.h>
namespace cdroid{
#define OVERSCROLL_LIMIT_DIVISOR 3
#define CHECK_POSITION_SEARCH_DISTANCE 20
class AbsListView:public AdapterView{
class AbsListView:public AdapterView,Filter::FilterListener{
public:
friend RecycleBin;
enum ChoiceMode{
@ -207,6 +208,7 @@ private:
bool mScrollProfilingStarted = false;
bool mFlingProfilingStarted =false;
PopupWindow*mPopup;
class EditText* mTextFilter;
OnScrollListener mOnScrollListener;
void initAbsListView(const AttributeSet&atts);
void useDefaultSelector();
@ -241,6 +243,9 @@ private:
void dismissPopup();
void showPopup();
void positionPopup();
bool acceptFilter()const;
void createTextFilter(bool animateEntrance);
EditText* getTextFilterInput();
protected:
int mChoiceMode;
int mCheckedItemCount;
@ -252,6 +257,7 @@ protected:
bool mFastScrollEnabled;
bool mFastScrollAlwaysVisible;
std::string mFastScrollStyle;
bool mGlobalLayoutListenerAddedFilter;
int mSelectorPosition;
int mResurrectToPosition;
int mMinimumVelocity;
@ -403,6 +409,15 @@ public:
void setStackFromBottom(bool stackFromBottom);
bool isStackFromBottom()const;
bool isTextFilterEnabled()const;
void setTextFilterEnabled(bool);
void setFilterText(const std::string& filterText);
void clearTextFilter();
bool hasTextFilter()const;
const std::string getTextFilter()const;
void beforeTextChanged(const std::string& s, int start, int count, int after);//override textwatcher
void onTextChanged(const std::string& s, int start, int before, int count);//override textwatcher
void onFilterComplete(int count)override;
bool verifyDrawable(Drawable* dr)const override;
void jumpDrawablesToCurrentState()override;
void dispatchDrawableHotspotChanged(float x, float y)override;

13
src/gui/widget/filterable.cc Executable file
View File

@ -0,0 +1,13 @@
#include <widget/filterable.h>
namespace cdroid{
Filter::Filter(){
}
void Filter::filter(const std::string& constraint){
}
void Filter::filter(const std::string& constraint, Filter::FilterListener* listener){
}
}//endof namespace

40
src/gui/widget/filterable.h Executable file
View File

@ -0,0 +1,40 @@
#ifndef __FILTERABLE_H__
#define __FILTERABLE_H__
#include <functional>
#include <string>
namespace cdroid{
class Filter{
public:
class FilterListener{
public:
virtual void onFilterComplete(int count)=0;
};
class FilterResults{
};
protected:
virtual FilterResults performFiltering(const std::string& constraint) = 0;
virtual void publishResults(const std::string& constraint, FilterResults results) = 0;
public:
Filter();
void filter(const std::string& constraint);
void filter(const std::string& constraint, FilterListener* listener);
};
class Filterable {
public:
/**
* <p>Returns a filter that can be used to constrain data with a filtering
* pattern.</p>
*
* <p>This method is usually implemented by {@link android.widget.Adapter}
* classes.</p>
*
* @return a filter used to constrain data
*/
virtual Filter* getFilter() = 0;
};
}//endof namespace
#endif

View File

@ -26,7 +26,7 @@ public:
uint32_t stride;
uint32_t handle;
uint32_t fb;
uint8_t*map;
uint8_t* map;
}GFXFB;
private:
int fd;