鸿蒙开发(Harmonyos兼容与Harmonyos适配)

布局的实现

Layout_ability_main.xml布局:

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">

    <TextField
        ohos:id="$+id:content"
        ohos:height="0vp"
        ohos:weight="1"
        ohos:width="match_parent"
        ohos:enabled="false"
        ohos:padding="20vp"
        ohos:text="0"
        ohos:text_alignment="center"
        ohos:text_size="30"/>

    <ScrollView
        ohos:height="0vp"
        ohos:weight="1.8"
        ohos:width="match_parent">

        <DirectionalLayout
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:alignment="horizontal_center"
            ohos:orientation="vertical">

            <DirectionalLayout
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:orientation="horizontal">

                <Button
                    ohos:id="$+id:reset"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="c"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:except"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="÷"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:ride"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="x"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:delete"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="←"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

            </DirectionalLayout>

            <DirectionalLayout
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:orientation="horizontal">

                <Button
                    ohos:id="$+id:seven"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="7"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:eight"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="8"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:nine"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="9"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:reduce"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="-"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

            </DirectionalLayout>

            <DirectionalLayout
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:orientation="horizontal">

                <Button
                    ohos:id="$+id:four"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="4"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:five"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="5"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:six"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="6"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:add"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="+"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

            </DirectionalLayout>

            <DirectionalLayout
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:orientation="horizontal">

                <Button
                    ohos:id="$+id:one"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="1"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:two"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="2"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:three"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button1"
                    ohos:margin="6vp"
                    ohos:text="3"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:decimal_point"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="."
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

            </DirectionalLayout>

            <DirectionalLayout
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:orientation="horizontal">


                <Button
                    ohos:id="$+id:percentage"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="%"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:zero"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button2"
                    ohos:margin="6vp"
                    ohos:text="0"
                    ohos:text_size="30vp"
                    ohos:weight="1"/>

                <Button
                    ohos:id="$+id:equal"
                    ohos:height="70vp"
                    ohos:width="0vp"
                    ohos:background_element="$graphic:background_button3"
                    ohos:margin="6vp"
                    ohos:text="="
                    ohos:text_size="30vp"
                    ohos:weight="2"/>

            </DirectionalLayout>

        </DirectionalLayout>
    </ScrollView>
</DirectionalLayout>

background_button1.xml背景样式:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:shape="rectangle">
    <solid ohos:color="#CCF1F1F1"/>
    <corners ohos:radius="20vp"/>
</shape>

background_button2.xml背景样式:

<shape
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:shape="rectangle">
    <solid ohos:color="#FFE4F2FE"/>
    <corners ohos:radius="20vp"/>
</shape>

background_button3.xml背景样式:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:shape="rectangle">
    <solid ohos:color="#FF007CFD"/>
    <corners ohos:radius="20vp"/>
</shape>

嗯,编写布局页面不难、稍微难点的是电视、车载设备、Pad、手机、手表五个端的屏幕适配。

界面编写完,发现各个端的屏幕高度还没有做适配,一开始认为Android与HarmonyOS用Java语言都可以编写,HarmonyOS也可以使用Android的相关框架,便想着如何在HarmonyOS上去使用Android的屏幕适配方案,在用了今日头条的屏幕适配方案开刀后,发现压根行不通,今日头条的屏幕适配方案用的单位是dp,这个单位在HarmonyOS上并没有,只有类似的vp,看来还是我太天真了。

Android屏幕单位有dp、in、mm、pt、px、sp,HarmonOS屏幕单位有fp、px、vp。

其中两者相同的单位是px,Android的dp与HarmonOS的vp都是为各自设备量身打造的单位,若想要搞一个两者都可以用的屏幕适配框架,也许,只能从px找突破口。今日头条的屏幕适配方案用的单位虽然是HarmonyOS所没有的dp,但其实它最终都是要拿dp来转换成px的喔~

Java代码逻辑

继承AbilitySlice的MainAbilitySlice类:

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Utils utils = Utils.getInstance();
    private TextField content;
    private String formula = "";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
        highlyAdaptive();
    }

    /**
     * 各个按钮点击事件
     * @param component
     */
    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_one:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "1");
                else formula = "1";
                break;
            case ResourceTable.Id_two:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "2");
                else formula = "2";
                break;
            case ResourceTable.Id_three:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "3");
                else formula = "3";
                break;
            case ResourceTable.Id_four:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "4");
                else formula = "4";
                break;
            case ResourceTable.Id_five:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "5");
                else formula = "5";
                break;
            case ResourceTable.Id_six:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "6");
                else formula = "6";
                break;
            case ResourceTable.Id_seven:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "7");
                else formula = "7";
                break;
            case ResourceTable.Id_eight:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "8");
                else formula = "8";
                break;
            case ResourceTable.Id_nine:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "9");
                else formula = "9";
                break;
            case ResourceTable.Id_zero:
                if (utils.isNumStart(formula)) formula = utils.isZero(formula, "0");
                else formula = "0";
                break;
            case ResourceTable.Id_reset:
                formula = "0";
                break;
            case ResourceTable.Id_except:
                if (utils.isNumEnd(formula)) formula += "÷";
                else if (!formula.substring(formula.length() - 1, formula.length()).equals("."))
                    formula = formula.substring(0, formula.length() - 1) + "÷";
                break;
            case ResourceTable.Id_ride:
                formula = utils.isNum(formula, "x");
                break;
            case ResourceTable.Id_percentage:
                formula = utils.isNum(formula, "%");
                break;
            case ResourceTable.Id_decimal_point:
                if (utils.isNumEnd(formula) && !utils.isDecimals(formula)) formula += ".";
                break;
            case ResourceTable.Id_delete:
                if (!formula.equals("") && !formula.equals("0")) {
                    formula = formula.substring(0, formula.length() - 1);
                    if (formula.equals("")) formula = "0";
                }
                break;
            case ResourceTable.Id_reduce:
                if (utils.isNumEnd(formula)) formula += "-";
                else formula = formula.substring(0, formula.length() - 1) + "-";
                break;
            case ResourceTable.Id_add:
                if (utils.isNumEnd(formula)) formula += "+";
                else formula =
                        formula.substring(0, formula.length() - 1) + "+";
                break;
            case ResourceTable.Id_equal:
                equal();
                break;
            default:
                break;
        }
        if (component.getId() != ResourceTable.Id_equal) {
            content.setText(formula);
        }
    }

    private void equal() {
        if (formula.equals("")) {
            // 如果没有输入公式
            utils.toast(this, "还没输入公式呢");
            return;
        } else if (!utils.isNumEnd(formula)) {
            // 如果公式的最后一位数非数字
            utils.toast(this, "计算器表示没见过这样的数学公式,运算不出来");
            return;
        }
        String[] split;
        if (!utils.isContains(formula, ".")) {
            // 计算整数
            if (utils.isContains(formula, "-")) {
                // 减法
                split = formula.split("-");
                if (split.length > 1)
                    result((Integer.parseInt(split[0]) + Integer.parseInt(split[1])) + "");
            } else if (utils.isContains(formula, "+")) {
                // 加法
                split = formula.split("\\+");
                if (split.length > 1)
                    result((Integer.parseInt(split[0]) + Integer.parseInt(split[1])) + "");
            } else if (utils.isContains(formula, "x")) {
                // 乘法
                split = formula.split("x");
                if (split.length > 1)
                    result((Integer.parseInt(split[0]) + Integer.parseInt(split[1])) + "");
            } else if (utils.isContains(formula, "÷")) {
                // 除法
                split = formula.split("÷");
                if (split.length > 1)
                    result((Integer.parseInt(split[0]) + Integer.parseInt(split[1])) + "");
            } else if (utils.isContains(formula, "%")) {
                // 取余
                split = formula.split("%");
                if (split.length > 1)
                    result((Integer.parseInt(split[0]) + Integer.parseInt(split[1])) + "");
            }
        } else {
            // 计算小数
            if (utils.isContains(formula, "-")) {
                // 减法
                split = formula.split("-");
                if (split.length > 1)
                    result((Double.parseDouble(split[0]) - Double.parseDouble(split[1])) + "");
            } else if (utils.isContains(formula, "+")) {
                // 加法
                split = formula.split("\\+");
                if (split.length > 1)
                    result((Double.parseDouble(split[0]) - Double.parseDouble(split[1])) + "");
            } else if (utils.isContains(formula, "x")) {
                // 乘法
                split = formula.split("x");
                if (split.length > 1)
                    result((Double.parseDouble(split[0]) - Double.parseDouble(split[1])) + "");
            } else if (utils.isContains(formula, "÷")) {
                // 除法`
                split = formula.split("÷");
                if (split.length > 1)
                    result((Double.parseDouble(split[0]) - Double.parseDouble(split[1])) + "");
            } else if (utils.isContains(formula, "%")) {
                // 取余
                split = formula.split("%");
                if (split.length > 1)
                    result((Double.parseDouble(split[0]) - Double.parseDouble(split[1])) + "");
            }
        }
    }

    private void result(String value) {
        formula = value;
        content.setText(value);
    }

    /**
     * 根据不同设备调整高度
     */
    private void highlyAdaptive() {
        if (DeviceInfo.getDeviceType().equals("phone")) {
            // 手机设备
            ComponentContainer.LayoutConfig layoutConfig = new ComponentContainer.LayoutConfig();
            layoutConfig.height = 1100;
            content.setLayoutConfig(layoutConfig);
        } else if (DeviceInfo.getDeviceType().equals("tablet")) {
            // 平板设备
            ComponentContainer.LayoutConfig layoutConfig = new ComponentContainer.LayoutConfig();
            layoutConfig.height = 1200;
            content.setLayoutConfig(layoutConfig);
        } else if (DeviceInfo.getDeviceType().equals("tv")) {
            // TV设备
            ComponentContainer.LayoutConfig layoutConfig = new ComponentContainer.LayoutConfig();
            layoutConfig.height = 160;
            content.setLayoutConfig(layoutConfig);
        } else if (DeviceInfo.getDeviceType().equals("wearable")) {
            // 可穿戴设备
            ComponentContainer.LayoutConfig layoutConfig = new ComponentContainer.LayoutConfig();
            layoutConfig.height = 150;
            content.setLayoutConfig(layoutConfig);
        } else if (DeviceInfo.getDeviceType().equals("car")) {
            // 车载设备
            ComponentContainer.LayoutConfig layoutConfig = new ComponentContainer.LayoutConfig();
            layoutConfig.height = 500;
            content.setLayoutConfig(layoutConfig);
        }
    }

    /**
     * 初始化xml布局控件
     */
    private void initView() {
        content = (TextField) findComponentById(ResourceTable.Id_content);
        ((Button) findComponentById(ResourceTable.Id_one)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_two)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_three)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_four)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_five)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_six)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_seven)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_eight)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_nine)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_zero)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_reset)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_except)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_ride)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_delete)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_reduce)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_add)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_equal)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_decimal_point)).setClickedListener(this);
        ((Button) findComponentById(ResourceTable.Id_percentage)).setClickedListener(this);
    }
}

由于在编写xml UI时屏幕适配只能做到宽度适配或高度适配,没办法在一个xml界面同时适配宽度与高度,为此写了一个highlyAdaptive方法处理xml没能完成的高度适配,方法通过DeviceInfo.getDeviceType()来得到设备的类型,根据不同的设备去修改它的高度,也算是实现了高度适配。

Utils类:

public class Utils {
    private static Utils utils = new Utils();
    private static ToastDialog toastDialog;
    private String[] symbol = new String[]{"+", "-", "x", "÷", "%"};

    public static Utils getInstance() {
        return utils;
    }

    public void toast(Context context, String text) {
        if (toastDialog == null) {
            toastDialog = new ToastDialog(context);
        }
        toastDialog.setAlignment(LayoutAlignment.CENTER);
        toastDialog.setText(text);
        toastDialog.show();
    }

    /**
     * 判断最后一位是否数字
     * @param content
     */
    public boolean isNumber(String content){
        char[] chars = content.substring(content.length() - 1, content.length()).toCharArray();
        return Character.isDigit(chars[0]);
    }

    /**
     * 判断是否是小数
     */
    public boolean isDecimals(String str) {
        if (isDecimal(str)) {
            for (String s : symbol) {
                if (isContains(str, s)) {
                    String[] split = str.split(s);
                    if (split != null){
                        if (!isDecimal(split[split.length - 1])) {
                            return false;
                        } else {
                            return true;
                        }
                    }
                }
            }
            return true;
        }
        return false;
    }

    /**
     * 判断一位数是否是小数
     */
    public boolean isDecimal(String str) {
        if (isContains(str, "."))
            return true;
        else
            return false;
    }

    /**
     * 是否包含某一个运算符
     */
    public boolean isContains(String value, String contain) {
        if (value.indexOf(contain) == -1)
            return false;
        else
            return true;
    }

    /**
     * 最后一个值是数字就加符号,不是数字则替换它
     * @param str 符号
     */
    public String isNum(String content,String str) {
        if (isNumEnd(content)) content += str;
        else content = content.substring(0, content.length() - 1) + str;
        return content;
    }

    /**
     * 第一个值是0,输入整数则替换掉
     */
    public String isZero(String content,String str) {
        if (content.equals("0")) {
            content = str;
        } else {
            content += str;
        }
        return content;
    }

    /**
     * 得到第一个值是否是数字
     */
    public boolean isNumStart(String str) {
        if (str.startsWith("+") || str.startsWith("x") || str.startsWith("÷") || str.startsWith("%") || str.equals("")) {
            return false;
        }
        return true;
    }

    /**
     * 得到最后一个值是否是数字
     */
    public boolean isNumEnd(String str) {
        char[] chars = str.substring(str.length() - 1, str.length()).toCharArray();
        if (!Character.isDigit(chars[chars.length - 1])) {
            return false;
        }
        return true;
    }
}

GIF演示实现效果

  • Phone 设备实现效果

  • Pad 设备实现效果

  • TV 设备实现效果

  • Wearable 设备实现效果

    目前所有设备中,Wearable是几个设备中最不好适配、最难适配的设备,但,想实现也并非不可能。
    如果继续适配Wearable,目前能想到Wearable屏幕适配的方法有三种:
    1、需要将背景换成一个圆,按钮都放进一个自动换行的组件。只是,这个想法不是很现实,Android的RecycleView组件也只是一行固定多少个才会换行,HarmonyOS的ListContainer组件能否实现效果还是个未知数。
    2、使用他人开源的屏幕适配框架。不过,这个很遗憾,截止至发稿,还未能了解到有相关的适配框架。
    3、另外写一个适配Wearable的布局。在onState方法执行super.setUIContent前更换专门为Wearable而写的xml,如:

@Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        // wearable设备换一个布局
        if (DeviceInfo.getDeviceType().equals("wearable")){
            super.setUIContent(Wearable布局);
        }else{
            super.setUIContent(ResourceTable.Layout_ability_main);
        }
    }

Car 实现效果

截止至发稿,Car还没有开放对应的机型,没能使用远程真机进行测试查看最终效果。这个效果图也只是点击Previewer进行查看的样式及效果。

Previewer注意事项:

1、点击Previewer查看xml,偶尔点击xml的一些样式并不会有响应,需要关闭Previewer并重新打开。

2、Previewer展示的样式不会显示ToastDialog等对话框、不会打印日志、不能点击Debug进行测试,还是使用真机测试真机测试香。

此次是我自HarmonyOS的DevEco Studio开发工具发布以来第一次开发的APP,身为一个Android开发工程师,做起HarmonyOS开发并不是很难,其中有很多东西都类似。DevEco Studio的远程真机测试与Previewer,效果杠杠的,要知道网上很多远程真机测试可都是收费制,且按使用时间收费,这一功能的出现可降低了不少开发费用。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/350738.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

AI引爆算力需求,思腾推出支持大规模深度学习训练的高性能AI服务器

近日人工智能研究公司OpenAI公布了其大型语言模型的最新版本——GPT-4&#xff0c;可10秒钟做出一个网站&#xff0c;60秒做出一个游戏&#xff0c;参加了多种基准考试测试&#xff0c;它的得分高于88%的应试者&#xff1b;随后百度CEO李彦宏宣布正式推出大语言模型“文心一言”…

zuul网关

zuul网关 zuul自定义过滤器hystrix和ribbon时间RibbonAutoConfiguration自动配置FeignAutoConfiguration自动配置RibbonEurekaAutoConfigurationSendErrorFilter过滤器EnableZuulServerHasFeatures EnableZuulProxy zuul自定义过滤器 继承ZuulFilter类&#xff0c;实现其方法f…

Java 设计者模式以及与Spring关系(五) 策略和观察者模式

目录 简介: 23设计者模式以及重点模式 策略模式&#xff08;Strategy Pattern&#xff09; 示例 spring中应用 观察者模式&#xff08;Observer&#xff09; 示例 spring中应用 简介: 本文是个系列一次会出两个设计者模式作用&#xff0c;如果有关联就三个&#xff0c;…

Objective-C方法的声明实现及调用

1.无参数的方法 1)声明 a.位置&#xff1a;在interface括弧的外面 b.语法&#xff1a; - (返回值类型)方法名称; interface Person : NSObject -(void) run; end 2)实现 a.位置&#xff1a;在implementation中实现 b.语法&#xff1a;加大括弧将方法实现的代码写在大括孤之中 …

【C++】filesystem

文章目录 1. 基本配置1.1. VS2019修改C标准1.2. filesystem的引入 2. 日常使用2.1. 认识2.2. 控制台输入路径并对路径进行基本操作 <filesystem>是C 17标准引入的标准库&#xff0c;主要用于处理文件系统的目录和文件操作&#xff0c;接下来总结该库的基本配置和日常使用…

python基础2

1.注释 每行注释大可不必&#xff0c;不是翻译代码&#xff0c;注释的位置一般在代码的上方书写用#表示这是注释 一个#只是单行注释 一般不写在后边&#xff0c;右边&#xff0c;多行注释’’’ ‘’’是一对配套的 eg:’’’333’’’ python爬虫里面复数不用&#xff0c…

纯血鸿蒙来了,企业开发者应该关注什么

2024年对于鸿蒙来说是一个里程碑&#xff0c;鸿蒙将正式对外发布 HarmonyOS NEXT 5.0&#xff0c;而此前传言的系统将不再对开发者层面兼容Android等消息将成为定论。 为什么鸿蒙能有这个底气&#xff1f;因为研究机构TechInsights发布预测报告称&#xff0c;华为HarmonyOS将在…

根据tree结构数据自动生成多层级勾选自定义tree-table

一、需求 需要根据tree嵌套结构数据渲染出 多层级带勾选的table&#xff0c;想要的对应结构table 二、思路 手撸原生table的demo&#xff0c;然后根据多层级嵌套的遍历&#xff0c;写成html拼接&#xff0c; 由于有几层的遍历逻辑和 tr只能包裹td元素&#xff0c;html拼接后…

MS7256C:L1 频段卫星导航射频前端低噪声放大器芯片

1、描述 MS7256C 是一款具有高增益、低噪声系数的低噪声放 大器&#xff08;LNA&#xff09;芯片&#xff0c;支持 L1 频段多模式全球卫星定位&#xff0c;可 以应用于 GPS、北斗二代、伽利略、Glonass 等 GNSS 导航 接收机中。芯片采用先进工艺制造&#xff0c;封装采用 1…

Hive3.1.3基础

参考B站尚硅谷 目录 什么是HiveHive架构原理 Hive安装Hive安装地址Hive安装部署安装Hive启动并使用Hive MySQL安装安装MySQL配置MySQL 配置Hive元数据存储到MySQL配置元数据到MySQL Hive服务部署hiveserver2服务metastore服务编写Hive服务启动脚本&#xff08;了解&#xff09…

【C++中STL】list链表

List链表 基本概念构造函数赋值和交换大小操作插入和删除数据存取反转和排序 基本概念 将数据进行链式存储 链表list是一种物理存储单元上非连续的存储结构&#xff0c;数据元素的逻辑顺序是通过链表中的指针链接实现的&#xff0c;链表是由一系列结点组成&#xff0c;结点的组…

linux基础学习(7):find命令

1.按照文件名搜索 find 搜索路径 选项 文件名 选项&#xff1a; -name&#xff1a;按文件名搜索 -ineme&#xff1a;不区分文件名大小写搜索 -inum&#xff1a;按inode号搜索 按文件名搜索跟按关键词搜索不一样&#xff0c;只能搜到文件名完整对应的文件 *根据文件名…

Vulnhub靶机:FunBox11

一、介绍 运行环境&#xff1a;Virtualbox 攻击机&#xff1a;kali&#xff08;10.0.2.15&#xff09; 靶机&#xff1a;FunBox11&#xff08;10.0.2.36&#xff09; 目标&#xff1a;获取靶机root权限和flag 靶机下载地址&#xff1a;https://www.vulnhub.com/entry/funb…

Java编程的利器:Pair和Triple无缝解决多值返回问题,助力编写高效代码

在实际编码中&#xff0c;经常会遇到一个方法需要返回多个值的情况&#xff0c;你编写一个方法&#xff0c;需要同时返回某个操作的结果和一些相关的附加信息。使用传统的方式&#xff0c;你可能需要创建一个包含这些信息的自定义类或者使用集合&#xff08;如 Map&#xff09;…

下拉回显问题案例大全

下拉回显问题案例大全 一、原生js案例 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>下拉框数据回…

Ubuntu18编译jdk8源码

环境 系统 ubuntu18 Linux ubuntu 5.4.0-150-generic #167~18.04.1-Ubuntu SMP Wed May 24 00:51:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux jdk源码openjdk-8u41-src-b04-14_jan_2020.zip bootJdk jdk-8u391-linux-x64.tar.gz ps -e|grep ssh sudo apt-get install ssh…

GitBook可以搭建知识库吗?有无其他更好更方便的?

在一个现代化的企业中&#xff0c;知识是一项宝贵的资产。拥有一个完善的企业知识库&#xff0c;不仅可以加速员工的学习和成长&#xff0c;还能提高工作效率和团队协作能力。然而&#xff0c;随着企业不断发展和扩大规模&#xff0c;知识库的构建和管理变得更加复杂和耗时。 |…

steam搬砖项目真的假的?怎么赚钱?到底能不能做

steam搬砖是真的还是假的&#xff1f;不管能不能做到&#xff0c;你一定因为这个问题找到了我&#xff0c;看了这篇文章。我已经练习蒸砖项目3年多了。我可以负责任地说&#xff0c;相比其他互联网项目&#xff0c;蒸汽砖项目绝对是门槛最低、最稳定、期限最长、变现最快的一个…

2982. 找出出现至少三次的最长特殊子字符串 II

字典树思路 用字典树搞一下就好了&#xff0c;比如aaaaa &#xff1a; a存5次 aa 4次以此类推&#xff5e; 字典树板子复习&#xff1a;P8306 【模板】字典树 这里这个清空方式 很好 因为很多时候memset T #include<iostream> #include<cstring> using namesp…

如何训练和导出模型

介绍如何通过DI-engine使用DQN算法训练强化学习模型 一、什么是DQN算法 DQN算法&#xff0c;全称为Deep Q-Network算法&#xff0c;是一种结合了Q学习&#xff08;一种价值基础的强化学习算法&#xff09;和深度学习的算法。该算法是由DeepMind团队在2013年提出的&#xff0c;…
最新文章