/**
* Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
*
* 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.
*/
package com.cysion.ktbox.utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author Michael Yang(www.yangfuhai.com) update at 2013.08.07
*/
public class ACache {
public static final int TIME_HOUR = 60 * 60;
public static final int TIME_DAY = TIME_HOUR * 24;
private static final int MAX_SIZE = 1000 * 1000 * 50; // 50 mb
private static final int MAX_COUNT = Integer.MAX_VALUE; // 不限制存放数据的数量
private static Map<String, ACache> mInstanceMap = new HashMap<String, ACache>();
private ACacheManager mCache;
public static ACache get(Context ctx) {
return get(ctx, "ACache");
}
public static ACache get(Context ctx, String cacheName) {
File f = new File(ctx.getCacheDir(), cacheName);
return get(f, MAX_SIZE, MAX_COUNT);
}
public static ACache get(File cacheDir) {
return get(cacheDir, MAX_SIZE, MAX_COUNT);
}
public static ACache get(Context ctx, long max_zise, int max_count) {
File f = new File(ctx.getCacheDir(), "ACache");
return get(f, max_zise, max_count);
}
public static ACache get(File cacheDir, long max_zise, int max_count) {
ACache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
if (manager == null) {
manager = new ACache(cacheDir, max_zise, max_count);
mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
}
return manager;
}
private static String myPid() {
return "_" + android.os.Process.myPid();
}
private ACache(File cacheDir, long max_size, int max_count) {
if (!cacheDir.exists() && !cacheDir.mkdirs()) {
throw new RuntimeException("can't make dirs in "
+ cacheDir.getAbsolutePath());
}
mCache = new ACacheManager(cacheDir, max_size, max_count);
}
// =======================================
// ============ String数据 读写 ==============
// =======================================
/**
* 保存 String数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的String数据
*/
public void put(String key, String value) {
File file = mCache.newFile(key);
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(file), 1024);
out.write(value);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
}
/**
* 保存 String数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的String数据
* @param saveTime
* 保存的时间,单位:秒
*/
public void put(String key, String value, int saveTime) {
put(key, Utils.newStringWithDateInfo(saveTime, value));
}
/**
* 读取 String数据
*
* @param key
* @return String 数据
*/
public String getAsString(String key) {
File file = mCache.get(key);
if (!file.exists())
return null;
boolean removeFile = false;
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
String readString = "";
String currentLine;
while ((currentLine = in.readLine()) != null) {
readString += currentLine;
}
if (!Utils.isDue(readString)) {
return Utils.clearDateInfo(readString);
} else {
removeFile = true;
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (removeFile)
remove(key);
}
}
// =======================================
// ============= JSONObject 数据 读写 ==============
// =======================================
/**
* 保存 JSONObject数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的JSON数据
*/
public void put(String key, JSONObject value) {
put(key, value.toString());
}
/**
* 保存 JSONObject数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的JSONObject数据
* @param saveTime
* 保存的时间,单位:秒
*/
public void put(String key, JSONObject value, int saveTime) {
put(key, value.toString(), saveTime);
}
/**
* 读取JSONObject数据
*
* @param key
* @return JSONObject数据
*/
public JSONObject getAsJSONObject(String key) {
String JSONString = getAsString(key);
try {
JSONObject obj = new JSONObject(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============ JSONArray 数据 读写 =============
// =======================================
/**
* 保存 JSONArray数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的JSONArray数据
*/
public void put(String key, JSONArray value) {
put(key, value.toString());
}
/**
* 保存 JSONArray数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的JSONArray数据
* @param saveTime
* 保存的时间,单位:秒
*/
public void put(String key, JSONArray value, int saveTime) {
put(key, value.toString(), saveTime);
}
/**
* 读取JSONArray数据
*
* @param key
* @return JSONArray数据
*/
public JSONArray getAsJSONArray(String key) {
String JSONString = getAsString(key);
try {
JSONArray obj = new JSONArray(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============== byte 数据 读写 =============
// =======================================
/**
* 保存 byte数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的数据
*/
public void put(String key, byte[] value) {
File file = mCache.newFile(key);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(value);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
}
/**
* 保存 byte数据 到 缓存中
*
* @param key
* 保存的key
* @param value
* 保存的数据
* @param saveTime
* 保存的时间,单位:秒
*/
public void put(String key, byte[] value, int saveTime) {
put(key, Utils.newByteArrayWithDateInfo(saveTime, value));
}
/**
* 获取 byte 数据
*
* @param key
* @return byte 数据
*/
public byte[] getAsBinary(String key) {
RandomAccessFile RAFile = null;
boolean removeFile = false;
try {
File fi
没有合适的资源?快使用搜索试试~ 我知道了~
Kotlin实现组件化的app项目代码.zip
共217个文件
kt:89个
xml:63个
png:36个
需积分: 5 0 下载量 73 浏览量
2024-07-19
15:53:41
上传
评论
收藏 483KB ZIP 举报
温馨提示
Kotlin实现组件化的app项目代码.zip Kotlin实现组件化的app项目代码.zip
资源推荐
资源详情
资源评论
收起资源包目录
Kotlin实现组件化的app项目代码.zip (217个子文件)
gradlew.bat 2KB
.gitignore 183B
.gitignore 7B
.gitignore 7B
.gitignore 7B
.gitignore 7B
.gitignore 7B
.gitignore 7B
config.gradle 2KB
build.gradle 1KB
build.gradle 1KB
build.gradle 1009B
build.gradle 992B
build.gradle 952B
build.gradle 924B
build.gradle 908B
settings.gradle 73B
gradlew 5KB
gradle-wrapper.jar 53KB
ACache.java 20KB
NewsInfoEntity.java 1KB
SquareFragment.kt 8KB
BlogDetailActivity.kt 7KB
BlogAdapter.kt 5KB
UserBlogActivity.kt 5KB
BlogDetailPresenter.kt 5KB
BlogEditorActivity.kt 4KB
UserApi.kt 4KB
CollectActivitiy.kt 4KB
BaseCaller.kt 3KB
TopBar.kt 3KB
UserFragment.kt 3KB
PeopleInfoActivity.kt 3KB
Alert.kt 3KB
BaseFragment.kt 3KB
UserBlogPresenter.kt 3KB
SquarePresenter.kt 3KB
MusicChannelFragment.kt 3KB
NewsFragment.kt 3KB
UserDetailActivity.kt 2KB
ChannelDetailActivity.kt 2KB
RegisterActivity.kt 2KB
MainActivity.kt 2KB
ErrorHandler.kt 2KB
LoginActivity.kt 2KB
abbr.kt 2KB
BaseFragmentAdapter.kt 2KB
HomeTopPageAdapter.kt 2KB
NewsDetailActivity.kt 2KB
NewsAdapter.kt 2KB
RoundTransform.kt 2KB
BlogEditorPresenter.kt 2KB
CollectPresenter.kt 1KB
MyToast.kt 1KB
CommentAdapter.kt 1KB
MyApplication.kt 1KB
SongAdapter.kt 1KB
BaseActivity.kt 1KB
BlogHelper.kt 1KB
MusicChnAdapter.kt 1KB
ListVals.kt 1KB
BaseClient.kt 1KB
ActivityApiIml.kt 1KB
BaseViewHolder.kt 1KB
UserCache.kt 1018B
BaseAdapter.kt 993B
BaseResp.kt 977B
BaseResponse.kt 942B
BasePresenter.kt 933B
SongPresenter.kt 913B
LoginPresenter.kt 905B
BlogView.kt 881B
News.kt 874B
NewsPresenter.kt 866B
ChnPresenter.kt 829B
NoSlideViewPager.kt 684B
BaseEvent.kt 637B
ChnsApi.kt 624B
SplashActivity.kt 609B
MediaApplication.kt 591B
Box.kt 587B
MediaUrls.kt 551B
FragmentApiIml.kt 529B
Song.kt 517B
BlogEntity.kt 487B
UserUrls.kt 450B
Multi.kt 443B
NewsApi.kt 417B
UserApplication.kt 399B
Resolver.kt 375B
Keys.kt 323B
ChnView.kt 314B
Events.kt 309B
CollectEntity.kt 305B
OnTypeClickListener.kt 301B
Music.kt 295B
CommentEntity.kt 284B
DetailUserEntity.kt 282B
IView.kt 282B
UserEntity.kt 272B
共 217 条
- 1
- 2
- 3
资源评论
yava_free
- 粉丝: 3646
- 资源: 1458
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功