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();
}
}
荣华富贵8
- 粉丝: 222
- 资源: 7653
最新资源
- 基于移动平台的远程在线诊疗系统+ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 基于微信小程序的跳蚤市场设计与实现ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 基于微信小程序的影院选座系统+ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 基于微信小程序的水果销售系统的设计与实现springboot-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- COMSOL光学模型:一维光子晶体nanobeam三维模型仿真(包含场分布,透射光谱)
- 家具购物小程序+php-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 计算机实验室排课与查询系统+ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 家庭财务管理系统的设计与实现+ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 基于微信小程序的小说阅读系统ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 基于微信小程序的外卖点餐系统设计与实现ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 基于微信小程序的网约巴士订票平台的设计与实现ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 家庭事务管理微信小程序+ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 家庭大厨微信小程序+ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 家政服务管理系统+ssm-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.rar
- 基于微信小程序的校园兼职系统-微信小程序毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 汇川MD500E变频器开发方案 源码+解析+控制板原理图, MD500E代码方案和解析文档+原理图+送仿真资料 资料全 包含pmsm的foc控制算法,电阻、电感、磁链等参数的辩识算法,死
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈