其他分享
首页 > 其他分享> > 基于Canvas的MyMathDraw[我的数学板][底部弹窗][API V6]

基于Canvas的MyMathDraw[我的数学板][底部弹窗][API V6]

作者:互联网

目录

1. 名称

在这里插入图片描述

2. 功能描述

在这里插入图片描述

3. app实现关键技巧

4. 源代码

  4.1 java源代码

    4.1.1 MainAbilitySlice.java

package com.tdtxdcxm.mymathdraw.slice;

import com.tdtxdcxm.mymathdraw.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import parsii.eval.Expression;
import parsii.eval.Parser;
import parsii.eval.Scope;
import parsii.eval.Variable;
import parsii.tokenizer.ParseException;

import java.util.ArrayList;

public class MainAbilitySlice extends AbilitySlice {

    DirectionalLayout rootdl_stkl_ddl2,rootdl_stkl_ddl2_set;
    Button topdl_but;

    TextField bottomdl_tfd;

    Text topdl_txt,paintswitch_text,uiswitch_text;
    Switch switch_paintcolor,switch_uicolor;

    Paint bluepaint = new Paint();
    Paint purplepaint = new Paint();

    Paint paint = bluepaint;//用于绘制任务的默认画笔(蓝色)
    int origin_x,origin_y;

    boolean isgeneratexy = false;

    public void initPaint(){
        bluepaint.setColor(Color.BLUE);
        bluepaint.setStrokeWidth(8);

        purplepaint.setColor(new Color(Color.rgb(160, 32, 240)));
        purplepaint.setStrokeWidth(8);
    }

    public void initMASComponents(){
        topdl_txt = (Text) findComponentById(ResourceTable.Id_topdl_txt);
        topdl_but = (Button) findComponentById(ResourceTable.Id_topdl_but);
        bottomdl_tfd = (TextField) findComponentById(ResourceTable.Id_bottomdl_tfd);


        rootdl_stkl_ddl2 = (DirectionalLayout) findComponentById(ResourceTable.Id_rootdl_stkl_ddl2);
        rootdl_stkl_ddl2_set = (DirectionalLayout) findComponentById(ResourceTable.Id_rootdl_stkl_ddl2_set);

        paintswitch_text = (Text) findComponentById(ResourceTable.Id_paintswitch_text);
        uiswitch_text = (Text) findComponentById(ResourceTable.Id_uiswitch_text);

        switch_paintcolor = (Switch) findComponentById(ResourceTable.Id_switch_paintcolor);
        switch_uicolor = (Switch) findComponentById(ResourceTable.Id_switch_uicolor);

        bottomdl_tfd.setHint("输入函数>>>"+"\n【右上角表情】:\n1.单击—绘制"+"\n2.长按-清空");


        topdl_txt.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                bottomdl_tfd.clearFocus();
                rootdl_stkl_ddl2.setVisibility(Component.VISIBLE);
                if(topdl_but.getText().equals("

标签:Canvas,MyMathDraw,ohos,Component,API,text,import,new,public
来源: https://www.cnblogs.com/TDTX/p/16030631.html