// 从设置闹钟周期Activity返回的数据 protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE && resultCode == WeekRepeatActivity.RESULT_CODE) { param.setRepeat(data.getBooleanArrayExtra("repeat")); clockCircleButton.setText("闹钟周期:" + param.getRepeatInfo(param.getRepeat())); } if (requestCode == REQUEST_CODE && resultCode == SelectMusicActivity.RESULT_CODE) { String path = data.getExtras().getString("path"); param.setAudiotype(path); String[] name = path.split("/"); System.out.println("return ring" + path + " name " + name[name.length - 1]); musicButton.setText("铃声:" + name[name.length - 1]); } }
// 初始化各个按钮的文本信息 void initButtonText() { timeButton.setText( "闹钟时间: " + param.getHour() + ":" + (param.getMinute() > 9 ? param.getMinute() : ("0" + param.getMinute()))); clockNameButton.setText("闹钟名称: " + param.getName()); clockCircleButton.setText("闹钟周期: " + param.getRepeatInfo(param.getRepeat())); levelButton.setText("闹钟难度: " + (param.getLevel() == 1 ? "简单-加法" : "困难-乘法")); vibrateButton.setText(param.isIsvabrate() ? "震动: 开启" : "震动: 关闭"); String s = param.getAudiotype(); System.out.println("getAudiotype:" + s); if (s.equals("default")) s = "默认"; else { String[] name = s.split("/"); s = name[name.length - 1]; } musicButton.setText("铃声: " + s); }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.ring_time: // 修改闹钟时间 showDialog(TIME_PICKER_ID); break; case R.id.save: // 保存闹钟 callBack(true); finish(); break; case R.id.delete_clock: // 删除闹钟,弹出确认对话框 showDeleteDialog(); break; case R.id.clock_model: showLevelDialog(); // 选择题目的困难度 break; case R.id.clock_tag: // 修改闹钟名称 showClockTagDialog(); break; case R.id.clock_sound: // 选择闹钟铃声 selectMusic(); break; case R.id.clock_repeat: // 设置闹钟重复日期 setRepeatDay(); break; case R.id.vibrate: // 开启或者关闭闹钟的震动功能 if (param.isIsvabrate()) // 处于开启状态,转换为关闭 { vibrateButton.setText("震动: 关闭"); param.setIsvabrate(false); } else // 处于关闭状态,转换为开启 { vibrateButton.setText("震动: 开启"); param.setIsvabrate(true); } break; } }
// 难度等级选择 Dialog void showLevelDialog() { new AlertDialog.Builder(this) .setTitle("请选择难度") .setIcon(android.R.drawable.ic_dialog_info) .setSingleChoiceItems( new String[] {"简单:加法", "困难:乘法"}, param.getLevel() - 1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { param.setLevel(which + 1); levelButton.setText("闹钟难度: " + ((which + 1) == 1 ? "简单-加法" : "困难-乘法")); dialog.dismiss(); } }) .setNegativeButton("取消", null) .show(); }
// 选择闹钟铃声的Dialog,若选择默认 则设置为软件默认铃声 // 选择自定义的话,弹出SD卡的文件列表(调用SelectMusicActivity),从中选择符合格式的作为铃声 void selectMusic() { int index = param.getAudiotype().equals("default") ? 0 : 1; new AlertDialog.Builder(this) .setTitle(" 选择闹铃铃声 ") .setIcon(android.R.drawable.ic_dialog_info) .setSingleChoiceItems( new String[] {"默认铃声", "自定义铃声"}, index, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == 0) { param.setAudiotype("default"); musicButton.setText("铃声: 默认"); } else { Intent intent = new Intent(EditClockActivity.this, SelectMusicActivity.class); startActivityForResult(intent, REQUEST_CODE); } dialog.dismiss(); } }) .setNegativeButton("取消", null) .show(); }
// 时间选择框被调用时响应,初始化默认时间为闹钟当前的时间 protected Dialog onCreateDialog(int id) { return new TimePickerDialog(this, onTimeListener, param.getHour(), param.getMinute(), false); }
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { param.setHour(hourOfDay); param.setMinute(minute); timeButton.setText("闹钟时间:" + hourOfDay + ":" + (minute > 9 ? minute : ("0" + minute))); }
// 设置闹钟重复周期 周一到周末 void setRepeatDay() { Intent intent = new Intent(EditClockActivity.this, WeekRepeatActivity.class); intent.putExtra("repeat", param.getRepeat()); startActivityForResult(intent, REQUEST_CODE); }