本项目实现了一个带有自动提醒功能的记事本,用户可选择日期和时间进行记录,当用户关闭app后,比对进程不受影响,用户关开机后,提醒进程自动启动,手机关机状态下无法提醒。本项目只实现了基本功能,界面还需优化。
具体实现如下:
1、声明权限
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2、声明接收开机广播的广播接收器
<receiver android:name=".receiver.MainReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
3、新建主界面activity
public class MainActivity extends AppCompatActivity implements View.OnClickListener, NotepadeAdapter.ClickFunction {
private TextView tv_add;
private ListView lv_contents;
private List<NotepadWithDataBean> notepadWithDataBeanList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent1 = new Intent(MainActivity.this, MainService.class);
/**启动MainService,用于注册广播,service能在app关闭的状态下常驻内存,从而解决了app关闭状态下接收到广播处理出错的问题**/
startService(intent1);
findViews();
setListeners();
initView();
}
private void findViews() {
tv_add = (TextView) findViewById(R.id.tv_add);
lv_contents = (ListView) findViewById(R.id.lv_content);
}
private void setListeners() {
tv_add.setOnClickListener(this);
}
private void initView() {
/**从数据库中读取数据,并转化类型,实现按照日期的集中显示**/
DataHelper helper = new DataHelper(MainActivity.this);
notepadWithDataBeanList = new ArrayList<NotepadWithDataBean>();
List<NotepadBean> notepadBeanList = helper.getNotepadList();
for (int i = 0; i < notepadBeanList.size(); i++) {
if (0 == notepadWithDataBeanList.size()) {
NotepadWithDataBean notepadWithDataBean = new NotepadWithDataBean();
notepadWithDataBean.setData(notepadBeanList.get(0).getDate());
notepadWithDataBeanList.add(notepadWithDataBean);
}
boolean flag = true;
for (int j = 0; j < notepadWithDataBeanList.size(); j++) {
int date = notepadWithDataBeanList.get(j).getData();
if (date == notepadBeanList.get(i).getDate()) {
notepadWithDataBeanList.get(j).getNotepadBeenList().add(notepadBeanList.get(i));
flag = false;
break;
}
}
if (flag) {
NotepadWithDataBean notepadWithDataBean = new NotepadWithDataBean();
notepadWithDataBean.setData(notepadBeanList.get(i).getDate());
notepadWithDataBeanList.add(notepadWithDataBean);
notepadWithDataBeanList.get(notepadWithDataBeanList.size() - 1).getNotepadBeenList().add(notepadBeanList.get(i));
}
}
NotepadeAdapter adapter = new NotepadeAdapter(MainActivity.this, notepadWithDataBeanList, this);
lv_contents.setAdapter(adapter);
// setListViewHeightBasedOnChildren(lv_contents);
}
public void setListViewHeightBasedOnChildren(ListView listView) {
if (listView == null) return;
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_add:
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putInt(GlobalParams.TYPE_KEY, GlobalParams.TYPE_ADD);
intent.putExtras(bundle);
intent.setClass(MainActivity.this, AddContentActivity.class);
startActivityForResult(intent, GlobalParams.ADD_REQUEST);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case GlobalParams.ADD_REQUEST:
if (GlobalParams.ADD_RESULT_OK == resultCode) {
initView();
}
break;
}
}
@Override
public void clickItem(int position, int itemPosition) {
Bundle bundle = new Bundle();
bundle.putInt(GlobalParams.TYPE_KEY, GlobalParams.TYPE_EDIT);
bundle.putSerializable(GlobalParams.BEAN_KEY, notepadWithDataBeanList.get(position));
bundle.putInt(GlobalParams.ITEM_POSITION_KEY, itemPosition);
Intent intent = new Intent(this, AddContentActivity.class);
intent.putExtras(bundle);
startActivityForResult(intent, GlobalParams.ADD_REQUEST);
}
@Override
public void longClickItem(final int position, final int itemPostion) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("确认删除吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
DataHelper helper = new DataHelper(MainActivity.this);
helper.deleteNotepad(notepadWithDataBeanList.get(position).getNotepadBeenList().get(itemPostion).getId());
initView();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
}
4、添加和修改的activity
public class AddContentActivity extends AppCompatActivity implements View.OnClickListener {
private TextView tv_save;
private TextView tv_date;
private TextView tv_time;
private TextView tv_cancel;
private EditText et_content;
private String time = "";
private String date = "";
private Bundle bundle;
private int type;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_content);
bundle=getIntent().getExtras();
type=bundle.getInt(GlobalParams.TYPE_KEY);
findViews();
setListeners();
initDate();
}
private void findViews() {
et_content=(EditText)findViewById(R.id.et_content);
tv_save = (TextView) findViewById(R.id.tv_save);
tv_date = (TextView) findViewById(R.id.tv_date);
tv_time = (TextView) findViewById(R.id.tv_time);
tv_cancel=(TextView)findViewById(R.id.tv_cancel);
}
private void setListeners() {
tv_save.setOnClickListener(this);
tv_date.setOnClickListener(this);
tv_time.setOnClickListener(this);
tv_cancel.setOnClickListener(this);
}
private void initDate() {
Calendar c = Calendar.getInstance();
int year=c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH);
int day=c.get(Calendar.DAY_OF_MONTH);
date=getDate(year,month,day);
if(type==GlobalParams.TYPE_EDIT){
NotepadWithDataBean notepadWithDataBean=(NotepadWithDataBean)(bundle.getSerializable(GlobalParams.BEAN_KEY));
et_content.setText(notepadWithDataBean.getNotepadBeenList().get(bundle.getInt(GlobalParams.ITEM_POSITION_KEY)).getContent());
date=notepadWithDataBean.getData()+"";
tv_date.setText(date);
time=notepadWithDataBean.getNotepadBeenList().get(bundle.getInt(GlobalParams.ITEM_POSITION_KEY)).getTime();
tv_time.setText(time);
}
}
private String getDate(int year,int month,int day){
String date="";
date+=year;
if(month<9){
date=date+"0"+(month+1);
}else{
date+=(month+1);
}
if(day<10){
date=date+"0"+day;
}else {
date+=day;
}
return date;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_save:
if(type==GlobalParams.TYPE_EDIT){
update();
}else {
save();
}
break;
case R.id.tv_date:
selectDateDialog();
break;
case R.id.tv_time:
selectTimeDialog();
break;
case R.id.tv_cancel:
finish();
break;
}
}
private void selectDateDialog(){
Calendar c = Calendar.getInstance();
int year=c.get(Calendar.YEAR);
final int month=c.get(Calendar.MONTH)+1;
int day=c.get(Calendar.DAY_OF_MONTH);
new DatePickerDialog(AddContentActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
date=getDate(year,monthOfYear,dayOfMonth);
tv_date.setText(date);
}
},year,month,day).show();
}
private void selectTimeDialog() {
Calendar c = Calendar.getInstance();
int mHour = c.get(Calendar.HOUR_OF_DAY);
int mMinute = c.get(Calendar.MINUTE);
new TimePickerDialog(AddContentActivity.this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view,
int hourOfDay, int minute) {
time=formatTime(hourOfDay,minute);
tv_time.setText(time);
}
}, mHour, mMinute, true).show();
}
private String formatTime(int hour,int minute){
String time=hour+":";
if(minute<10){
time=time+"0"+minute;
}else{
time+=minute;
}
return time;
}
private void save() {
String content = et_content.getText().toString();
if ("".equals(content)) {
Toast.makeText(AddContentActivity.this, "请输入内容", Toast.LENGTH_SHORT).show();
return;
}
if ("".equals(time)) {
Toast.makeText(AddContentActivity.this, "请选择时间", Toast.LENGTH_SHORT).show();
return;
}
NotepadBean notepadBean = new NotepadBean();
notepadBean.setContent(content);
notepadBean.setDate(Integer.parseInt(date));
notepadBean.setTime(time);
DataHelper helper = new DataHelper(AddContentActivity.this);
helper.insertData(notepadBean);
setResult(GlobalParams.ADD_RESULT_OK);
finish();
}
private void update(){
DataHelper helper=new DataHelper(AddContentActivity.this);
NotepadWithDataBean bean=(NotepadWithDataBean)(bundle.getSerializable(GlobalParams.BEAN_KEY));
int itemPosition=bundle.getInt(GlobalParams.ITEM_POSITION_KEY);
helper.update(bean.getNotepadBeenList().get(itemPosition).getId(),date,time,et_content.getText().toString());
setResult(GlobalParams.ADD_RESULT_OK);
finish();
}
}
5、提醒界面
public class RemindActivity extends AppCompatActivity {
private TextView tv_content;
private Button bt_confirm;
private MediaPlayer mMediaPlayer;;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_remind);
findViews();
setListeners();
Bundle bundle=getIntent().getExtras();
String content=bundle.getString(GlobalParams.CONTENT_KEY);
tv_content.setText(content);
playSound();
}
private void findViews(){
tv_content=(TextView)findViewById(R.id.tv_content);
bt_confirm=(Button) findViewById(R.id.bt_confirm);
}
private void setListeners(){
bt_confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(null!=mMediaPlayer){
mMediaPlayer.stop();
finish();
}
}
});
}
public void playSound() {
new Thread(new Runnable() {
@Override
public void run() {
mMediaPlayer = MediaPlayer.create(RemindActivity.this, getSystemDefultRingtoneUri());
mMediaPlayer.setLooping(true);//设置循环
try {
mMediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mMediaPlayer.start();
}
}).start();
}
//获取系统默认铃声的Uri
private Uri getSystemDefultRingtoneUri() {
return RingtoneManager.getActualDefaultRingtoneUri(RemindActivity.this,
RingtoneManager.TYPE_RINGTONE);
}
}
6、Service,动态注册接收时间变化的广播接收器和发起提醒的广播,并作出提醒处理
public class MainService extends Service {
TimeReceiver receiver;
RemindReceiver remindReceiver;
public MainService() {
}
@Override
public void onCreate() {
super.onCreate();
registeReceiver();
registeRemindReceiver();
}
private void registeRemindReceiver(){
IntentFilter filter = new IntentFilter();
filter.addAction(GlobalParams.START_REMIND_ACTIVITY_ACTION);
filter.setPriority(Integer.MAX_VALUE);
remindReceiver = new RemindReceiver();
registerReceiver(remindReceiver,filter);
}
private void registeReceiver(){
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.setPriority(Integer.MAX_VALUE);
receiver = new TimeReceiver();
registerReceiver(receiver,filter);
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
unregisterReceiver(remindReceiver);
}
public class RemindReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent data) {
String action=data.getAction();
if(null!=action){
switch (action){
case GlobalParams.START_REMIND_ACTIVITY_ACTION:
Intent intent=new Intent(context, RemindActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundle=new Bundle();
bundle.putString(GlobalParams.CONTENT_KEY,data.getExtras().getString(GlobalParams.CONTENT_KEY));
intent.putExtras(bundle);
startActivity(intent);
break;
}
}
}
}
}
7、接收时间变化的广播接收器,接收时间变化的通知,并读取数据库中的数据,与当前时间比对,若时间一致,发送提醒广播
public class TimeReceiver extends BroadcastReceiver {
private List<NotepadWithDataBean> notepadWithDataBeanList;
private final String PARENT_POSITION_KEY="parentPosition";
private final String ITEM_POSITION_KEY="item_position_key";
private final int START_REMIND=1;
private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
this.mContext=context;
if(Intent.ACTION_TIME_TICK.equals(intent.getAction())){
getData();
for(int i=0;i<notepadWithDataBeanList.size();i++) {
NotepadWithDataBean notepadWithDataBean = notepadWithDataBeanList.get(i);
if (notepadWithDataBean.getData() == getDate()) {
List<NotepadBean> notepadBeenList = notepadWithDataBeanList.get(i).getNotepadBeenList();
for (int j = 0; j < notepadBeenList.size(); j++) {
if(getTime().equals(notepadBeenList.get(j).getTime())){
Message message=new Message();
message.what=START_REMIND;
Bundle bundle=new Bundle();
bundle.putInt(PARENT_POSITION_KEY,i);
bundle.putInt(ITEM_POSITION_KEY,j);
message.setData(bundle);
handler.sendMessage(message);
}
}
}else{
continue;
}
}
}
}
Handler handler=new Handler(){
public void handleMessage(Message message){
switch (message.what){
case START_REMIND:
Bundle bundle=message.getData();
int parentPosition=bundle.getInt(PARENT_POSITION_KEY);
int itemPosition=bundle.getInt(ITEM_POSITION_KEY);
gotoRemindActivity(parentPosition,itemPosition);
break;
}
}
};
private void gotoRemindActivity(int parentPosition,int itemPosition){
Intent intent=new Intent();
Bundle bundle=new Bundle();
bundle.putString(GlobalParams.CONTENT_KEY,notepadWithDataBeanList.get(parentPosition).getNotepadBeenList().get(itemPosition).getContent());
intent.putExtras(bundle);
intent.setAction(GlobalParams.START_REMIND_ACTIVITY_ACTION);
mContext.sendBroadcast(intent);
}
private void getData(){
DataHelper helper = new DataHelper(mContext);
notepadWithDataBeanList = new ArrayList<NotepadWithDataBean>();
List<NotepadBean> notepadBeanList = helper.getNotepadList();
for (int i = 0; i < notepadBeanList.size(); i++) {
if (0 == notepadWithDataBeanList.size()) {
NotepadWithDataBean notepadWithDataBean = new NotepadWithDataBean();
notepadWithDataBean.setData(notepadBeanList.get(0).getDate());
notepadWithDataBeanList.add(notepadWithDataBean);
}
boolean flag = true;
for (int j = 0; j < notepadWithDataBeanList.size(); j++) {
int date = notepadWithDataBeanList.get(j).getData();
if (date == notepadBeanList.get(i).getDate()) {
notepadWithDataBeanList.get(j).getNotepadBeenList().add(notepadBeanList.get(i));
flag = false;
break;
}
}
if (flag) {
NotepadWithDataBean notepadWithDataBean = new NotepadWithDataBean();
notepadWithDataBean.setData(notepadBeanList.get(i).getDate());
notepadWithDataBeanList.add(notepadWithDataBean);
notepadWithDataBeanList.get(notepadWithDataBeanList.size() - 1).getNotepadBeenList().add(notepadBeanList.get(i));
}
}
}
private String getTime(){
Calendar calendar=Calendar.getInstance();
int hourOfDay=calendar.get(Calendar.HOUR_OF_DAY);
int minute=calendar.get(Calendar.MINUTE);
String time = formatTime(hourOfDay,minute);
return time;
}
private int getDate(){
Calendar calendar=Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH);
int day=calendar.get(Calendar.DAY_OF_MONTH);
int date=Integer.parseInt(getDate(year,month,day));
return date;
}
private String getDate(int year,int month,int day){
String date="";
date+=year;
if(month<9){
date=date+"0"+(month+1);
}else{
date+=(month+1);
}
if(day<10){
date=date+"0"+day;
}else {
date+=day;
}
return date;
}
private String formatTime(int hour,int minute){
String time=hour+":";
if(minute<10){
time=time+"0"+minute;
}else{
time+=minute;
}
return time;
}
}
8、DataHelper.java
public class DataHelper {
MySQLiteOpenHelper helper = null;
public DataHelper(Context cxt) {
helper = new MySQLiteOpenHelper(cxt);
}
public DataHelper(Context cxt, int version) {
helper = new MySQLiteOpenHelper(cxt, version);
}
public void insertData(NotepadBean notepadBean) {
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(GlobalParams.DB_VALUE_DATE_KEY, notepadBean.getDate() + "");
cv.put(GlobalParams.DB_VALUE_TIME_KEY, notepadBean.getTime());
cv.put(GlobalParams.DB_VALUE_CONTENT_KEY, notepadBean.getContent());
db.insert(GlobalParams.DB_NAME, null, cv);
cv.clear();
db.close();
helper.close();
}
public List<NotepadBean> getNotepadList() {
List<NotepadBean> notepadBeanList = new ArrayList<NotepadBean>();
SQLiteDatabase db = helper.getReadableDatabase();
Cursor c = db.rawQuery("SELECT * FROM " + GlobalParams.DB_NAME + " order by " + GlobalParams.DB_VALUE_DATE_KEY, null);
while (c.moveToNext()) {
NotepadBean notepadBean = new NotepadBean();
notepadBean.setId(c.getInt(c.getColumnIndex(GlobalParams.DB_VALUE_ID_KEY)));
notepadBean.setDate(c.getInt(c.getColumnIndex(GlobalParams.DB_VALUE_DATE_KEY)));
notepadBean.setTime(c.getString(c.getColumnIndex(GlobalParams.DB_VALUE_TIME_KEY)));
notepadBean.setContent(c.getString(c.getColumnIndex(GlobalParams.DB_VALUE_CONTENT_KEY)));
notepadBeanList.add(notepadBean);
}
c.close();
db.close();
helper.close();
return notepadBeanList;
}
public void deleteNotepad(int id) {
SQLiteDatabase db = helper.getWritableDatabase();
db.delete(GlobalParams.DB_NAME, GlobalParams.DB_VALUE_ID_KEY + " = ?", new String[]{id + ""});
db.close();
helper.close();
}
public void update(int id, String date, String time, String content) {
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(GlobalParams.DB_VALUE_DATE_KEY, date);
cv.put(GlobalParams.DB_VALUE_TIME_KEY, time);
cv.put(GlobalParams.DB_VALUE_CONTENT_KEY, content);
db.update(GlobalParams.DB_NAME, cv, GlobalParams.DB_VALUE_ID_KEY + " = ?", new String[]{id + ""});
cv.clear();
db.close();
helper.close();
}
}
9、MySQLiteOpenHelper.java
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
private final static String DB_NAME ="smart_notepad.db";
private final static int VERSION = 1;//版本号
public MySQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
int version) {
super(context, name, factory, version);
}
public MySQLiteOpenHelper(Context cxt){
this(cxt, DB_NAME, null, VERSION);
}
public MySQLiteOpenHelper(Context cxt,int version) {
this(cxt,DB_NAME,null,version);
}
public void onCreate(SQLiteDatabase db) {
String sql = "create table "+ GlobalParams.DB_NAME+" ( " +GlobalParams.DB_VALUE_ID_KEY+
" integer primary key autoincrement, " +GlobalParams.DB_VALUE_DATE_KEY+" integer , "+
GlobalParams.DB_VALUE_TIME_KEY+" varchar(20) , "+
GlobalParams.DB_VALUE_CONTENT_KEY+" text )";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
10、NotepadBean类
public class NotepadBean implements Serializable{
private int id;
private int date;
private String time;
private String content;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getDate() {
return date;
}
public void setDate(int date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
11、NotepadWithDataBean类
public class NotepadWithDataBean implements Serializable{
private int data;
private List<NotepadBean> notepadBeenList;
public NotepadWithDataBean(){
notepadBeenList=new ArrayList<NotepadBean>();
}
public int getData() {
return data;
}
public void setData(int data) {
this.data = data;
}
public List<NotepadBean> getNotepadBeenList() {
return notepadBeenList;
}
public void setNotepadBeenList(List<NotepadBean> notepadBeenList) {
this.notepadBeenList = notepadBeenList;
}
}
12、GlobalParams 参数
public class GlobalParams {
public static final String START_PHONE_ACTION="android.intent.action.BOOT_COMPLETED";
public static final String DB_NAME="smart_notepad";
public static final String DB_VALUE_ID_KEY="id";
public static final String DB_VALUE_CONTENT_KEY="content";
public static final String DB_VALUE_DATE_KEY="date";
public static final String DB_VALUE_TIME_KEY="time";
public static final int ADD_RESULT_OK=1;
public static final int ADD_REQUEST=1;
public static final String BEAN_KEY="bean_key";
public static final String TYPE_KEY="type_key";
public static final int TYPE_ADD=1;
public static final int TYPE_EDIT=2;
public static final String PARENT_POSITION_KEY="parent_position_key";
public static final String ITEM_POSITION_KEY="item_position_key";
public static final String CONTENT_KEY="content_key";
public static final String START_REMIND_ACTIVITY_ACTION="start_remind_activity_actioin";
}
13、activity_add_content.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_add_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="gcp.com.smartnotepad.activity.AddContentActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/title_color"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="取消"
android:textColor="@color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="18sp"
android:layout_centerInParent="true"
android:text="智能记事本"/>
<TextView
android:id="@+id/tv_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="保存"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="今天"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" -- "/>
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="请选择时间"
/>
</LinearLayout>
<EditText
android:id="@+id/et_content"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:gravity="left|top"
android:layout_margin="20dp"
android:padding="10dp"
android:hint="请输入内容"
android:background="@drawable/edit_back"/>
</LinearLayout>
14、activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="gcp.com.smartnotepad.activity.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/title_color"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="18sp"
android:layout_centerInParent="true"
android:text="智能记事本"/>
<TextView
android:id="@+id/tv_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:text="新增"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="13sp"/>
</RelativeLayout>
<ListView
android:id="@+id/lv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
15、activity_remind.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
tools:context="gcp.com.smartnotepad.activity.RemindActivity">
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<Button
android:id="@+id/bt_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="取消" />
</LinearLayout>
16、view_notepad.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/tv_date"
android:paddingLeft="10dp"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/main_back"
/>
<ListView
android:id="@+id/lv_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"></ListView>
</LinearLayout>
17、view_notepad_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="@color/white">
<TextView
android:id="@+id/tv_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/tv_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"/>
</LinearLayout>