Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
android-custom-view
提交
93d7ab65
A
android-custom-view
项目概览
门心叼龙
/
android-custom-view
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
android-custom-view
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
93d7ab65
编写于
11月 26, 2019
作者:
门心叼龙
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code perfect
上级
ae55c3ec
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
1224 addition
and
1 deletion
+1224
-1
app/src/main/java/com/mxdl/customview/MainActivity.java
app/src/main/java/com/mxdl/customview/MainActivity.java
+9
-0
app/src/main/java/com/mxdl/customview/bitmap/DiskLruCache.java
...rc/main/java/com/mxdl/customview/bitmap/DiskLruCache.java
+942
-0
app/src/main/java/com/mxdl/customview/bitmap/StrictLineReader.java
...ain/java/com/mxdl/customview/bitmap/StrictLineReader.java
+195
-0
app/src/main/java/com/mxdl/customview/bitmap/Util.java
app/src/main/java/com/mxdl/customview/bitmap/Util.java
+76
-0
app/src/main/java/com/mxdl/customview/test/Test.java
app/src/main/java/com/mxdl/customview/test/Test.java
+2
-0
test.txt
test.txt
+0
-1
未找到文件。
app/src/main/java/com/mxdl/customview/MainActivity.java
浏览文件 @
93d7ab65
...
...
@@ -10,9 +10,13 @@ import android.view.MenuItem;
import
android.view.View
;
import
android.widget.Button
;
import
com.mxdl.customview.bitmap.DiskLruCache
;
import
com.mxdl.customview.test.MainTestActivity
;
import
com.mxdl.customview.thread.MyAsyncTask
;
import
java.io.File
;
import
java.io.IOException
;
/**
* Description: <MainActivity><br>
* Author: mxdl<br>
...
...
@@ -53,6 +57,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
mBtnService
.
setOnClickListener
(
this
);
mBtnAsyncTask
.
setOnClickListener
(
this
);
final
long
DISK_CACHE_SIZE
=
1024
*
1024
*
50
;
//50MB
File
diskCacheDir
=
getBaseContext
().
getCacheDir
();
if
(!
diskCacheDir
.
exists
())
{
diskCacheDir
.
mkdirs
();
}
}
...
...
app/src/main/java/com/mxdl/customview/bitmap/DiskLruCache.java
0 → 100644
浏览文件 @
93d7ab65
此差异已折叠。
点击以展开。
app/src/main/java/com/mxdl/customview/bitmap/StrictLineReader.java
0 → 100644
浏览文件 @
93d7ab65
package
com.mxdl.customview.bitmap
;
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
java.io.ByteArrayOutputStream
;
import
java.io.Closeable
;
import
java.io.EOFException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.Charset
;
/**
* Buffers input from an {@link InputStream} for reading lines.
*
* <p>This class is used for buffered reading of lines. For purposes of this class, a line ends
* with "\n" or "\r\n". End of input is reported by throwing {@code EOFException}. Unterminated
* line at end of input is invalid and will be ignored, the caller may use {@code
* hasUnterminatedLine()} to detect it after catching the {@code EOFException}.
*
* <p>This class is intended for reading input that strictly consists of lines, such as line-based
* cache entries or cache journal. Unlike the {@link java.io.BufferedReader} which in conjunction
* with {@link java.io.InputStreamReader} provides similar functionality, this class uses different
* end-of-input reporting and a more restrictive definition of a line.
*
* <p>This class supports only charsets that encode '\r' and '\n' as a single byte with value 13
* and 10, respectively, and the representation of no other character contains these values.
* We currently check in constructor that the charset is one of US-ASCII, UTF-8 and ISO-8859-1.
* The default charset is US_ASCII.
*/
public
class
StrictLineReader
implements
Closeable
{
private
static
final
byte
CR
=
(
byte
)
'\r'
;
private
static
final
byte
LF
=
(
byte
)
'\n'
;
private
final
InputStream
in
;
private
final
Charset
charset
;
/*
* Buffered data is stored in {@code buf}. As long as no exception occurs, 0 <= pos <= end
* and the data in the range [pos, end) is buffered for reading. At end of input, if there is
* an unterminated line, we set end == -1, otherwise end == pos. If the underlying
* {@code InputStream} throws an {@code IOException}, end may remain as either pos or -1.
*/
private
byte
[]
buf
;
private
int
pos
;
private
int
end
;
/**
* Constructs a new {@code LineReader} with the specified charset and the default capacity.
*
* @param in the {@code InputStream} to read data from.
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
* supported.
* @throws NullPointerException if {@code in} or {@code charset} is null.
* @throws IllegalArgumentException if the specified charset is not supported.
*/
public
StrictLineReader
(
InputStream
in
,
Charset
charset
)
{
this
(
in
,
8192
,
charset
);
}
/**
* Constructs a new {@code LineReader} with the specified capacity and charset.
*
* @param in the {@code InputStream} to read data from.
* @param capacity the capacity of the buffer.
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
* supported.
* @throws NullPointerException if {@code in} or {@code charset} is null.
* @throws IllegalArgumentException if {@code capacity} is negative or zero
* or the specified charset is not supported.
*/
public
StrictLineReader
(
InputStream
in
,
int
capacity
,
Charset
charset
)
{
if
(
in
==
null
||
charset
==
null
)
{
throw
new
NullPointerException
();
}
if
(
capacity
<
0
)
{
throw
new
IllegalArgumentException
(
"capacity <= 0"
);
}
if
(!(
charset
.
equals
(
Util
.
US_ASCII
)))
{
throw
new
IllegalArgumentException
(
"Unsupported encoding"
);
}
this
.
in
=
in
;
this
.
charset
=
charset
;
buf
=
new
byte
[
capacity
];
}
/**
* Closes the reader by closing the underlying {@code InputStream} and
* marking this reader as closed.
*
* @throws IOException for errors when closing the underlying {@code InputStream}.
*/
public
void
close
()
throws
IOException
{
synchronized
(
in
)
{
if
(
buf
!=
null
)
{
buf
=
null
;
in
.
close
();
}
}
}
/**
* Reads the next line. A line ends with {@code "\n"} or {@code "\r\n"},
* this end of line marker is not included in the result.
*
* @return the next line from the input.
* @throws IOException for underlying {@code InputStream} errors.
* @throws EOFException for the end of source stream.
*/
public
String
readLine
()
throws
IOException
{
synchronized
(
in
)
{
if
(
buf
==
null
)
{
throw
new
IOException
(
"LineReader is closed"
);
}
// Read more data if we are at the end of the buffered data.
// Though it's an error to read after an exception, we will let {@code fillBuf()}
// throw again if that happens; thus we need to handle end == -1 as well as end == pos.
if
(
pos
>=
end
)
{
fillBuf
();
}
// Try to find LF in the buffered data and return the line if successful.
for
(
int
i
=
pos
;
i
!=
end
;
++
i
)
{
if
(
buf
[
i
]
==
LF
)
{
int
lineEnd
=
(
i
!=
pos
&&
buf
[
i
-
1
]
==
CR
)
?
i
-
1
:
i
;
String
res
=
new
String
(
buf
,
pos
,
lineEnd
-
pos
,
charset
.
name
());
pos
=
i
+
1
;
return
res
;
}
}
// Let's anticipate up to 80 characters on top of those already read.
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
(
end
-
pos
+
80
)
{
@Override
public
String
toString
()
{
int
length
=
(
count
>
0
&&
buf
[
count
-
1
]
==
CR
)
?
count
-
1
:
count
;
try
{
return
new
String
(
buf
,
0
,
length
,
charset
.
name
());
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
AssertionError
(
e
);
// Since we control the charset this will never happen.
}
}
};
while
(
true
)
{
out
.
write
(
buf
,
pos
,
end
-
pos
);
// Mark unterminated line in case fillBuf throws EOFException or IOException.
end
=
-
1
;
fillBuf
();
// Try to find LF in the buffered data and return the line if successful.
for
(
int
i
=
pos
;
i
!=
end
;
++
i
)
{
if
(
buf
[
i
]
==
LF
)
{
if
(
i
!=
pos
)
{
out
.
write
(
buf
,
pos
,
i
-
pos
);
}
pos
=
i
+
1
;
return
out
.
toString
();
}
}
}
}
}
public
boolean
hasUnterminatedLine
()
{
return
end
==
-
1
;
}
/**
* Reads new input data into the buffer. Call only with pos == end or end == -1,
* depending on the desired outcome if the function throws.
*/
private
void
fillBuf
()
throws
IOException
{
int
result
=
in
.
read
(
buf
,
0
,
buf
.
length
);
if
(
result
==
-
1
)
{
throw
new
EOFException
();
}
pos
=
0
;
end
=
result
;
}
}
\ No newline at end of file
app/src/main/java/com/mxdl/customview/bitmap/Util.java
0 → 100644
浏览文件 @
93d7ab65
package
com.mxdl.customview.bitmap
;
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
java.io.Closeable
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.io.StringWriter
;
import
java.nio.charset.Charset
;
/** Junk drawer of utility methods. */
public
class
Util
{
static
final
Charset
US_ASCII
=
Charset
.
forName
(
"US-ASCII"
);
static
final
Charset
UTF_8
=
Charset
.
forName
(
"UTF-8"
);
private
Util
()
{
}
static
String
readFully
(
Reader
reader
)
throws
IOException
{
try
{
StringWriter
writer
=
new
StringWriter
();
char
[]
buffer
=
new
char
[
1024
];
int
count
;
while
((
count
=
reader
.
read
(
buffer
))
!=
-
1
)
{
writer
.
write
(
buffer
,
0
,
count
);
}
return
writer
.
toString
();
}
finally
{
reader
.
close
();
}
}
/**
* Deletes the contents of {@code dir}. Throws an IOException if any file
* could not be deleted, or if {@code dir} is not a readable directory.
*/
static
void
deleteContents
(
File
dir
)
throws
IOException
{
File
[]
files
=
dir
.
listFiles
();
if
(
files
==
null
)
{
throw
new
IOException
(
"not a readable directory: "
+
dir
);
}
for
(
File
file
:
files
)
{
if
(
file
.
isDirectory
())
{
deleteContents
(
file
);
}
if
(!
file
.
delete
())
{
throw
new
IOException
(
"failed to delete file: "
+
file
);
}
}
}
static
void
closeQuietly
(
/*Auto*/
Closeable
closeable
)
{
if
(
closeable
!=
null
)
{
try
{
closeable
.
close
();
}
catch
(
RuntimeException
rethrown
)
{
throw
rethrown
;
}
catch
(
Exception
ignored
)
{
}
}
}
}
\ No newline at end of file
app/src/main/java/com/mxdl/customview/test/Test.java
浏览文件 @
93d7ab65
...
...
@@ -17,5 +17,7 @@ public class Test {
LinearInterpolator
interpolator
=
new
LinearInterpolator
();
IntEvaluator
intEvaluator
=
new
IntEvaluator
();
PopupWindow
window
=
new
PopupWindow
();
}
}
test.txt
已删除
100644 → 0
浏览文件 @
ae55c3ec
test
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录