mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-29 18:59:14 +08:00
1.fix assets.getArray. 2.add EventSet for widget's Listener container
This commit is contained in:
parent
c54fc11a14
commit
cffcf4547e
@ -197,7 +197,7 @@ static bool guessExtension(ZIPArchive*pak,std::string&ioname) {
|
||||
}
|
||||
|
||||
//"@[package:][+]id/filname"
|
||||
void Assets::parseResource(const std::string&fullResId,std::string*res,std::string*ns)const {
|
||||
const std::string Assets::parseResource(const std::string&fullResId,std::string*res,std::string*ns)const {
|
||||
std::string pkg = mName;
|
||||
std::string relname= fullResId;
|
||||
std::string fullid = fullResId;
|
||||
@ -218,6 +218,7 @@ void Assets::parseResource(const std::string&fullResId,std::string*res,std::stri
|
||||
if(pkg=="android") pkg="cdroid";
|
||||
if( ns) *ns = pkg;
|
||||
if(res)*res= relname;
|
||||
return pkg+":"+relname;
|
||||
}
|
||||
|
||||
ZIPArchive*Assets::getResource(const std::string&fullResId,std::string*relativeResID,std::string*outPackage)const {
|
||||
@ -300,11 +301,11 @@ const std::string& Assets::getString(const std::string& resid,const std::string&
|
||||
|
||||
int Assets::getArray(const std::string&resid,std::vector<int>&out) {
|
||||
std::string pkg,name = resid;
|
||||
parseResource(resid,&name,&pkg);
|
||||
name = AttributeSet::normalize(pkg,name);
|
||||
auto it = mArraies.find(name);
|
||||
std::string fullname = parseResource(resid,&name,&pkg);
|
||||
auto it = mArraies.find(fullname);
|
||||
if(it != mArraies.end()) {
|
||||
//out=it->second;
|
||||
for(auto itm:it->second)
|
||||
out.push_back(std::stoi(itm));
|
||||
return out.size();
|
||||
}
|
||||
return 0;
|
||||
@ -312,9 +313,8 @@ int Assets::getArray(const std::string&resid,std::vector<int>&out) {
|
||||
|
||||
int Assets::getArray(const std::string&resid,std::vector<std::string>&out) {
|
||||
std::string pkg,name = resid;
|
||||
parseResource(resid,&name,&pkg);
|
||||
name = AttributeSet::normalize(pkg,name);
|
||||
auto it = mArraies.find(name);
|
||||
std::string fullname=parseResource(resid,&name,&pkg);
|
||||
auto it = mArraies.find(fullname);
|
||||
if(it != mArraies.end()) {
|
||||
out = it->second;
|
||||
return out.size();
|
||||
|
@ -22,7 +22,7 @@ private:
|
||||
std::map<const std::string,AttributeSet>mStyles;
|
||||
struct COMPLEXCOLOR;
|
||||
std::map<const std::string,std::unique_ptr<COMPLEXCOLOR>>mColors;
|
||||
void parseResource(const std::string&fullresid,std::string*res,std::string*ns)const;
|
||||
const std::string parseResource(const std::string&fullresid,std::string*res,std::string*ns)const;
|
||||
void parseItem(const std::string&package,const std::vector<std::string>&tag,std::vector<AttributeSet>atts,const std::string&value);
|
||||
ZIPArchive*getResource(const std::string & fullresid, std::string* relativeResid,std::string*package)const;
|
||||
protected:
|
||||
|
@ -51,6 +51,30 @@ public:
|
||||
return (*mFunctor)(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
class EventSet{
|
||||
/*The Event(Listener)'s container to hold multi Evnet(Listener)*/
|
||||
protected:
|
||||
std::shared_ptr<void*>mID;
|
||||
public:
|
||||
EventSet(){
|
||||
mID=std::make_shared<void*>(this);
|
||||
}
|
||||
EventSet(const EventSet&other){
|
||||
mID = other.mID;
|
||||
}
|
||||
EventSet& operator=(const EventSet&other){
|
||||
mID = other.mID;
|
||||
return *this;
|
||||
}
|
||||
bool operator == (const EventSet&other){
|
||||
return mID == other.mID;
|
||||
}
|
||||
bool operator != (const EventSet&other){
|
||||
return mID != other.mID;
|
||||
}
|
||||
};
|
||||
|
||||
typedef CallbackBase<void>Runnable;
|
||||
|
||||
}//endof namespace
|
||||
|
@ -107,7 +107,7 @@ void WindowManager::removeWindow(Window*w){
|
||||
w->onDeactive();
|
||||
auto itw = std::find(mWindows.begin(),mWindows.end(),w);
|
||||
const Rect wrect = w->getBound();
|
||||
const int wc=mWindows.size();
|
||||
const int wc = mWindows.size();
|
||||
mWindows.erase(itw);
|
||||
for(auto itr=mWindows.begin();itr!=mWindows.end();itr++){
|
||||
Window*w1 = (*itr);
|
||||
@ -173,6 +173,7 @@ void WindowManager::sendToBack(Window*win){
|
||||
Window *w = mWindows.at(idx);
|
||||
w->mLayer = (w->window_type<<16)|(idx+1);
|
||||
}
|
||||
mActiveWindow = mWindows.back();
|
||||
win->mPendingRgn->do_union({0,0,win->getWidth(),win->getHeight()});
|
||||
GraphDevice::getInstance().flip();
|
||||
}
|
||||
@ -187,6 +188,7 @@ void WindowManager::bringToFront(Window*win){
|
||||
Window *w = mWindows.at(idx);
|
||||
w->mLayer = (w->window_type<<16)|(idx+1);
|
||||
}
|
||||
mActiveWindow = win;
|
||||
win->mPendingRgn->do_union({0,0,win->getWidth(),win->getHeight()});
|
||||
GraphDevice::getInstance().flip();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<selector xmlns:cdroid="http://schemas.android.com/apk/res/android">
|
||||
<item cdroid:state_focused="false" cdroid:alpha="#ff" cdroid:color="#ffff0000"/>
|
||||
<item cdroid:state_focused="true" cdroid:alpha="#ff" cdroid:color="#ff00ff00"/>
|
||||
<item cdroid:state_focused="true" cdroid:alpha="#ff" cdroid:color="#ffff0000"/>
|
||||
<item cdroid:state_pressed="true" cdroid:alpha="#ff" cdroid:color="#ff00ff00"/>
|
||||
<item cdroid:alpha="#ff" cdroid:color="#ff0000ff"/>
|
||||
</selector>
|
||||
|
@ -119,7 +119,7 @@ void ViewTreeObserver::merge(ViewTreeObserver& observer) {
|
||||
observer.kill();
|
||||
}
|
||||
|
||||
void ViewTreeObserver::addOnWindowAttachListener(ViewTreeObserver::OnWindowAttachListener listener) {
|
||||
void ViewTreeObserver::addOnWindowAttachListener(const OnWindowAttachListener& listener) {
|
||||
checkIsAlive();
|
||||
|
||||
/*if (mOnWindowAttachListeners == nullptr) {
|
||||
@ -129,7 +129,7 @@ void ViewTreeObserver::addOnWindowAttachListener(ViewTreeObserver::OnWindowAttac
|
||||
mOnWindowAttachListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnWindowAttachListener(ViewTreeObserver::OnWindowAttachListener victim) {
|
||||
void ViewTreeObserver::removeOnWindowAttachListener(const OnWindowAttachListener& victim) {
|
||||
checkIsAlive();
|
||||
for(auto it = mOnWindowAttachListeners.begin();it!=mOnWindowAttachListeners.end();it++){
|
||||
if(it->onWindowDetached==victim.onWindowDetached){
|
||||
@ -139,7 +139,7 @@ void ViewTreeObserver::removeOnWindowAttachListener(ViewTreeObserver::OnWindowAt
|
||||
}
|
||||
}
|
||||
|
||||
void ViewTreeObserver::addOnWindowFocusChangeListener(ViewTreeObserver::OnWindowFocusChangeListener listener) {
|
||||
void ViewTreeObserver::addOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) {
|
||||
checkIsAlive();
|
||||
|
||||
/*if (mOnWindowFocusListeners == nullptr) {
|
||||
@ -149,7 +149,7 @@ void ViewTreeObserver::addOnWindowFocusChangeListener(ViewTreeObserver::OnWindow
|
||||
mOnWindowFocusListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnWindowFocusChangeListener(ViewTreeObserver::OnWindowFocusChangeListener victim) {
|
||||
void ViewTreeObserver::removeOnWindowFocusChangeListener(OnWindowFocusChangeListener victim) {
|
||||
checkIsAlive();
|
||||
if (mOnWindowFocusListeners.empty()) {
|
||||
return;
|
||||
@ -169,7 +169,7 @@ void ViewTreeObserver::addOnGlobalFocusChangeListener(OnGlobalFocusChangeListene
|
||||
mOnGlobalFocusListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnGlobalFocusChangeListener(ViewTreeObserver::OnGlobalFocusChangeListener victim) {
|
||||
void ViewTreeObserver::removeOnGlobalFocusChangeListener(OnGlobalFocusChangeListener victim) {
|
||||
checkIsAlive();
|
||||
if (mOnGlobalFocusListeners.empty()) {
|
||||
return;
|
||||
@ -179,7 +179,7 @@ void ViewTreeObserver::removeOnGlobalFocusChangeListener(ViewTreeObserver::OnGlo
|
||||
mOnGlobalFocusListeners.erase(it);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::addOnGlobalLayoutListener(ViewTreeObserver::OnGlobalLayoutListener listener) {
|
||||
void ViewTreeObserver::addOnGlobalLayoutListener(OnGlobalLayoutListener listener) {
|
||||
checkIsAlive();
|
||||
|
||||
/*if (mOnGlobalLayoutListeners == nullptr) {
|
||||
@ -266,7 +266,7 @@ void ViewTreeObserver::addOnDrawListener(OnDrawListener listener) {
|
||||
mOnDrawListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnDrawListener(ViewTreeObserver::OnDrawListener victim) {
|
||||
void ViewTreeObserver::removeOnDrawListener(OnDrawListener victim) {
|
||||
checkIsAlive();
|
||||
if (mOnDrawListeners.size()) {
|
||||
return;
|
||||
@ -294,7 +294,7 @@ void ViewTreeObserver::addOnScrollChangedListener(OnScrollChangedListener listen
|
||||
mOnScrollChangedListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnScrollChangedListener(ViewTreeObserver::OnScrollChangedListener victim) {
|
||||
void ViewTreeObserver::removeOnScrollChangedListener(OnScrollChangedListener victim) {
|
||||
checkIsAlive();
|
||||
if (mOnScrollChangedListeners.size()) {
|
||||
return;
|
||||
@ -304,7 +304,7 @@ void ViewTreeObserver::removeOnScrollChangedListener(ViewTreeObserver::OnScrollC
|
||||
mOnScrollChangedListeners.erase(it);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::addOnTouchModeChangeListener(ViewTreeObserver::OnTouchModeChangeListener listener) {
|
||||
void ViewTreeObserver::addOnTouchModeChangeListener(OnTouchModeChangeListener listener) {
|
||||
checkIsAlive();
|
||||
|
||||
/*if (mOnTouchModeChangeListeners == nullptr) {
|
||||
@ -314,7 +314,7 @@ void ViewTreeObserver::addOnTouchModeChangeListener(ViewTreeObserver::OnTouchMod
|
||||
mOnTouchModeChangeListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnTouchModeChangeListener(ViewTreeObserver::OnTouchModeChangeListener victim) {
|
||||
void ViewTreeObserver::removeOnTouchModeChangeListener(OnTouchModeChangeListener victim) {
|
||||
checkIsAlive();
|
||||
if (mOnTouchModeChangeListeners.size()) {
|
||||
return;
|
||||
@ -324,7 +324,7 @@ void ViewTreeObserver::removeOnTouchModeChangeListener(ViewTreeObserver::OnTouch
|
||||
mOnTouchModeChangeListeners.erase(it);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::addOnComputeInternalInsetsListener(ViewTreeObserver::OnComputeInternalInsetsListener listener) {
|
||||
void ViewTreeObserver::addOnComputeInternalInsetsListener(OnComputeInternalInsetsListener listener) {
|
||||
checkIsAlive();
|
||||
|
||||
if (mOnComputeInternalInsetsListeners.size()) {
|
||||
@ -334,7 +334,7 @@ void ViewTreeObserver::addOnComputeInternalInsetsListener(ViewTreeObserver::OnCo
|
||||
mOnComputeInternalInsetsListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnComputeInternalInsetsListener(ViewTreeObserver::OnComputeInternalInsetsListener victim) {
|
||||
void ViewTreeObserver::removeOnComputeInternalInsetsListener(OnComputeInternalInsetsListener victim) {
|
||||
checkIsAlive();
|
||||
if (mOnComputeInternalInsetsListeners.size()) {
|
||||
return;
|
||||
@ -344,7 +344,7 @@ void ViewTreeObserver::removeOnComputeInternalInsetsListener(ViewTreeObserver::O
|
||||
mOnComputeInternalInsetsListeners.erase(it);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::addOnEnterAnimationCompleteListener(ViewTreeObserver::OnEnterAnimationCompleteListener listener) {
|
||||
void ViewTreeObserver::addOnEnterAnimationCompleteListener(OnEnterAnimationCompleteListener listener) {
|
||||
checkIsAlive();
|
||||
if (mOnEnterAnimationCompleteListeners.size()) {
|
||||
//mOnEnterAnimationCompleteListeners = new CopyOnWriteArrayList<OnEnterAnimationCompleteListener>();
|
||||
@ -352,7 +352,7 @@ void ViewTreeObserver::addOnEnterAnimationCompleteListener(ViewTreeObserver::OnE
|
||||
mOnEnterAnimationCompleteListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewTreeObserver::removeOnEnterAnimationCompleteListener(ViewTreeObserver::OnEnterAnimationCompleteListener listener) {
|
||||
void ViewTreeObserver::removeOnEnterAnimationCompleteListener(OnEnterAnimationCompleteListener listener) {
|
||||
checkIsAlive();
|
||||
if (mOnEnterAnimationCompleteListeners.size()) {
|
||||
return;
|
||||
@ -461,7 +461,7 @@ bool ViewTreeObserver::hasComputeInternalInsetsListeners() {
|
||||
return listeners.size() > 0;
|
||||
}
|
||||
|
||||
void ViewTreeObserver::dispatchOnComputeInternalInsets(ViewTreeObserver::InternalInsetsInfo inoutInfo) {
|
||||
void ViewTreeObserver::dispatchOnComputeInternalInsets(InternalInsetsInfo& inoutInfo) {
|
||||
auto listeners = mOnComputeInternalInsetsListeners;
|
||||
for (auto listener:listeners){
|
||||
listener(inoutInfo);//onComputeInternalInsets(inoutInfo);
|
||||
|
@ -9,7 +9,8 @@ class View;
|
||||
class Context;
|
||||
class ViewTreeObserver{
|
||||
public:
|
||||
struct OnWindowAttachListener{
|
||||
class OnWindowAttachListener:public EventSet{
|
||||
public:
|
||||
CallbackBase <void> onWindowAttached;
|
||||
CallbackBase <void> onWindowDetached;
|
||||
};
|
||||
@ -41,7 +42,7 @@ public:
|
||||
bool equals(Object*)const;
|
||||
void set(const InternalInsetsInfo& other);
|
||||
};
|
||||
typedef CallbackBase <void,InternalInsetsInfo> OnComputeInternalInsetsListener;
|
||||
typedef CallbackBase <void,InternalInsetsInfo&> OnComputeInternalInsetsListener;
|
||||
typedef CallbackBase <void> OnEnterAnimationCompleteListener;
|
||||
private:
|
||||
std::vector <OnWindowFocusChangeListener> mOnWindowFocusListeners;
|
||||
@ -64,8 +65,8 @@ private:
|
||||
public:
|
||||
ViewTreeObserver(cdroid::Context* context);
|
||||
void merge(ViewTreeObserver& observer);
|
||||
void addOnWindowAttachListener(OnWindowAttachListener);
|
||||
void removeOnWindowAttachListener(OnWindowAttachListener victim);
|
||||
void addOnWindowAttachListener(const OnWindowAttachListener& victim);
|
||||
void removeOnWindowAttachListener(const OnWindowAttachListener& victim);
|
||||
void addOnWindowFocusChangeListener(OnWindowFocusChangeListener listener);
|
||||
void removeOnWindowFocusChangeListener(OnWindowFocusChangeListener victim);
|
||||
void addOnGlobalFocusChangeListener(OnGlobalFocusChangeListener listener);
|
||||
@ -101,7 +102,7 @@ public:
|
||||
void dispatchOnTouchModeChanged(bool inTouchMode);
|
||||
void dispatchOnScrollChanged();
|
||||
bool hasComputeInternalInsetsListeners();
|
||||
void dispatchOnComputeInternalInsets(InternalInsetsInfo inoutInfo);
|
||||
void dispatchOnComputeInternalInsets(InternalInsetsInfo& inoutInfo);
|
||||
void dispatchOnEnterAnimationComplete();
|
||||
};
|
||||
}//endof namespace
|
||||
|
@ -917,6 +917,49 @@ TabLayout::TabView::~TabView(){
|
||||
delete mTab;
|
||||
}
|
||||
|
||||
void TabLayout::TabView::updateBackgroundDrawable(Context* context) {
|
||||
if (mParent->mTabBackgroundResId.size()) {
|
||||
mBaseBackgroundDrawable = context->getDrawable(mParent->mTabBackgroundResId);
|
||||
if (mBaseBackgroundDrawable && mBaseBackgroundDrawable->isStateful()) {
|
||||
mBaseBackgroundDrawable->setState(getDrawableState());
|
||||
}
|
||||
} else {
|
||||
mBaseBackgroundDrawable = nullptr;
|
||||
}
|
||||
|
||||
Drawable* background;
|
||||
Drawable* contentDrawable = new GradientDrawable();
|
||||
((GradientDrawable*) contentDrawable)->setColor(Color::TRANSPARENT);
|
||||
|
||||
if (0/*tabRippleColorStateList*/) {
|
||||
GradientDrawable* maskDrawable = new GradientDrawable();
|
||||
// TODO: Find a workaround for this. Currently on certain devices/versions,
|
||||
// LayerDrawable will draw a black background underneath any layer with a non-opaque color,
|
||||
// (e.g. ripple) unless we set the shape to be something that's not a perfect rectangle.
|
||||
maskDrawable->setCornerRadius(0.00001F);
|
||||
maskDrawable->setColor(Color::WHITE);
|
||||
|
||||
//ColorStateList* rippleColor = RippleUtils.convertToRippleDrawableColor(tabRippleColorStateList);
|
||||
|
||||
// TODO: Add support to RippleUtils.compositeRippleColorStateList for different ripple color
|
||||
// for selected items vs non-selected items
|
||||
/*if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
||||
background =new RippleDrawable(
|
||||
rippleColor,
|
||||
unboundedRipple ? null : contentDrawable,
|
||||
unboundedRipple ? null : maskDrawable);
|
||||
} else {
|
||||
Drawable* rippleDrawable = DrawableCompat.wrap(maskDrawable);
|
||||
rippleDrawable->setTintList(rippleColor);
|
||||
background = new LayerDrawable(new Drawable[] {contentDrawable, rippleDrawable});
|
||||
}*/
|
||||
} else {
|
||||
background = contentDrawable;
|
||||
}
|
||||
setBackground(background);
|
||||
mParent->invalidate();
|
||||
}
|
||||
|
||||
bool TabLayout::TabView::performClick(){
|
||||
bool handled = LinearLayout::performClick();
|
||||
|
||||
@ -1047,7 +1090,7 @@ void TabLayout::TabView::update() {
|
||||
|
||||
mCustomTextView = (TextView*) custom->findViewById(cdroid::R::id::text1);
|
||||
if (mCustomTextView != nullptr) {
|
||||
mDefaultMaxLines = mCustomTextView->getMaxLines();// TextViewCompat.getMaxLines(mCustomTextView);
|
||||
mDefaultMaxLines = mCustomTextView->getMaxLines();
|
||||
}
|
||||
mCustomIconView = (ImageView*) custom->findViewById(cdroid::R::id::icon);
|
||||
} else {
|
||||
|
@ -64,11 +64,12 @@ public:
|
||||
View* mCustomView;
|
||||
TextView* mCustomTextView;
|
||||
ImageView* mCustomIconView;
|
||||
|
||||
Drawable* mBaseBackgroundDrawable;
|
||||
int mDefaultMaxLines = 2;
|
||||
int getContentWidth();
|
||||
void updateTextAndIcon(TextView* textView,ImageView* iconView);
|
||||
float approximateLineWidth(Layout* layout, int line, float textSize);
|
||||
void updateBackgroundDrawable(Context* context);
|
||||
public:
|
||||
TabView(Context* context,const AttributeSet&atts,TabLayout*parent);
|
||||
~TabView();
|
||||
|
@ -549,19 +549,16 @@ void TextView::applyTextAppearance(class TextAppearanceAttributes *attr){
|
||||
}*/
|
||||
}
|
||||
|
||||
void TextView::addTextChangedListener(TextWatcher watcher){
|
||||
mListeners.push_back(watcher);
|
||||
void TextView::addTextChangedListener(const TextWatcher& watcher){
|
||||
auto it = std::find(mListeners.begin(),mListeners.end(),watcher);
|
||||
if(it==mListeners.end())
|
||||
mListeners.push_back(watcher);
|
||||
}
|
||||
|
||||
void TextView::removeTextChangedListener(TextWatcher watcher){
|
||||
for(auto i= mListeners.begin();i!= mListeners.end();i++){
|
||||
TextWatcher w=(*i);
|
||||
if( (w.onTextChanged==watcher.onTextChanged)
|
||||
&&(w.beforeTextChanged==watcher.beforeTextChanged) ){
|
||||
mListeners.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void TextView::removeTextChangedListener(const TextWatcher& watcher){
|
||||
auto it = std::find(mListeners.begin(),mListeners.end(),watcher);
|
||||
if( it !=mListeners.end())
|
||||
mListeners.erase(it);
|
||||
}
|
||||
|
||||
void TextView::sendBeforeTextChanged(const std::wstring& text, int start, int before, int after){
|
||||
|
@ -20,18 +20,10 @@
|
||||
#include <view/view.h>
|
||||
#include <core/layout.h>
|
||||
#include <core/typeface.h>
|
||||
#include <widget/textwatcher.h>
|
||||
|
||||
namespace cdroid {
|
||||
|
||||
struct TextWatcher{
|
||||
//void beforeTextChanged(CharSequence s,int start,int count, int after)
|
||||
CallbackBase<void,const std::wstring&,int,int,int>beforeTextChanged;
|
||||
//void onTextChanged(CharSequence s, int start, int before, int count);
|
||||
CallbackBase<void,const std::wstring&,int,int,int>onTextChanged;
|
||||
//void afterTextChanged(Editable s);
|
||||
CallbackBase<void,std::wstring&>afterTextChanged;
|
||||
};
|
||||
|
||||
class TextView : public View{
|
||||
private:
|
||||
static constexpr int DEFAULT_TYPEFACE = -1;
|
||||
@ -286,8 +278,8 @@ public:
|
||||
int computeHorizontalScrollRange()override;
|
||||
int computeVerticalScrollRange()override;
|
||||
|
||||
void addTextChangedListener(TextWatcher watcher);
|
||||
void removeTextChangedListener(TextWatcher watcher);
|
||||
void addTextChangedListener(const TextWatcher& watcher);
|
||||
void removeTextChangedListener(const TextWatcher& watcher);
|
||||
void onResolveDrawables(int layoutDirection)override;
|
||||
bool onTouchEvent(MotionEvent& event)override;
|
||||
};
|
||||
|
45
src/gui/widget/textwatcher.h
Executable file
45
src/gui/widget/textwatcher.h
Executable file
@ -0,0 +1,45 @@
|
||||
#ifndef __TEXT_WATCHER_H__
|
||||
#define __TEXT_WATCHER_H__
|
||||
#include <core/callbackbase.h>
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
class TextWatcher:virtual public EventSet{
|
||||
public:
|
||||
/**
|
||||
* This method is called to notify you that, within <code>s</code>,
|
||||
* the <code>count</code> characters beginning at <code>start</code>
|
||||
* are about to be replaced by new text with length <code>after</code>.
|
||||
* It is an error to attempt to make changes to <code>s</code> from
|
||||
* this callback.
|
||||
*/
|
||||
CallbackBase<void,const std::wstring&, int /*start*/, int /*count*/, int /*after*/> beforeTextChanged;
|
||||
/**
|
||||
* This method is called to notify you that, within <code>s</code>,
|
||||
* the <code>count</code> characters beginning at <code>start</code>
|
||||
* have just replaced old text that had length <code>before</code>.
|
||||
* It is an error to attempt to make changes to <code>s</code> from
|
||||
* this callback.
|
||||
*/
|
||||
CallbackBase<void,const std::wstring&, int /*start*/, int /*count*/, int /*after*/>onTextChanged;
|
||||
|
||||
/**
|
||||
* This method is called to notify you that, somewhere within
|
||||
* <code>s</code>, the text has been changed.
|
||||
* It is legitimate to make further changes to <code>s</code> from
|
||||
* this callback, but be careful not to get yourself into an infinite
|
||||
* loop, because any changes you make will cause this method to be
|
||||
* called again recursively.
|
||||
* (You are not told where the change took place because other
|
||||
* afterTextChanged() methods may already have made other changes
|
||||
* and invalidated the offsets. But if you need to know here,
|
||||
* you can use {@link Spannable#setSpan} in {@link #onTextChanged}
|
||||
* to mark your place and then look up from here where the span
|
||||
* ended up.
|
||||
*/
|
||||
CallbackBase<void,const std::wstring&>afterTextChanged;
|
||||
};
|
||||
|
||||
}
|
||||
//endof namespace cdroid
|
||||
#endif
|
@ -256,11 +256,16 @@ static int constrain(int amount, int low, int high) {//get the
|
||||
return amount < low ? low : (amount > high ? high : amount);
|
||||
}
|
||||
|
||||
void ViewPager::addOnPageChangeListener(OnPageChangeListener listener){
|
||||
mOnPageChangeListeners.push_back(listener);
|
||||
void ViewPager::addOnPageChangeListener(const OnPageChangeListener& listener){
|
||||
auto it = std::find(mOnPageChangeListeners.begin(),mOnPageChangeListeners.end(),listener);
|
||||
if(it == mOnPageChangeListeners.end())
|
||||
mOnPageChangeListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void ViewPager::removeOnPageChangeListener(OnPageChangeListener listener){
|
||||
void ViewPager::removeOnPageChangeListener(const OnPageChangeListener& listener){
|
||||
auto it = std::find(mOnPageChangeListeners.begin(),mOnPageChangeListeners.end(),listener);
|
||||
if(it !=mOnPageChangeListeners.end())
|
||||
mOnPageChangeListeners.erase(it);
|
||||
}
|
||||
|
||||
void ViewPager::clearOnPageChangeListeners() {
|
||||
|
@ -20,7 +20,8 @@ public:
|
||||
public:
|
||||
virtual void transformPage(View& page, float position)=0;//typedef std::function<void(View&v,float position)>PageTransformer;
|
||||
};
|
||||
struct OnPageChangeListener{
|
||||
class OnPageChangeListener:public virtual EventSet{
|
||||
public:
|
||||
CallbackBase<void,int,float,int>onPageScrolled;//void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
|
||||
CallbackBase<void,int>onPageSelected;//void onPageSelected(int position);
|
||||
CallbackBase<void,int>onPageScrollStateChanged;//void onPageScrollStateChanged(int state);
|
||||
@ -209,8 +210,8 @@ public:
|
||||
void addOnAdapterChangeListener(OnAdapterChangeListener listener);
|
||||
void removeOnAdapterChangeListener(OnAdapterChangeListener listener);
|
||||
|
||||
void addOnPageChangeListener(OnPageChangeListener listener);
|
||||
void removeOnPageChangeListener(OnPageChangeListener listener);
|
||||
void addOnPageChangeListener(const OnPageChangeListener& listener);
|
||||
void removeOnPageChangeListener(const OnPageChangeListener& listener);
|
||||
void clearOnPageChangeListeners();
|
||||
OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener);
|
||||
int getCurrentItem()const;
|
||||
|
@ -23,6 +23,16 @@ TEST_F(ASSETS,array){
|
||||
std::vector<std::string>array;
|
||||
app.getArray("cdroid:array/resolver_target_actions_unpin",array);
|
||||
for(auto a:array)printf("%s\r\n",a.c_str());
|
||||
printf("size=%d\r\n",array.size());
|
||||
ASSERT_TRUE(array.size()>0);
|
||||
}
|
||||
|
||||
TEST_F(ASSETS,array2){
|
||||
App app(0,NULL);
|
||||
std::vector<std::string>array;
|
||||
app.getArray("@cdroid:array/preloaded_drawables",array);
|
||||
for(auto a:array)printf("%s\r\n",a.c_str());
|
||||
printf("size=%d\r\n",array.size());
|
||||
ASSERT_TRUE(array.size()>0);
|
||||
}
|
||||
TEST_F(ASSETS,color){
|
||||
@ -33,3 +43,15 @@ TEST_F(ASSETS,color){
|
||||
ASSERT_TRUE(cl!=NULL);
|
||||
cl->dump();
|
||||
}
|
||||
TEST_F(ASSETS,drawable){
|
||||
App app;
|
||||
ColorDrawable*cl=(ColorDrawable*)app.getDrawable("@cdroid:color/black");
|
||||
ASSERT_TRUE(cl!=NULL);
|
||||
LOGD("COLOR=%x",(uint32_t)cl->getColor());
|
||||
ASSERT_EQ((uint32_t)cl->getColor(),(uint32_t)0xFF000000);
|
||||
cl=(ColorDrawable*)app.getDrawable("@cdroid:color/transparent");
|
||||
ASSERT_TRUE(cl!=NULL);
|
||||
LOGD("COLOR=%x",(uint32_t)cl->getColor());
|
||||
ASSERT_EQ((uint32_t)cl->getColor(),0);
|
||||
app.exec();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user