autojs之新手引导

作者: 牙叔

使用场景:

引导新用户, 学习软件的使用方法

效果展示:

仅为演示功能, 未做美化
autojs之新手引导_第1张图片


实现步骤

  1. 等待页面布局加载完毕

    ui.guide.click(function () {
           
      log("开启新手引导");
      setTimeout(function () {
           
        新手引导();
      }, 500);
    });
    
  2. 截图

    function screenCapture(activity) {
           
      log("screenCapture");
      // 获取windows中最顶层的view
      view = activity.getWindow().getDecorView();
      view.buildDrawingCache();
    
      // 获取状态栏高度
      rect = new Rect();
      view.getWindowVisibleDisplayFrame(rect);
      statusBarHeights = rect.top;
      display = activity.getWindowManager().getDefaultDisplay();
    
      // 获取屏幕宽和高
      widths = display.getWidth();
      heights = display.getHeight();
    
      // 允许当前窗口保存缓存信息
      view.setDrawingCacheEnabled(true);
    
      // 去掉状态栏
      let bmp = Bitmap.createBitmap(view.getDrawingCache(), 0, statusBarHeights, widths, heights - statusBarHeights);
    
      // 销毁缓存信息
      view.destroyDrawingCache();
    
      return bmp;
    }
    
  3. 添加一个popWindow, 里面只有一个

      let contentView = ui.inflate(
        <vertical>
          <img id="img" layout_width="match_parent" layout_height="match_parent"></img>
        </vertical>,
        null,
        false
      );
      let mPopWindow = new PopupWindow(
        contentView,
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.WRAP_CONTENT,
        true
      );
    
  4. 画一层遮罩

    canvas.drawARGB(200, 125, 125, 125);
    
  5. 指定按钮处画边框

    paint.setStyle(Paint.Style.STROKE); //空心矩形框
    paint.setStrokeWidth(20);
    paint.setColor(colors.parseColor("#0000ff"));
    canvas.drawRect(data.left, data.top, data.right, data.bottom, paint);
    
  6. 指定按钮从图片中裁剪出来

    let clip = images.clip(img, data.left, data.top, data.right - data.left, data.bottom - data.top);
    let smallBitmap = clip.getBitmap();
    
  7. 画指定按钮

    canvas.drawBitmap(smallBitmap, data.left, data.top, paint);
    
  8. 添加文字

    paint.setTextAlign(Paint.Align.CENTER);
    paint.setTextSize(70);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(colors.parseColor("#f000ff"));
    canvas.drawText(data.introduction, data.left + parseInt((data.right - data.left) / 2), data.bottom + 100, paint);
    
  9. img控件加载图片

    imgView.attr("src", "file://" + compositeImgpath);
    

项目地址

https://gitee.com/yashujs/autojs-newbie-guide

微信公众号 AutoJsPro教程

autojs之新手引导_第2张图片

QQ群

747748653

你可能感兴趣的:(autojs,canvas,imageview,android,java)