Skip to content

Commit

Permalink
- Fix custom layout problem
Browse files Browse the repository at this point in the history
  • Loading branch information
iammert committed Feb 13, 2017
1 parent 81100b4 commit 02d5d6b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="NABER YAAAA"/>
android:layout_margin="8dp"/>

<iammert.com.library.ConnectionStatusView
android:id="@+id/status"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/custom_layout_complete.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#22FF99">

</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/custom_layout_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#993333">

</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/custom_layout_loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#333333">

</LinearLayout>
42 changes: 31 additions & 11 deletions library/src/main/java/iammert/com/library/StatusView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 02d5d6b

Please sign in to comment.