种Android网易新闻之新闻阅读器制作(1)

类Android网易新闻之新闻阅读器制作(1)首先欢迎大家访问我的独立博客与我进行交流。? ? ? ? ? ? ?程序的主

类Android网易新闻之新闻阅读器制作(1)

首先欢迎大家访问我的独立博客与我进行交流。

? ? ? ? ? ? ?种Android网易新闻之新闻阅读器制作(1)

程序的主要部分是列表页部分和文章显示页部分,列表页有拖动更新功能和分页功能,用以显示所有的文章列表,文章显示部分具有离线悦读、图片异步加载等功能,看上去很简单的两个页面其实有很多附加功能。

现在按顺序来讲述编码流程。

首先,进入程序前会有个splash,splash有多种功能,可以用于告诉用户一些关于应用程序的信息,也可以用来进行手机环境的检测,比如网络、存储卡等的检测,还可以进行数据库以及部分数据的初始化等等。


public class CiSplash extends Activity{// timerTimer timer = null;// start timelong startTime = 0;// is or not touchedBoolean _active = true;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.splash);// set the timerstartTime = System.currentTimeMillis();setTimer();}    private final TimerTask task = new TimerTask() {        @Override        public void run() {        // after 2 seconds or screen has been touched, send a message        if (task.scheduledExecutionTime() - startTime >= 2000        || !_active) {        Message message = new Message();        message.what = 1;                timerHandler.sendMessage(message);                timer.cancel();                this.cancel();        }        }    };    private final Handler timerHandler = new Handler() {    @Override        public void handleMessage(Message msg) {        // skip the splash        if (msg.what == 1) {             if(ApplicationEx.isSDCardMounted() &&         !ApplicationEx.isSDCardMountedReadOnly()){            Intent intent = new Intent(CiSplash.this,                                CiReader.class);        CiSplash.this.finish();        startActivity(intent);        }else{        Tools.displayMsg(CiSplash.this, "请插入存储卡");        CiSplash.this.finish();        }        }        super.handleMessage(msg);           }    };        // set the task executed per 0.2 seconds    public void setTimer(){    timer = new Timer(true);    timer.schedule(task, 0, 200);    } // when screen has been touched    @Override    public boolean onTouchEvent(MotionEvent event) {        if (event.getAction() == MotionEvent.ACTION_DOWN) {            _active = false;        }        return true;    }    }

我这里展示了一张splash图,图中展示了应用程序的大概内容,除此之外Activity中还有一个功能就是检测存储卡,由于该阅读器需要sdcard来作为离线存储的空间,因此在没有sdcard的情况下会提示用户,当然这里也有不人性化的地方,就是这里自动退出了,其实没有sdcard用户也还是可以在线阅读的,这里没做处理。

另外这里splash的跳过除了等待2秒外,用户还可以通过触碰界面直接跳过splash,代码很简单,相信大家能看得懂。

这里就讲到这儿,下面一讲主要论述列表页的制作。

1 楼 duni_读你 2011-09-24   原码什么时候拿出来说一声,顶你。麻烦到时候说一声,发到邮箱wencun2011@sina.com也行,谢了。