Skip to content

Commit

Permalink
Merge branch 'master' into androidx
Browse files Browse the repository at this point in the history
  • Loading branch information
goweii committed May 10, 2020
2 parents 34234e1 + 0ad19be commit 5d627ef
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
39 changes: 23 additions & 16 deletions anylayer/src/main/java/per/goweii/anylayer/DecorLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ protected ViewGroup onGetParent() {
parent.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
group.addView(parent, lastIndex + 1);
}
parent.setVisibility(View.VISIBLE);
getViewHolder().setParent(parent);
return parent;
}
Expand Down Expand Up @@ -131,25 +130,17 @@ public void onDetach() {
if (group == null) {
return;
}
LevelLayout parent = null;
final int count = group.getChildCount();
for (int i = 0; i < count; i++) {
View child = group.getChildAt(i);
if (child instanceof LevelLayout) {
LevelLayout levelLayout = (LevelLayout) child;
if (getLevel() == levelLayout.getLevel()) {
parent = levelLayout;
break;
}
}
}
final LevelLayout parent = findLevelLayoutFromGroup(group);
if (parent == null) {
return;
}
if (parent.getChildCount() == 0) {
parent.setVisibility(View.GONE);
// group.removeView(parent);
// 存在toastLayer时,滑动关闭会崩溃
parent.post(new Runnable() {
@Override
public void run() {
group.removeView(parent);
}
});
}
if (group.getChildCount() == 0) {
removeLayerLayoutFromDecor(group);
Expand Down Expand Up @@ -199,6 +190,22 @@ private LayerLayout findLayerLayoutFromDecor() {
return layerLayout;
}

private LevelLayout findLevelLayoutFromGroup(LayerLayout group) {
LevelLayout parent = null;
final int count = group.getChildCount();
for (int i = 0; i < count; i++) {
View child = group.getChildAt(i);
if (child instanceof LevelLayout) {
LevelLayout levelLayout = (LevelLayout) child;
if (getLevel() == levelLayout.getLevel()) {
parent = levelLayout;
break;
}
}
}
return parent;
}

private LayerLayout addNewLayerLayoutToDecor() {
final ViewGroup decor = getViewHolder().mDecor;
LayerLayout layerLayout = new LayerLayout(decor.getContext());
Expand Down
17 changes: 10 additions & 7 deletions anylayer/src/main/java/per/goweii/anylayer/ViewManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ private void checkChildParent() {
}

public void attach() {
if (mParent == null) {
throw new RuntimeException("parent cannot be null on attach");
}
if (mChild == null) {
throw new RuntimeException("parent cannot be null on attach");
}
Utils.requireNonNull(mParent, "parent cannot be null on attach");
Utils.requireNonNull(mChild, "child cannot be null on attach");
checkChildParent();
if (!isAttached()) {
onAttach();
Expand All @@ -71,7 +67,14 @@ public void attach() {

public void detach() {
if (isAttached()) {
onDetach();
mChild.post(new Runnable() {
@Override
public void run() {
if (isAttached()) {
onDetach();
}
}
});
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/per/goweii/android/anylayer/DragActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import per.goweii.anylayer.AnyLayer;
import per.goweii.anylayer.DragLayout;
import per.goweii.anylayer.Layer;

public class DragActivity extends AppCompatActivity implements View.OnClickListener {

Expand Down Expand Up @@ -66,6 +67,18 @@ public void onClick(View v) {
.gravity(Gravity.BOTTOM)
.dragDismiss(DragLayout.DragStyle.Bottom)
.onClickToDismiss(R.id.fl_dialog_no)
.bindData(new Layer.DataBinder() {
@Override
public void bindData(Layer layer) {
layer.getView(R.id.tv_dialog_title).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
findViewById(R.id.tv_show_top).performClick();
return false;
}
});
}
})
.show();
break;
}
Expand Down

0 comments on commit 5d627ef

Please sign in to comment.