First of all, you are welcome to visit my independent blog to communicate with me.
Recently I made a news reader, which is basically similar to Netease news. Although there are few downloads in the market, there are still some worthy of recognition. Next I will share several articles to describe how to create the reader. I will release the source code later.
First, let's look at the effects of the previous images.
The main part of the program is the list page and the article display page. The list page provides the drag update function and paging function to display the list of all articles, the article shows that some of the pages have functions such as offline reading and asynchronous image loading. The seemingly simple pages actually have many additional functions.
The encoding process is described in sequence.
First, there will be a splash before entering the program. splash has multiple features that can be used to tell users about the application or to detect the mobile phone environment, such as network and memory card detection, and initialization of databases and some data.
1 public class CiSplash extends Activity {
2
3 // timer
4 Timer timer = null;
5
6 // start time
7 long startTime = 0;
8
9 // is or not touched
10 Boolean _ active = true;
11
12 @ Override
13 protected void onCreate (Bundle savedInstanceState ){
14 // TODO Auto-generated method stub
15 super. onCreate (savedInstanceState );
16 requestWindowFeature (Window. FEATURE_NO_TITLE );
17 setContentView (R. layout. splash );
18
19 // set the timer
20 startTime = System. currentTimeMillis ();
21 setTimer ();
22}
23
24 private final TimerTask task = new TimerTask (){
25 @ Override
26 public void run (){
27 // after 2 seconds or screen has been touched, send a message
28 if (task. scheduledExecutionTime ()-startTime> = 2000
29 |! _ Active ){
30 Message message = new Message ();
31 message. what = 1;
32 timerHandler. sendMessage (message );
33 timer. cancel ();
34 this. cancel ();
35}
36}
37 };
38
39 private final Handler timerHandler = new Handler (){
40 @ Override
41 public void handleMessage (Message msg ){
42 // skip the splash
43 if (msg. what = 1 ){
44 if (ApplicationEx. isSDCardMounted ()&&
45! ApplicationEx. isSDCardMountedReadOnly ()){
46 Intent intent = new Intent (CiSplash. this,
47 CiReader. class );
48 CiSplash. this. finish ();
49 startActivity (intent );
50} else {
51 Tools. displayMsg (CiSplash. this, "Please insert a memory card ");
52 CiSplash. this. finish ();
53}
54}
55 super. handleMessage (msg );
56}
57 };
58
59 // set the task executed per 0.2 seconds
60 public void setTimer (){
61 timer = new Timer (true );
62 timer. schedule (task, 0,200 );
63}
64
65 // when screen has been touched
66 @ Override
67 public boolean onTouchEvent (MotionEvent event ){
68 if (event. getAction () = MotionEvent. ACTION_DOWN ){
69 _ active = false;
70}
71 return true;
72}
73
74
75}
76
I have shown a splash chart, which shows the approximate content of the application. In addition, the Activity also has a function of detecting the memory card. Because the reader needs sdcard as the offline storage space, therefore, the user will be prompted if there is no sdcard. Of course, there are also some unfriendly aspects, that is, the user will exit automatically. In fact, no sdcard user can still read it online, no processing is performed here.
In addition to waiting for 2 seconds, you can also directly skip the splash through the touch interface. The code is very simple and you can understand it.
The following describes how to create a list page.
Author: "fengzhizi's blog"