opt: layout inspector view

This commit is contained in:
hyb1996
2017-12-09 12:36:43 +08:00
parent 6128aa28a6
commit 0e6616c1dc
5 changed files with 25 additions and 19 deletions

View File

@@ -9,8 +9,10 @@ import android.view.WindowManager;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.Theme;
import com.stardust.app.DialogUtils;
import com.stardust.enhancedfloaty.FloatyService;
import com.stardust.scriptdroid.R;
import com.stardust.scriptdroid.ui.codegeneration.CodeGenerateDialog;
import com.stardust.scriptdroid.ui.floating.FullScreenFloatyWindow;
import com.stardust.view.accessibility.NodeInfo;
import com.stardust.scriptdroid.ui.widget.BubblePopupMenu;
@@ -82,22 +84,27 @@ public class LayoutHierarchyFloatyWindow extends FullScreenFloatyWindow {
return;
mBubblePopMenu = new BubblePopupMenu(mContext, Arrays.asList(
mContext.getString(R.string.text_show_widget_infomation),
mContext.getString(R.string.text_show_layout_bounds)));
mBubblePopMenu.setOnItemClickListener(new BubblePopupMenu.OnItemClickListener() {
@Override
public void onClick(View view, int position) {
mBubblePopMenu.dismiss();
if (position == 0) {
showNodeInfo();
} else {
showLayoutBounds();
}
mContext.getString(R.string.text_show_layout_bounds),
mContext.getString(R.string.text_generate_code)));
mBubblePopMenu.setOnItemClickListener((view, position) -> {
mBubblePopMenu.dismiss();
if (position == 0) {
showNodeInfo();
} else if (position == 1) {
showLayoutBounds();
} else {
generateCode();
}
});
mBubblePopMenu.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
mBubblePopMenu.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
}
private void generateCode() {
DialogUtils.showDialog(new CodeGenerateDialog(mContext, mRootNode, mSelectedNode)
.build());
}
private void showLayoutBounds() {
close();
LayoutBoundsFloatyWindow window = new LayoutBoundsFloatyWindow(mRootNode);

View File

@@ -47,6 +47,7 @@ public class NodeInfoView extends RecyclerView {
"editable",
"enabled",
"focusable",
"indexInParent",
"longClickable",
"row",
"rowCount",

View File

@@ -34,12 +34,7 @@ public class BubblePopupMenu extends PopupWindow {
View view = View.inflate(context, R.layout.bubble_popup_menu, null);
mLittleTriangle = view.findViewById(R.id.little_triangle);
mRecyclerView = (RecyclerView) view.findViewById(R.id.list);
mRecyclerView.setAdapter(new SimpleRecyclerViewAdapter<>(R.layout.bubble_popup_menu_item, options, new SimpleRecyclerViewAdapter.ViewHolderFactory<MenuItemViewHolder>() {
@Override
public MenuItemViewHolder create(View itemView) {
return new MenuItemViewHolder(itemView);
}
}));
mRecyclerView.setAdapter(new SimpleRecyclerViewAdapter<>(R.layout.bubble_popup_menu_item, options, MenuItemViewHolder::new));
setContentView(view);
setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setOutsideTouchable(true);
@@ -53,8 +48,8 @@ public class BubblePopupMenu extends PopupWindow {
public void showAsDropDownAtLocation(View parent, int contentHeight, int x, int y) {
int screenWidth = getContentView().getResources().getDisplayMetrics().widthPixels;
int screenHeight = getContentView().getResources().getDisplayMetrics().heightPixels;
int width = getContentView().getWidth();
int height = getContentView().getHeight();
int width = getContentView().getMeasuredWidth();
int height = getContentView().getMeasuredHeight();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mLittleTriangle.getLayoutParams();
if (x + width > screenWidth) {
params.leftMargin = x + width - screenWidth;

View File

@@ -196,7 +196,7 @@ public class ScriptRuntime {
throw new IllegalStateException("already initialized");
timers = new Timers(bridges);
loopers = new Loopers(this);
events = new Events(uiHandler.getContext(), accessibilityBridge, bridges, loopers);
events = new Events(uiHandler.getContext(), accessibilityBridge, this);
}
public static void setApplicationContext(Context context) {

View File

@@ -50,9 +50,11 @@ public class NodeInfo {
public boolean checkable;
public boolean focused;
public boolean visibleToUser;
public int indexInParent;
public NodeInfo parent;
public NodeInfo(UiObject node, NodeInfo parent) {
id = simplifyId(node.getViewIdResourceName());
desc = node.desc();
@@ -87,6 +89,7 @@ public class NodeInfo {
node.getBoundsInScreen(mBoundsInScreen);
node.getBoundsInParent(mBoundsInParent);
bounds = boundsToString(mBoundsInScreen);
indexInParent = node.indexInParent();
this.parent = parent;