每日冲刺2

设计语音功能相关代码

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">
    <!--标题-->
    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        app:navigationIcon="@mipmap/icon_back"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/white">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="手动输入"
            android:textColor="@color/black"
            android:textSize="18sp" />
    </com.google.android.material.appbar.MaterialToolbar>
    <!--搜索物品布局-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="36dp"
            android:layout_marginStart="@dimen/sp_16"
            android:layout_marginTop="@dimen/dp_12"
            android:layout_marginEnd="@dimen/dp_16"
            android:layout_marginBottom="@dimen/dp_12"
            android:background="@drawable/search_et_bg"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/iv_search"
                android:layout_width="@dimen/dp_16"
                android:layout_height="@dimen/dp_16"
                android:layout_centerVertical="true"
                android:layout_marginStart="@dimen/dp_12"
                android:layout_marginEnd="@dimen/dp_8"
                app:srcCompat="@mipmap/icon_search" />

            <EditText
                android:id="@+id/et_goods"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_toStartOf="@+id/iv_clear"
                android:layout_toEndOf="@+id/iv_search"
                android:background="@null"
                android:hint="请输入物品"
                android:imeOptions="actionSearch"
                android:singleLine="true"
                android:textColor="@color/black"
                android:textColorHint="@color/hint_color"
                android:textCursorDrawable="@drawable/cursor_style"
                android:textSize="@dimen/sp_14" />

            <ImageView
                android:id="@+id/iv_clear"
                android:layout_width="@dimen/dp_36"
                android:layout_height="@dimen/dp_36"
                android:layout_alignParentEnd="true"
                android:padding="@dimen/dp_10"
                android:src="@mipmap/icon_clear"
                android:visibility="invisible" />
        </RelativeLayout>
    </LinearLayout>
    <!--列表-->
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_result"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:overScrollMode="never"
        android:scrollbars="none" />
</LinearLayout>
复制代码
复制代码
package com.llw.goodtrash.contract;

import android.annotation.SuppressLint;

import com.llw.goodtrash.api.ApiService;
import com.llw.goodtrash.model.TrashResponse;
import com.llw.mvplibrary.base.BasePresenter;
import com.llw.mvplibrary.base.BaseView;
import com.llw.mvplibrary.network.NetworkApi;
import com.llw.mvplibrary.network.observer.BaseObserver;

/**
 * 手动文字输入页面访问网络
 */
public class TextContract {

    public static class TextPresenter extends BasePresenter<TextView> {
        /**
         * 搜索物品
         *
         * @param word 物品名
         */
        @SuppressLint("CheckResult")
        public void searchGoods(String word) {
            ApiService service = NetworkApi.createService(ApiService.class);
            service.searchGoods(word).compose(NetworkApi.applySchedulers(new BaseObserver<TrashResponse>() {
                @Override
                public void onSuccess(TrashResponse groupResponse) {
                    if (getView() != null) {
                        getView().getSearchResponse(groupResponse);
                    }
                }

                @Override
                public void onFailure(Throwable e) {
                    if (getView() != null) {
                        getView().getSearchResponseFailed(e);
                    }
                }
            }));
        }
    }

    public interface TextView extends BaseView {
        /**
         * 搜索物品返回
         *
         * @param response
         */
        void getSearchResponse(TrashResponse response);

        /**
         * 搜索物品异常返回
         *
         * @param throwable
         */
        void getSearchResponseFailed(Throwable throwable);
    }
}
复制代码

今日尝试语音功能实现

posted @   摆烂达人  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示