Android 应用--->睡眠助手功能实现
Android 应用--->睡眠助手功能实现
这篇文章()上纪录了睡眠助手的UI的实现。现在纪录下睡眠助手功能的实现
这篇文章(睡眠助手" href="" target=_self>Android应用--->睡眠助手)的时间和开关设置是单独的按钮实现的,后来发现这样设计不合理,就把时间设置改成了只有在选中了开关设置的开之后才可以设置时间。整合代码如下:
print?
- //设置开关按钮事件监听
- class SetOnOffListener implements OnClickListener {
- AlertDialog singleDialog = null ;
- @Override
- public void onClick(View v) {
- final String[] strs = new String[]{"开","关"};
- singleDialog = new AlertDialog.Builder(HelperMain.this)
- .setTitle("设置开关")
- .setIcon(Android.R.drawable.ic_dialog_info)
- .setSingleChoiceItems(strs, 0,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if(strs[which].equals("开")) {
- helper = true ;
- setTime();
- //openHelper();
- } else if(strs[which].equals("关")){
- close();
- helper = false ;
- onOffShow.setText("关");
- Toast.makeText(HelperMain.this, "助手已关", Toast.LENGTH_SHORT).show();
- }
- singleDialog.dismiss();
- SharedPreferences uiState = getPreferences(0);
- SharedPreferences.Editor editor = uiState.edit();
- editor.putBoolean("on_off", helper);
- editor.commit();
- }
- })
- .create();
- singleDialog.show();
- }
- }
这里是时间的设置:
- public void setTime() {
- final Time t = new Time();
到这里就完成了开关,时间和回复内容的设置。
评论暂时关闭