日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

android 通知灯 测试,Android灯光系统通知灯【转】

發布時間:2024/7/23 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 通知灯 测试,Android灯光系统通知灯【转】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

標簽:

一、通知燈應用程序的編寫

1、首先實現一個按鈕功能

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">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Flashing Light at 20S"

android:id="@+id/button"

/>

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);

}

}

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:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Flashing Light at 20S"

android:id="@+id/button" />

標簽:

來源: https://www.cnblogs.com/zzb-Dream-90Time/p/10199094.html

總結

以上是生活随笔為你收集整理的android 通知灯 测试,Android灯光系统通知灯【转】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。