Skip to content

Commit

Permalink
清理代码
Browse files Browse the repository at this point in the history
删除默认图片存放,节省内存
  • Loading branch information
dodola committed Nov 28, 2012
1 parent 743fd27 commit 3f0a833
Show file tree
Hide file tree
Showing 39 changed files with 110 additions and 208 deletions.
Binary file modified bin/classes.dex
Binary file not shown.
Binary file modified bin/classes/com/dodola/R$anim.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/R$attr.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/R$drawable.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/R$id.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/R$layout.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/R$string.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/activity/ContentActivity$1.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/activity/ContentActivity$2.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/activity/ContentActivity$3.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/activity/ContentActivity$ManagerBmp.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/activity/ContentActivity.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/base/ActivityBase.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/task/ContentFootTask.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/task/ContentTask.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/tools/AsyncImageLoader$1.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/tools/AsyncImageLoader$2.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/tools/AsyncImageLoader.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/views/InfoImageView.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/views/InfosListAdapter$1.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/views/InfosListAdapter$2.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/views/InfosListAdapter.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/views/InfosListLayout$1.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/views/InfosListLayout$2.class
Binary file not shown.
Binary file modified bin/classes/com/dodola/views/InfosListLayout.class
Binary file not shown.
Binary file removed bin/classes/com/dodola/views/InfosSmallBmp.class
Binary file not shown.
Binary file modified bin/dodo_waterfall.apk
Binary file not shown.
Binary file modified bin/resources.ap_
Binary file not shown.
3 changes: 2 additions & 1 deletion gen/com/dodola/R.java
Expand Up @@ -9,7 +9,8 @@

public final class R {
public static final class anim {
public static final int rotate_left=0x7f040000;
public static final int gradually=0x7f040000;
public static final int rotate_left=0x7f040001;
}
public static final class attr {
}
Expand Down
8 changes: 8 additions & 0 deletions res/anim/gradually.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="2000"
/>
</set>
117 changes: 45 additions & 72 deletions src/com/dodola/activity/ContentActivity.java
Expand Up @@ -12,6 +12,8 @@
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
Expand All @@ -29,10 +31,8 @@
import com.dodola.views.InfosListAdapter;
import com.dodola.views.InfosListLayout;
import com.dodola.views.InfosListLayoutInterface;
import com.dodola.views.InfosSmallBmp;

public class ContentActivity extends ActivityBase implements
InfosListLayoutInterface {
public class ContentActivity extends ActivityBase implements InfosListLayoutInterface {
public InfosListAdapter listAdapter;
public InfosListLayout newsListLayout; // 列表控件
public LinearLayout newsButtonPro;
Expand All @@ -48,7 +48,6 @@ public class ContentActivity extends ActivityBase implements
private int isFirstCreate = 1;
public int isDetailBcak = 0;

public InfosSmallBmp smallBmp;
private int iIndex;
private List<List<View>> all_screen_view; // 封装每屏View集合的集合
boolean thread_once_flag = true; // 确保线程只被开启一次
Expand All @@ -59,6 +58,8 @@ public ContentActivity() {
newsLeft = new Infos();
}

Animation animation;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -72,9 +73,9 @@ protected void onCreate(Bundle savedInstanceState) {
progressBar = (ProgressBar) findViewById(R.id.progressBar);
newsButtonPro = (LinearLayout) findViewById(R.id.newsButtonPro);

smallBmp = new InfosSmallBmp();
newsListLayout.setScrollView(scrollView);
newsListLayout.setEvent(this);
animation = AnimationUtils.loadAnimation(ContentActivity.this, R.anim.gradually);

upDateList();

Expand All @@ -93,15 +94,12 @@ public void setListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_UP && flag == 0
&& progressBar.getVisibility() == View.INVISIBLE) { // 当手指离开ScrollView且数据已经加载完成
if (event.getAction() == MotionEvent.ACTION_UP && flag == 0 && progressBar.getVisibility() == View.INVISIBLE) { // 当手指离开ScrollView且数据已经加载完成
View view = ((ScrollView) v).getChildAt(0);
if (view.getMeasuredHeight() <= v.getScrollY()
+ v.getHeight()) { // 当ScrollView中包含的View的高度小于已经滚动了的值+SrollView本身的高度时
if (view.getMeasuredHeight() <= v.getScrollY() + v.getHeight()) { // 当ScrollView中包含的View的高度小于已经滚动了的值+SrollView本身的高度时
newsLoadMore.setVisibility(android.view.View.VISIBLE);
if (newsListLayout != null) {
new ContentFootTask(ContentActivity.this)
.execute("http://www.duitang.com/album/369270/masn/p/4/24/");
new ContentFootTask(ContentActivity.this).execute("http://www.duitang.com/album/369270/masn/p/4/24/");
} else {
return false;
}
Expand All @@ -116,8 +114,7 @@ public boolean onTouch(View v, MotionEvent event) {

@Override
public void onClick(View v) {
new ContentFootTask(ContentActivity.this)
.execute("http://www.duitang.com/album/369270/masn/p/4/24/");
new ContentFootTask(ContentActivity.this).execute("http://www.duitang.com/album/369270/masn/p/4/24/");
}
});
}
Expand All @@ -143,20 +140,17 @@ public void setFlag(int flag) {
* 加载数据资源
* */
public void upDateList() {
new ContentTask(this)
.execute("http://www.duitang.com/album/369270/masn/p/4/24/"); // 请求数据
new ContentTask(this).execute("http://www.duitang.com/album/369270/masn/p/4/24/"); // 请求数据
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (isFirstCreate == 1) {
isFirstCreate = 0;
} else if (isDetailBcak == 1) {
isDetailBcak = 0;
ImageView imgCover = (ImageView) selectedView
.findViewById(R.id.news_cover);
ImageView imgCover = (ImageView) selectedView.findViewById(R.id.news_cover);
AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f);
alphaAnimation.setDuration(1500);
alphaAnimation.setFillAfter(true);
Expand All @@ -174,6 +168,7 @@ public void handleMessage(Message msg) {
} else if (1 == msg.what) {
((ProgressBar) msg.obj).setVisibility(View.VISIBLE);
}

}
};

Expand All @@ -190,17 +185,12 @@ protected void onStop() {
List<View> one_screen_view = all_screen_view.get(i);
if (iIndex - 1 == i || iIndex + 1 == i) {
for (int j = 0; j < one_screen_view.size(); j++) {
RelativeLayout rootView = (RelativeLayout) one_screen_view
.get(j);
ProgressBar proBar = (ProgressBar) rootView
.findViewById(R.id.progressBar);
InfoImageView imageView = (InfoImageView) rootView
.findViewById(R.id.news_pic);
RelativeLayout rootView = (RelativeLayout) one_screen_view.get(j);
ProgressBar proBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
InfoImageView imageView = (InfoImageView) rootView.findViewById(R.id.news_pic);
if (proBar.getVisibility() == View.INVISIBLE) {
Bitmap bmp = imageView.getBmp();
imageView.setMyImageBitmap(smallBmp
.getSmalBmpList()
.get(iBeforPresentBmps + j));
imageView.setMyImageBitmap(null);
proBar.setVisibility(View.VISIBLE);
this.freeBmp(bmp);
}
Expand All @@ -219,22 +209,15 @@ protected void onDestroy() {
managerBmp.manaBmp_flag = false;
}

for (int i = 0; i < smallBmp.getSmalBmpList().size(); i++) {
this.freeBmp(smallBmp.getSmalBmpList().get(i));
}
smallBmp.getSmalBmpList().clear();

// 释放掉MyImageView中的所有Bitmap
if (null != this.all_screen_view) {
int iBeforPresentBmps = 0;// 当前屏以前共有多少张图片
for (int i = 0; i < all_screen_view.size(); i++) {
List<View> one_screen_view = all_screen_view.get(i);

for (int j = 0; j < one_screen_view.size(); j++) {
RelativeLayout rootView = (RelativeLayout) one_screen_view
.get(j);
InfoImageView imageView = (InfoImageView) rootView
.findViewById(R.id.news_pic);
RelativeLayout rootView = (RelativeLayout) one_screen_view.get(j);
InfoImageView imageView = (InfoImageView) rootView.findViewById(R.id.news_pic);
Bitmap bmp = imageView.getBmp();
imageView.setMyImageBitmap(null);
this.freeBmp(bmp);
Expand All @@ -243,10 +226,8 @@ protected void onDestroy() {
// 删除SD卡上的多余的缓存(只保留第一次加载的图片缓存,不保留下拉或点击获得更多的图片)
if (iBeforPresentBmps >= 10) {
for (int j = 0; j < one_screen_view.size(); j++) {
RelativeLayout rootView = (RelativeLayout) one_screen_view
.get(j);
FileCache.getInstance().clearImgByImgUrl(
rootView.getTag().toString());
RelativeLayout rootView = (RelativeLayout) one_screen_view.get(j);
FileCache.getInstance().clearImgByImgUrl(rootView.getTag().toString());
}
}
iBeforPresentBmps += one_screen_view.size();
Expand All @@ -264,18 +245,15 @@ public void freeBmp(Bitmap bmp) {

@Override
public void onCurChileCtrlScreen(int index, int direct, boolean flag) {
// TODO Auto-generated method stub
int preIndex = this.iIndex;
this.iIndex = index;
this.initFlag = flag;
if (null == managerBmp || !managerBmp.isAlive()) {
managerBmp = new ManagerBmp(handler); // 注意这里必须在重新赋值;如果不重新赋值的话线程结束后,这个引用指向的是已经结束了的线程对象(已经在内存中不存在咯)
if (null == managerBmp || !managerBmp.isAlive()) { // 线程处理完成后才会重新处理
managerBmp = new ManagerBmp(handler);
managerBmp.query_flag = true;
managerBmp.manaBmp_flag = false;
all_screen_view = newsListLayout.initScreenView();
// System.out.println("总共有多少屏---------------->"
// + all_screen_view.size());
// 取得封装每屏View集合的集合
all_screen_view = newsListLayout.initScreenView();
managerBmp.start(); // 守护线程只开启一次
}

Expand All @@ -284,6 +262,14 @@ public void onCurChileCtrlScreen(int index, int direct, boolean flag) {
}
}

public Runnable uiRunnable = new Runnable() {

@Override
public void run() {

}
};

class ManagerBmp extends Thread {
public boolean manaBmp_flag = false;
public boolean query_flag = true;
Expand All @@ -306,48 +292,36 @@ public void run() {
List<View> one_screen_view = all_screen_view.get(i);
if (iIndex - 1 == i || iIndex == i || iIndex + 1 == i) {
for (int j = 0; j < one_screen_view.size(); j++) {
RelativeLayout rootView = (RelativeLayout) one_screen_view
.get(j);
ProgressBar proBar = (ProgressBar) rootView
.findViewById(R.id.progressBar);
InfoImageView imageView = (InfoImageView) rootView
.findViewById(R.id.news_pic);
RelativeLayout rootView = (RelativeLayout) one_screen_view.get(j);
ProgressBar proBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
final InfoImageView imageView = (InfoImageView) rootView.findViewById(R.id.news_pic);

if (proBar.getVisibility() == View.VISIBLE) {
// 获得SD卡上的图片
Bitmap bmp = FileCache.getInstance().getBmp(
rootView.getTag().toString());
// System.out
// .println("从SD卡上读取图片-------------------------");
// System.out.println(rootView.getTag()
// + "------------>图片的URL地址");
// System.out.println("守护线程开始加载图片...");
Bitmap bmp = FileCache.getInstance().getBmp(rootView.getTag().toString());

if (null != bmp) {
imageView.setMyImageBitmap(bmp);
// System.out.println("开始加载第"
// + (iBeforPresentBmps + j) + "个View的图片");

Message msg3 = handler.obtainMessage();
msg3.what = 0; // 让ProgressBar消失
msg3.obj = proBar;

handler.sendMessage(msg3);
}
}
}
} else {
} else {// 其他的回收掉
for (int j = 0; j < one_screen_view.size(); j++) {
RelativeLayout rootView = (RelativeLayout) one_screen_view
.get(j);
ProgressBar proBar = (ProgressBar) rootView
.findViewById(R.id.progressBar);
InfoImageView imageView = (InfoImageView) rootView
.findViewById(R.id.news_pic);
RelativeLayout rootView = (RelativeLayout) one_screen_view.get(j);
ProgressBar proBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
InfoImageView imageView = (InfoImageView) rootView.findViewById(R.id.news_pic);
Bitmap bitmap = null;
if (proBar.getVisibility() == View.INVISIBLE) {
bitmap = imageView.getBmp();
imageView.setMyImageBitmap(smallBmp
.getSmalBmpList().get(
iBeforPresentBmps + j));// 先给它设置小内存的默认图片
imageView.setMyImageBitmap(null);// 空白
ContentActivity.this.freeBmp(bitmap);// 释放掉

Message msg = handler.obtainMessage();
msg.what = 1; // ProgressBar出现
msg.obj = proBar;
Expand All @@ -362,7 +336,6 @@ public void run() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/com/dodola/base/ActivityBase.java
Expand Up @@ -10,7 +10,6 @@ public class ActivityBase extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}

Expand All @@ -37,13 +36,11 @@ public boolean isWifi(Context mContext) {

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/dodola/task/ContentFootTask.java
Expand Up @@ -39,7 +39,7 @@ protected List<Map<String, Object>> doInBackground(String... params) {
protected void onPostExecute(List<Map<String, Object>> result) {
if (this.contentActivity.newsLeft != null && this.contentActivity.newsLeft.getNewsInfos() != null) {
if (null == this.contentActivity.listAdapter) {
this.contentActivity.listAdapter = new InfosListAdapter(this.contentActivity, this.contentActivity.newsLeft.getNewsInfos(), this.contentActivity.smallBmp);
this.contentActivity.listAdapter = new InfosListAdapter(this.contentActivity, this.contentActivity.newsLeft.getNewsInfos()/*, this.contentActivity.smallBmp*/);
}
this.contentActivity.listAdapter.setList(this.contentActivity.newsLeft.getNewsInfos());
this.contentActivity.listAdapter.notifyDataSetChanged();
Expand Down
9 changes: 8 additions & 1 deletion src/com/dodola/task/ContentTask.java
Expand Up @@ -39,7 +39,14 @@ protected List<Map<String, Object>> doInBackground(String... params) {
@Override
protected void onPostExecute(List<Map<String, Object>> result) {
if (this.contentActivity.newsLeft != null && this.contentActivity.newsLeft.getNewsInfos() != null) {
this.contentActivity.listAdapter = new InfosListAdapter(this.contentActivity, this.contentActivity.newsLeft.getNewsInfos(), this.contentActivity.smallBmp);
this.contentActivity.listAdapter = new InfosListAdapter(this.contentActivity, this.contentActivity.newsLeft.getNewsInfos()/*
* ,
* this
* .
* contentActivity
* .
* smallBmp
*/);
this.contentActivity.newsListLayout.clearData();
this.contentActivity.newsListLayout.setAdapter(this.contentActivity.listAdapter);
}
Expand Down
5 changes: 1 addition & 4 deletions src/com/dodola/tools/AsyncImageLoader.java
Expand Up @@ -12,7 +12,6 @@
import android.os.Handler;
import android.os.Message;


public class AsyncImageLoader {

public Map<String, SoftReference<Drawable>> imageCache;
Expand All @@ -21,8 +20,7 @@ public AsyncImageLoader() {
imageCache = new HashMap<String, SoftReference<Drawable>>();
}

public Drawable loaDrawable(final String imageUrl,
final ImageCallBack imageCallBack) {
public Drawable loaDrawable(final String imageUrl, final ImageCallBack imageCallBack) {
Bitmap bmpFromSD = FileCache.getInstance().getBmp(imageUrl);
if (null != bmpFromSD) {
return new BitmapDrawable(bmpFromSD);
Expand Down Expand Up @@ -63,7 +61,6 @@ public Drawable loadImageFromUrl(String url) {
tempUrl = new URL(url);
inputStream = (InputStream) tempUrl.getContent();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Expand Down
1 change: 1 addition & 0 deletions src/com/dodola/views/InfoImageView.java
Expand Up @@ -32,6 +32,7 @@ public Bitmap getBmp() {

@Override
protected void onDraw(Canvas canvas) {

if (null != bitmap) {
synchronized (bitmap) {// ......
if (null != bitmap && !bitmap.isRecycled()) {
Expand Down

0 comments on commit 3f0a833

Please sign in to comment.