- 博客(79)
- 收藏
- 关注
原创 Java之动态代理--Proxy.newProxyInstance
今天在项目中见到这个动态代理的实现,很是有趣,所以学习记录一下。动态代理,就是在运行的时候,动态的生成对某个/某些接口的新的实现类,通过在其中组合进我们想要代理的类的实例,就能够实现代理的功能。Proxy.newProxyInstance的操作,针对的是接口(Interface)而不是类(class),这也符合我们面向接口编程的编程思想。在动态代理中,我们主要会面对两个方法:一个是In...
2019-08-07 00:59:54 1459
原创 Android之EventBus
之前实习的时候就接触过这个框架,近来在弄模块化组件化的事情,感觉EventBus这个框架对于消除模块间依赖还是很有帮助的,顺便来整理一下。大概的内容分为以下几个部分:EventBus简介 订阅者的注册/解注册源码分析 事件的分发流程源码分析EventBus简介EventBus是设计模式中观察者(订阅者)模式的一种实现,为消除组件之间的耦合,实现组件之间的通信提供了一种很好的解决方...
2019-08-03 23:38:51 299
原创 Android之Layout总结
之前自己在用Layout的时候用的最多的就是LinearLayout和RelativeLayout了,对其他的其实也只是一知半解。近来也是接触到了更多的Layout在实际中的用途,也算是有了更多的认识。我现在接触到的比较多的Layout分为几种:LinearLayout,RelativeLayout,FrameLayout,ConstraintLayout。最后再讲一下自己去自定义layout...
2018-07-25 22:35:38 603
原创 Android之自定义view
通常来说自定义view可以分为两种方法,一种是继承自某个已有控件,如TextView,Button等,还有一种办法就是通过继承View来自绘控件。这里主要讲一下第二种办法。view的绘制过程主要分为三个步骤:measure,layout和draw。在自定义view的过程中,一般需要对measure和draw过程进行重写,即重写onMeasure和onDraw方法。 onMeasure(...
2018-07-25 17:00:24 237
原创 Android之ListView学习笔记--ListView基本使用
ListView算是我们平时经常使用到的一个工具了(当然现在有RecyclerView作为代替),之前一篇讲到ListView中的RecycleBin回收机制,这一篇先来大致讲一下ListView里面的一些用法吧。ListView布局在布局里面设置下ListView就可以了。对于ListView而言,里面的子view的布局只有一种,就是垂直布局。而在RecyclerView中对此进行了改进...
2018-05-29 22:50:02 479
原创 Android之ListView学习笔记--layout以及view的复用
ListView的一个很需要处理的,且很重要的点,就是如果处理数据的显示操作。一般在一个listView中会有很多数据,如果每个数据对应的view都预先缓存,那估计内存会爆了...所以ListView中采用的是对view进行复用的操作。因为每次展示的只有几个数据,也就是说只会用到几个view,所以ListView的做法就是将view进行复用,每当有新的数据进入屏幕也会伴随着旧的数据移出屏幕,所以只...
2018-05-26 17:21:23 1350 1
原创 Android之Fresco框架(五)--Hierarchy
之前说到Hierarchy在Fresco框架中相当于一个MODEL的作用,我们利用Hierarchy可以设置背景图片,加载时图标,占位图,对加载成功的图片进行处理等等。在Fresco中对图片都会存储为drawable对象,这也是方便我们对图片进行处理。Hierarchy中实质上是存储了这样的一组图片,以及这组图片的相关处理操作。首先先看一下在哪会调用到Hierarchy吧。一般当我们成功下载完一张...
2018-04-25 15:55:12 405
原创 Android之Fresco框架(四)--ImagePipeline的调用和使用
之前大致把ImagePipeline的配置和底层实现都讲了一下,这一篇来重点讲一下我们在发送图片请求的时候是怎么把请求传给ImagePipeline的,以及我们如何自己直接对ImagePipeline实例进行请求,内存管理等操作。SimpleDraweeView中ImagePipeline的调用在第一篇的时候,我们当时只需要对SimpleDraweeView进行setImageURI()方法,se...
2018-04-22 15:09:21 3038
原创 Android之Fresco框架(三)--ImagePipeline的Producer
上一篇主要是讲到了ImagePipelineFactory和ImagePipelineConfig里面的基本内容和配置。这篇来介绍一下ImagePipeline里面很重要的一个部分:Producer责任链模式与Pipeline引用《Java与模式》里面对责任链(Chain of Responsibility)模式的介绍:责任链模式是一种对象的行为模式。在责任链模式里,很多对象由每一个对象对其下家的...
2018-04-18 23:00:42 582
原创 Android之Fresco框架(二)--ImagePipeline基本内容和配置
先附上官网的介绍:Image pipeline 负责完成加载图像,变成Android设备可呈现的形式所要做的每个事情。大致流程如下:检查内存缓存,如有,返回后台线程开始后续工作检查是否在未解码内存缓存中。如有,解码,变换,返回,然后缓存到内存缓存中。检查是否在磁盘缓存中,如果有,变换,返回。缓存到未解码缓存和内存缓存中。从网络或者本地加载。加载完成后,解码,变换,返回。存到各个缓存中。从上面的讲述...
2018-04-15 12:00:22 2782 1
原创 android之Fresco框架(一)--Fresco基本使用
当下最常用的图片加载框架是:Gilde,Fresco,Picasso。Fresco是Facebook提供的开源图片加载库,它能够从网络,本地存储和Android资源文件中加载图片,且具有三级缓存设计(2级内存,1级文件)。Fresco中实现了各种加载过程以及加载后的图片绘制,整体都很强大。所以准备来好好学学这个框架啦。Frescp框架的设计主要采用的是MVC模式。DraweeView实现了View...
2018-04-08 12:42:13 12970
原创 Android之OkHttp框架(三)--Interceptor
之前第二部分的时候留下一块东西没有解决,就是Interceptor部分,这两天大概看了一下,做一下大致的整理吧。OkHttp框架里面对应用层相关的协议封装的真的是很好,以至于我看着看着发现看到什么代理啊路由啊TLS信息啊什么的,感觉这些实在是深入不下去了。如果以后真的要深入用到OkHttp且需要关系到这些的时候再来看好了。Interceptor中文解释是拦截器,它所实现的功能,就是对request...
2018-04-06 21:32:55 907
原创 Android之OkHttp框架(二)-- Dispatcher和RealCall
个人感觉,Dispatcher和RealCall算是OkHttp中两个很重要且比较好理解的部分了。RealCall继承于Call,主要是用于执行我们的请求,当我们调用client.newCall(request)的时候就会生成一个RealCall实例,我们用它进行同步或异步请求。Dispatcher中主要是对我们的所有请求进行管理,方便我们执行一些类似于cancelAll()这种取消所有请求的操作...
2018-04-03 21:49:44 506
原创 Android之OkHttp框架(一)--基本用法
第一次写这种技术类文章,感觉有点神奇。先写下自己现在的一些理解,然后有什么需要改进的以后再来修改。OkHttp依赖首先在使用OkHttp之前,需要app/build.gradle中添加OkHttp库的依赖。compile 'com.squareup.okhttp3:okhttp:3.4.1'通过其会自动下载两个库,一个是OkHttp库,一个是Okio库,后者是前者的通信基础。OkHttpClien...
2018-04-02 21:40:13 327
原创 (java)leetcode-89:Gray Code
Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the s
2017-08-30 21:04:36 268
原创 (java)leetcode-88:Merge Sorted Array
Merge Sorted ArrayGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to
2017-08-16 22:22:01 182
原创 (java)leetcode-86:Partition List
Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the
2017-08-16 21:57:40 249
原创 (java)leetcode-84:Largest Rectangle in Histogram
Largest Rectangle in HistogramGiven n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Abov
2017-08-15 21:34:45 290
原创 (java)leetcode-80:Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array IIFollow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function s
2017-08-03 11:12:27 286
原创 (java)leetcode-79:Word Search
Word SearchGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally
2017-07-26 22:36:30 243
原创 (java)leetcode-78:Subsets
SubsetsGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3],
2017-07-26 21:59:17 238
原创 (java)leetcode77:Combinations
CombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,
2017-07-26 21:23:10 253
原创 (java)leetcode-75:Sort Colors
Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use
2017-07-24 22:30:00 205
原创 (java)leetcode74:Search a 2D Matrix
Search a 2D MatrixWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The fir
2017-07-24 21:18:21 350
原创 (java)leetcode-73:Set Matrix Zeroes
Set Matrix ZeroesGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward s
2017-07-23 21:08:08 209
原创 (java)leetcode-70:Climbing Stairs
Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n
2017-07-23 20:02:09 208
原创 (java)leetcode-69:Sqrt(x)
Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.解题思路:这道题我的思路就是二分法查找结果了,这个比较简单就不多说。public class Solution { public int mySqrt(int x) { long longx = x
2017-07-23 19:42:42 263
原创 (java)leetcode-68:Text Justification
Text JustificationGiven an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a g
2017-07-23 19:04:12 282
原创 (java)leetcode-67:Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".解题思路:这道题就是两个二进制数相加,记得加上进位的值就好了。public class Solution {
2017-07-23 11:34:51 213
原创 (java)leetcode-66:Plus One
Plus OneGiven a non-negative integer represented as anon-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.
2017-07-23 10:52:37 216
原创 (java)leetcode-64:Minimum Path Sum
Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move eithe
2017-07-23 10:29:24 173
原创 (java)leetcode-63:Unique Paths II
Unique Paths IIFollow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respe
2017-07-20 22:14:19 171
原创 (java)leetcode-62:Unique Paths
Unique PathsA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying
2017-07-20 21:51:25 162
原创 (java)leetcode-61:Rotate List
Rotate ListGiven a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.解题思路:这个题我觉得要分成两种
2017-07-20 21:15:14 172
原创 (java)leetcode-60:Permutation Sequence
Permutation SequenceThe set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"1
2017-07-19 22:29:30 207
原创 (java)leetcode-54:Spiral Matrix
Spiral MatrixGiven a matrix of m x n elements (m rows,n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ],
2017-07-12 21:48:59 161
原创 (java)leetcode-55:Jump Game
Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.
2017-07-11 22:32:51 177
原创 (java)leetcode-53:Maximum Subarray
Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous
2017-07-10 22:03:53 158
原创 (java)leetcode-51:N-Queens
N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens
2017-07-08 13:20:09 228
原创 (java)leetcode-50:Pow(x, n)
Pow(x, n) Implement pow(x, n).解题思路:一开始的想法就是简单的一个一个乘...果断TLE了。后面想了以下,应该得用递归的方式,每次都是平方这样来乘,计算复杂度也会降到log2(n)。然后又有一个问题就是n取 -2^32次方的时候,不能直接用n = -n。所以我用一个index来存储n的符号,这样在下一次递归,n = n/2的时候乘以index就
2017-07-08 11:21:52 178
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人