个人记录 | 随心所意,记录点滴
/** * 合并颜色,支持argb8888 * @param fg 前景色 * @param bg 背景色 */ public static int blendColor(int fg, int bg) { int scr = Color.red(fg); int scg = Color.green(fg); int scb = Color.blue(fg); int sa = fg >>> 24; int dcr = Color.red(bg); int dcg = Color.green(bg); int dcb = Color.blue(bg); int color_r = dcr * (0xff - sa) / 0xff + scr * sa / 0xff; int color_g = dcg * (0xff - sa) / 0xff + scg * sa / 0xff; int color_b = dcb * (0xff - sa) / 0xff + scb * sa / 0xff; return ((color_r << 16) + (color_g << 8) + color_b) | (0xff000000); } /** Calculates the constrast between two colors, using the algorithm provided by the WCAG v2. */ public static float computeContrastBetweenColors(int bg, int fg) { float bgR = Color.red(bg) / 255f; float bgG = Color.green(bg) / 255f; float bgB = Color.blue(bg) / 255f; bgR = (bgR < 0.03928f) ? bgR / 12.92f : (float) Math.pow((bgR + 0.055f) / 1.055f, 2.4f); bgG = (bgG < 0.03928f) ? bgG / 12.92f : (float) Math.pow((bgG + 0.055f) / 1.055f, 2.4f); bgB = (bgB < 0.03928f) ? bgB / 12.92f : (float) Math.pow((bgB + 0.055f) / 1.055f, 2.4f); float bgL = 0.2126f * bgR + 0.7152f * bgG + 0.0722f * bgB; float fgR = Color.red(fg) / 255f; float fgG = Color.green(fg) / 255f; float fgB = Color.blue(fg) / 255f; fgR = (fgR < 0.03928f) ? fgR / 12.92f : (float) Math.pow((fgR + 0.055f) / 1.055f, 2.4f); fgG = (fgG < 0.03928f) ? fgG / 12.92f : (float) Math.pow((fgG + 0.055f) / 1.055f, 2.4f); fgB = (fgB < 0.03928f) ? fgB / 12.92f : (float) Math.pow((fgB + 0.055f) / 1.055f, 2.4f); float fgL = 0.2126f * fgR + 0.7152f * fgG + 0.0722f * fgB; return Math.abs((fgL + 0.05f) / (bgL + 0.05f)); } //判断是否是深色 isDark = computeContrastBetweenColors(color,Color.WHITE) > 3f;
mac上遇到unable to access ‘https://github.com/bitcoin/bitcoin.git/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54 或者git无法使用时,执行下面的指令即可:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
##总览 ###代码地址 https://github.com/EOSIO/eos
###代码结构图 ###对应说明 CMakeModules 描述编译过程的文件
Docker 容器,方便编译和运行。参考docker.com
contracts 智能合约代码(重要)
docs 文档
libraries EOS编译时依赖的其他项目
plugins(重要) 各种API插件
programs 可以运行的程序
scripts 辅助编译的脚本
tests 测试代码。编译完成后测试程序是否正常运行的程序。
tools 工具类
build.sh 开始编译的脚本
其他程序图标等不做解释。为什么contracts和plugins标注重要呢?因为其他所有的东西都是辅助而已,contracts是最为核心的东西,plugins是桥梁对程序员来说也很重要,programs等只是外包装。
###编译过程 在README文档中说的已经很清楚了,按照步骤一步一步即可编译完成。 ###运行过程 编译完成后,主要的运行程序(对应在programs目录下)有eosiod、eosioc、eosio-walletd 按照README提示,执行一次eosiod生成data-dir目录,配置config.ini后重新运行即可。
####eosiod 这是EOS的主程序
####eosioc eosioc 为了方面调用eosiod所暴露出来的REST接口的工具。
####eosio-wallet eosio-wallet启动后就是一个web服务器,默认监听本地8888接口,支持用 http://127.0.0.1:8888/v1/wallet/get_public_keys 等REST方法操作EOS账户、钱包相关动作。
private void getGLESTextureLimitBelowLollipop() { int[] maxSize = new int[1]; GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0); Toast.makeText(this," " + maxSize[0],Toast.LENGTH_LONG).show(); } private void getGLESTextureLimitEqualAboveLollipop() { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] vers = new int[2]; egl.eglInitialize(dpy, vers); int[] configAttr = { EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RGB_BUFFER, EGL10.EGL_LEVEL, 0, EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_NONE }; EGLConfig[] configs = new EGLConfig[1]; int[] numConfig = new int[1]; egl.eglChooseConfig(dpy, configAttr, configs, 1, numConfig); if (numConfig[0] == 0) {// TROUBLE! No config found. } EGLConfig config = configs[0]; int[] surfAttr = { EGL10.EGL_WIDTH, 64, EGL10.EGL_HEIGHT, 64, EGL10.EGL_NONE }; EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr); final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; // missing in EGL10 int[] ctxAttrib = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL10.EGL_NONE }; EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttrib); egl.eglMakeCurrent(dpy, surf, surf, ctx); int[] maxSize = new int[1]; GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0); egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); egl.eglDestroySurface(dpy, surf); egl.eglDestroyContext(dpy, ctx); egl.eglTerminate(dpy); Toast.makeText(this," " + maxSize[0],Toast.LENGTH_LONG).show(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getGLESTextureLimitEqualAboveLollipop(); } else { getGLESTextureLimitBelowLollipop(); }
private void setImageUrl() { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(model.getImage())) .setImageDecodeOptions(Utils.getFileTypeIsGif(model.getImage()) ? null ://null表示使用原有默认decoder ImageDecodeOptions.newBuilder() .setCustomImageDecoder(new ImageDecoder() { @Override public CloseableImage decode(EncodedImage encodedImage, int length, QualityInfo qualityInfo, ImageDecodeOptions options) { Bitmap bitmap = null; if (encodedImage.getHeight() > Utils.dip2px(manager.getContext(), 150)) { int height = Utils.dip2px(manager.getContext(), 150); int width = Utils.getWidth(manager.getContext()); width = width > encodedImage.getWidth() ? encodedImage.getWidth() : width; SkiaImageRegionDecoder inDecoder = new SkiaImageRegionDecoder(); Rect region = new Rect(); region.left = (encodedImage.getWidth() - width) / 2; region.right = region.left + width; region.top = (encodedImage.getHeight() - height) / 2; region.bottom = region.top + height; try { inDecoder.init(manager.getContext(), Uri.parse("file://" + FrescoUtils.getImageFileOnDisk(Uri.parse(model.getImage())).getAbsolutePath())); bitmap = inDecoder.decodeRegion(region, 1); } catch (Exception e) { LogInfo.LogOut(e); } } if (bitmap == null) {//TODO 此处最好使用原有默认decoder bitmap = BitmapFactory.decodeStream(encodedImage.getInputStream()); } return new CloseableStaticBitmap( bitmap, SimpleBitmapReleaser.getInstance(), ImmutableQualityInfo.FULL_QUALITY, 0); } }) .build()) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setAutoPlayAnimations(Utils.getFileTypeIsGif(model.getImage())) .setOldController(image.getController()) .setControllerListener(new BaseControllerListener()) .build(); image.setController(controller); }