StateView
StateView ????????, ??? View
, ??? ViewStub
?????, ??????????, ??????, ?????? ????????/??/?????, ?????????????
compile 'com.github.nukc.stateview:library:1.3.2'
// animator providers
compile 'com.github.nukc.stateview:animations:1.0.1'
????
????????:
- ??? Activity
mStateView = StateView.inject(Activity activity);
- ??? ViewGroup
mStateView = StateView.inject(ViewGroup parent);
mStateView = StateView.inject(ViewGroup parent, boolean hasActionBar);
// ?? View ?? ViewGroup?????? View ? parent ?
mStateView = StateView.inject(View view);
mStateView = StateView.inject(View view, boolean hasActionBar);
??????:
<com.github.nukc.stateview.StateView
android:id="@+id/stateView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
- ?????:
mStateView.showEmpty();
- ??????:
mStateView.showLoading();
- ??????:
mStateView.showRetry();
- ????:
mStateView.showContent();
????????:
mStateView.setOnRetryClickListener(new StateView.OnRetryClickListener() {
@Override
public void onRetryClick() {
//do something, no need to call showLoading()
//?????showLoading()??, StateView????
}
}
);
???????:
-
??????:??????layout???, ???StateView??layout????(???????). ??layout???:
base_empty
/base_retry
/base_loading
. -
?????:layout?????, ???????.
setEmptyResource(@LayoutRes int emptyResource)
setRetryResource(@LayoutRes int retryResource)
setLoadingResource(@LayoutRes int loadingResource)
?? OnInflateListener
????????????? ? view ????? parent ???????? viewType ??????
mStateView.setOnInflateListener(new StateView.OnInflateListener() {
@Override
public void onInflate(@StateView.ViewType int viewType, View view) {
if (viewType == StateView.EMPTY) {
// set text or other
ViewGroup emptyView = (ViewGroup) view;
TextView tvMessage = (TextView) emptyView.findViewById(R.id.tv_message);
ImageView ivState = (ImageView) emptyView.findViewById(R.id.iv_state);
tvMessage.setText("custom message");
ivState.setImageResource(R.drawable.retry);
}
else if (viewType == StateView.RETRY) {
// ...
}
}
}
);
Custom Attribute
<resources>
<declare-styleable name="StateView">
<attr name="emptyResource" format="reference" />
<attr name="retryResource" format="reference" />
<attr name="loadingResource" format="reference" />
</declare-styleable> </resources>
????
????????:
// ?? provider ? null???????????
// ?????????????
setAnimatorProvider(AnimatorProvider provider)
????????????????? animations ?????????????????????? library?
compile 'com.github.nukc.stateview:animations:1.0.1'
?????????????:
- ????:
FadeScaleAnimatorProvider
- ????:
FlipAnimatorProvider
- ????:
SlideAnimatorProvider
?????????? AnimatorProvider
????? Animator
????
public class FadeScaleAnimatorProvider implements AnimatorProvider {
@Override
public Animator showAnimation(View view) {
AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(view, "alpha", 0f, 1f),
ObjectAnimator.ofFloat(view, "scaleX", 0.1f, 1f),
ObjectAnimator.ofFloat(view, "scaleY", 0.1f, 1f)
);
return set;
}
@Override
public Animator hideAnimation(View view) {
AnimatorSet set = new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(view, "alpha", 1f, 0f),
ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.1f),
ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.1f)
);
return set;
}
}
ChangeLog
Version 1.3.2
?? OnInflateListener
?? view ????? parent ???????? viewType ??????? ?????? View ?????????????????
Version 1.3.1
?? AnimatorProvider
??????????????
Version 1.3.0
????????????????????????? animations
Version 1.2.1
?? inject ??????? StateView.inject(View view)
??? view ?? ViewGroup???????? view ?????? ?????? ViewGroup ? SwipeRefreshLayout/NestedScrollView ????
Version 1.1.0
fix issues #6
Version 1.0.0
????? Deprecated ???? ?? inject(ViewGroup parent) ??
Version 0.3.5
??inject(activity)??, ??????DecorView?, ???Content?. Deprecated????.
Version 0.3.3
????????Sample; ??library???layout??
Version 0.3.2
?????, ??Sample; ????????, ?????????????, ????inject??
Version 0.3.1
??????: inject(View view),???view???viewGroup,????Fragment?
Version 0.3.0
??????: inject(Activity activity),???StateView???DecorView?;
inject(ViewGroup parent),?????ViewGroup?
Version: 0.2.4
????LoadingView????????View
Version: 0.2.3
?? issues #2
Version: 0.2.1
??gradle?library??, ????????showView?
Version: 0.2.0
??v0.1.0??????layout_below???addView????????????
Version: 0.1.0
??Sample???
<com.github.nukc.stateview.StateView
android:id="@+id/stateView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
tools:visibility="gone" />
?? android:layout_below="@+id/ll" ?? , addView??????????????????????? 3???????????????????????
License
The MIT License (MIT) Copyright (c) 2016, 2017 Nukc Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.