Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AfinalDb相关更新,和FinalBitmap部分改进 #58

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 113 additions & 113 deletions src/net/tsz/afinal/FinalActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;

public class FinalActivity extends Activity {
public abstract class FinalActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}


public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
FinalActivity.initInjectedView(this);
}
}


public void setContentView(View view, LayoutParams params) {
super.setContentView(view, params);
public void setContentView(View view, LayoutParams params) {
super.setContentView(view, params);
FinalActivity.initInjectedView(this);
}
}



public void setContentView(View view) {
super.setContentView(view);
FinalActivity.initInjectedView(this);
}
public void setContentView(View view) {
super.setContentView(view);
FinalActivity.initInjectedView(this);
}

/**
* 初始化Actvity中的注入属性
Expand Down Expand Up @@ -84,106 +84,106 @@ public static void initInjectedView(Activity sourceActivity){
* </pre>
* @param sourceView
*/
public static void initInjectedView(Object injectedSource,View sourceView){
Field[] fields = injectedSource.getClass().getDeclaredFields();
if(fields!=null && fields.length>0){
for(Field field : fields){
ViewInject viewInject = field.getAnnotation(ViewInject.class);
if(viewInject!=null){
int viewId = viewInject.id();
try {
field.setAccessible(true);
public static void initInjectedView(Object injectedSource,View sourceView){
Field[] fields = injectedSource.getClass().getDeclaredFields();
if(fields!=null && fields.length>0){
for(Field field : fields){
ViewInject viewInject = field.getAnnotation(ViewInject.class);
if(viewInject!=null){
int viewId = viewInject.id();
try {
field.setAccessible(true);
/*当已经被赋值时,不在重复赋值,用于include,inflate情景下的viewinject组合*/
if(field.get(injectedSource)==null){
field.set(injectedSource,sourceView.findViewById(viewId));
field.set(injectedSource,sourceView.findViewById(viewId));
}else{
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
String clickMethod = viewInject.click();
if(!TextUtils.isEmpty(clickMethod))
setViewClickListener(injectedSource,field,clickMethod);
String longClickMethod = viewInject.longClick();
if(!TextUtils.isEmpty(longClickMethod))
setViewLongClickListener(injectedSource,field,longClickMethod);
String itemClickMethod = viewInject.itemClick();
if(!TextUtils.isEmpty(itemClickMethod))
setItemClickListener(injectedSource,field,itemClickMethod);


String itemLongClickMethod = viewInject.itemLongClick();
if(!TextUtils.isEmpty(itemLongClickMethod))
setItemLongClickListener(injectedSource,field,itemLongClickMethod);
Select select = viewInject.select();
if(!TextUtils.isEmpty(select.selected()))
setViewSelectListener(injectedSource,field,select.selected(),select.noSelected());
}
}
}
}
private static void setViewClickListener(Object injectedSource,Field field,String clickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof View){
((View)obj).setOnClickListener(new EventListener(injectedSource).click(clickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void setViewLongClickListener(Object injectedSource,Field field,String clickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof View){
((View)obj).setOnLongClickListener(new EventListener(injectedSource).longClick(clickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void setItemClickListener(Object injectedSource,Field field,String itemClickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof AbsListView){
((AbsListView)obj).setOnItemClickListener(new EventListener(injectedSource).itemClick(itemClickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void setItemLongClickListener(Object injectedSource,Field field,String itemClickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof AbsListView){
((AbsListView)obj).setOnItemLongClickListener(new EventListener(injectedSource).itemLongClick(itemClickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void setViewSelectListener(Object injectedSource,Field field,String select,String noSelect){
try {
Object obj = field.get(injectedSource);
if(obj instanceof View){
((AbsListView)obj).setOnItemSelectedListener(new EventListener(injectedSource).select(select).noSelect(noSelect));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}

String clickMethod = viewInject.click();
if(!TextUtils.isEmpty(clickMethod))
setViewClickListener(injectedSource,field,clickMethod);

String longClickMethod = viewInject.longClick();
if(!TextUtils.isEmpty(longClickMethod))
setViewLongClickListener(injectedSource,field,longClickMethod);

String itemClickMethod = viewInject.itemClick();
if(!TextUtils.isEmpty(itemClickMethod))
setItemClickListener(injectedSource,field,itemClickMethod);


String itemLongClickMethod = viewInject.itemLongClick();
if(!TextUtils.isEmpty(itemLongClickMethod))
setItemLongClickListener(injectedSource,field,itemLongClickMethod);

Select select = viewInject.select();
if(!TextUtils.isEmpty(select.selected()))
setViewSelectListener(injectedSource,field,select.selected(),select.noSelected());

}
}
}
}


private static void setViewClickListener(Object injectedSource,Field field,String clickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof View){
((View)obj).setOnClickListener(new EventListener(injectedSource).click(clickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}

private static void setViewLongClickListener(Object injectedSource,Field field,String clickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof View){
((View)obj).setOnLongClickListener(new EventListener(injectedSource).longClick(clickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}

private static void setItemClickListener(Object injectedSource,Field field,String itemClickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof AbsListView){
((AbsListView)obj).setOnItemClickListener(new EventListener(injectedSource).itemClick(itemClickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}

private static void setItemLongClickListener(Object injectedSource,Field field,String itemClickMethod){
try {
Object obj = field.get(injectedSource);
if(obj instanceof AbsListView){
((AbsListView)obj).setOnItemLongClickListener(new EventListener(injectedSource).itemLongClick(itemClickMethod));
}
} catch (Exception e) {
e.printStackTrace();
}
}

private static void setViewSelectListener(Object injectedSource,Field field,String select,String noSelect){
try {
Object obj = field.get(injectedSource);
if(obj instanceof View){
((AbsListView)obj).setOnItemSelectedListener(new EventListener(injectedSource).select(select).noSelect(noSelect));
}
} catch (Exception e) {
e.printStackTrace();
}
}


}
17 changes: 9 additions & 8 deletions src/net/tsz/afinal/FinalBitmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,15 @@ private void doDisplay(View imageView, String uri, BitmapDisplayConfig displayCo
}

if (bitmap != null) {
if(imageView instanceof ImageView){
((ImageView)imageView).setImageBitmap(bitmap);
}else{
imageView.setBackgroundDrawable(new BitmapDrawable(bitmap));
}


}else if (checkImageTask(uri, imageView)) {
// if(imageView instanceof ImageView){
// ((ImageView)imageView).setImageBitmap(bitmap);
// }else{
// imageView.setBackgroundDrawable(new BitmapDrawable(bitmap));
// }
//modify by pwy 20131015,确保loadCompletedisplay能在每次display时调用
mConfig.displayer.loadCompletedisplay(imageView,bitmap,displayConfig);

}else if (checkImageTask(uri, imageView)) {
final BitmapLoadAndDisplayTask task = new BitmapLoadAndDisplayTask(imageView, displayConfig );
//设置默认图片
final AsyncDrawable asyncDrawable = new AsyncDrawable(mContext.getResources(), displayConfig.getLoadingBitmap(), task);
Expand Down
Loading