Skip to content

Commit

Permalink
1 注解内部调整
Browse files Browse the repository at this point in the history
2 图片下载调整
3 下载离线缓存(简单缓存 自己修改)
4 增加了一个实例项目demo
  • Loading branch information
gdpancheng committed Jun 13, 2014
1 parent 87da0cf commit 86a7939
Show file tree
Hide file tree
Showing 25 changed files with 812 additions and 588 deletions.
4 changes: 4 additions & 0 deletions lint.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="InlinedApi" severity="error" />
</lint>
16 changes: 1 addition & 15 deletions src/com/android/pc/ioc/a/demo/FifthActivity.java
@@ -1,23 +1,9 @@
package com.android.pc.ioc.a.demo;

import java.util.ArrayList;
import com.wash.activity.R;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.pc.ioc.a.demo.ImageListAdapter.ViewHolder;
import com.android.pc.ioc.inject.InjectBinder;
import com.android.pc.ioc.inject.InjectView;
import com.android.pc.ioc.view.listener.OnClick;
import com.android.pc.util.Handler_Inject;
import com.wash.activity.R;


/**
Expand Down
3 changes: 3 additions & 0 deletions src/com/android/pc/ioc/a/demo/MainActivity.java
Expand Up @@ -40,6 +40,9 @@ public class MainActivity extends BaseActivity {
String action_settings;
@InjectResource
Drawable ic_launcher;



// --------------------------------------------------------------------------------------
// 第二种写法(内部类 全局定义点击事件)
@InjectAll(@InjectBinder(method = "click", listeners = { OnClick.class }))
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/pc/ioc/a/demo/MeApplication.java
Expand Up @@ -24,7 +24,7 @@ public void onCreate() {
ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams(this, "images");
cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of app memory
ImageLoadManager.instance().addImageCache(cacheParams);
// ImageLoadManager.instance().setCoding(coding);
ImageLoadManager.instance().setCoding(coding);
}

/**
Expand Down
9 changes: 2 additions & 7 deletions src/com/android/pc/ioc/a/demo/SecondFragment.java
Expand Up @@ -38,9 +38,6 @@ public class SecondFragment extends BaseFragment {

@InjectBefore
void test() {
// @InjectView(isasy=true)表示这个listview里面有网络图片下载,并且需要实现滑动停止才加载的功能
// @InjectView(isasy=true)框架会给listview自动注入OnScrollListener,如果你自己也要滚动监听
// 那么请在此配置,如下
System.out.println("before");
}

Expand All @@ -52,14 +49,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
Handler_Inject.injectFragment(this, rootView);
return rootView;
}

@InjectInit
private void init() {

// The ImageFetcher takes care of loading images into our ImageView children asynchronously
mImageFetcher = new ImageDownloader(getActivity(),300);
mImageFetcher.setLoadingImage(R.drawable.ic_launcher);

for (int i = 0; i < 1000; i++) {
image.add("http://bcs.duapp.com/question-image/201212310556374291.jpg?b=a" + i);
}
Expand All @@ -83,7 +79,7 @@ public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleI
}
});
}

@InjectMethod(@InjectListener(ids = { R.id.next }, listeners = { OnClick.class }))
private void click(View v) {
EventBus eventBus = EventBus.getDefault();
Expand All @@ -97,6 +93,5 @@ private void call(int type) {
PullToRefreshManager.getInstance().onFooterRefreshComplete();
//完成 刷新
PullToRefreshManager.getInstance().onHeaderRefreshComplete();

}
}
13 changes: 10 additions & 3 deletions src/com/android/pc/ioc/a/demo/ThirdFragment.java
@@ -1,6 +1,7 @@
package com.android.pc.ioc.a.demo;

import android.app.ProgressDialog;
import java.util.LinkedHashMap;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -53,11 +54,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
*/
@InjectInit
private void init() {
FastHttpHander.ajaxGet("http://211.152.52.1119:8080/app/api.php?act=category", this);

FastHttpHander.ajaxGet("http://211.152.52.119:8080/app/api.php?act=category", this);

InternetConfig config = new InternetConfig();
//是否保存数据 默认不保存 当没网络的时候 获取数据的时候 然后就会从之前存储的离线拿出数据
config.setSave(true);
config.setKey(1);
FastHttpHander.ajaxGet("http://211.152.52.119:8080/app/api.php?act=category", config, this);
LinkedHashMap<String, String> paHashMap = new LinkedHashMap<String, String>();
paHashMap.put("test", "haha");
FastHttpHander.ajaxGet("http://211.152.52.119:8080/app/api.php?act=category",paHashMap, config, this);

InternetConfig config2 = new InternetConfig();
config2.setKey(2);
Expand Down Expand Up @@ -87,6 +93,7 @@ private void result(ResponseEntity r) {

@InjectHttpOk(1)
private void resultOk(ResponseEntity r) {
System.out.println(r);
v.result.append("我是resultOk 当前key为:" + r.getKey() + "回调了\n");
v.result.setVisibility(View.VISIBLE);
v.progress.setVisibility(View.GONE);
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/pc/ioc/a/demo/ViewManager.java
Expand Up @@ -31,6 +31,6 @@ public View getView() {
}

private void click(){
Toast.makeText(MeApplication.app, "这个注解 不是在acitivity中哦", Toast.LENGTH_SHORT).show();
Toast.makeText(MeApplication.app, "这个注解 不是在acitivity中", Toast.LENGTH_SHORT).show();
}
}
1 change: 0 additions & 1 deletion src/com/android/pc/ioc/app/Ioc.java
Expand Up @@ -9,7 +9,6 @@

import android.app.Activity;
import android.app.Application;
import android.util.Log;
import android.view.View;

import com.android.pc.ioc.core.kernel.KernelObject;
Expand Down
4 changes: 2 additions & 2 deletions src/com/android/pc/ioc/image/ImageCache.java
Expand Up @@ -231,7 +231,7 @@ public BitmapDrawable getBitmapFromMemCache(String data) {
* Unique identifier for which item to get
* @return The bitmap if found in cache, null otherwise
*/
public Bitmap getBitmapFromDiskCache(String data, int w, int h) {
public Bitmap getBitmapFromDiskCache(String data, int w, int h,ImageWorker imWorker) {
final String key = hashKeyForDisk(data);

synchronized (mDiskCacheLock) {
Expand All @@ -244,7 +244,7 @@ public Bitmap getBitmapFromDiskCache(String data, int w, int h) {
File file = getFromFileCache(key);
Bitmap bitmap = null;
if (file != null && file.exists()) {
bitmap = ImageResizer.decodeSampledBitmapFromFile(file.getPath(), w, h, this);
bitmap = imWorker.decodeSampledBitmapFromFile(data,file.getPath(), w, h, this);
}
return bitmap;
}
Expand Down
24 changes: 7 additions & 17 deletions src/com/android/pc/ioc/image/ImageDownloader.java
Expand Up @@ -10,19 +10,17 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.widget.ImageView;
import android.widget.Toast;

import com.android.pc.ioc.app.Ioc;
import com.android.pc.util.Handler_Network;
import com.android.pc.util.Handler_System;

/**
* 图片下载类 可以设置图片高度宽度
*/
public class ImageDownloader extends ImageResizer {
public class ImageDownloader extends ImageWorker {

/**
* 限定高度宽度的
Expand Down Expand Up @@ -70,12 +68,9 @@ private void init(Context context) {
* @param context
*/
private void checkConnection(Context context) {
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
Toast.makeText(context, "无法连接到网络", Toast.LENGTH_LONG).show();
if (!Handler_Network.isNetworkAvailable(context)) {
Ioc.getIoc().getLogger().e("网络连接失败");
}
}
}

/**
Expand All @@ -93,20 +88,15 @@ private Bitmap processBitmap(String data,ImageView imageView) {
if (data.startsWith("http")) {
final String key = ImageCache.hashKeyForDisk(data);
file = ImageCache.getFromFileCache(key);
start(imageView);
start(imageView,lister);
downloadUrlToStream(data, file,imageView);
}else {
file = new File(data);
}

Bitmap bitmap = null;
if (file != null && file.exists()) {
bitmap = decodeSampledBitmapFromFile(file.getPath(), mImageWidth, mImageHeight, getImageCache());
}
if (bitmap==null) {
fail(imageView);
}else {
finish(bitmap, imageView);
bitmap = decodeSampledBitmapFromFile(data,file.getPath(), mImageWidth, mImageHeight, getImageCache());
}
return bitmap;
}
Expand Down Expand Up @@ -155,7 +145,7 @@ public boolean downloadUrlToStream(String urlString, File file,ImageView imageVi
n = n + count;
if (length>0) {
int percent = (int) (n * 100 / length);
process(percent,imageView);
process(percent,imageView,lister);
}
}
return true;
Expand Down

0 comments on commit 86a7939

Please sign in to comment.