"ui"; /* * @version: 1.0 * @Date: 2021-06-06 15:16:30 * @LastEditTime: 2021-06-06 16:04:19 * @LastEditors: 牙叔 * @Description: 普通版控制台美化, 用autoxjs_5.0.1测试的 * @FilePath: \autojs-normal-console\main.js * @名人名言: 牙叔教程 简单易学 * @bilibili: 牙叔教程 * @公众号: 牙叔教程 * @QQ群: 747748653 */ // bili.9.png 进群下载 importClass(Packages.androidx.recyclerview.widget.RecyclerView); importClass(java.io.FileInputStream); importClass(android.graphics.drawable.Drawable); importClass("android.graphics.Rect"); importClass("android.graphics.NinePatch"); importClass("android.graphics.drawable.NinePatchDrawable"); importClass("android.graphics.BitmapFactory"); importClass("android.graphics.Bitmap"); threads.start(function () { console.show(); console.setPosition(210, 330); ui.post(function () { let mConsoleView = getConsoleWindow(); log("mConsoleView ="); log(mConsoleView); log(mConsoleView.getChildAt(0).getChildAt(1)); let parent = mConsoleView.parent; var inputView = parent.findViewById(context.getResources().getIdentifier("input", "id", context.getPackageName())); var buttonView = parent.findViewById( context.getResources().getIdentifier("submit", "id", context.getPackageName()) ); var titleView = parent.findViewById(context.getResources().getIdentifier("title", "id", context.getPackageName())); // 这个是放日志的recycleView var logListView = parent.findViewById( context.getResources().getIdentifier("log_list", "id", context.getPackageName()) ); // 隐藏顶部view titleView.setText(""); clearImgViewSrc("minimize"); clearImgViewSrc("move_or_resize"); clearImgViewSrc("close"); // 隐藏底部view ui.run(function () { inputView.setVisibility(8); buttonView.setVisibility(8); }); function clearImgViewSrc(viewId) { var view = parent.findViewById(context.getResources().getIdentifier(viewId, "id", context.getPackageName())); view.setAlpha(0); } let parentViewOfTheTitleView = titleView.parent; ui.run(function () { // parentViewOfTheTitleView.attr("visibility", "invisible"); parentViewOfTheTitleView.getBackground().setAlpha(1); }); var consoleView = parent.findViewById( context.getResources().getIdentifier("console", "id", context.getPackageName()) ); // 默认情况下,所有的从同一资源(R.drawable.***)加载的drawable实例都共享一个共用的状态,如果你更改一个实例的状态,其余的实例都会接收到相同的通知。使用mutate可以使该drawable状态不定。一个不定状态的drawable不会共享状态。 drawable = consoleView.getBackground().mutate(); drawable.setCornerRadius(30); setTimeout(function () { let filePath = "./bili.9.png"; filePath = files.path(filePath); let drw = imageOperations(filePath); consoleView.setBackground(drw); consoleView.setPadding(120, 150, 10, 10); }, 1000); function imageOperations(filePath) { let bitmap = BitmapFactory.decodeFile(filePath); let chunk = bitmap.getNinePatchChunk(); let npd = new NinePatchDrawable(context.getResources(), bitmap, chunk, new Rect(), null); return npd; } events.on("exit", function () { console.hide(); }); function getConsoleWindow() { var mConsole = runtime.console; let field = mConsole.class.getDeclaredField("mConsoleFloaty"); field.setAccessible(true); mConsoleFloaty = field.get(mConsole); mConsoleView = mConsoleFloaty.getExpandedView(); return mConsoleView; } let r = filterView(mConsoleView); function filterView(view, arr) { arr = arr || []; if (view instanceof android.view.ViewGroup) { arr.push(view); let childCount = view.childCount; for (var i = 0; i < childCount; i++) { let chileView = view.getChildAt(i); filterView(chileView, arr); } } else { arr.push(view); } return arr; } ui.run(function () { let boxXml = ( <TextView id="content" layout_width="match_parent" layout_height="wrap_content" textIsSelectable="true" textSize="19sp" textColor="#ffffff" margin="6" ></TextView> ); function getLogEntries() { let rvConsoleView = mConsoleView.getChildAt(0).getChildAt(1); let field = rvConsoleView.getClass().getDeclaredField("mLogEntries"); field.setAccessible(true); let mLogEntries = field.get(rvConsoleView); return mLogEntries; } let mLogEntries = getLogEntries(); function createAdapter(mLogEntries) { return RecyclerView.Adapter({ onCreateViewHolder: function (parent, viewType) { // 视图创建 let view; let holder; view = ui.inflate(boxXml, parent, false); holder = JavaAdapter(RecyclerView.ViewHolder, {}, view); return holder; }, onBindViewHolder: function (holder, position) { // 数据绑定 let logEntry = mLogEntries.get(position); holder.itemView.setText(logEntry.content); }, getItemCount: function () { return mLogEntries.size(); }, }); } let newAdapter = createAdapter(mLogEntries); logListView.setAdapter(newAdapter); }); for (var i = 0; i < 1; i++) { console.log("牙叔教程"); console.log("简单易学"); } setInterval(() => {}, 1000); // 普通版和pro版唯一的区别是两个控件的id不一样, 布局是一模一样的. // logList --> log_list // inputContainer --> input_container let arr = [ "android.widget.RelativeLayout{9308131 V.E...... ......I. 0,0-0,0}", // 整个控制台的父view "android.widget.LinearLayout{73d1bee V.E...... ......ID 36,36-924,1683}", "android.widget.LinearLayout{2d85df2 V.E...... ......ID 0,0-888,120}", "android.widget.TextView{e4232c0 V.ED..... ......ID 48,0-528,120 #7f0902e7 app:id/title}", "android.widget.LinearLayout{e264bf9 V.E...... ......ID 528,0-888,120}", "android.widget.ImageView{d0a673e VFED..C.. ......ID 0,0-120,120 #7f0901dc app:id/minimize}", "android.widget.ImageView{d7099f VFED..C.. ......ID 120,0-240,120 #7f0901e9 app:id/move_or_resize}", "android.widget.ImageView{77baec VFED..C.. ......ID 240,0-360,120 #7f0900de app:id/close}", "com.stardust.autojs.core.console.ConsoleView{debec43 V.E...... ......ID 0,120-888,1647 #7f0900e9 app:id/console}", // 9 "android.widget.LinearLayout{b952908 V.E...... ......ID 0,0-888,1527}", "androidx.recyclerview.widget.RecyclerView{c76aeb5 VFED..... .F...... 0,0-648,328 #7f0901a5 app:id/logList}", "android.widget.LinearLayout{cc1b94a VFE...C.. ........ 24,328-648,448 #7f090185 app:id/inputContainer}", "android.widget.EditText{e2ca0bb VFED..CL. ......I. 0,13-360,133 #7f090184 app:id/input}", "android.widget.Button{d9b99d8 VFED..C.. ......I. 360,0-624,120 #7f0902bb app:id/submit}", "android.widget.ImageView{a10b84d G.ED..... ......I. 0,0-0,0 #7f090247 app:id/resizer}", "android.widget.ImageView{9c80250 G.ED..... ......I. 0,0-0,0 #7f0901e8 app:id/move_cursor}", ]; }, 1); });