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();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android 简单代码实现的Android 计算器源码.zip项目安卓应用源码下载Android 简单代码实现的Android 计算器源码.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android 简单代码实现的Android 计算器源码.zip (44个子文件)
Android 简单代码实现的Android 计算器源码
Android 简单代码实现的Android 计算器源码
2-1210191551480-L.jpg 25KB
简单代码实现的Android 计算器源码
.project 813B
bin
TimingDial.apk 20KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
icon.png 3KB
drawable-mdpi
ic_launcher.png 2KB
resources.ap_ 12KB
classes
com
zhuyan
TimingDialActivity.class 4KB
R$string.class 470B
R$layout.class 458B
TimingDialActivity$2.class 2KB
TimingDialActivity$2$1.class 4KB
R$drawable.class 411B
R.class 475B
model
Person.class 835B
TimingDialActivity$1.class 1KB
adapter
DialogListViewAdapter.class 4KB
DialogListViewAdapter$ViewHolder.class 485B
R$attr.class 316B
dialog
LongClickDialog.class 2KB
LongClickDialog$1.class 2KB
service
TimingDialService.class 477B
R$id.class 575B
TimingDialActivity$3.class 2KB
broadcast
AlarmReceiver.class 3KB
classes.dex 14KB
proguard.cfg 1KB
AndroidManifest.xml 1KB
src
com
zhuyan
model
Person.java 537B
adapter
DialogListViewAdapter.java 3KB
TimingDialActivity.java 5KB
dialog
LongClickDialog.java 1KB
service
TimingDialService.java 273B
broadcast
AlarmReceiver.java 2KB
project.properties 376B
res
values
strings.xml 263B
layout
dialog_listview_item.xml 877B
main.xml 1KB
dialog_listview_view.xml 272B
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
icon.png 3KB
drawable-mdpi
ic_launcher.png 3KB
.classpath 356B
gen
com
zhuyan
R.java 1KB
assets
共 44 条
- 1
资源评论
- 2201_754107202022-12-23资源有很好的参考价值,总算找到了自己需要的资源啦。
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功