Android 弹窗
弹出和隐藏进度条
1 | private Dialog dialog; |
单个操作的 alert
1 | public class AlertOneItem { |
多个操作的 alert (方案 1)
1 | enum OperateType { |
多个操作的 alert(方案 2)
1 | public class AlertMultiItem { |
1 | private Dialog dialog; |
1 | public class AlertOneItem { |
1 | enum OperateType { |
1 | public class AlertMultiItem { |
配置ndk路径ctrl+shift+alt+s
,ndk location
配置app下 build.gradle
1 | // 指定生成lib so文件的名称 |
修改gradle.properties文件
1 | android.userDeprecatedNdk=true |
设置native接口
1 | package com.lyloou.secretjni; |
build项目,生成Ujni.class文件
通过Ujni.class文件生成头文件
1 | javah -d jni -classpath MyProject/app/build/intermediates/classes/debug/com.lyloou.secretjni.Ujni |
编写c文件
将上一步骤生成的头文件,放在main/jni文件夹下
另外新建一个cpp文件实现业务逻辑。
获取so文件
编译运行后,在build/intermediates/ndk/debug/lib文件夹下得到一系列包含so文件的文件夹。
只需要保留so文件即可运行项目,jni文件备份起来吧。
Android NDK 运行错误:java.lang.UnsatisfiedLinkError: Couldn’t load XXX indLibrary returned null
1 | //目录结构一定要改成这个样子 |
1 | android { |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 第一步:根据流得到bitmap
// 方案1
Bitmap bitmap = Glide.with(applicationContext)
.load(url)
.asBitmap()
.into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get();
// 方案2
Bitmap bitmap = BitmapFactory.decodeStream(new URL(url).openStream());
// 压缩图片
// bitmap = Bitmap.createScaledBitmap(bitmap, 120, 120, true);
// 第二步:保存成文件
// 保存图片
File imgDir = new File(getDiskCacheDir(applicationContext), "image_caches");
if (!imgDir.exists()) {
imgDir.mkdirs();
}
File imgFile = new File(imgDir, fileName);
fileOutputStream = new FileOutputStream(imgFile);
Bitmap.CompressFormat compressFormat = Bitmap.CompressFormat.PNG;
bitmap.compress(compressFormat, 100, fileOutputStream);
fileOutputStream.flush();
1 | public static void preloadImage(Context context, AdZone adZone) { |
1 | Glide.with(getApplicationContext()) |
Design patterns implemented in Java http://java-design-patterns.com
1 | public class P66{ |
逆序记录
| Status –p59
| The TRACE method is used primarily for diagnostics;
It’s also a good tool for seeing the effects of proxies and other applications
on your requests. –p56
| The TRACE method allows clients to see how its request looks when it finally
makes it to the server. –p55
| PUT:
Because PUT allows you to change content, many web servers require you to log in
with a password before you can perform a PUT. –p55
| HEAD METHOD:
The HEAD method behaves exactly like the GET method, but the server returns
only the headers in the response. No entity body is ever returned.
Using HEAD, you can:
| The GET and HEAD methods are said to be safe, meaning that no action should
occur as a result of an HTTP request that uses either the GET or HEAD method.
–p53
| HTTP mesages can carry many kinds of digital data: –p52
| HTTP headers are classified into: –p51
| Version:
Note that version numbers are not treated as fractional numbers.
Each number in the version is treated as a separate number.
HTTP/2.22 > HTTP/2.3, because 22 > 3
| The numeric code makes error processing easy for programs, while the reason
phrase is easily understood by humans.(这样的存在总是有意义的)
| The method begins the start line of requests, telling the server what to do.
–p48
| The headders are terminated by a blank line (CRLF), marking the
end of the list of headers and the beginning of the entity body.
–p47
| messages –p46
request message:
1 | <method> <request-URL> <version> |
response message:
1 | <version> <status> <reason-phrase> |
| Both request and response messages have the same basic message structure.
(start line; headers; body) –pp45
| The Parts of a Message: –p44
| HTTP messages flow like rivers. All messages flow downstream,regardless of
whether they are request messages or response messages.(所有的消息流都downstream)
The sender of any message is upstream of the receiver.
在图3-2中,代理1是代理3请求的上流,回应的下流。 –p44
| Messages travel inbound to the origin server, and when their work is done,
they travel outbound back to the user agent. –p43
| Describe message direction: –p43
| HTTP messages are the blocks of data sent between HTTP applications (clients,
servers, and proxies). These blocks of data begin with some text meta-information
describing the message contents and meaning, followed by optional data. –p43
| The chapter 3 aim to: –p43
If HTTP is the Internet’s courier, HTTP messages are the packages it uses
to move things around. –p43
| https: The https scheme is a twin to the http scheme. The only difference is
that the https scheme uses Netscape’s Secure Sockets Layer (SSL), which provides
end-to-end encryption of HTTP connnections. Its syntax is idential to that of
HTTP, with a default port of 443. –p38
| In general, applications interpreting URLs must decode the URLs before
processing them. –p37
| 字符限制(Character Restrictions):有些字符是保留的,是有特殊意义的,
不允许直接在URL中使用。(例如:% / . # ? ; : % + @ & = { } [ ] ~ < >)–p36
| Encoding Mechanisms –p36
%7E == ~
%20 == [space]
%25 == %
%40 == -
| Shady Characters
nonprinting characters also are prohibited in URLs, even though these characters
may pass through mailers and otherwise be portable. –p35
| Expandomatic URLs –p34
two flavors:
http://www.joes-
your browserhttp://www.joes-hardware.com
)| Using this URL as a base, we can infer the missing information. –p32
| Fragments (
URLs support a frag component to identify pieces within a resource. –p30
(精确定位到文档具体位置,这个过程在 client 端进行,而不是 server 端。
the server sends the entire object and the agent applies the fragment
identifier to the resource)
| Query component: There is no requirement for the format of the query component, except that some
characters are illegal.(查询组件对格式没有要求,但必须是合法的字符) –p29
跟在 ?
后面的名值对,多个查询条件用 &
分割:?item=12731&color=blue
| Auery Strings:
Some resources, such as database services, can be asked questions or queries to
narrow down the type of resource being requested. –p29
| If an application is using a URL scheme that requires a username and password,
such as FTP, it generally will insert a default username and password if
they aren’t supplied. –p27
| Scheme names are case-insensitive –p27
(Scheme的名字不区分大小写:例如http://
和HTTP://
是等效的)
| The scheme is really the main identifier of how to access a given resource.
–p27
| Most URL schemes base their URL syntax on this nine-part general format: –p26
1 | ------------------------------------------------------------------------- |
| Urls give you and your browser all you need to find a piece of
information. They define the particular resource you want,
where it is located, and how to get it.
|
| Agents
User agents (or just agents) are client programs that make HTTP requests on the
user’s behalf. (用来发出HTTP请求的客户端程序,例如:web浏览器) –p19
| Tunnels
HTTP tunnels are often used to transport non-HTTP data over one or more HTTP
connections, without looking at the data. –p19
| Gateways
| Caches
| Proxies
A proxy sits between a client and a server.
Proxies are often used for security, acting as trusted intermediaries
through which all web traffic flows. –p18
| Protocol Versions –p16
HTTP/0.9 supports only the GET method.
1.0 was the first version of HTTP that was widely deployed.
| An HTTP transaction using telnet:
1 | [root@localhost ~]# telnet www.lyloou.com 80 |
| Telnet is commonly used for remote terminal sessions, but it can
generally connect to any TCP server, including HTTP servers.
| Establish a TCP/IP connection between the client and server:
| TCP/IP
Once a TCP connections is established, messages exchanged between the client and
server computers will never be lost, damaged, or received out of order. –p12
| HTTP messages consist of three parts: –p11
| Messages
| Status Codes
Every HTTP response message comes back with a status code. –p9
| Methods
The method tells the server what action to perform (e.g. fetch a web page,
delete a file, etc.) –p8
| Transactions
An HTTP transaction consists of: –p8
| URNs
A URNs serves as a unique name for a particular piece of content,
independent of where the resource currently resides.
URNs are still experimental and not yet widely adopted. –p7
| URLs
URLs describe the specific location of a resource on a particular server.
contains three main parts: –p7
| URIs
URIs come in two flavors: URLs and URNs.
| Media Types
MIME was originally designed to solve problems encountered in moving messages
between different electronic mail systems.
MIME worked so well for email that HTTP adopted it to describe and label its
own multimedia content. –p5
eg.
| Resources
| Because HTTP uses reliable data-transmission protocols, it guarantees that
your data will not be damaged or scrambled in transit, even when it comes from
the other side of the globe. –p3
| Throughout the book, we are careful to explain the “why” of HTTP, not just the
“how”.
| There are many books that explain how to use Web,
but this is the book that explains how the Web works.
| The Definitive Guide is in understanding how the Web works
and how to apply that knowledge to web programming and administration.
| crypto模块:提供通用的加密和哈希算法。
| 服务器案例(模块http、path、fs的运用):
1 | 'use strict' |
| pipe
1 | var fs = require("fs"); |
| stream 是node.js提供的仅在服务端可用的模块;
基于事件的、异步的方式:
1 | var fs = require("fs"); |
| 同步的写文件:fs.writeFileSync()
;
| 写文件:fs.writeFile("output.txt", data, function(x){})
,如果data是String,默认
编码是UTF-8;如果传入的是Buffer,则写入的是二进制文件;回调函数只关心成功与否。
| 同步读文件使用fs.readFileSync()
方法,不接受回调函数,函数直接返回结果。
通过try...catch
来捕获同步获取文件时的错误。
| Buffer
对象可以和String做转换:
1 | // Buffer -> String |
| fs模块
utf-8
的文件;1 | var fs = require("fs"); |
1 | fs.readFile("hello.js", console.log); |
| 在需要使用回调函数的地方,传入console.log
,可以打印出回调函数的参数信息。
| 建议始终使用module.exports
的方式,而不是省写的exports
;
| 如果要输出一个键值对象{}
,可以利用exports
这个已经存在的空对象{}
,
并继续在上面添加新的键值;
var exported = load(module.exports, module);
因为对exports重新赋值,对module.exports没有任何副作用。
如果要输出一个函数或数组,必须直接对module.exports
对象赋值;
| 实现“模块”功能的奥妙就在于JavaScript是一种函数式编程语言,它支持闭包。
| 引入的对象具体是什么,取决于引用模块输出的变量。(输出的变量可以是任意对象、函数、数组等等)
| 一个模块想要对外暴露变量(函数也是变量),可以用module.exports = variable;
;
一个模块想要引用其他模块暴露的变量,用var ref = require('module_name')
就拿到了引用模块变量;
| 使用模块的好处:
| 在Node环境中,一个.js文件就称之为一个模块(module)。
| 让node直接为所有js文件都开启严格模式:
1 | node --use_strict myFile.js |
http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000