package com.note;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.DatePickerDialog;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;
import android.widget.Toast;
public class ActivityMain extends Activity {
private EditText etName;
private EditText etMain, etTime;
private Button btnCommit;
private Button btnCancel;
private SQLiteDatabase sdb;
private ActivityManager am;
private int year, month, day, hours, minute, second;
private Calendar c;
private PendingIntent pi;
private AlarmManager alm;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
am = ActivityManager.getInstance();
am.addActivity(this);
etName = (EditText) findViewById(R.id.noteName);
etMain = (EditText) findViewById(R.id.noteMain);
btnCommit = (Button) findViewById(R.id.btnCommit);
btnCancel = (Button) findViewById(R.id.btnCancel);
etTime = (EditText) findViewById(R.id.noteTime);
SqliteDBConnect sd = new SqliteDBConnect(ActivityMain.this);
sdb = sd.getReadableDatabase();
etTime.setText(am.returnTime());
// etTime.setEnabled(false);
etTime.setTextColor(Color.RED);
etTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
hours = c.get(Calendar.HOUR);
minute = c.get(Calendar.MINUTE);
second = c.get(Calendar.SECOND);
DatePickerDialog dpd = new DatePickerDialog(ActivityMain.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int y,
int monthOfYear, int dayOfMonth) {
String[] time = { "",
hours + ":" + minute + ":" + second };
try {
String[] time2 = etTime.getText()
.toString().trim().split(" ");
if (time2.length == 2) {
time[1] = time2[1];
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String mo = "", da = "";
if (monthOfYear < 10) {
mo = "0" + (monthOfYear + 1);
} else {
mo = monthOfYear + "";
}
if (dayOfMonth < 10) {
da = "0" + dayOfMonth;
} else {
da = dayOfMonth + "";
}
etTime.setText(y + "-" + mo + "-" + da + " "
+ time[1]);
}
}, year, month, day);
dpd.setTitle("设置日期");
dpd.show();
}
});
etTime.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
hours = c.get(Calendar.HOUR);
minute = c.get(Calendar.MINUTE);
second = c.get(Calendar.SECOND);
TimePickerDialog tpd = new TimePickerDialog(ActivityMain.this,
new OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view,
int hourOfDay, int minute) {
String[] time = {
year + "-" + month + "-" + day, "" };
try {
time = etTime.getText().toString().trim()
.split(" ");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String ho = "", mi = "";
if (hourOfDay < 10) {
ho = "0" + hourOfDay;
} else {
ho = hourOfDay + "";
}
if (minute < 10) {
mi = "0" + minute;
} else {
mi = minute + "";
}
etTime.setText(time[0] + " " + ho + ":" + mi);
}
}, hours, minute, true);
tpd.setTitle("设置时间");
tpd.show();
return true;
}
});
btnCommit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int n = testTime();
if (n == 0) {
return;
}
AlertDialog.Builder adb = new Builder(ActivityMain.this);
adb.setTitle("保存");
adb.setMessage("Are you sure to Save?");
adb.setPositiveButton("保存",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
baocunNote();
}
});
adb.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Toast.makeText(ActivityMain.this, "Don't Save",
Toast.LENGTH_SHORT).show();
}
});
adb.show();
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder adb = new Builder(ActivityMain.this);
adb.setTitle("提示");
adb.setMessage("Are you sure don't Save?");
adb.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Intent intent = new Intent();
intent.setClass(ActivityMain.this,
MainShow.class);
startActivity(intent);
}
});
adb.setNegativeButton("取消", null);
adb.show();
}
});
etName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (etName.getText().toString().trim().equals("请输入记事名称")) {
etName.setText("");
}
}
});
etName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if ("".equals(etName.getText().toString().trim())) {
etName.setText(R.string.etnameinit);
}
}
});
etMain.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (etMain.getText().toString().trim().equals("请输入记事内容")) {
etMain.setText("");
}
}
});
etMain.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if ("".equals(etMain.getText().toString().trim())) {
etMain.setText(R.string.etmaininit);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 1, 1, "关于");
menu.add(0, 2, 2, "设置闹铃声");
menu.add(0, 3, 3, "退出");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case 1:
AlertDialog.Builder adb = new Builder(ActivityMain.this);
adb.setTitle("关于我们");
adb.setMessage("湖南工业大学\n\t Android团队制作");
adb.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(ActivityMain.this, "Thanks",
Toast.LENGTH_SHORT).show();
}
});
adb.show();
break;
case 2:
Intent intent = new Intent();
intent.setClass(ActivityMain.this, SetAl
- 1
- 2
- 3
- 4
- 5
- 6
前往页