Skip to content

Commit

Permalink
opt elements sort
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyuwei.jeason committed Jun 27, 2019
1 parent cf070eb commit 7f4cdbf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ At present, UETool provides functionality as follows:

```gradle
dependencies {
debugImplementation 'me.ele:uetool:1.2.0'
releaseImplementation 'me.ele:uetool-no-op:1.2.0'
debugImplementation 'me.ele:uetool:1.2.1'
releaseImplementation 'me.ele:uetool-no-op:1.2.1'
// if you want to show more attrs about Fresco's DraweeView
debugImplementation 'me.ele:uetool-fresco:1.2.0'
debugImplementation 'me.ele:uetool-fresco:1.2.1'
}
```

Expand Down
6 changes: 3 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ UETool 是一个各方人员(设计师、程序员、测试)都可以使用

```gradle
dependencies {
debugImplementation 'me.ele:uetool:1.2.0'
releaseImplementation 'me.ele:uetool-no-op:1.2.0'
debugImplementation 'me.ele:uetool:1.2.1'
releaseImplementation 'me.ele:uetool-no-op:1.2.1'
// if you want to show more attrs about Fresco's DraweeView
debugImplementation 'me.ele:uetool-fresco:1.2.0'
debugImplementation 'me.ele:uetool-fresco:1.2.1'
}
```

Expand Down
27 changes: 15 additions & 12 deletions app/src/main/res/layout/activity_second.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email"
/>
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email"/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#20000000"/>

</android.support.design.widget.CoordinatorLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
'supportLibrary': '27.1.1',
'fresco' : '1.0.1',

'release' : '1.2.0',]
'release' : '1.2.1',]
repositories {
jcenter()
google()
Expand Down
5 changes: 5 additions & 0 deletions uetool-base/src/main/java/me/ele/uetool/base/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public Element getParentElement() {
return parentElement;
}

// view 的面积
public int getArea() {
return view.getWidth() * view.getHeight();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
31 changes: 23 additions & 8 deletions uetool/src/main/java/me/ele/uetool/CollectViewsLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import me.ele.uetool.base.ReflectionP;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

import static me.ele.uetool.base.DimenUtil.*;

Expand Down Expand Up @@ -94,7 +92,7 @@ protected void onAttachedToWindow() {
for (int i = views.size() - 1; i >= 0; i--) {
View targetView = getTargetDecorView(targetActivity, views.get(i));
if (targetView != null) {
traverse(targetView);
createElements(targetView);
break;
}
}
Expand All @@ -118,7 +116,7 @@ public void call() {
WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) mWindowAttributesField.get(object);
if (layoutParams.getTitle().toString().contains(targetActivity.getClass().getName())
|| getTargetDecorView(targetActivity, decorView) != null) {
traverse(decorView);
createElements(decorView);
break;
}
}
Expand All @@ -138,7 +136,7 @@ public void call() {
for (int i = views.size() - 1; i >= 0; i--) {
View targetView = getTargetDecorView(targetActivity, views.get(i));
if (targetView != null) {
traverse(targetView);
createElements(targetView);
break;
}
}
Expand All @@ -156,15 +154,32 @@ protected void onDetachedFromWindow() {
parentElement = null;
}

private void traverse(View view) {
private void createElements(View view) {

List<Element> elements = new ArrayList<>();
traverse(view, elements);

// 面积从大到小排序
Collections.sort(elements, new Comparator<Element>() {
@Override
public int compare(Element o1, Element o2) {
return o2.getArea() - o1.getArea();
}
});

this.elements.addAll(elements);

}

private void traverse(View view, List<Element> elements) {
if (UETool.getInstance().getFilterClasses().contains(view.getClass().getName())) return;
if (view.getAlpha() == 0 || view.getVisibility() != View.VISIBLE) return;
if (getResources().getString(R.string.uet_disable).equals(view.getTag())) return;
elements.add(new Element(view));
if (view instanceof ViewGroup) {
ViewGroup parent = (ViewGroup) view;
for (int i = 0; i < parent.getChildCount(); i++) {
traverse(parent.getChildAt(i));
traverse(parent.getChildAt(i), elements);
}
}
}
Expand Down

0 comments on commit 7f4cdbf

Please sign in to comment.