Skip to content

Commit

Permalink
move some constants to Constants Class and remove some useless import
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjieting committed Sep 10, 2012
1 parent fa56c47 commit 7a85763
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
13 changes: 13 additions & 0 deletions src/com/dodowaterfall/Constants.java
@@ -0,0 +1,13 @@
package com.dodowaterfall;

public class Constants {

public final static int COLUMN_COUNT = 4; // 显示列数

public final static int PICTURE_COUNT_PER_LOAD = 30; // 每次加载30张图片

public final static int PICTURE_TOTAL_COUNT = 10000; //可以加载的最多文件数

public final static int HANDLER_WHAT = 1;

}
23 changes: 9 additions & 14 deletions src/com/dodowaterfall/MainActivity.java
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
Expand All @@ -14,18 +13,13 @@
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;

public class MainActivity extends Activity {

Expand All @@ -39,8 +33,8 @@ public class MainActivity extends Activity {
private Handler handler;
private int item_width;

private int column_count = 4;// 显示列数
private int page_count = 30;// 每次加载30张图片
private int column_count = Constants.COLUMN_COUNT;// 显示列数
private int page_count = Constants.PICTURE_COUNT_PER_LOAD;// 每次加载30张图片

private int current_page = 0;// 当前页数

Expand All @@ -67,7 +61,7 @@ public void onCreate(Bundle savedInstanceState) {

display = this.getWindowManager().getDefaultDisplay();
item_width = display.getWidth() / column_count;// 根据屏幕大小计算每列大小
asset_manager = this.getAssets();
asset_manager = getAssets();

column_height = new int[column_count];
context = this;
Expand Down Expand Up @@ -203,7 +197,7 @@ public void handleMessage(Message msg) {
// super.handleMessage(msg);

switch (msg.what) {
case 1:
case Constants.HANDLER_WHAT:

FlowView v = (FlowView) msg.obj;
int w = msg.arg1;
Expand Down Expand Up @@ -259,21 +253,21 @@ public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
}

// 加载所有图片路径

try {
image_filenames = Arrays.asList(asset_manager.list(image_path));

} catch (IOException e) {
e.printStackTrace();
}

// 第一次加载
AddItemToContainer(current_page, page_count);
}

private void AddItemToContainer(int pageindex, int pagecount) {

int currentIndex = pageindex * pagecount;

int imagecount = 10000;// image_filenames.size();
int imagecount = Constants.PICTURE_TOTAL_COUNT;// image_filenames.size();

for (int i = currentIndex; i < pagecount * (pageindex + 1)
&& i < imagecount; i++) {
loaded_count++;
Expand All @@ -294,6 +288,7 @@ private void AddImage(String filename, int rowIndex, int id) {
item.setRowIndex(rowIndex);
item.setId(id);
item.setViewHandler(this.handler);

// 多线程参数
FlowTag param = new FlowTag();
param.setFlowId(id);
Expand Down
11 changes: 7 additions & 4 deletions src/com/dodowaterfall/widget/FlowTag.java
@@ -1,11 +1,17 @@
package com.dodowaterfall.widget;

import com.dodowaterfall.Constants;

import android.content.res.AssetManager;

public class FlowTag {

public final int what = Constants.HANDLER_WHAT;

private int flowId;
private String fileName;
public final int what = 1;
private int ItemWidth;
private AssetManager assetManager;

public int getFlowId() {
return flowId;
Expand All @@ -23,9 +29,6 @@ public void setFileName(String fileName) {
this.fileName = fileName;
}

private AssetManager assetManager;
private int ItemWidth;

public AssetManager getAssetManager() {
return assetManager;
}
Expand Down
3 changes: 1 addition & 2 deletions src/com/dodowaterfall/widget/FlowView.java
Expand Up @@ -9,7 +9,6 @@
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.Toast;
import android.os.Handler;
import android.os.Message;
Expand Down Expand Up @@ -51,7 +50,7 @@ public FlowView(Context c) {
private void Init() {

setOnClickListener(this);
this.setOnLongClickListener(this);
setOnLongClickListener(this);
setAdjustViewBounds(true);

}
Expand Down

0 comments on commit 7a85763

Please sign in to comment.