|
|
|
@ -14,6 +14,7 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
@ -39,7 +40,6 @@ import net.micode.notes.tool.DataUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
|
|
|
|
|
private long mNoteId; //文本在数据库存储中的ID号
|
|
|
|
|
private String mSnippet; //闹钟提示时出现的文本片段
|
|
|
|
@ -93,7 +93,6 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
// 异常处理
|
|
|
|
|
}
|
|
|
|
|
代码区如果有错误,就会返回所写异常的处理。*/
|
|
|
|
|
|
|
|
|
|
mPlayer = new MediaPlayer();
|
|
|
|
|
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
|
|
|
|
|
showActionDialog();
|
|
|
|
@ -106,13 +105,16 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);//调用系统的铃声管理URI,得到闹钟提示音
|
|
|
|
|
private void playAlarmSound() {
|
|
|
|
|
//闹钟提示音激发
|
|
|
|
|
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
|
|
|
|
|
//调用系统的铃声管理URI,得到闹钟提示音
|
|
|
|
|
int silentModeStreams = Settings.System.getInt(getContentResolver(),
|
|
|
|
|
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
|
|
|
|
|
|
|
|
|
@ -124,7 +126,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
try {
|
|
|
|
|
mPlayer.setDataSource(this, url);
|
|
|
|
|
//方法:setDataSource(Context context, Uri uri)
|
|
|
|
|
//解释:无返回值,设置多媒体数据来源
|
|
|
|
|
//解释:无返回值,设置多媒体数据来源【根据 Uri】
|
|
|
|
|
mPlayer.prepare();
|
|
|
|
|
//准备同步
|
|
|
|
|
mPlayer.setLooping(true);
|
|
|
|
@ -134,11 +136,11 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
//e.printStackTrace()函数功能是抛出异常, 还将显示出更深的调用信息
|
|
|
|
|
//System.out.println(e),这个方法打印出异常,并且输出在哪里出现的异常
|
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
//e.printStackTrace()函数功能是抛出异常, 还将显示出更深的调用信息
|
|
|
|
|
//System.out.println(e),这个方法打印出异常,并且输出在哪里出现的异常
|
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -154,16 +156,15 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
//所以不能直接通过new一个AlertDialog来创建出一个AlertDialog。
|
|
|
|
|
//要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法
|
|
|
|
|
//如这里的dialog就是新建了一个AlertDialog
|
|
|
|
|
|
|
|
|
|
dialog.setTitle(R.string.app_name);
|
|
|
|
|
//对话框设置标题
|
|
|
|
|
//为对话框设置标题
|
|
|
|
|
dialog.setMessage(mSnippet);
|
|
|
|
|
//为对话框设置内容
|
|
|
|
|
dialog.setPositiveButton(R.string.notealert_ok, this);
|
|
|
|
|
//给对话框添加“Yes”按钮
|
|
|
|
|
//给对话框添加"Yes"按钮
|
|
|
|
|
if (isScreenOn()) {
|
|
|
|
|
dialog.setNegativeButton(R.string.notealert_enter, this);
|
|
|
|
|
}//对话框添加“No”按钮
|
|
|
|
|
}//对话框添加"No"按钮
|
|
|
|
|
dialog.show().setOnDismissListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -171,20 +172,25 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
switch (which) {
|
|
|
|
|
//用which来选择click后下一步的操作
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
|
//这是取消操作
|
|
|
|
|
Intent intent = new Intent(this, NoteEditActivity.class);
|
|
|
|
|
//实现类间传输
|
|
|
|
|
//实现两个类间的数据传输
|
|
|
|
|
intent.setAction(Intent.ACTION_VIEW);
|
|
|
|
|
//设置动作属性
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, mNoteId);
|
|
|
|
|
//实现key-value对
|
|
|
|
|
//EXTRA_UID为key;mNoteId为键
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
//开始动作
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
//这是确定操作
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
|
//忽略
|
|
|
|
|
stopAlarmSound();
|
|
|
|
|
//停止闹钟声音
|
|
|
|
|
finish();
|
|
|
|
@ -196,7 +202,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|
|
|
|
mPlayer.stop();
|
|
|
|
|
//停止播放
|
|
|
|
|
mPlayer.release();
|
|
|
|
|
//释放Player对象
|
|
|
|
|
//释放MediaPlayer对象
|
|
|
|
|
mPlayer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|