找传奇、传世资源到传世资源站!

android 闹铃(响铃、震动)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboard
from clipboard package com.pf.testalarm;import android.os.Handler;import android.os.Message;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.EditText;import android.widget.Toast;import java.lang.ref.SoftReference;public class MainActivity extends AppCompatActivity implements View.OnClickListener { private EditText etNumber; private CheckBox cbIsloop; private Button btnClock; private Button btnCancleClock; private static SoftReference<Handler> handlerSoftReference; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etNumber = findViewById(R.id.et_number); cbIsloop = findViewById(R.id.cb_isloop); btnClock = findViewById(R.id.btn_clock); btnCancleClock = findViewById(R.id.btn_cancle_clock); btnClock.setOnClickListener(this); btnCancleClock.setOnClickListener(this); handlerSoftReference = new SoftReference<Handler>(new MHandler()); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_clock: String etContent = etNumber.getText().toString(); if (TextUtils.isEmpty(etContent)) { Toast.makeText(this, "请输入时间间隔", Toast.LENGTH_SHORT).show(); return; } int number = Integer.valueOf(etContent); boolean checked = cbIsloop.isChecked(); AlarmHelper.startAlarm(this, number, checked); break; case R.id.btn_cancle_clock: AlarmHelper.cancenAlarm(); break; default: break; } } private class MHandler extends Handler { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (null == msg) { return; } int what = msg.what; if (what == AlarmDialogUtil.DialogUtil_FLAG) { // 显示弹框 AlarmDialogUtil.showDialog(MainActivity.this); // 震动 AlarmVibrateUtil.vibrate(MainActivity.this, new long[]{500, 500}, 0); // 铃声 AlarmMediaPlayer.playing(MainActivity.this); } } } public static SoftReference<Handler> getHandlerSoftReference() { return handlerSoftReference; }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复