diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b66c65e4cb2c3e5f4221a13e0b00df1e9ed19c..53dc537428a8e031fec752d980e48aa9244d612c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.0.3 + +和原组件保持接口一致性,新增空视图、错误视图、无网络视图的视图资源ID, +新增onFinishInflate()方法 + # 1.0.2 增加组件效果动态图 diff --git a/README.md b/README.md index f383bc985b545f8bb4485c88f8230c0cb7a42e2e..a43fe8fb4b9d2cb671428450b1c9a178c6c11625 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - 网络异常视图 - 内容视图 - + ## 依赖 ``` @@ -50,25 +50,34 @@ multipleStatusView.showLoading(); // multipleStatusView.showLoading(customView, layoutParams); //显示空视图 -multipleStatusView.showEmpty(ResourceTable.Id_empty_retry_view); -// mMultipleStatusView.showEmpty("自定义提示内容",ResourceTable.Id_empty_retry_view); -// mMultipleStatusView.showEmpty(ResourceTable.String_custom_hint_content, ResourceTable.Id_empty_retry_view,"占位符1", "占位符2", "..."); -// multipleStatusView.showEmpty(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_empty_retry_view); -// multipleStatusView.showEmpty(customView, layoutParams,ResourceTable.Id_empty_retry_view); +首先先调用 +multipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view)设置空视图资源id +再次调用以下方法: +multipleStatusView.showEmpty(); +// mMultipleStatusView.showEmpty("自定义提示内容"); +// mMultipleStatusView.showEmpty(ResourceTable.String_custom_hint_content,"占位符1", "占位符2", "..."); +// multipleStatusView.showEmpty(ResourceTable.Layout_xxx, layoutParams); +// multipleStatusView.showEmpty(customView, layoutParams); //显示错误视图 -multipleStatusView.showError(ResourceTable.Id_error_retry_view); -// mMultipleStatusView.showError("自定义提示内容",ResourceTable.Id_error_retry_view); -// mMultipleStatusView.showError(ResourceTable.String_custom_hint_content, ResourceTable.Id_error_retry_view,"占位符1", "占位符2", "..."); -// multipleStatusView.showError(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_error_retry_view); -// multipleStatusView.showError(customView, layoutParams,ResourceTable.Id_error_retry_view); +首先先调用 +multipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view)设置错误视图资源id +再次调用以下方法: +multipleStatusView.showError(); +// mMultipleStatusView.showError("自定义提示内容"); +// mMultipleStatusView.showError(ResourceTable.String_custom_hint_content,"占位符1", "占位符2", "..."); +// multipleStatusView.showError(ResourceTable.Layout_xxx, layoutParams); +// multipleStatusView.showError(customView, layoutParams); //显示无网络视图 -multipleStatusView.showNoNetwork(ResourceTable.Id_no_network_retry_view); +首先先调用 +multipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view)设置无网络视图资源id +再次调用以下方法: +multipleStatusView.showNoNetwork(); // mMultipleStatusView.showNoNetwork("自定义提示内容"); -// mMultipleStatusView.showNoNetwork(ResourceTable.String_custom_hint_content,ResourceTable.Id_no_network_retry_view, "占位符1", "占位符2", "..."); -// multipleStatusView.showNoNetwork(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_no_network_retry_view); -// multipleStatusView.showNoNetwork(customView, layoutParams,ResourceTable.Id_no_network_retry_view); +// mMultipleStatusView.showNoNetwork(ResourceTable.String_custom_hint_content, "占位符1", "占位符2", "..."); +// multipleStatusView.showNoNetwork(ResourceTable.Layout_xxx, layoutParams); +// multipleStatusView.showNoNetwork(customView, layoutParams); //显示内容视图 multipleStatusView.showContent(); diff --git a/build.gradle b/build.gradle index ef3f57778829a3a3db8f688a13cdf9f686af29cb..2f6ae0237aa128984f333f303d1e30224f6092c0 100644 --- a/build.gradle +++ b/build.gradle @@ -2,9 +2,9 @@ apply plugin: 'com.huawei.ohos.app' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { - compatibleSdkVersion 5 + compatibleSdkVersion 6 } } @@ -19,8 +19,8 @@ buildscript { jcenter() } dependencies { - classpath 'com.huawei.ohos:hap:2.4.2.5' - classpath 'com.huawei.ohos:decctest:1.0.0.6' + classpath 'com.huawei.ohos:hap:2.4.5.5' + classpath 'com.huawei.ohos:decctest:1.2.5.1' } } diff --git a/entry/build.gradle b/entry/build.gradle index e9bd1fa599122271f8214678a6866868eea371a8..617391fb7c8e80ec18019b9374f9faf4d4a453d2 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -1,9 +1,9 @@ apply plugin: 'com.huawei.ohos.hap' apply plugin: 'com.huawei.ohos.decctest' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { - compatibleSdkVersion 5 + compatibleSdkVersion 6 } } diff --git a/entry/src/main/config.json b/entry/src/main/config.json index fd088366f788247e7a6a6d3a1958b960a5a9adb9..6c057e5467e71fa2a02a96bc1e40898572d418d0 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -7,9 +7,8 @@ "name": "1.0" }, "apiVersion": { - "compatible": 5, - "target": 5, - "releaseType": "Beta1" + "compatible": 6, + "target": 6 } }, "deviceConfig": {}, @@ -23,7 +22,8 @@ "distro": { "deliveryWithInstall": true, "moduleName": "entry", - "moduleType": "entry" + "moduleType": "entry", + "installationFree": false }, "abilities": [ { @@ -41,9 +41,9 @@ "name": "com.classic.common.simple.MainAbility", "icon": "$media:icon", "description": "", - "label": "MultipleStatusView", + "label": "$string:app_name", "type": "page", - "visible": false, + "visible": true, "launchType": "standard" }, { @@ -51,7 +51,7 @@ "name": "com.classic.common.simple.CustomActivity", "icon": "$media:icon", "description": "", - "label": "CustomActivity", + "label": "$string:ability_cust", "type": "page", "launchType": "standard" }, @@ -60,7 +60,7 @@ "name": "com.classic.common.simple.SimpleActivity", "icon": "$media:icon", "description": "", - "label": "CustomActivity", + "label": "$string:ability_sim1", "type": "page", "launchType": "standard" }, @@ -69,7 +69,7 @@ "name": "com.classic.common.simple.Simple2Activity", "icon": "$media:icon", "description": "", - "label": "CustomActivity", + "label": "$string:ability_sim2", "type": "page", "launchType": "standard" }, @@ -78,7 +78,7 @@ "name": "com.classic.common.simple.Simple3Activity", "icon": "$media:icon", "description": "", - "label": "CustomActivity", + "label": "$string:ability_sim3", "type": "page", "launchType": "standard" }, @@ -87,7 +87,7 @@ "name": "com.classic.common.simple.ListActivity", "icon": "$media:icon", "description": "", - "label": "CustomActivity", + "label": "$string:ability_list", "type": "page", "launchType": "standard" } diff --git a/entry/src/main/java/com/classic/common/simple/AbsActivity.java b/entry/src/main/java/com/classic/common/simple/AbsActivity.java index 52c647961a9eb8d21edf3ca53d4ccd44d6637c23..35a9375f91592cf0da90ff3e4698dea4adc5dc0f 100644 --- a/entry/src/main/java/com/classic/common/simple/AbsActivity.java +++ b/entry/src/main/java/com/classic/common/simple/AbsActivity.java @@ -89,13 +89,16 @@ public abstract class AbsActivity extends Ability implements Component.ClickedLi loading(); break; case ResourceTable.Id_fab_empty: - mMultipleStatusView.showEmpty(ResourceTable.String_test_hint_content, ResourceTable.Id_empty_retry_view, "aa", "bb"); + mMultipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view); + mMultipleStatusView.showEmpty(ResourceTable.String_test_hint_content, "aa", "bb"); break; case ResourceTable.Id_fab_error: - mMultipleStatusView.showError("自定义错误文本", ResourceTable.Id_error_retry_view); + mMultipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view); + mMultipleStatusView.showError("自定义错误文本"); break; case ResourceTable.Id_fab_no_network: - mMultipleStatusView.showNoNetwork("自定义无网络文本", ResourceTable.Id_no_network_retry_view); + mMultipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view); + mMultipleStatusView.showNoNetwork("自定义无网络文本"); break; case ResourceTable.Id_fab_content: mMultipleStatusView.showContent(); diff --git a/entry/src/main/java/com/classic/common/simple/CustomActivity.java b/entry/src/main/java/com/classic/common/simple/CustomActivity.java index a09aa51a3e36ceb6431cb744a76cdcc18526e5d0..5cd23430f6c75d12cf07966c64bd602a626d6274 100644 --- a/entry/src/main/java/com/classic/common/simple/CustomActivity.java +++ b/entry/src/main/java/com/classic/common/simple/CustomActivity.java @@ -21,7 +21,6 @@ public class CustomActivity extends AbsActivity { setUIContent(ResourceTable.Layout_activity_custom); mMultipleStatusView = (MultipleStatusView) findComponentById(ResourceTable.Id_custom_multiple_status_view); mMultipleStatusView.setOnRetryClickListener(mRetryClickListener); - mMultipleStatusView.showContent(); mLayoutParams.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT); } @@ -32,25 +31,29 @@ public class CustomActivity extends AbsActivity { if (null == mLoadingView) { mLoadingView = createCustomView("自定义加载中视图"); } - mMultipleStatusView.showLoading(mLoadingView, mLayoutParams); +// mMultipleStatusView.showLoading(mLoadingView, mLayoutParams); + mMultipleStatusView.showLoading("Show loading hint"); break; case ResourceTable.Id_fab_empty: if (null == mEmptyView) { mEmptyView = createCustomView("自定义空视图"); } - mMultipleStatusView.showEmpty(mEmptyView, mLayoutParams, ResourceTable.Id_empty_retry_view); + mMultipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view); + mMultipleStatusView.showEmpty(mEmptyView, mLayoutParams); break; case ResourceTable.Id_fab_error: if (null == mErrorView) { mErrorView = createCustomView("自定义错误视图"); } - mMultipleStatusView.showError(mErrorView, mLayoutParams, ResourceTable.Id_error_retry_view); + mMultipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view); + mMultipleStatusView.showError(mErrorView, mLayoutParams); break; case ResourceTable.Id_fab_no_network: if (null == mNoNetworkView) { mNoNetworkView = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_no_network, null, false); } - mMultipleStatusView.showNoNetwork(mNoNetworkView, mLayoutParams, ResourceTable.Id_no_network_retry_view); + mMultipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view); + mMultipleStatusView.showNoNetwork(mNoNetworkView, mLayoutParams); break; case ResourceTable.Id_fab_content: mMultipleStatusView.showContent(ResourceTable.Layout_custom_content_view, mLayoutParams); diff --git a/entry/src/main/java/com/classic/common/simple/ListActivity.java b/entry/src/main/java/com/classic/common/simple/ListActivity.java index fd7e2f609b1224b7d529889bf7c43df97550d8a2..d5d927be91cf19f45169a090d8e1935203b8e449 100644 --- a/entry/src/main/java/com/classic/common/simple/ListActivity.java +++ b/entry/src/main/java/com/classic/common/simple/ListActivity.java @@ -14,10 +14,6 @@ public class ListActivity extends AbsActivity { void initView() { setUIContent(ResourceTable.Layout_activity_list); mMultipleStatusView = (MultipleStatusView) findComponentById(ResourceTable.Id_list_multiple_status_view); - /** - * 如果不showContent(),mRecyclerView的获取是null - */ - mMultipleStatusView.showContent(); mRecyclerView = (ListContainer) mMultipleStatusView.findComponentById(ResourceTable.Id_recycler_view); mNewsAdapter = new EasyListProvider(this, Arrays.asList(data)); mRecyclerView.setItemProvider(mNewsAdapter); diff --git a/entry/src/main/java/com/classic/common/simple/Simple3Activity.java b/entry/src/main/java/com/classic/common/simple/Simple3Activity.java index 39698e8579cd3bbe1435fd3af1f4fed135d3e1eb..48207a1ce30b873467e9cb556cfd6bf32346d57e 100644 --- a/entry/src/main/java/com/classic/common/simple/Simple3Activity.java +++ b/entry/src/main/java/com/classic/common/simple/Simple3Activity.java @@ -19,13 +19,16 @@ public class Simple3Activity extends AbsActivity { loading(); break; case ResourceTable.Id_fab_empty: - mMultipleStatusView.showEmpty(ResourceTable.Id_empty_retry_view); + mMultipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view); + mMultipleStatusView.showEmpty(); break; case ResourceTable.Id_fab_error: - mMultipleStatusView.showError(ResourceTable.Id_error_retry_view); + mMultipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view); + mMultipleStatusView.showError(); break; case ResourceTable.Id_fab_no_network: - mMultipleStatusView.showNoNetwork(ResourceTable.Id_no_network_retry_view); + mMultipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view); + mMultipleStatusView.showNoNetwork(); break; case ResourceTable.Id_fab_content: mMultipleStatusView.showContent(); diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 3d31a25452eba58c29fa78e410063c09e8c54672..9cd777ccf117e778257f2de1c080a5b077c2d3af 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -19,6 +19,26 @@ { "name": "no_network_view_hint", "value": "网络异常" + }, + { + "name": "ability_cust", + "value": "CustomActivity" + }, + { + "name": "ability_sim1", + "value": "SimpleActivity" + }, + { + "name": "ability_sim2", + "value": "Simple2Activity" + }, + { + "name": "ability_sim3", + "value": "Simple3Activity" + }, + { + "name": "ability_list", + "value": "ListActivity" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/activity_custom.xml b/entry/src/main/resources/base/layout/activity_custom.xml index 3ed2d27921d74f530f2c86263a88ac92803645f1..4bc697fa0dab5ec604139b7f1c5d2c1258a72dd7 100644 --- a/entry/src/main/resources/base/layout/activity_custom.xml +++ b/entry/src/main/resources/base/layout/activity_custom.xml @@ -1,23 +1,20 @@ - - - + ohos:height="match_parent" + ohos:width="match_parent"> + ohos:width="match_parent" + ohos:contentView="$layout:content_text" + ohos:menu_animationDelayPerItem="100"/> - + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/activity_list.xml b/entry/src/main/resources/base/layout/activity_list.xml index a14ecf243e87ac057e79fad98a335e3ab8579599..42a6eb7247272189aca3d43f96b0864394285bef 100644 --- a/entry/src/main/resources/base/layout/activity_list.xml +++ b/entry/src/main/resources/base/layout/activity_list.xml @@ -1,28 +1,26 @@ - - - + /> - + diff --git a/entry/src/main/resources/base/layout/activity_main.xml b/entry/src/main/resources/base/layout/activity_main.xml index a9e0d6468e8575c730d9739e84ab0bc3b3998b12..8e458eb56bbfdfe8af533bb90398123d62594286 100644 --- a/entry/src/main/resources/base/layout/activity_main.xml +++ b/entry/src/main/resources/base/layout/activity_main.xml @@ -1,99 +1,99 @@ + - + ohos:padding="16vp"> + ohos:id="$+id:main_simple" + ohos:height="match_content" + ohos:width="match_content" + ohos:bottom_padding="16vp" + ohos:multiple_lines="false" + ohos:text="简单布局1" + ohos:text_color="$color:color_item_intro" + ohos:text_size="24fp" + ohos:top_padding="16vp"/> + ohos:height="1vp" + ohos:width="match_parent" + ohos:background_element="#E6E6E6"/> + ohos:id="$+id:main_simple2" + ohos:height="match_content" + ohos:width="match_content" + ohos:bottom_padding="16vp" + ohos:multiple_lines="false" + ohos:text="简单布局2" + ohos:text_color="$color:color_item_intro" + ohos:text_size="24fp" + ohos:top_padding="16vp" + /> - + + ohos:id="$+id:main_simple3" + ohos:height="match_content" + ohos:width="match_content" + ohos:bottom_padding="16vp" + ohos:multiple_lines="false" + ohos:text="简单布局3" + ohos:text_color="$color:color_item_intro" + ohos:text_size="24fp" + ohos:top_padding="16vp" + /> - + + ohos:id="$+id:main_custom" + ohos:height="match_content" + ohos:width="match_content" + ohos:bottom_padding="16vp" + ohos:multiple_lines="false" + ohos:text="自定义布局" + ohos:text_color="$color:color_item_intro" + ohos:text_size="24fp" + ohos:top_padding="16vp" + /> - + - + ohos:id="$+id:main_list" + ohos:height="match_content" + ohos:width="match_content" + ohos:bottom_padding="16vp" + ohos:multiple_lines="false" + ohos:text="列表展示" + ohos:text_color="$color:color_item_intro" + ohos:text_size="24fp" + ohos:top_padding="16vp" + /> - + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/activity_simple.xml b/entry/src/main/resources/base/layout/activity_simple.xml index a2a3e2265f6840e1247bf0743d55cebe9c906320..abefa83f06f860e3a7772a4574a1909f941797ef 100644 --- a/entry/src/main/resources/base/layout/activity_simple.xml +++ b/entry/src/main/resources/base/layout/activity_simple.xml @@ -1,26 +1,23 @@ - - + ohos:height="match_parent" + ohos:width="match_parent"> + ohos:layout_alignment="bottom|right" + ohos:margin="16vp" + layout="$layout:fab_menu"/> \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/activity_simple2.xml b/entry/src/main/resources/base/layout/activity_simple2.xml index ff46ed84fa768ddf04cfcf93a25bc1c419987944..2aaf7bd883734e3b426653d7600f3fb5b935d461 100644 --- a/entry/src/main/resources/base/layout/activity_simple2.xml +++ b/entry/src/main/resources/base/layout/activity_simple2.xml @@ -1,36 +1,33 @@ - - + ohos:height="match_parent" + ohos:width="match_parent"> + ohos:layout_alignment="bottom|right" + ohos:margin="16vp" + layout="$layout:fab_menu"/> \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/activity_simple3.xml b/entry/src/main/resources/base/layout/activity_simple3.xml index 818952f894c246f4c1ffe3cd89297a029d8bb065..4d11830b97983ed85885ae3929f024afc9ba9f64 100644 --- a/entry/src/main/resources/base/layout/activity_simple3.xml +++ b/entry/src/main/resources/base/layout/activity_simple3.xml @@ -1,38 +1,36 @@ - - + xmlns:ohos="http://schemas.huawei.com/res/ohos" + ohos:id="$+id:root" + ohos:height="match_parent" + ohos:width="match_parent" + ohos:orientation="vertical" + > + ohos:height="match_parent" + ohos:width="match_parent"> + ohos:id="$+id:ll_content" + ohos:height="match_parent" + ohos:width="match_parent" + ohos:alignment="center" + ohos:orientation="vertical"> + ohos:id="$+id:tv_content" + ohos:height="match_content" + ohos:width="match_content" + ohos:text="内容视图" + ohos:text_size="20fp"/> + ohos:layout_alignment="bottom|right" + ohos:margin="16vp" + layout="$layout:fab_menu"/> diff --git a/multiple_status_view/build.gradle b/multiple_status_view/build.gradle index 115ec9dab4917734bb2e858c3797e205259e0bf5..8687866f6ec553b52598c658be54bc0b18ed70e0 100644 --- a/multiple_status_view/build.gradle +++ b/multiple_status_view/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.huawei.ohos.library' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { - compatibleSdkVersion 5 + compatibleSdkVersion 6 } } diff --git a/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java b/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java index 1c6cd0ca880c193da59ba7c0f77f085c6555053f..e193573f301c36364cab1cb89d2a9fa4939f90d6 100644 --- a/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java +++ b/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java @@ -1,6 +1,7 @@ package com.classic.common; import ohos.aafwk.ability.Ability; +import ohos.aafwk.ability.fraction.Fraction; import ohos.agp.components.AttrSet; import ohos.agp.components.Component; import ohos.agp.components.ComponentContainer; @@ -22,7 +23,7 @@ import java.util.logging.Logger; * 创建时间: 2016/1/15 10:20. */ @SuppressWarnings("unused") -public class MultipleStatusView extends DependentLayout { +public class MultipleStatusView extends DependentLayout implements Component.BindStateChangedListener { private static final String TAG = "MultipleStatusView"; private static final String VIEW_EMPTY = "emptyView"; private static final String VIEW_ERROR = "errorView"; @@ -54,6 +55,11 @@ public class MultipleStatusView extends DependentLayout { private ClickedListener mOnRetryClickListener; private OnViewStatusChangeListener mViewStatusListener; private EventHandler handler; + // 新增资源根目录id + private static int xmlRootLayoutResId = -1; + private int emptyResId = -1; + private int errorResId = -1; + private int networkResId = -1; private final ArrayList mOtherIds = new ArrayList<>(); @@ -107,6 +113,12 @@ public class MultipleStatusView extends DependentLayout { } } mInflater = LayoutScatter.getInstance(getContext()); + setBindStateChangedListener(this); + onFinishInflate(); + } + + private void onFinishInflate(){ + showContent(); } /** @@ -127,35 +139,35 @@ public class MultipleStatusView extends DependentLayout { this.mOnRetryClickListener = onRetryClickListener; } + public void setEmptyResId(int resId) { + emptyResId = resId; + } + /** * 显示空视图 - * - * @param viewId 资源Id */ - public final void showEmpty(int viewId) { - showEmpty(mEmptyViewResId, DEFAULT_LAYOUT_PARAMS, viewId); + public final void showEmpty() { + showEmpty(mEmptyViewResId, DEFAULT_LAYOUT_PARAMS); } /** * 显示空视图 * * @param hintResId 自定义提示文本内容 - * @param viewId 资源Id * @param formatArgs 占位符参数 */ - public final void showEmpty(int hintResId, int viewId, Object... formatArgs) { - showEmpty(viewId); + public final void showEmpty(int hintResId, Object... formatArgs) { + showEmpty(); setStatusHintContent(mEmptyView, hintResId, formatArgs); } /** * 显示空视图 * - * @param hint 自定义提示文本内容 - * @param viewId 资源Id + * @param hint 自定义提示文本内容 */ - public final void showEmpty(String hint, int viewId) { - showEmpty(viewId); + public final void showEmpty(String hint) { + showEmpty(); setStatusHintContent(mEmptyView, hint); } @@ -164,10 +176,9 @@ public class MultipleStatusView extends DependentLayout { * * @param layoutId 自定义布局文件 * @param layoutParams 布局参数 - * @param viewId 资源Id */ - public final void showEmpty(int layoutId, ComponentContainer.LayoutConfig layoutParams, int viewId) { - showEmpty(null == mEmptyView ? inflateView(layoutId) : mEmptyView, layoutParams, viewId); + public final void showEmpty(int layoutId, ComponentContainer.LayoutConfig layoutParams) { + showEmpty(null == mEmptyView ? inflateView(layoutId) : mEmptyView, layoutParams); } /** @@ -175,15 +186,17 @@ public class MultipleStatusView extends DependentLayout { * * @param view 自定义视图 * @param layoutParams 布局参数 - * @param viewId 资源Id */ - public final void showEmpty(Component view, ComponentContainer.LayoutConfig layoutParams, int viewId) { + public final void showEmpty(Component view, ComponentContainer.LayoutConfig layoutParams) { checkNull(view, "Empty view is null."); checkNull(layoutParams, "Layout params is null."); + if (emptyResId == -1) { + throw new NullPointerException("emptyResId is invalid,ues setEmptyResId(int resId)"); + } changeViewStatus(STATUS_EMPTY); if (null == mEmptyView) { mEmptyView = view; - Component emptyRetryView = mEmptyView.findComponentById(viewId); + Component emptyRetryView = mEmptyView.findComponentById(emptyResId); if (null != mOnRetryClickListener && null != emptyRetryView) { emptyRetryView.setClickedListener(mOnRetryClickListener); } @@ -193,35 +206,35 @@ public class MultipleStatusView extends DependentLayout { showViewById(mEmptyView.getId()); } + public void setErrorResId(int resId) { + errorResId = resId; + } + /** * 显示错误视图 - * - * @param viewId 资源Id */ - public final void showError(int viewId) { - showError(mErrorViewResId, DEFAULT_LAYOUT_PARAMS, viewId); + public final void showError() { + showError(mErrorViewResId, DEFAULT_LAYOUT_PARAMS); } /** * 显示错误视图 * * @param hintResId 自定义提示文本内容 - * @param viewId 资源Id * @param formatArgs 占位符参数 */ - public final void showError(int hintResId, int viewId, Object... formatArgs) { - showError(viewId); + public final void showError(int hintResId, Object... formatArgs) { + showError(); setStatusHintContent(mErrorView, hintResId, formatArgs); } /** * 显示错误视图 * - * @param hint 自定义提示文本内容 - * @param viewId 资源Id + * @param hint 自定义提示文本内容 */ - public final void showError(String hint, int viewId) { - showError(viewId); + public final void showError(String hint) { + showError(); setStatusHintContent(mErrorView, hint); } @@ -230,10 +243,9 @@ public class MultipleStatusView extends DependentLayout { * * @param layoutId 自定义布局文件 * @param layoutParams 布局参数 - * @param viewId 资源Id */ - public final void showError(int layoutId, ComponentContainer.LayoutConfig layoutParams, int viewId) { - showError(null == mErrorView ? inflateView(layoutId) : mErrorView, layoutParams, viewId); + public final void showError(int layoutId, ComponentContainer.LayoutConfig layoutParams) { + showError(null == mErrorView ? inflateView(layoutId) : mErrorView, layoutParams); } /** @@ -241,15 +253,17 @@ public class MultipleStatusView extends DependentLayout { * * @param view 自定义视图 * @param layoutParams 布局参数 - * @param viewId 资源Id */ - public final void showError(Component view, ComponentContainer.LayoutConfig layoutParams, int viewId) { + public final void showError(Component view, ComponentContainer.LayoutConfig layoutParams) { checkNull(view, "Error view is null."); checkNull(layoutParams, "Layout params is null."); + if (errorResId == -1) { + throw new NullPointerException("errorResId is invalid,ues setErrorResId(int resId)"); + } changeViewStatus(STATUS_ERROR); if (null == mErrorView) { mErrorView = view; - Component errorRetryView = mErrorView.findComponentById(viewId); + Component errorRetryView = mErrorView.findComponentById(errorResId); if (null != mOnRetryClickListener && null != errorRetryView) { errorRetryView.setClickedListener(mOnRetryClickListener); } @@ -315,35 +329,35 @@ public class MultipleStatusView extends DependentLayout { showViewById(mLoadingView.getId()); } + public void setNetWorkResId(int resId) { + networkResId = resId; + } + /** * 显示无网络视图 - * - * @param viewId 资源Id */ - public final void showNoNetwork(int viewId) { - showNoNetwork(mNoNetworkViewResId, DEFAULT_LAYOUT_PARAMS, viewId); + public final void showNoNetwork() { + showNoNetwork(mNoNetworkViewResId, DEFAULT_LAYOUT_PARAMS); } /** * 显示无网络视图 * * @param hintResId 自定义提示文本内容 - * @param viewId 资源Id * @param formatArgs 占位符参数 */ - public final void showNoNetwork(int hintResId, int viewId, Object... formatArgs) { - showNoNetwork(viewId); + public final void showNoNetwork(int hintResId, Object... formatArgs) { + showNoNetwork(); setStatusHintContent(mNoNetworkView, hintResId, formatArgs); } /** * 显示无网络视图 * - * @param hint 自定义提示文本内容 - * @param viewId 资源Id + * @param hint 自定义提示文本内容 */ - public final void showNoNetwork(String hint, int viewId) { - showNoNetwork(viewId); + public final void showNoNetwork(String hint) { + showNoNetwork(); setStatusHintContent(mNoNetworkView, hint); } @@ -352,10 +366,9 @@ public class MultipleStatusView extends DependentLayout { * * @param layoutId 自定义布局文件 * @param layoutParams 布局参数 - * @param viewId 资源Id */ - public final void showNoNetwork(int layoutId, ComponentContainer.LayoutConfig layoutParams, int viewId) { - showNoNetwork(null == mNoNetworkView ? inflateView(layoutId) : mNoNetworkView, layoutParams, viewId); + public final void showNoNetwork(int layoutId, ComponentContainer.LayoutConfig layoutParams) { + showNoNetwork(null == mNoNetworkView ? inflateView(layoutId) : mNoNetworkView, layoutParams); } /** @@ -363,15 +376,17 @@ public class MultipleStatusView extends DependentLayout { * * @param view 自定义视图 * @param layoutParams 布局参数 - * @param viewId 资源Id */ - public final void showNoNetwork(Component view, ComponentContainer.LayoutConfig layoutParams, int viewId) { + public final void showNoNetwork(Component view, ComponentContainer.LayoutConfig layoutParams) { checkNull(view, "No network view is null."); checkNull(layoutParams, "Layout params is null."); + if (networkResId == -1) { + throw new NullPointerException("networkResId is invalid,ues setNetWorkResId(int resId)"); + } changeViewStatus(STATUS_NO_NETWORK); if (null == mNoNetworkView) { mNoNetworkView = view; - Component noNetworkRetryView = mNoNetworkView.findComponentById(viewId); + Component noNetworkRetryView = mNoNetworkView.findComponentById(networkResId); if (null != mOnRetryClickListener && null != noNetworkRetryView) { noNetworkRetryView.setClickedListener(mOnRetryClickListener); } @@ -430,12 +445,16 @@ public class MultipleStatusView extends DependentLayout { private void setStatusHintContent(Component view, String hint) { checkNull(view, "Target view is null."); - if (mhintResId != -1) { Text hintView = (Text) view.findComponentById(mhintResId); - hintView.setText(hint); + if (null != hintView) { + hintView.setText(hint); + } else { + throw new NullPointerException("Not find the view ID status hint content"); + } + } else { - throw new NullPointerException("Not find the view ID `status_hint_content`"); + throw new NullPointerException("Hint view is not set,use setStatusHintRes(int hintRes)"); } } @@ -480,6 +499,25 @@ public class MultipleStatusView extends DependentLayout { } } + @Override + public void onComponentBoundToWindow(Component component) { + + } + + @Override + public void onComponentUnboundFromWindow(Component component) { + clear(mEmptyView, mLoadingView, mErrorView, mNoNetworkView); + if (!mOtherIds.isEmpty()) { + mOtherIds.clear(); + } + if (null != mOnRetryClickListener) { + mOnRetryClickListener = null; + } + if (null != mViewStatusListener) { + mViewStatusListener = null; + } + } + /** * 视图状态改变接口 */ @@ -530,7 +568,24 @@ public class MultipleStatusView extends DependentLayout { addComponent(mContentView, 0, DEFAULT_LAYOUT_PARAMS); } - public static MultipleStatusView attach(Ability activity, int rootAnchor, int xmlRootLayoutResId) { + public static MultipleStatusView attach(Fraction fraction, int rootAnchor) { + if (xmlRootLayoutResId == -1) { + throw new NullPointerException("xmlRootLayoutResId is invalid,use setXmlRootLayoutResId(int rootId)"); + } + if (-1 != rootAnchor) { + ComponentContainer contentAnchor = (ComponentContainer) fraction.getComponent().findComponentById(xmlRootLayoutResId); + if (null != contentAnchor) { + attach(contentAnchor); + } + } + ComponentContainer defaultAnchor = (ComponentContainer) fraction.getComponent().findComponentById(xmlRootLayoutResId); + return attach(defaultAnchor); + } + + public static MultipleStatusView attach(Ability activity, int rootAnchor) { + if (xmlRootLayoutResId == -1) { + throw new NullPointerException("xmlRootLayoutResId is invalid,use setXmlRootLayoutResId(int rootId)"); + } if (-1 != rootAnchor) { ComponentContainer contentAnchor = (ComponentContainer) activity.findComponentById(rootAnchor); if (null != contentAnchor) { @@ -558,6 +613,10 @@ public class MultipleStatusView extends DependentLayout { return null; } + public void setXmlRootLayoutResId(int rootId) { + xmlRootLayoutResId = rootId; + } + public void removeCallbacks(Runnable runnable) { handler.removeTask(runnable); }