package com.zhuyan;
import java.util.Calendar;
import com.zhuyan.broadcast.AlarmReceiver;
import com.zhuyan.dialog.LongClickDialog;
import android.util.Log;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
public class TimingDialActivity extends Activity {
/** Called when the activity is first created. */
private static final String TAG = "TimingDialActivity";
Button mButtonStart;
Button mButtonStop;
EditText interval;
EditText telPhoneEditText;
LongClickDialog dialog;
TextView mTextView;
Calendar calendar;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
calendar = Calendar.getInstance();
mTextView = (TextView) findViewById(R.id.phone_view);
mButtonStart = (Button) findViewById(R.id.set_time);
mButtonStop = (Button) findViewById(R.id.cancel_time);
interval = (EditText) findViewById(R.id.interval);
telPhoneEditText = (EditText) findViewById(R.id.tel_number);
dialog = new LongClickDialog(this, telPhoneEditText);
telPhoneEditText.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Log.i(TAG, "");
dialog.show();
return true;
}
});
mButtonStart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
calendar.setTimeInMillis(System.currentTimeMillis());
int mHour = calendar.get(Calendar.HOUR_OF_DAY);
int mMinute = calendar.get(Calendar.MINUTE);
new TimePickerDialog(TimingDialActivity.this,
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view,
int hourOfDay, int minute) {
calendar.setTimeInMillis(System
.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Intent intent = new Intent(
TimingDialActivity.this,
AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent
.getBroadcast(TimingDialActivity.this,
0, intent, 0);
AlarmManager am;
am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(),
pendingIntent);
String tmpS = telPhoneEditText.getText()
.toString()
+ "->"
+ format(hourOfDay)
+ ":" + format(minute);
int tempInterval = 0;
if (!interval.getText().toString().equals("")) {
tempInterval = Integer.valueOf(interval
.getText().toString());
}
SharedPreferences preference = getSharedPreferences(
"zhuyan", Context.MODE_PRIVATE);
Editor edit = preference.edit();
edit.putString("tel_phone", telPhoneEditText
.getText().toString());
edit.putString("info", mTextView.getText()
.toString());
if (tempInterval != 0) {
edit.putLong("time",
calendar.getTimeInMillis()
+ tempInterval * 60 * 1000);
tmpS += "//interval time is "
+ tempInterval + "minters";
}else{
edit.putLong("time",0);
}
edit.commit();
mTextView.setText(tmpS);
}
}, mHour, mMinute, true).show();
}
});
mButtonStop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(TimingDialActivity.this,
AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
TimingDialActivity.this, 0, intent, 0);
AlarmManager am;
am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.cancel(pendingIntent);
mTextView.setText("Cancelled");
}
});
}
/* ��ʽ���ַ�(7:3->07:03) */
private String format(int x) {
String s = "" + x;
if (s.length() == 1)
s = "0" + s;
return s;
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
SharedPreferences preference = getSharedPreferences("zhuyan",
Context.MODE_PRIVATE);
telPhoneEditText.setText(preference.getString("tel_phone", "10086"));
mTextView.setText(preference.getString("info", "demo"));
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
SharedPreferences preference = getSharedPreferences("zhuyan",
Context.MODE_PRIVATE);
Editor edit = preference.edit();
edit.putString("tel_phone", telPhoneEditText.getText().toString());
edit.putString("info", mTextView.getText().toString());
edit.commit();
}
}
yxkfw
- 粉丝: 82
- 资源: 2万+
最新资源
- 基于java+ssm+mysql+微信小程序的食堂校园预约就餐小程序 源码+数据库+论文(高分毕业设计).zip
- 基于java+ssm+mysql+微信小程序的食堂线上订餐小程序 源码+数据库+论文(高分毕业设计).zip
- springboot-vue-民谣网站的设计与实现-源码工程-29页从零开始全套图文详解-32页设计论文-21页答辩ppt-全套开发环境工具、文档模板、电子教程、视频教学资源分享
- 基于python编写的视频合成代码
- T型三电平并网逆变器Matlab Simulink仿真模型,采用双闭环控制策略,并网电流外环,电容电流有源阻尼内环,电流波形质量完美, THD不到2%,采用三电平SVPWM算法,大扇区小扇区判断 报
- 河南地下粮仓工艺与设备设计
- 基于java+ssm+mysql+微信小程序的童装购买平台 源码+数据库+论文(高分毕业设计).zip
- 基于java+ssm+mysql+微信小程序的投票评选系统 源码+数据库+论文(高分毕业设计).zip
- 基于java+ssm+mysql+微信小程序的外卖点餐系统 源码+数据库+论文(高分毕业设计).zip
- Javascript数据类型转换规则电脑资料
- 基于java+ssm+mysql+微信小程序的微信评分小程序 源码+数据库+论文(高分毕业设计).zip
- 梯形图转HEX 51plc方案5.6.4.2版本,低成本plc方案,支持温湿度传感器,支持ds18b20.,支持无线联网,支持数码管按钮,最近发现软件在个别系统运行不良,(w764位95%可以用)
- java程序员辞职报告
- 多状态挠曲电结构电性能不确定性分析与仿真
- 微信小程序源码-大学生闲置物品交易平台的分析与设计-微信端-毕业设计源码-期末大作业.zip
- 微信小程序源码-大学生心理健康服务-微信端-毕业设计源码-期末大作业.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈