Illustrator教程之AI开发实战11-加密功能插件的开发
白羽 2018-08-15 来源 :网络 阅读 1176 评论 0

摘要:本文将带你了解Illustrator教程之AI开发实战11-加密功能插件的开发,希望本文对大家学Illustrator有所帮助

        本文将带你了解Illustrator教程之AI开发实战11-加密功能插件的开发,希望本文对大家学Illustrator有所帮助


20.1.1 插件的实现
首先需要建立存放插件源码的文件夹:
/appinventor/components/src/com/qz/extensions
然后创建源码文件Encryption.java,其中的代码如下:
//插件的包名,通常是三段式com. + 功能描述. + extension
package com.encryption.extension;    

import android.content.Context;     
import android.util.Log;            
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

@DesignerComponent(
    //插件的版本号
version = Encryption.VERSION,  
//插件的说明文字                         
description = "功能:数据加密 开发者:QZ",     
//如果在网上有插件的说明文字,可以在此设置网址
helpUrl = "//www.baidu.com",
//设置组件的类型为插件
category = ComponentCategory.EXTENSION,    
//插件是否可见,由于目前App Inventor2只能开发和使用不可见的插件,因此这里只能设置成true
                           
nonVisible = true,    
//插件的图标,在此使用App Invento2提供的图标                                                 
    iconName = "images/extension.png") 

//设置让编译器识别到是一个可扩展控件(与前一个注解的Category不同,这一个标识是给编译器处理可扩展控件识别的),然后将其独立打包生成一个aix文件
@SimpleObject(external = true)        
public class Encryption extends AndroidNonvisibleComponent    
implements Component {                                           
    public static final int VERSION = 1;                        
    private ComponentContainer container;                        
    private Context context;                                     
    private static final String LOG_TAG = "Encryption";       
    public Encryption(ComponentContainer container) { 
         
        super(container.$form());                                
        this.container = container;                              
        context = (Context) container.$context(); 
               
        Log.d(LOG_TAG, "Encryption Created" );                 
    }
    
  //此插件对外提供的函数
    @SimpleFunction(description = "对数据进行MD5加密")
    public String makeMD5Hash(String srcStr) {
      String MD5Str;
      try {
          final MessageDigest mDigest = MessageDigest.getInstance("MD5");
          mDigest.reset();
          mDigest.update(srcStr.getBytes());
          MD5Str = bytesToHexString(mDigest.digest());
      } catch (NoSuchAlgorithmException e) {
          MD5Str = String.valueOf(srcStr.hashCode());
      }
      return MD5Str;
  }
  
  private String bytesToHexString(byte[] bytes) {
      StringBuilder sb = new StringBuilder();
      for (byte value : bytes) {
          String hex = Integer.toHexString(0xFF & value);
          if (hex.length() == 1) {
              sb.append('0');
          }
          sb.append(hex);
      }
      return sb.toString();
  }
}
20.1.2 插件的编译
在appinventor目录下执行"ant extensions"命令即可生成相应的插件:com.encryption.extension.aix,生成的文件存放路径如下:
appinventor-sources/appinventor/components/build/extensions/com.encryption.extension.aix    

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标常用软件之Illustrator!

本文由 @白羽 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程