Skip to content

Commit 23a77c8

Browse files
author
zxy
committed
提交带缓存的网络访问
1 parent 3fa3d40 commit 23a77c8

File tree

71 files changed

+8029
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+8029
-34
lines changed

AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
package="com.it114.android.oneframework.core"
44
android:versionCode="1"
55
android:versionName="1.0.0">
6-
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
6+
<uses-sdk android:minSdkVersion="8" />
77
<application/>
88
</manifest>

Sample1/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
package="com.it114.android.oneframework.sample1"
44
android:versionCode="1"
55
android:versionName="1.0">
6-
<uses-sdk android:minSdkVersion="22"/>
6+
<uses-sdk android:minSdkVersion="8"/>
77
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
8-
<activity android:name="MyActivity"
8+
<activity android:name=".eventbus.EventBusActivity"
99
android:label="@string/app_name">
1010
<intent-filter>
1111
<action android:name="android.intent.action.MAIN"/>

Sample1/project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
1212

1313
# Project target.
14+
android.library.reference.1=../../OneFramework
1415
target=android-22
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="PostThread == Default" android:id="@+id/btn_PostThread"/>
8+
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="MainThread" android:id="@+id/btn_MainThread"/>
9+
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="BackgroundThread" android:id="@+id/btn_BackgroundThread"/>
10+
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="Async" android:id="@+id/btn_Async"/>
11+
12+
</LinearLayout>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.it114.android.oneframework.sample1.eventbus;
2+
3+
import android.os.Bundle;
4+
import android.widget.Button;
5+
import android.widget.Toast;
6+
import butterknife.Bind;
7+
import butterknife.ButterKnife;
8+
import butterknife.OnClick;
9+
import com.it114.android.oneframework.core.ui.BaseActivity;
10+
import com.it114.android.oneframework.sample1.R;
11+
import de.greenrobot.event.EventBus;
12+
import de.greenrobot.event.Subscribe;
13+
14+
/**
15+
* Created by andy on 10/10/2015.
16+
*/
17+
public class EventBusActivity extends BaseActivity {
18+
19+
@Bind(R.id.btn_PostThread)
20+
Button btnPostThread;
21+
@Bind(R.id.btn_MainThread)
22+
Button btnMainThread;
23+
@Bind(R.id.btn_BackgroundThread)
24+
Button btnBackgroundThread;
25+
@Bind(R.id.btn_Async)
26+
Button btnAsync;
27+
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
setContentView(R.layout.eventbus_activity_layout);
32+
ButterKnife.bind(this);
33+
}
34+
35+
@OnClick(R.id.btn_PostThread)
36+
public void onPostThreadClick(){
37+
EventBus.getDefault().post(new PostThreadEvent("hello post thread !"));
38+
}
39+
40+
@OnClick(R.id.btn_Async)
41+
public void onAsync(){
42+
43+
}
44+
45+
@OnClick(R.id.btn_BackgroundThread)
46+
public void onBackgroundThread(){
47+
48+
}
49+
50+
@OnClick(R.id.btn_MainThread)
51+
public void onMainThread(){
52+
53+
}
54+
55+
@Subscribe
56+
public void onEvent(PostThreadEvent event){
57+
Toast.makeText(this, event.message, 1).show();
58+
}
59+
60+
61+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.it114.android.oneframework.sample1.eventbus;
2+
3+
/**
4+
* Created by andy on 10/10/2015.
5+
*/
6+
public class PostThreadEvent {
7+
8+
public final String message;
9+
public PostThreadEvent(String message) {
10+
this.message = message;
11+
}
12+
13+
14+
15+
16+
}

doc/docs.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
EventBus document
3+
https://github.com/greenrobot/EventBus/blob/master/HOWTO.md
4+
http://www.cnblogs.com/angeldevil/p/3715934.html
5+
6+
7+
8+
http://jakewharton.github.io/butterknife/
9+
http://jakewharton.github.io/butterknife/ide-idea.html

doc/todo.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
1����async�����װ
3+
A��֧��rest
4+
B��֧�ֻ���
5+
6+
7+
2�������ݿ������
8+
֧�ֽӿڷ��ʣ�֧���ļ��ϴ�������
9+
10+
11+
3�������������
12+

libs/butterknife-7.0.1.jar

54.2 KB
Binary file not shown.

libs/eventbus-3.0.0-beta1.jar

46.8 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Generated code from Butter Knife. Do not modify!
2+
package com.it114.android.oneframework.sample1.eventbus;
3+
4+
import android.view.View;
5+
import butterknife.ButterKnife.Finder;
6+
import butterknife.ButterKnife.ViewBinder;
7+
8+
public class EventBusActivity$$ViewBinder<T extends com.it114.android.oneframework.sample1.eventbus.EventBusActivity> implements ViewBinder<T> {
9+
@Override public void bind(final Finder finder, final T target, Object source) {
10+
View view;
11+
view = finder.findRequiredView(source, 2131034112, "field 'btnPostThread' and method 'onPostThreadClick'");
12+
target.btnPostThread = finder.castView(view, 2131034112, "field 'btnPostThread'");
13+
view.setOnClickListener(
14+
new butterknife.internal.DebouncingOnClickListener() {
15+
@Override public void doClick(
16+
android.view.View p0
17+
) {
18+
target.onPostThreadClick();
19+
}
20+
});
21+
view = finder.findRequiredView(source, 2131034113, "field 'btnMainThread' and method 'onMainThread'");
22+
target.btnMainThread = finder.castView(view, 2131034113, "field 'btnMainThread'");
23+
view.setOnClickListener(
24+
new butterknife.internal.DebouncingOnClickListener() {
25+
@Override public void doClick(
26+
android.view.View p0
27+
) {
28+
target.onMainThread();
29+
}
30+
});
31+
view = finder.findRequiredView(source, 2131034114, "field 'btnBackgroundThread' and method 'onBackgroundThread'");
32+
target.btnBackgroundThread = finder.castView(view, 2131034114, "field 'btnBackgroundThread'");
33+
view.setOnClickListener(
34+
new butterknife.internal.DebouncingOnClickListener() {
35+
@Override public void doClick(
36+
android.view.View p0
37+
) {
38+
target.onBackgroundThread();
39+
}
40+
});
41+
view = finder.findRequiredView(source, 2131034115, "field 'btnAsync' and method 'onAsync'");
42+
target.btnAsync = finder.castView(view, 2131034115, "field 'btnAsync'");
43+
view.setOnClickListener(
44+
new butterknife.internal.DebouncingOnClickListener() {
45+
@Override public void doClick(
46+
android.view.View p0
47+
) {
48+
target.onAsync();
49+
}
50+
});
51+
}
52+
53+
@Override public void unbind(T target) {
54+
target.btnPostThread = null;
55+
target.btnMainThread = null;
56+
target.btnBackgroundThread = null;
57+
target.btnAsync = null;
58+
}
59+
}

proguard-project.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}
21+
22+
#event bus
23+
-keepclassmembers class ** {
24+
public void onEvent*(**);
25+
}
26+
27+
# Only required if you use AsyncExecutor
28+
-keepclassmembers class * extends de.greenrobot.event.util.ThrowableFailureEvent {
29+
<init>(java.lang.Throwable);
30+
}
31+
32+
#butterknife
33+
-keep class butterknife.** { *; }
34+
-dontwarn butterknife.internal.**
35+
-keep class **$$ViewBinder { *; }
36+
37+
-keepclasseswithmembernames class * {
38+
@butterknife.* <fields>;
39+
}
40+
41+
-keepclasseswithmembernames class * {
42+
@butterknife.* <methods>;
43+
}

proguard-project.txt.bak

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

res/drawable-hdpi/empty_image.png

2.72 KB
Loading

res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="app_name">core</string>
4+
<string name="error_data_valid">服务器返回数据不合法</string>
5+
</resources>

src/com/it114/android/oneframework/core/OneApplication.java

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import android.graphics.Bitmap;
55
import android.os.Environment;
66
import com.it114.android.oneframework.core.BuildConfig;
7+
import com.it114.android.oneframework.core.data.Config;
8+
import com.it114.android.oneframework.core.data.Constants;
9+
import com.it114.android.oneframework.core.util.FileUtil;
10+
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache;
711
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
812
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
913
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
@@ -15,17 +19,24 @@
1519
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
1620

1721
import java.io.File;
22+
import java.io.IOException;
1823

1924
/**
2025
* Created by andy on 10/9/2015.
2126
*/
2227
public class OneApplication extends Application {
28+
static OneApplication INSTANCE;
2329
@Override
2430
public void onCreate() {
2531
super.onCreate();
32+
INSTANCE = this;
2633
initImageLoader();
2734
}
2835

36+
public static OneApplication getInstance(){
37+
return INSTANCE;
38+
}
39+
2940
@Override
3041
public void onTerminate() {
3142
super.onTerminate();
@@ -50,29 +61,37 @@ private void initImageLoader() {
5061
.displayer(new FadeInBitmapDisplayer(200))
5162
.build();
5263

53-
File cacheDir;
54-
if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
55-
cacheDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
56-
} else {
57-
cacheDir = getCacheDir();
64+
File cacheDir = new File(FileUtil.getCacheDir().getAbsolutePath() + "/" + Constants.IMAGE_CACHE_DIR);
65+
ImageLoaderConfiguration.Builder configBuilder = null;
66+
try {
67+
configBuilder = new ImageLoaderConfiguration.Builder(getApplicationContext())
68+
.memoryCache(new WeakMemoryCache())
69+
.diskCache(new LruDiskCache(cacheDir,new Md5FileNameGenerator(),500))
70+
.denyCacheImageMultipleSizesInMemory()
71+
.threadPoolSize(3)//线程池内加载的数量
72+
.threadPriority(Thread.NORM_PRIORITY - 2)
73+
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现
74+
.memoryCacheSize(2 * 1024 * 1024)
75+
.discCacheSize(50 * 1024 * 1024)
76+
.discCacheFileNameGenerator(new Md5FileNameGenerator())//将保存的时候的URI名称用MD5 加密
77+
.tasksProcessingOrder(QueueProcessingType.LIFO)
78+
.discCacheFileCount(100) //缓存的文件数量
79+
//.discCache(new UnlimitedDiscCache(cacheDir))
80+
.defaultDisplayImageOptions(options);
81+
} catch (IOException e) {
82+
e.printStackTrace();
5883
}
59-
ImageLoaderConfiguration.Builder configBuilder = new ImageLoaderConfiguration.Builder(getApplicationContext())
60-
.memoryCache(new WeakMemoryCache())
61-
.denyCacheImageMultipleSizesInMemory()
62-
.threadPoolSize(3)//线程池内加载的数量
63-
.threadPriority(Thread.NORM_PRIORITY - 2)
64-
.denyCacheImageMultipleSizesInMemory()
65-
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现
66-
.memoryCacheSize(2 * 1024 * 1024)
67-
.discCacheSize(50 * 1024 * 1024)
68-
.discCacheFileNameGenerator(new Md5FileNameGenerator())//将保存的时候的URI名称用MD5 加密
69-
.tasksProcessingOrder(QueueProcessingType.LIFO)
70-
.discCacheFileCount(100) //缓存的文件数量
71-
//.discCache(new UnlimitedDiscCache(cacheDir))
72-
.defaultDisplayImageOptions(options);
7384
if (BuildConfig.DEBUG) {
7485
configBuilder.writeDebugLogs();
7586
}
7687
ImageLoader.getInstance().init(configBuilder.build());
7788
}
89+
90+
public void setDebugModel(boolean debugModel){
91+
if(debugModel) {
92+
Config.showLogcat = true;
93+
} else {
94+
Config.showLogcat = false;
95+
}
96+
}
7897
}

src/com/it114/android/oneframework/core/activity/BaseActivity.java

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.it114.android.oneframework.core.data;
2+
3+
/**
4+
* Created by andy on 10/10/2015.
5+
*/
6+
public class Config {
7+
public static boolean debug = true;
8+
public static final String API_HOST_DEBUG = "";
9+
public static final String API_HOST_RELEASE = "";
10+
11+
12+
}

0 commit comments

Comments
 (0)