接入框架

更新时间:2024-03-19 03:24:58下载pdf

本文介绍了涂鸦商业照明 App SDK 安卓版业务包通用配置说明。

前提条件

业务包支持的安卓 minSdkVersion 为 23,targetSdkVersion 为 33,且仅支持通过 AndroidX 构建。

配置业务包

本小节介绍配置业务包涉及的文件介绍及修改说明,及相关安卓依赖的设置。

配置文件

业务包更新时,您必须重新下载配置文件。

配置项 说明 是否必选
assets 将 Demo 中的 assets 目录下的文件,全部拷贝到应用的 assets 目录下
res
  • res/values/compat-colors.xml:业务包配置文件及默认颜色
  • res/values:资源配置文件
  • res:多语言文件可根据情况选择配置
  • res/values/compat-colors.xmlres/values 为必选
    主题色
  • res/values/colors.xml:主题资源配置
  • assets/thingTheme/ui_theme_config.json:主题色 assets 资源配置
  • 您需要同时修改 colors.xmlui_theme_config.json 两个文件的内容来实现主题色配置。
    否(此资源不再维护)

    主题色 配置文件修改说明:

    • colors.xml 参数说明:

      参数 说明 默认值
      thing_theme_color_m1 正常态主题色资源 #FFFF5A28
      thing_theme_color_m1_1 禁用态主题色资源 #33FF5A28
      thing_theme_color_m1_2 按压态主题色资源 #FFFF6B3E
      thing_theme_color_m1_alpha_5 5% 透明度的主题色资源 #0DFF5A28
      thing_theme_color_m1_alpha_10 10% 透明度的主题色资源 #1AFF5A28
      thing_theme_color_m1_alpha_15 15% 透明度的主题色资源 #26FF5A28
      thing_theme_color_m1_alpha_20 20% 透明度的主题色资源 #33FF5A28
      thing_theme_color_m1_alpha_25 25% 透明度的主题色资源 #40FF5A28
      thing_theme_color_m1_alpha_30 30% 透明度的主题色资源 #4DFF5A28
      thing_theme_color_m1_alpha_35 35% 透明度的主题色资源 #59FF5A28
      thing_theme_color_m1_alpha_40 40% 透明度的主题色资源 #66FF5A28
      thing_theme_color_m1_alpha_45 45% 透明度的主题色资源 #73FF5A28
      thing_theme_color_m1_alpha_50 50% 透明度的主题色资源 #80FF5A28
      thing_theme_color_m1_alpha_55 55% 透明度的主题色资源 #8CFF5A28
      thing_theme_color_m1_alpha_60 60% 透明度的主题色资源 #99FF5A28
      thing_theme_color_m1_alpha_65 65% 透明度的主题色资源 #A6FF5A28
      thing_theme_color_m1_alpha_70 70% 透明度的主题色资源 #B3FF5A28
      thing_theme_color_m1_alpha_75 75% 透明度的主题色资源 #BFFF5A28
      thing_theme_color_m1_alpha_80 80% 透明度的主题色资源 #CCFF5A28
      thing_theme_color_m1_alpha_85 85% 透明度的主题色资源 #D9FF5A28
      thing_theme_color_m1_alpha_90 90% 透明度的主题色资源 #E6FF5A28
      thing_theme_color_m1_alpha_95 95% 透明度的主题色资源 #F2FF5A28
    • ui_theme_config.json 修改说明:

      {
      	"color_alpha":{
      	"N1":0.9,
      	"N2":0.7,
      	"N3":0.5,
      	"N4":0.3,
      	"N5":0.7,
      	"N6":0.2,
      	"N7":0.1,
      	"N8":0.4
      	},
      	"colors":{
      	"B1":"#F8F8F8",
      	"B2":"#FFFFFF",
      	"B3":"#FFFFFF",
      	"B4":"#FFFFFF",
      	"B5":"#FFFFFF",
      	"M1":"#FF5A28", // M1表示主题色配置,默认值为#FF5A28;仅M1支持修改为其他值,其他属性字段不支持修改
      	"M2":"#FF4444",
      	"M3":"#00CC99",
      	"M4":"#1989FA",
      	"M5":"#FF5A28"
      	},
      	"corner":{
      	"alert_corner_type":"angle",
      	"button_corner_type":"angle",
      	"card_corner_type":"angle"
      	},
      	"font":{
      	"app_bold_font":"",
      	"app_font":""
      	}
      }
      

    Drawable 配置

    bg_text_bts.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
    	<item android:state_focused="true">
    		<shape android:shape="rectangle">
    			<corners android:radius="@dimen/thing_mg_2" />
    
    			<solid android:color="@color/primary_button_select_color" />
    		</shape>
    	</item>
    	<item android:state_selected="true">
    		<shape android:shape="rectangle">
    			<corners android:radius="@dimen/thing_mg_2" />
    
    			<solid android:color="@color/primary_button_select_color" />
    		</shape>
    	</item>
    	<item android:state_pressed="true">
    		<shape android:shape="rectangle">
    			<corners android:radius="@dimen/thing_mg_2" />
    
    			<solid android:color="@color/primary_button_select_color" />
    		</shape>
    	</item>
    	<item android:state_enabled="true">
    		<shape android:shape="rectangle">
    			<corners android:radius="@dimen/thing_mg_2" />
    
    			<solid android:color="@color/primary_button_bg_color" />
    		</shape>
    	</item>
    	<item android:state_enabled="false">
    		<shape>
    			<corners android:radius="@dimen/thing_mg_2" />
    
    			<solid android:color="@color/gray_99" />
    		</shape>
    	</item>
    
    </selector>
    

    主题(style)配置

    <!-- 必选配置 -->
    <!-- Base application theme. -->
    <style name="Base_BizBundle_Theme" parent="AppTheme">
    	<item name="status_font_color">@color/status_font_color</item>
    	<item name="status_bg_color">@color/status_bg_color</item>
    	<item name="navbar_font_color">@color/navbar_font_color</item>
    	<item name="navbar_bg_color">@color/navbar_bg_color</item>
    	<item name="app_bg_color">@color/app_bg_color</item>
    	<item name="fragment_bg_color">@color/app_bg_color</item>
    	<item name="list_primary_color">@color/list_primary_color</item>
    	<item name="list_sub_color">@color/list_sub_color</item>
    	<item name="list_secondary_color">@color/list_secondary_color</item>
    	<item name="list_line_color">@color/list_line_color</item>
    	<item name="list_bg_color">@color/list_bg_color</item>
    	<item name="primary_button_font_color">@color/primary_button_font_color</item>
    	<item name="primary_button_bg_color">@color/primary_button_bg_color</item>
    	<item name="secondary_button_font_color">@color/secondary_button_font_color</item>
    	<item name="secondary_button_bg_color">@color/secondary_button_bg_color</item>
    	<item name="notice_font_color">@color/notice_font_color</item>
    	<item name="notice_bg_color">@color/notice_bg_color</item>
    	<item name="bg_normal_text_bt">@drawable/bg_text_bts</item>
    	<item name="app_name">@string/app_name</item>
    	<item name="is_splash_used">false</item>
    	<item name="ap_default_ssid">@string/ap_mode_ssid</item>
    	<item name="ap_connect_description">@string/ty_ap_connect_description</item>
    	<item name="is_scan_support">@bool/is_scan_support</item>
    	<item name="is_need_blemesh_support">@bool/is_need_blemesh_support</item>
    	<item name="status_bg_color_75">@color/status_bg_color_75</item>
    	<item name="status_bg_color_90">@color/status_bg_color_90</item>
    </style>
    

    应用清单(AndroidManifest.xml)

    <!-- 必选配置 -->
    <application
    	android:supportsRtl="false"
    	android:theme="@style/Base_BizBundle_Theme"
    	tools:replace="android:theme"/>
    

    依赖源

    • 根目录的 build.gradle 文件配置如下:

      allprojects {
      	repositories {
      		maven { url "https://maven-other.tuya.com/repository/maven-commercial-releases/" }
                          google()
                          mavenCentral()
      	}
      }
      
    • app 的 build.gradle 文件配置:

      NDK 配置只支持 ARM 指令架构的 CPU 版本。

      android {
      	packagingOptions {
      	        pickFirst 'lib/*/liblog.so'
                          pickFirst 'lib/*/libc++_shared.so'
                          pickFirst 'lib/*/libyuv.so'
                          pickFirst 'lib/*/libopenh264.so'
                          pickFirst 'lib/*/libv8wrapper.so'
                          pickFirst 'lib/*/libv8android.so'
      	}
      
      	lintOptions {
      		abortOnError false
      	}
      
      	defaultConfig {
      		ndk { abiFilters "armeabi-v7a", "arm64-v8a" }
      	}
      
      	compileOptions {
      		sourceCompatibility 1.8
      		targetCompatibility 1.8
      	}
      }
      
      configurations.all {
          exclude group: 'com.thingclips.smart.rnplugin', module: 'trctrtspmediaplayermanager'
          exclude group: 'com.thingclips.smart.rnplugin', module: 'trctrtspmediamanager'
      }
      

    初始化应用

    在主线程初始化业务包通用设置:

            Fresco.initialize(this);
    
            ThingSdk.setDebugMode(true);
            ThingSdk.init(this);
            ThingSmartNetWork.mAppRNVersion = RNAPIUtil.getAPPRNVersion();
            ThingSdk.setOnNeedLoginListener(new INeedLoginListener() {
                @Override
                public void onNeedLogin(Context context) {
                  
                }
            });
    
            ThingWrapper.init(this, new RouteEventListener() {
                @Override
                public void onFaild(int errorCode, UrlBuilder urlBuilder) {
                    Log.e("router not implement", urlBuilder.target + urlBuilder.params.toString());
                }
            }, new ServiceEventListener() {
                @Override
                public void onFaild(String serviceName) {
                    Log.e("service not implement", serviceName);
                }
            });
            ThingThemeInitializer.INSTANCE.init(this);
    //        ThingOptimusSdk.init(this);
    
            //register project service,it is necessary for bizbundle
            ThingWrapper.registerService(AbsBizBundleProjectService.class, new BizBundleProjectServiceImpl());
    
            RedirectService service = MicroContext.getServiceManager().findServiceByInterface(RedirectService.class.getName());
            service.registerUrlInterceptor(new RedirectService.UrlInterceptor() {
                @Override
                public void forUrlBuilder(UrlBuilder urlBuilder, RedirectService.InterceptorCallback interceptorCallback) {
                    //Such as:
                    //Intercept the event of clicking the panel right menu and jump to the custom page with the parameters of urlBuilder
                    if (urlBuilder.target.equals("panelAction") && urlBuilder.params.getString("action").equals("gotoPanelMore")) {
                        interceptorCallback.interceptor("interceptor");
                        Log.e("interceptor", urlBuilder.params.toString());
                    } else {
                        interceptorCallback.onContinue(urlBuilder);
                    }
                }
            });
    
            //init mini app config
            GZLMiniAppInitial.init();
    

    登录或退出账号

    业务包接入后,请在登录和退出用户账号时分别调用如下方法:

    //登录
    ThingWrapper.onLogin();
    //退出
    ThingWrapper.onLogout(Context context);
    

    实现项目服务

    您可以通过继承 AbsBizBundleProjectService 抽象类,实现设置当前项目 projectId 和当前项目名称 projectName。示例代码如下:

    
    public abstract class AbsBizBundleProjectService extends MicroService {
        public abstract long getCurrentHomeId();
    
        private AbsCommonbizSpaceService mSpaceService = MicroServiceManager.getInstance().findServiceByInterface(AbsCommonbizSpaceService.class.getName());
    
        @CallSuper
        public void shiftCurrentProject(long familyId, String curName) {
            AbsRelationService relationService = MicroContext.findServiceByInterface(AbsRelationService.class.getName());
            if (relationService != null) {
                relationService.shiftCurrentRelation(familyId, curName);
            }
        }
    
        public void onEnterArea(long areaId) {
            mSpaceService.onSpaceEnter(areaId);
        }
    
        public void onLeaveArea(long areaId) {
            mSpaceService.onSpaceExit(areaId);
        }
    
    }
    
    
    public class BizBundleProjectServiceImpl extends AbsBizBundleProjectService {
        private long mHomeId;
    
        @Override
        public long getCurrentHomeId() {
            return mHomeId;
        }
    
        @Override
        public void shiftCurrentProject(long familyId, String curName) {
            super.shiftCurrentProject(familyId, curName);
            mHomeId = familyId;
        }
    }
    

    设置项目数据

    当获取项目列表后,通过服务化调用设置项目 projectIdprojectName。示例代码如下:

    AbsBizBundleProjectService service = MicroServiceManager.getInstance().findServiceByInterface(AbsBizBundleProjectService.class.getName());
    
    // 设置为当前项目的 projectId 和 projectName
    service.shiftCurrentProject(homeBean.getHomeId(), homeBean.getName());
    

    设置区域数据

    当从一个区域进入另外一个区域时,需设置区域入栈。示例代码如下:

    AbsBizBundleProjectService service = MicroServiceManager.getInstance().findServiceByInterface(AbsBizBundleProjectService.class.getName());
    
    service.onEnterArea(areaId)
    

    当从一个区域退出时,需设置区域出栈。示例代码如下:

    AbsBizBundleProjectService service = MicroServiceManager.getInstance().findServiceByInterface(AbsBizBundleProjectService.class.getName());
    
    service.onLeaveArea(areaId)