From 02d5d6b154b854e913b259296a1d82e021424400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20=C5=9Eim=C5=9Fek?= Date: Mon, 13 Feb 2017 10:15:27 +0300 Subject: [PATCH] - Fix custom layout problem --- app/src/main/res/layout/activity_main.xml | 3 +- .../res/layout/custom_layout_complete.xml | 7 ++++ .../main/res/layout/custom_layout_error.xml | 7 ++++ .../main/res/layout/custom_layout_loading.xml | 7 ++++ .../java/iammert/com/library/StatusView.java | 42 ++++++++++++++----- 5 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 app/src/main/res/layout/custom_layout_complete.xml create mode 100644 app/src/main/res/layout/custom_layout_error.xml create mode 100644 app/src/main/res/layout/custom_layout_loading.xml diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f06c1df..8f54e3b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -10,8 +10,7 @@ + android:layout_margin="8dp"/> + + + \ No newline at end of file diff --git a/app/src/main/res/layout/custom_layout_error.xml b/app/src/main/res/layout/custom_layout_error.xml new file mode 100644 index 0000000..69d8520 --- /dev/null +++ b/app/src/main/res/layout/custom_layout_error.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/custom_layout_loading.xml b/app/src/main/res/layout/custom_layout_loading.xml new file mode 100644 index 0000000..6b9c8f4 --- /dev/null +++ b/app/src/main/res/layout/custom_layout_loading.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/library/src/main/java/iammert/com/library/StatusView.java b/library/src/main/java/iammert/com/library/StatusView.java index ad78d38..cb51191 100644 --- a/library/src/main/java/iammert/com/library/StatusView.java +++ b/library/src/main/java/iammert/com/library/StatusView.java @@ -65,6 +65,26 @@ public void run() { } }; + public StatusView(Context context) { + super(context); + init(context, null, 0, 0, 0); + } + + public StatusView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs, 0, 0, 0); + } + + public StatusView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context, attrs, 0, 0, 0); + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public StatusView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + public StatusView(Context context, int completeLayout, int errorLayout, int loadingLayout) { super(context); init(context, null, completeLayout, errorLayout, loadingLayout); @@ -77,13 +97,13 @@ public StatusView(Context context, AttributeSet attrs, int completeLayout, int e public StatusView(Context context, AttributeSet attrs, int defStyleAttr, int completeLayout, int errorLayout, int loadingLayout) { super(context, attrs, defStyleAttr); - init(context, attrs,completeLayout, errorLayout, loadingLayout); + init(context, attrs, completeLayout, errorLayout, loadingLayout); } @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public StatusView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int completeLayout, int errorLayout, int loadingLayout) { super(context, attrs, defStyleAttr, defStyleRes); - init(context, attrs,completeLayout, errorLayout, loadingLayout); + init(context, attrs, completeLayout, errorLayout, loadingLayout); } private void init(Context context, AttributeSet attrs, int completeLayout, int errorLayout, int loadingLayout) { @@ -112,11 +132,11 @@ private void init(Context context, AttributeSet attrs, int completeLayout, int e /** * inflate layouts */ - if(completeLayout == 0){ + if (completeLayout == 0) { completeView = inflater.inflate(completeLayoutId, null); errorView = inflater.inflate(errorLayoutId, null); loadingview = inflater.inflate(loadingLayoutId, null); - }else{ + } else { completeView = inflater.inflate(completeLayout, null); errorView = inflater.inflate(errorLayout, null); loadingview = inflater.inflate(loadingLayout, null); @@ -146,23 +166,23 @@ private void init(Context context, AttributeSet attrs, int completeLayout, int e a.recycle(); } - public void setOnErrorClickListener(OnClickListener onErrorClickListener){ + public void setOnErrorClickListener(OnClickListener onErrorClickListener) { errorView.setOnClickListener(onErrorClickListener); } - public void setOnLoadingClickListener(OnClickListener onLoadingClickListener){ + public void setOnLoadingClickListener(OnClickListener onLoadingClickListener) { loadingview.setOnClickListener(onLoadingClickListener); } - public View getErrorView(){ + public View getErrorView() { return errorView; } - public View getCompleteView(){ + public View getCompleteView() { return completeView; } - public View getLoadingView(){ + public View getLoadingView() { return loadingview; } @@ -178,7 +198,7 @@ public void setStatus(final Status status) { } handler.removeCallbacksAndMessages(null); - if(status == Status.COMPLETE) + if (status == Status.COMPLETE) handler.postDelayed(autoDismissOnComplete, DISMISS_ON_COMPLETE_DELAY); } @@ -218,7 +238,7 @@ private void enterAnimation(View enterView) { } private void exitAnimation(final View exitView) { - if(exitView == null) + if (exitView == null) return; exitView.startAnimation(slideOut);