Skip to content

Commit

Permalink
update StatusLayout to support all of the direct and indirect child o…
Browse files Browse the repository at this point in the history
…f StatusLayout to hide and show ,fix issus vlonjat-gashi/progress-activity#16
  • Loading branch information
ProgrammerAnthony committed Nov 9, 2016
1 parent b547469 commit 8d8e7d4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
Expand Down Expand Up @@ -167,42 +168,47 @@ public void addView(@NonNull View child, int index, ViewGroup.LayoutParams param
!child.getTag().equals(TAG_EMPTY) && !child.getTag().equals(TAG_ERROR))) {

// contentViews.add(child);
contentViews = getAllChildren(child);
Log.i("StatusLayout", "sub children count of statuslayout is" + contentViews.size());
contentViews.addAll(getAllChildren(child));
Log.i("StatusLayout", "sub children count of StatusLayout is" + contentViews.size());
}
}


/**
* save all of the ids of child view
* save all of the direct and indirect children views
*
* @param
*/
private ArrayList<View> getAllChildren(View v) {
private List<View> getAllChildren(View v) {

if (!(v instanceof ViewGroup)) {
ArrayList<View> viewArrayList = new ArrayList<View>();
List<View> viewArrayList = new ArrayList<>();
viewArrayList.add(v);
return viewArrayList;
}

ArrayList<View> result = new ArrayList<View>();
} else {
if (((ViewGroup) v).getChildCount() == 0) {
List<View> viewArrayList = new ArrayList<>();
viewArrayList.add(v);
return viewArrayList;
} else {
List<View> result = new ArrayList<>();

ViewGroup vg = (ViewGroup) v;
for (int i = 0; i < vg.getChildCount(); i++) {
ViewGroup vg = (ViewGroup) v;
for (int i = 0; i < vg.getChildCount(); i++) {

View child = vg.getChildAt(i);
View child = vg.getChildAt(i);

ArrayList<View> viewArrayList = new ArrayList<View>();
viewArrayList.add(v);
viewArrayList.addAll(getAllChildren(child));
List<View> viewArrayList = new ArrayList<>();
viewArrayList.add(v);
viewArrayList.addAll(getAllChildren(child));

result.addAll(viewArrayList);
result.addAll(viewArrayList);
}
return result;
}
}
return result;
}


/**
* Hide all other states and show content
*/
Expand Down Expand Up @@ -476,23 +482,47 @@ private void setErrorView() {

/**
* set children visibility of StatusLayout
* notice!!! now Only support direct child
* cause we add direct children in {@link #contentViews}
*
* @param visible
* @param skipIds
*/
private void setContentVisibility(boolean visible, List<Integer> skipIds) {
boolean parentVisibleFlag = false;
for (View v : contentViews) {
if (v != null) {
if (!skipIds.contains(v.getId())) {
v.setVisibility(visible ? View.VISIBLE : View.GONE);
// when visible is true,which means set content Layout, the skipIds component need to be hide
if (visible) {
if (skipIds.contains(v.getId())) {
v.setVisibility(View.INVISIBLE);
}
}
if (!skipIds.contains(v.getId())) {
v.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
}

//set parent visible flag to be visible when one child want to be visible
if (v.getVisibility() == View.VISIBLE) {
parentVisibleFlag = true;
}
//set all of the parent to be visible
if(parentVisibleFlag &&(contentViews.get(contentViews.size()-1)==v)){
setParentToVisible(v);
}
int visibility = v.getVisibility();
Log.i("StatusLayout", v + " view id " + v.getId() + " visibility " + visibility);
}
}

public void setParentToVisible(View v) {
ViewParent mParent = v.getParent();
if (mParent != null && (mParent instanceof ViewGroup)) {
((ViewGroup) mParent).setVisibility(View.VISIBLE);
if (mParent.getParent() != null) {
setParentToVisible((View) mParent);
}
}
}


private void hideLoadingView() {
if (loadingStateRelativeLayout != null) {
loadingStateRelativeLayout.setVisibility(GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ protected void showToast(String content) {
toastUtils.showToast(content);
}


protected void showContent() {
showContent(null);
}

/**
* Hide all other states and show content
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ protected void initViewsAndEvents() {

List<Integer> skipIds = new ArrayList<>();
skipIds.add(R.id.activityToolbar);
skipIds.add(R.id.tv_title_login);
// skipIds.add(R.id.test_sub_iv);
// skipIds.add(R.id.test_sub_iv2);

String state = getIntent().getStringExtra("STATE");
switch (state) {
case "CONTENT":
showContent(null);
showContent();
setTitle("Content");
break;
case "LOADING":
Expand Down
39 changes: 19 additions & 20 deletions app/src/main/res/layout/activity_show_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,31 @@


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="@color/app_primary">
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true">

<ImageView
android:id="@+id/test_sub_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/app_primary" />

<RelativeLayout
android:id="@+id/layout_back"
android:layout_width="40dp"
android:layout_height="match_parent">

android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true">

<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:src="@mipmap/prj_default_pic_big" />
android:id="@+id/test_sub_iv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/colorAccent" />
</RelativeLayout>

<TextView
android:id="@+id/tv_title_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="测试"
android:textColor="@color/black"
android:textSize="@dimen/TextTitleBar" />
</RelativeLayout>


</LinearLayout>


0 comments on commit 8d8e7d4

Please sign in to comment.