默认显示当前时间:
time.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="日期和时间控件的使用DEMO" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/showdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/pickdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择日期" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/showtime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/picktime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择时间" />
</LinearLayout>
</LinearLayout>TimeActivity.java
public class TimeActivity extends Activity {
private EditText showDate = null;
private Button pickDate = null;
private EditText showTime = null;
private Button pickTime = null;
private static final int SHOW_DATAPICK = 0;
private static final int DATE_DIALOG_ID = 1;
private static final int SHOW_TIMEPICK = 2;
private static final int TIME_DIALOG_ID = 3;
private int mYear;
private int mMonth;
private int mDay;
private int mHour;
private int mMinute;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.time);
initializeViews();
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
setDateTime();
setTimeOfDay();
}
/**
* 初始化控件和UI视图
*/
private void initializeViews(){
showDate = (EditText) findViewById(R.id.showdate);
pickDate = (Button) findViewById(R.id.pickdate);
showTime = (EditText)findViewById(R.id.showtime);
pickTime = (Button)findViewById(R.id.picktime);
pickDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message msg = new Message();
if (pickDate.equals((Button) v)) {
msg.what = TimeActivity.SHOW_DATAPICK;
}
TimeActivity.this.dateandtimeHandler.sendMessage(msg);
}
});
pickTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message msg = new Message();
if (pickTime.equals((Button) v)) {
msg.what = TimeActivity.SHOW_TIMEPICK;
}
TimeActivity.this.dateandtimeHandler.sendMessage(msg);
}
});
}
/**
* 设置日期
*/
private void setDateTime(){
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
updateDateDisplay();
}
/**
* 更新日期显示
*/
private void updateDateDisplay(){
showDate.setText(new StringBuilder().append(mYear).append("-")
.append((mMonth + 1) < 10 ? "0" + (mMonth + 1) : (mMonth + 1)).append("-")
.append((mDay < 10) ? "0" + mDay : mDay));
}
/**
* 日期控件的事件
*/
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDateDisplay();
}
};
/**
* 设置时间
*/
private void setTimeOfDay(){
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
updateTimeDisplay();
}
/**
* 更新时间显示
*/
private void updateTimeDisplay(){
showTime.setText(new StringBuilder().append(mHour).append(":")
.append((mMinute < 10) ? "0" + mMinute : mMinute));
}
/**
* 时间控件事件
*/
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour = hourOfDay;
mMinute = minute;
updateTimeDisplay();
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
mDay);
case TIME_DIALOG_ID:
return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute, true);
}
return null;
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
break;
case TIME_DIALOG_ID:
((TimePickerDialog) dialog).updateTime(mHour, mMinute);
break;
}
}
/**
* 处理日期和时间控件的Handler
*/
Handler dateandtimeHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case TimeActivity.SHOW_DATAPICK:
showDialog(DATE_DIALOG_ID);
break;
case TimeActivity.SHOW_TIMEPICK:
showDialog(TIME_DIALOG_ID);
break;
}
}
};
}
mail:bookworepeng@Hotmail.com
qq:196568501
phone:13410905075
author:drivermonkey
-欢迎交流
1)根文件系统创建,所谓的建立根文件系统就是将所需要根文件copy 到一个目录,用压缩命令压缩为指定格式。
2)将更文件系统编译进内核。具体方法就是在 编译内核的时候指定第一步生成的根文件路径,然后编译。
KERNEL OPTIONS:
# # General setup # ... CONFIG_BLK_DEV_INITRD=y CONFIG_INITRAMFS_SOURCE="<path_to>/target_fs>" ... # # UBI - Unsorted block images # ... CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_COUNT=1 CONFIG_BLK_DEV_RAM_SIZE=8192 CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
3)把内核直接放到sd或者nand中,系统起来
在系统启动的过程中遇到了这样的问题:
1.WARNING: Unable to open an initial console解决方式:在根文件加入:
cd /dev
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3
2. 在系统启动的时候找不到init 程序
解决方式:
创建 link 使其指向 init 程序
3.启动到level 5 的时候可能出现 找不到 库文件的情况。
解决防止:
直接将缺少库文件 copy 到根文件系统里
参考资料:
http://processors.wiki.ti.com/index.php/Initrd
ASIHTTPRequest可以实现断点续传。网上有一些介绍类似使用:
[request setAllowResumeForFileDownloads:YES];
方法的。但是它不是真正意义的断点续传。它只能让应用在下载过程中,暂停和继续。如果退出应用再进入是无效的。
不过,通过ASIHTTPRequest的异步请求以及delegate还是可以实现断点续传的。
本文还是以Grails编写断点续传服务器端为例。
异步请求的代码:
-(void) doSimpleGetBinary{
NSURL *url = [NSURL URLWithString:@"http://localhost:8080/BookProto/book/image"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:@"GET"];
//[request addRequestHeader:@"Range" value:@"bytes=3-"];
[request setDelegate:self];
[request startAsynchronous];
}
这里设置了Delegate, 要在头文件中实现相应的protocol:
@interface CFHttpDemoViewController : UIViewController<ASIProgressDelegate> {
本例中使用到了delegate的如下方法。
requestFinished:
- (void)requestFinished:(ASIHTTPRequest *)request{
NSLog(@"response status code: %i",[request responseStatusCode]);
NSLog(@"response content length: %@",[[request responseHeaders] objectForKey:@"Content-Length" ]);
NSLog(@"request finished.");
label.text=@"request finished.";
}
这个方法在异步请求结束后调用。
下面的方法,是当缓冲区接收到部分数据后调用,看起来是每间隔一定的毫秒,就调用一下,并传入缓冲区的NSData对象。
-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data{
NSLog(@"did receive data, data length: %i",[data length]);
//复制到字节数组中
Byte *byteData=(Byte *)malloc([data length]);
memcpy(byteData,[data bytes],[data length]);
for (int i=0; i<=10; i++) {
NSLog(@"%i: %i",i+1,byteData[i]);
}
free(byteData);
[request cancel];
label.text=@"canceled.";
}
运行代码,屏蔽:
[request addRequestHeader:@"Range" value:@"bytes=3-"];
和取消屏蔽,数据分别如下:
2011-07-12 14:17:13.497 CFHttpDemo[2647:207] did receive data, data length: 10172
2011-07-12 14:17:13.514 CFHttpDemo[2647:207] 1: 137
2011-07-12 14:17:13.515 CFHttpDemo[2647:207] 2: 80
2011-07-12 14:17:13.516 CFHttpDemo[2647:207] 3: 78
2011-07-12 14:17:13.516 CFHttpDemo[2647:207] 4: 71
2011-07-12 14:17:13.517 CFHttpDemo[2647:207] 5: 13
2011-07-12 14:17:13.518 CFHttpDemo[2647:207] 6: 10
2011-07-12 14:17:13.518 CFHttpDemo[2647:207] 7: 26
2011-07-12 14:17:13.519 CFHttpDemo[2647:207] 8: 10
2011-07-12 14:17:13.520 CFHttpDemo[2647:207] 9: 0
2011-07-12 14:17:13.520 CFHttpDemo[2647:207] 10: 0
2011-07-12 14:17:13.521 CFHttpDemo[2647:207] 11: 0
2011-07-12 14:17:13.522 CFHttpDemo[2647:207] response status code: 200
2011-07-12 14:17:13.523 CFHttpDemo[2647:207] response content length: 10172
2011-07-12 14:17:13.523 CFHttpDemo[2647:207] request finished.
2011-07-12 14:02:24.551 CFHttpDemo[2578:207] did receive data, data length: 10169
2011-07-12 14:02:24.553 CFHttpDemo[2578:207] byteData ok.
2011-07-12 14:02:24.554 CFHttpDemo[2578:207] 1: 71
2011-07-12 14:02:24.554 CFHttpDemo[2578:207] 2: 13
2011-07-12 14:02:24.555 CFHttpDemo[2578:207] 3: 10
2011-07-12 14:02:24.555 CFHttpDemo[2578:207] 4: 26
2011-07-12 14:02:24.556 CFHttpDemo[2578:207] 5: 10
2011-07-12 14:02:24.556 CFHttpDemo[2578:207] 6: 0
2011-07-12 14:02:24.557 CFHttpDemo[2578:207] 7: 0
2011-07-12 14:02:24.557 CFHttpDemo[2578:207] 8: 0
2011-07-12 14:02:24.558 CFHttpDemo[2578:207] 9: 13
2011-07-12 14:02:24.558 CFHttpDemo[2578:207] 10: 73
2011-07-12 14:02:24.560 CFHttpDemo[2578:207] 11: 72
2011-07-12 14:02:24.561 CFHttpDemo[2578:207] response status code: 206
2011-07-12 14:02:24.561 CFHttpDemo[2578:207] response content length: 10169
2011-07-12 14:02:24.562 CFHttpDemo[2578:207] request finished.
2.
Range头域
Range头域可以请求实体的一个或者多个子范围。例如,
表示头500个字节:bytes=0-499
表示第二个500字节:bytes=500-999
表示最后500个字节:bytes=-500
表示500字节以后的范围:bytes=500-
第一个和最后一个字节:bytes=0-0,-1
同时指定几个范围:bytes=500-600,601-999
但是服务器可以忽略此请求头,如果无条件GET包含Range请求头,响应会以状态码206(PartialContent)返回而不是以200(OK)。
在ios中使用NSMutableURLRequest来定义头部域