mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-29 18:59:14 +08:00
add default style for all widgets
This commit is contained in:
parent
1487d4839d
commit
d04f2ca82e
@ -133,13 +133,13 @@ int Assets::addResource(const std::string&path,const std::string&name){
|
||||
static bool guessExtension(ZIPArchive*pak,std::string&ioname){
|
||||
bool ret=(ioname.find('.')!=std::string::npos);
|
||||
if(ret)return ret;
|
||||
if(TextUtils::startWith(ioname,"drawable")){
|
||||
if(ret=pak->hasEntry(ioname+".xml",false))
|
||||
ioname+=".xml";
|
||||
}else if(TextUtils::startWith(ioname,"mipmap")){
|
||||
if(TextUtils::startWith(ioname,"mipmap")){
|
||||
if(ret=pak->hasEntry(ioname+".png",false)) ioname+=".png";
|
||||
else if(ret=pak->hasEntry(ioname+".9.png",false))ioname+=".9.png";
|
||||
else if(ret=pak->hasEntry(ioname+".jpg",false))ioname+=".jpg";
|
||||
}else{
|
||||
if(ret=pak->hasEntry(ioname+".xml",false))
|
||||
ioname+=".xml";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
4
src/gui/drawables/statelistdrawable.cc
Normal file → Executable file
4
src/gui/drawables/statelistdrawable.cc
Normal file → Executable file
@ -23,7 +23,7 @@ int StateListDrawable::StateListState::addStateSet(const std::vector<int>&stateS
|
||||
return pos;
|
||||
}
|
||||
|
||||
int StateListDrawable::StateListState::indexOfStateSet(const std::vector<int>stateSet){
|
||||
int StateListDrawable::StateListState::indexOfStateSet(const std::vector<int>&stateSet){
|
||||
const int N = getChildCount();
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (StateSet::stateSetMatches(mStateSets[i], stateSet)) {
|
||||
@ -109,7 +109,7 @@ int StateListDrawable::getStateDrawableIndex(const std::vector<int>&stateSet)con
|
||||
bool StateListDrawable::onStateChange(const std::vector<int>&stateSet){
|
||||
const bool changed =DrawableContainer::onStateChange(stateSet);
|
||||
int idx=getStateDrawableIndex(stateSet);
|
||||
LOGV("%p set stateIndex=%d/%d",this,idx,getChildCount());
|
||||
LOGD("%p set stateIndex=%d/%d ",this,idx,getChildCount(),idx>=0?getChild(idx):nullptr);
|
||||
return selectDrawable(idx) || changed;
|
||||
}
|
||||
|
||||
|
2
src/gui/drawables/statelistdrawable.h
Normal file → Executable file
2
src/gui/drawables/statelistdrawable.h
Normal file → Executable file
@ -12,7 +12,7 @@ private:
|
||||
void mutate();
|
||||
Drawable*newDrawable()override;
|
||||
int addStateSet(const std::vector<int>&stateSet, Drawable*drawable);
|
||||
int indexOfStateSet(const std::vector<int>stateSet);
|
||||
int indexOfStateSet(const std::vector<int>&stateSet);
|
||||
bool hasFocusStateSpecified()const;
|
||||
};
|
||||
std::shared_ptr<StateListState>mStateListState;
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:cdroid="http://schemas.android.com/apk/res/android"
|
||||
cdroid:tint="?attr/colorForeground">
|
||||
cdroid:tint="?attr/colorForeground"
|
||||
cdroid:shape="rectangle">
|
||||
<solid cdroid:color="#1f000000" />
|
||||
<size
|
||||
cdroid:height="1dp"
|
||||
|
6
src/gui/res/layout/design_layout_tab_icon.xml
Executable file
6
src/gui/res/layout/design_layout_tab_icon.xml
Executable file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView xmlns:cdroid="http://schemas.android.com/apk/res/android"
|
||||
cdroid:layout_width="24dp"
|
||||
cdroid:layout_height="24dp"
|
||||
cdroid:contentDescription="@null"
|
||||
cdroid:scaleType="centerInside"/>
|
7
src/gui/res/layout/design_layout_tab_text.xml
Executable file
7
src/gui/res/layout/design_layout_tab_text.xml
Executable file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:cdroid="http://schemas.android.com/apk/res/android"
|
||||
cdroid:layout_width="wrap_content"
|
||||
cdroid:layout_height="wrap_content"
|
||||
cdroid:ellipsize="end"
|
||||
cdroid:gravity="center"
|
||||
cdroid:maxLines="2"/>
|
@ -1,8 +1,10 @@
|
||||
#ifndef __CHECK_BOX_H__
|
||||
#define __CHECK_BOX_H__
|
||||
#include <widget/compoundbutton.h>
|
||||
#include <widget/layoutinflater.h>
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
class CheckBox:public CompoundButton{
|
||||
public:
|
||||
CheckBox(Context*ctx,const AttributeSet& attrs)
|
||||
@ -11,8 +13,7 @@ public:
|
||||
setButtonDrawable("cdroid:drawable/btn_check.xml");
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_WIDGET(CheckBox)
|
||||
DECLARE_WIDGET2(CheckBox,"cdroid:attr/checkboxStyle")
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
namespace cdroid {
|
||||
|
||||
DECLARE_WIDGET(GridView)
|
||||
DECLARE_WIDGET2(GridView,"cdroid:attr/gridViewStyle")
|
||||
|
||||
GridView::GridView(int w,int h):AbsListView(w,h){
|
||||
initGridView();
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
DECLARE_WIDGET(HorizontalScrollView)
|
||||
DECLARE_WIDGET2(HorizontalScrollView,"cdroid:attr/horizontalScrollViewStyle")
|
||||
|
||||
HorizontalScrollView::HorizontalScrollView(int w,int h):FrameLayout(w,h){
|
||||
initScrollView();
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include<app.h>
|
||||
namespace cdroid{
|
||||
|
||||
DECLARE_WIDGET(ImageButton)
|
||||
DECLARE_WIDGET2(ImageButton,"cdroid:attr/imageButtonStyle")
|
||||
|
||||
ImageButton::ImageButton(Context*ctx,const AttributeSet& attrs)
|
||||
:ImageView(ctx,attrs){
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
DECLARE_WIDGET2(KeyboardView,"cdroid:attr/keyboardViewStyle")
|
||||
|
||||
KeyboardView::KeyboardView(int w,int h):View(w,h){
|
||||
init();
|
||||
mKeyBackground = new ColorDrawable(0xFF112211);
|
||||
|
@ -74,7 +74,7 @@ typedef struct{
|
||||
ViewGroup* root;
|
||||
std::vector<View*>views;//the first element is rootview setted by inflate
|
||||
std::vector<int>flags;
|
||||
ViewGroup*returnedView;
|
||||
View*returnedView;
|
||||
int parsedView;
|
||||
}WindowParserData;
|
||||
|
||||
@ -126,11 +126,10 @@ static void startElement(void *userData, const XML_Char *name, const XML_Char **
|
||||
|
||||
static void endElement(void *userData, const XML_Char *name){
|
||||
WindowParserData*pd=(WindowParserData*)userData;
|
||||
ViewGroup*p = dynamic_cast<ViewGroup*>(pd->views.back());
|
||||
if(strcmp(name,"include")==0)return;
|
||||
|
||||
if(p&&(pd->views.size()==1) && (pd->flags.back()==0))
|
||||
pd->returnedView=p;
|
||||
if((pd->views.size()==1) && (pd->flags.back()==0))
|
||||
pd->returnedView=pd->views.back();
|
||||
pd->flags.pop_back();
|
||||
pd->views.pop_back();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace cdroid {
|
||||
#define MIN_SCROLL_PREVIEW_PIXELS 2
|
||||
#define NO_POSITION (-1)
|
||||
|
||||
DECLARE_WIDGET(ListView)
|
||||
DECLARE_WIDGET2(ListView,"cdroid:attr/listViewStyle")
|
||||
|
||||
ListView::ListView(int w,int h):AbsListView(w,h) {
|
||||
initListView();
|
||||
|
@ -9,15 +9,16 @@
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
DECLARE_WIDGET(NumberPicker)
|
||||
DECLARE_WIDGET2(NumberPicker,"cdroid:attr/numberPickerStyle")
|
||||
|
||||
NumberPicker::NumberPicker(int w,int h):LinearLayout(w,h){
|
||||
initView();
|
||||
setOrientation(VERTICAL);//HORIZONTAL);
|
||||
|
||||
LayoutInflater*inflater=LayoutInflater::from(mContext);
|
||||
inflater->inflate("cdroid:layout/number_picker.xml",this,true);
|
||||
delete inflater;
|
||||
AttributeSet atts=mContext->obtainStyledAttributes("cdroid:attr/numberPickerStyle");
|
||||
std::string layoutres=atts.getString("internalLayout","cdroid:layout/number_picker.xml");
|
||||
inflater->inflate(layoutres,this,true);
|
||||
|
||||
if(!mHasSelectorWheel){
|
||||
mDecrementButton=(ImageButton*)findViewById(R::id::decrement);
|
||||
@ -70,8 +71,10 @@ NumberPicker::NumberPicker(Context* context,const AttributeSet& atts)
|
||||
&& mMinWidth > mMaxWidth) {
|
||||
throw "minWidth > maxWidth";
|
||||
}
|
||||
mVirtualButtonPressedDrawable = context->getDrawable(atts,"virtualButtonPressedDrawable");
|
||||
LayoutInflater*inflater=LayoutInflater::from(mContext);
|
||||
inflater->inflate("cdroid:layout/number_picker.xml",this);
|
||||
std::string layoutres=atts.getString("internalLayout","cdroid:layout/number_picker.xml");
|
||||
inflater->inflate(layoutres,this);
|
||||
mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);
|
||||
setWillNotDraw(!mHasSelectorWheel);
|
||||
|
||||
|
@ -14,8 +14,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_WIDGET(RadioButton)
|
||||
|
||||
}//namespace
|
||||
|
||||
#endif
|
||||
|
@ -1,9 +1,13 @@
|
||||
#include <widget/radiogroup.h>
|
||||
#include <widget/radiobutton.h>
|
||||
#include <cdlog.h>
|
||||
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
DECLARE_WIDGET(RadioGroup)
|
||||
DECLARE_WIDGET2(RadioButton,"cdroid:attr/radioButtonStyle")
|
||||
|
||||
RadioGroup::RadioGroup(int w,int h):LinearLayout(w,h){
|
||||
setOrientation(VERTICAL);
|
||||
init();
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
DECLARE_WIDGET2(RatingBar,"cdroid:attr/ratingBarStyle")
|
||||
|
||||
RatingBar::RatingBar(int w,int h):AbsSeekBar(w,h){
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <cdlog.h>
|
||||
namespace cdroid {
|
||||
|
||||
DECLARE_WIDGET(ScrollView)
|
||||
DECLARE_WIDGET2(ScrollView,"cdroid:attr/scrollViewStyle")
|
||||
|
||||
ScrollView::ScrollView(int w,int h):FrameLayout(w,h){
|
||||
initScrollView();
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <widget/seekbar.h>
|
||||
namespace cdroid{
|
||||
|
||||
DECLARE_WIDGET(SeekBar)
|
||||
DECLARE_WIDGET2(SeekBar,"cdroid:attr/seekBarStyle")
|
||||
|
||||
SeekBar::SeekBar(Context*ctx,const AttributeSet& attrs)
|
||||
:AbsSeekBar(ctx,attrs){
|
||||
|
@ -8,7 +8,7 @@ namespace cdroid{
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DECLARE_WIDGET(Spinner)
|
||||
DECLARE_WIDGET2(Spinner,"cdroid:attr/spinnerStyle")
|
||||
|
||||
Spinner::Spinner(int w,int h,int mode):AbsSpinner(w,h){
|
||||
mPopupContext=nullptr;
|
||||
|
@ -1022,7 +1022,7 @@ void TabLayout::TabView::update() {
|
||||
mIconView->setImageDrawable(nullptr);
|
||||
}
|
||||
|
||||
//mCustomTextView = (TextView*) custom->findViewById(cdroid::R::id::text1);
|
||||
mCustomTextView = (TextView*) custom->findViewById(cdroid::R::id::text1);
|
||||
if (mCustomTextView != nullptr) {
|
||||
mDefaultMaxLines = mCustomTextView->getMaxLines();// TextViewCompat.getMaxLines(mCustomTextView);
|
||||
}
|
||||
@ -1039,14 +1039,13 @@ void TabLayout::TabView::update() {
|
||||
|
||||
if (mCustomView == nullptr) {
|
||||
// If there isn't a custom view, we'll us our own in-built layouts
|
||||
LayoutInflater* inflater =LayoutInflater::from(getContext());
|
||||
if (mIconView == nullptr) {
|
||||
ImageView* iconView = new ImageView(0,0);//(ImageView*) LayoutInflater.from(getContext()).inflate(R.layout.design_layout_tab_icon, this, false);
|
||||
addView(iconView, 0);
|
||||
ImageView* iconView = (ImageView*)inflater->inflate("cdroid:layout/design_layout_tab_icon.xml", this, false);
|
||||
mIconView = iconView;
|
||||
}
|
||||
if (mTextView == nullptr) {
|
||||
TextView* textView = new TextView("",0,0);//(TextView*) LayoutInflater.from(getContext()).inflate(R.layout.design_layout_tab_text, this, false);
|
||||
addView(textView);
|
||||
TextView* textView = (TextView*)inflater->inflate("cdroid:layout/design_layout_tab_text.xml", this, false);
|
||||
mTextView = textView;
|
||||
mDefaultMaxLines = mTextView->getMaxLines();
|
||||
}
|
||||
@ -1098,7 +1097,7 @@ void TabLayout::TabView::updateTextAndIcon(TextView* textView,ImageView* iconVie
|
||||
iconView->setVisibility(GONE);
|
||||
iconView->setImageDrawable(nullptr);
|
||||
}
|
||||
//iconView->setContentDescription(contentDesc);
|
||||
iconView->setContentDescription(contentDesc);
|
||||
}
|
||||
|
||||
bool hasText = !text.empty();//!TextUtils.isEmpty(text);
|
||||
@ -1111,7 +1110,7 @@ void TabLayout::TabView::updateTextAndIcon(TextView* textView,ImageView* iconVie
|
||||
textView->setVisibility(GONE);
|
||||
textView->setText("");
|
||||
}
|
||||
//textView->setContentDescription(contentDesc);
|
||||
textView->setContentDescription(contentDesc);
|
||||
}
|
||||
|
||||
if (iconView != nullptr) {
|
||||
|
@ -6,7 +6,7 @@ namespace cdroid{
|
||||
#define TOGGLE 1
|
||||
#define NO_ALPHA 0xFF
|
||||
|
||||
DECLARE_WIDGET(ToggleButton)
|
||||
DECLARE_WIDGET2(ToggleButton,"cdroid:attr/buttonStyleToggle")
|
||||
|
||||
ToggleButton::ToggleButton(Context*ctx,const AttributeSet& attrs)
|
||||
:CompoundButton(ctx,attrs){
|
||||
|
@ -211,7 +211,7 @@ View::View(Context*ctx,const AttributeSet&attrs){
|
||||
if(viewFlagMasks)
|
||||
setFlags(viewFlagValues, viewFlagMasks);
|
||||
|
||||
mBackground=ctx->getDrawable(attrs,"background");
|
||||
setBackground(ctx->getDrawable(attrs,"background"));
|
||||
|
||||
int leftPadding,topPadding,rightPadding,bottomPadding;
|
||||
int padding=attrs.getDimensionPixelSize("padding",-1);
|
||||
@ -2060,7 +2060,7 @@ void View::setOnScrollChangeListener(OnScrollChangeListener l){
|
||||
|
||||
void View::setDrawingCacheEnabled(bool enabled) {
|
||||
mCachingFailed = false;
|
||||
setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED);
|
||||
//setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED);
|
||||
}
|
||||
|
||||
bool View::isDrawingCacheEnabled()const{
|
||||
@ -3114,6 +3114,9 @@ std::vector<int>View::onCreateDrawableState()const{
|
||||
if(mPrivateFlags & PFLAG_HOVERED ) viewStateIndex |= StateSet::VIEW_STATE_HOVERED;
|
||||
|
||||
states = StateSet::get(viewStateIndex);
|
||||
std::ostringstream oss;
|
||||
for(auto s:states)oss<<s<<",";
|
||||
LOGD("%p:%d state=%s",this,mID,oss.str().c_str());
|
||||
#endif
|
||||
return states;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <widget/yearpickerview.h>
|
||||
#include <widget/textview.h>
|
||||
#include <widget/layoutinflater.h>
|
||||
|
||||
namespace cdroid{
|
||||
|
||||
@ -8,18 +9,16 @@ DECLARE_WIDGET(YearPickerView)
|
||||
class YearAdapter:public ArrayAdapter<int> {
|
||||
private:
|
||||
/*static int ITEM_LAYOUT = R.layout.year_label_text_view;
|
||||
static int ITEM_TEXT_APPEARANCE =
|
||||
R.style.TextAppearance_Material_DatePicker_List_YearLabel;
|
||||
static int ITEM_TEXT_ACTIVATED_APPEARANCE =
|
||||
R.style.TextAppearance_Material_DatePicker_List_YearLabel_Activated;
|
||||
//LayoutInflater mInflater;*/
|
||||
static int ITEM_TEXT_APPEARANCE = R.style.TextAppearance_Material_DatePicker_List_YearLabel;
|
||||
static int ITEM_TEXT_ACTIVATED_APPEARANCE = R.style.TextAppearance_Material_DatePicker_List_YearLabel_Activated;*/
|
||||
LayoutInflater* mInflater;
|
||||
int mActivatedYear;
|
||||
int mMinYear;
|
||||
int mCount;
|
||||
|
||||
public:
|
||||
YearAdapter(Context* context) {
|
||||
//mInflater = LayoutInflater.from(context);
|
||||
mInflater = LayoutInflater::from(context);
|
||||
}
|
||||
|
||||
void setRange(int minDate,int maxDate/*Calendar minDate, Calendar maxDate*/) {
|
||||
@ -65,7 +64,7 @@ public:
|
||||
View* getView(int position, View* convertView, ViewGroup* parent) {
|
||||
TextView* v;
|
||||
if (convertView==nullptr) {
|
||||
v = new TextView("",0,0);//(TextView*) mInflater.inflate(ITEM_LAYOUT, parent, false);
|
||||
v = (TextView*) mInflater->inflate("cdroid:layout/year_label_text_view.xml", parent, false);
|
||||
} else {
|
||||
v = (TextView*) convertView;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user