Android灯光系统通知灯【转】
本文转载自:https://blog.csdn.net/danwuxie/article/details/82193880
一、通知灯应用程序的编写
1、首先实现一个按钮功能
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flashing Light at 20S"
android:id="@+id/button"
/>
</LinearLayout>
2、实现按钮的点击监听
mLightButton = (Button)findViewById(R.id.button);
mLightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
flashing = !flashing;
if (flashing){
mLightButton.setText("Stop Flashing the Light");
}else {
mLightButton.setText("Flashing Light at 20S");
}
mLightHander.postDelayed(mLightRunnable, 20000);
}
});
3、实现延时
private Handler mLightHander = new Handler();
private LightRunnable mLightRunnable = new LightRunnable();
class LightRunnable implements Runnable {
@Override
public void run() {
if (flashing) {
FlashingLight();
} else {
ClearLED();
}
}
}
mLightHander.postDelayed(mLightRunnable, 20000);
4、实现通知
private void FlashingLight()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
Notification notif = new Notification();
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledARGB = 0xFF0000ff;
notif.ledOnMS = 100;
notif.ledOffMS = 100;
nm.notify(LED_NOTIFICATION_ID, notif);
}
5、取消通知
private void ClearLED()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
nm.cancel(LED_NOTIFICATION_ID);
}
6、实现点击延时
mLightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
flashing = !flashing;
if (flashing){
mLightButton.setText("Stop Flashing the Light");
}else {
mLightButton.setText("Flashing Light at 20S");
}
mLightHander.postDelayed(mLightRunnable, 20000);
}
});
二、测试
用法:
1. 先在单板上"Setting"->"Display"->"Sleep"设为"15S"
2. 运行程序
3. 点击按钮后不再操作
4. 等屏幕再次变黑即可看到通知灯闪烁
注意:黑屏期间可以通过menu键或K1键返回程序界面
三、程序
package com.thisway.app_0002_lightdemo;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.app.NotificationManager;
import android.app.Notification;
import android.view.View;
public class MainActivity extends AppCompatActivity {
private Button mLightButton = null;
boolean flashing = false;
final private int LED_NOTIFICATION_ID = 123;
private Handler mLightHander = new Handler();
private LightRunnable mLightRunnable = new LightRunnable();
class LightRunnable implements Runnable {
@Override
public void run() {
if (flashing) {
FlashingLight();
} else {
ClearLED();
}
}
}
private void FlashingLight()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
Notification notif = new Notification();
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledARGB = 0xFF0000ff;
notif.ledOnMS = 100;
notif.ledOffMS = 100;
nm.notify(LED_NOTIFICATION_ID, notif);
}
private void ClearLED()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
nm.cancel(LED_NOTIFICATION_ID);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLightButton = (Button)findViewById(R.id.button);
mLightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
flashing = !flashing;
if (flashing){
mLightButton.setText("Stop Flashing the Light");
}else {
mLightButton.setText("Flashing Light at 20S");
}
mLightHander.postDelayed(mLightRunnable, 20000);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flashing Light at 20S"
android:id="@+id/button" />
</LinearLayout>
Android灯光系统通知灯【转】的更多相关文章
- Android灯光系统--通知灯深入分析【转】
本文转自:https://www.cnblogs.com/lkq1220/p/6406261.html Android灯光系统--通知灯深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 ...
- Android灯光系统--通知灯深入分析
Android灯光系统--通知灯深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 getSystemService(获得通知服务) 构造notification 类别 其他参数(颜色, ...
- Android · 广告走灯
layout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:and ...
- 013 Android 实现流水灯功能+自定义控件的样式(可以复用)
1.介绍 (1)获取屏幕的焦点 android:focusable与android:focusableInTouchMode(获取屏幕焦点) 前者针对在键盘下操作的情况,如果设置为true,则键盘上下 ...
- Android系统之灯光系统--通知灯深入分析
Android通知灯的深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 getSystemService(通知服务) 构造notification 类别 其他参数(颜色,onMS,of ...
- Android开发-之认识palette
Android开发中,Google工程师已经给我们封装好了很多的按钮,使得我们在开发中非常的方便和便捷. 那么今天就来认识一下常用的按钮,那么在之前的课程中我已经详细讲过了Button按钮,那么这里就 ...
- Android仿微信UI布局视图(圆角布局的实现)
圆角button.或布局能够在xml文件里实现,但也能够使用图片直接达到所需的效果,曾经版本号的微信就使用了这样的方法. 实现效果图: watermark/2/text/aHR0cDovL2Js ...
- android客服端+eps8266+单片机+路由器之远程控制系统
用android客服端+eps8266+单片机+路由器做了一个远程控制的系统,因为自己是在实验室里,所以把实验室的门,灯做成了远程控制的. 控制距离有多远------只能说很远很远,只要你手机能上网的 ...
- Android Environment 获取各种路径的方法
<pre name="code" class="java">package com.deepoon.beyond.environment; impo ...
随机推荐
- sqlserver 用一个表的值 更新另一个表
update cas set cas.DocumentHeaderIdOfTransferredForForm = apply.Id from dbo.CaseTransfer cas join db ...
- http与https区别
1.安全. 内容采用对称加密,身份认证.建立一个信息安全通道来保证数据传输的安全.采用对称加密算法,来加密真实传输的数据.采用非对称加密算法(公钥和私钥),来保证连接的安全性.防止内容被第三方冒充和篡 ...
- 【转】Loadrunder场景设计篇——添加windows Resource计数器和指标说明
转至:https://www.cnblogs.com/langhuagungun/p/8488270.html Loadrunder场景设计篇——添加windows Resource计数器和指标说明 ...
- Python 7 -- 文件存储数据
上一节总结了一个基本web应用的代码,这一节主要讲用户访问的数据记录在log文件中,并显示在页面上. 这节步骤: 按以下目录建好相应的文件夹及内容 webapp|----vsearch4web.py ...
- 网关绑定命令,解决arp攻击
一般家里的宽带都采用ADSL设备,通过固定IP地址接入Internet,但是经常会出现断网的现象,那么如何通过ARP命令绑定默认网关来解决这个问题呢? 工具/原料 ARP命令 CMD命令提示符 方法/ ...
- Linux服务器---邮件服务器dovecot
安装dovecot Dovecot是CentOS系统中著名的POP3/IMAP服务器实现.POP3/IMAP是从邮件服务器中读取邮件时使用的协议,POP3将邮件全部从服务器中拖取下来:IMAP则每次从 ...
- 关于mapreducer 读取hbase数据 存入mysql的实现过程
mapreducer编程模型是一种八股文的代码逻辑,就以用户行为分析求流存率的作为例子 1.map端来说:必须继承hadoop规定好的mapper类:在读取hbase数据时,已经有现成的接口 Tabl ...
- Django框架----Object Relational Mapping(ORM)
Django中的ORM Django项目使用MySQL数据库 1. 在Django项目的settings.py文件中,配置数据库连接信息: DATABASES = { "default&qu ...
- Linux 安装 mysql 数据库
1. 克隆虚拟机 2. 上传安装文件 1.上传文件 2.解压文件 tar -xvf 文件 3. 安装数据库 安装顺序: .debuginfo .shared .client .server 1. rp ...
- 怎样从外网访问内网IIS?
本地安装了一个IIS,只能在局域网内访问,怎样从外网也能访问到本地的IIS呢?本文将介绍具体的实现步骤. 准备工作 安装并启动IIS 默认安装的IIS端口是80. 实现步骤 下载并解压holer软件包 ...