代码注释

LSL
Sally-Liao 2 years ago
parent 4772fdfd29
commit 7a6767218e

@ -41,57 +41,59 @@ import java.io.IOException;
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
private long mNoteId;
private String mSnippet;
private long mNoteId; //文本再数据库存储中的id号
private String mSnippet; //闹钟提醒时的文字
private static final int SNIPPET_PREW_MAX_LEN = 60;
MediaPlayer mPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_NO_TITLE); //界面显示无标题
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if (!isScreenOn()) {
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
if (!isScreenOn()) { //锁屏后到了提示时间点亮屏幕,
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕亮着
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON //点亮屏幕
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON //允许点亮时锁屏
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
}
Intent intent = getIntent();
try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));//获取ID
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);//根据ID获取标签的内容利用getContentResolver()可以得到当前应用的实例
/*判断标签是否达到符合的长度*/
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
: mSnippet;
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) { //处理异常,显示异常信息
e.printStackTrace();
return;
}
mPlayer = new MediaPlayer();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog();
playAlarmSound();
showActionDialog(); //弹出对话框
playAlarmSound(); //响起提示音
} else {
finish();
finish(); //完成闹钟
}
}
private boolean isScreenOn() {
private boolean isScreenOn() { //判断是否锁屏
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
private void playAlarmSound() {
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
private void playAlarmSound() { //响起提示音
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM); //获取系统默认铃声
int silentModeStreams = Settings.System.getInt(getContentResolver(),
int silentModeStreams = Settings.System.getInt(getContentResolver(), //通过settings这个类来获取数据库中的数据
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
@ -100,20 +102,20 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
}
try {
mPlayer.setDataSource(this, url);
mPlayer.prepare();
mPlayer.setLooping(true);
mPlayer.start();
} catch (IllegalArgumentException e) {
mPlayer.setDataSource(this, url); //设置数据来源url
mPlayer.prepare(); //准备同步
mPlayer.setLooping(true); //设置循环播放
mPlayer.start(); //开始播放
} catch (IllegalArgumentException e) { //传递了一个不合法或不正确的参数时出现异常
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
} catch (SecurityException e) { //程序使用不当存在某些危险的操作引发安全问题
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
} catch (IllegalStateException e) { //在不合理或不正确时间内唤醒一方法时出现异常
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
} catch (IOException e) { //文件读取异常
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -121,37 +123,39 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
private void showActionDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.app_name);
dialog.setMessage(mSnippet);
dialog.setPositiveButton(R.string.notealert_ok, this);
dialog.setTitle(R.string.app_name); //对话框设置标题
dialog.setMessage(mSnippet); //对话框设置内容
dialog.setPositiveButton(R.string.notealert_ok, this); //设置确定按钮
if (isScreenOn()) {
dialog.setNegativeButton(R.string.notealert_enter, this);
dialog.setNegativeButton(R.string.notealert_enter, this); //设置取消按钮
}
dialog.show().setOnDismissListener(this);
}
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE:
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, mNoteId);
startActivity(intent);
switch (which) { //选择下一步的操作
case DialogInterface.BUTTON_NEGATIVE: //取消
/*实现两个类的跳转*/
Intent intent = new Intent(this, NoteEditActivity.class); //创建intent对象
intent.setAction(Intent.ACTION_VIEW); //调用隐式intent调用
intent.putExtra(Intent.EXTRA_UID, mNoteId); //Intent.EXTRA_UID为键名mNoteId为键对应的值把想要传递的数据暂存在intent中当另一个活动启动后再把这些数据从intent缓存中取出
startActivity(intent); //开始跳转
break;
default:
break;
break; //确定
}
}
public void onDismiss(DialogInterface dialog) {
stopAlarmSound();
finish();
stopAlarmSound(); //停止闹钟声音
finish(); //完成动作
}
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
mPlayer.stop(); //停止播放
mPlayer.release(); //释放对象
mPlayer = null;
}
}

Loading…
Cancel
Save