package com.example.clock;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
public class ClockDemo extends Activity {
private Button mSet;
Calendar mCalendar = Calendar.getInstance();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ObjectPool.mAlarmHelper = new AlarmHelper(this);
mSet = (Button) findViewById(R.id.mSet);
setListener();
}
public void setListener() {
mSet.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mCalendar.setTimeInMillis(System.currentTimeMillis());
int mHour = mCalendar.get(Calendar.HOUR_OF_DAY);
int mMinute = mCalendar.get(Calendar.MINUTE);
new TimePickerDialog(ClockDemo.this,
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view,
int hourOfDay, int minute) {
mCalendar.setTimeInMillis(System
.currentTimeMillis());
mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
mCalendar.set(Calendar.MINUTE, minute);
mCalendar.set(Calendar.SECOND, 0);
mCalendar.set(Calendar.MILLISECOND, 0);
ObjectPool.mAlarmHelper.openAlarm(32, "ddd",
"ffff", mCalendar.getTimeInMillis());
}
}, mHour, mMinute, true).show();
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
showBackDialog();
return true;
}
return super.onKeyDown(keyCode, event);
}
/** Give the tip when exit the application. */
public void showBackDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("提示")
.setIcon(R.drawable.icon)
.setMessage("是否退出?")
.setPositiveButton("sure",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
System.exit(0);
android.os.Process
.killProcess(android.os.Process.myPid());
dialog.dismiss();
}
})
.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
AlertDialog ad = builder.create();
ad.show();
}
}
package com.example.clock;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
public class AlarmHelper {
private Context c;
private AlarmManager mAlarmManager;
public AlarmHelper(Context c) {
this.c = c;
mAlarmManager = (AlarmManager) c
.getSystemService(Context.ALARM_SERVICE);
}
public void openAlarm(int id, String title, String content, long time) {
Intent intent = new Intent();
intent.putExtra("_id", id);
intent.putExtra("title", title);
intent.putExtra("content", content);
intent.setClass(c, CallAlarm.class);
PendingIntent pi = PendingIntent.getBroadcast(c, id, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, time, pi);
}
public void closeAlarm(int id, String title, String content) {
Intent intent = new Intent();
intent.putExtra("_id", id);
intent.putExtra("title", title);
intent.putExtra("content", content);
intent.setClass(c, CallAlarm.class);
PendingIntent pi = PendingIntent.getBroadcast(c, id, intent, 0);
mAlarmManager.cancel(pi);
}
}
package com.example.clock;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class CallAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
intent.setClass(context, AlarmAlert.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
package com.example.clock;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
public class AlarmAlert extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new AlertDialog.Builder(AlarmAlert.this)
.setIcon(R.drawable.clock)
.setTitle("ddd")
.setMessage("fff")
.setPositiveButton("ddd",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
System.exit(0);
android.os.Process
.killProcess(android.os.Process.myPid());
}
}).show();
}
}
ObjectPool.java
public class ObjectPool {
/** The alarm object. */
public static AlarmHelper mAlarmHelper;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有