From 7f4cdbfd6430729a2eebb5599c48f6443ab70702 Mon Sep 17 00:00:00 2001 From: "wangyuwei.jeason" Date: Thu, 27 Jun 2019 15:02:38 +0800 Subject: [PATCH] opt elements sort --- README.md | 6 ++-- README_zh.md | 6 ++-- app/src/main/res/layout/activity_second.xml | 27 +++++++++------- build.gradle | 2 +- .../main/java/me/ele/uetool/base/Element.java | 5 +++ .../me/ele/uetool/CollectViewsLayout.java | 31 ++++++++++++++----- 6 files changed, 50 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 6a896fb..473595e 100644 --- a/README.md +++ b/README.md @@ -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' } ``` diff --git a/README_zh.md b/README_zh.md index ab44c5e..c1c0b01 100644 --- a/README_zh.md +++ b/README_zh.md @@ -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' } ``` diff --git a/app/src/main/res/layout/activity_second.xml b/app/src/main/res/layout/activity_second.xml index c4a7edb..5004c9f 100644 --- a/app/src/main/res/layout/activity_second.xml +++ b/app/src/main/res/layout/activity_second.xml @@ -1,18 +1,21 @@ + 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: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"/> + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index afae533..78daf1c 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { 'supportLibrary': '27.1.1', 'fresco' : '1.0.1', - 'release' : '1.2.0',] + 'release' : '1.2.1',] repositories { jcenter() google() diff --git a/uetool-base/src/main/java/me/ele/uetool/base/Element.java b/uetool-base/src/main/java/me/ele/uetool/base/Element.java index 9824908..646bd74 100644 --- a/uetool-base/src/main/java/me/ele/uetool/base/Element.java +++ b/uetool-base/src/main/java/me/ele/uetool/base/Element.java @@ -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; diff --git a/uetool/src/main/java/me/ele/uetool/CollectViewsLayout.java b/uetool/src/main/java/me/ele/uetool/CollectViewsLayout.java index e280a85..9215fca 100644 --- a/uetool/src/main/java/me/ele/uetool/CollectViewsLayout.java +++ b/uetool/src/main/java/me/ele/uetool/CollectViewsLayout.java @@ -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.*; @@ -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; } } @@ -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; } } @@ -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; } } @@ -156,7 +154,24 @@ protected void onDetachedFromWindow() { parentElement = null; } - private void traverse(View view) { + private void createElements(View view) { + + List elements = new ArrayList<>(); + traverse(view, elements); + + // 面积从大到小排序 + Collections.sort(elements, new Comparator() { + @Override + public int compare(Element o1, Element o2) { + return o2.getArea() - o1.getArea(); + } + }); + + this.elements.addAll(elements); + + } + + private void traverse(View view, List 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; @@ -164,7 +179,7 @@ private void traverse(View 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); } } }