⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statusbarnotifications.java

📁 android 模拟器
💻 JAVA
字号:
/*  * Copyright (C) 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.android.samples.app;import com.google.android.samples.R;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.RemoteViews;/** * Demonstrates adding notifications to the status bar */public class StatusBarNotifications extends Activity {    private NotificationManager mNotificationManager;    // Use our layout id for a unique identifier    private static int MOOD_NOTIFICATIONS = R.layout.status_bar_notifications;    @Override    protected void onCreate(Bundle icicle) {        super.onCreate(icicle);        setContentView(R.layout.status_bar_notifications);        Button button;        // Get the notification manager serivce.        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        button = (Button) findViewById(R.id.happy);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMood(R.drawable.stat_happy, R.string.status_bar_notifications_happy_message,                        false);            }        });        button = (Button) findViewById(R.id.neutral);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMood(R.drawable.stat_neutral, R.string.status_bar_notifications_ok_message,                        false);            }        });        button = (Button) findViewById(R.id.sad);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMood(R.drawable.stat_sad, R.string.status_bar_notifications_sad_message, false);            }        });        button = (Button) findViewById(R.id.happyMarquee);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMood(R.drawable.stat_happy, R.string.status_bar_notifications_happy_message,                        true);            }        });        button = (Button) findViewById(R.id.neutralMarquee);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMood(R.drawable.stat_neutral, R.string.status_bar_notifications_ok_message, true);            }        });        button = (Button) findViewById(R.id.sadMarquee);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMood(R.drawable.stat_sad, R.string.status_bar_notifications_sad_message, true);            }        });        button = (Button) findViewById(R.id.happyViews);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMoodRemoteView(R.drawable.stat_happy, R.string.status_bar_notifications_happy_message);            }        });        button = (Button) findViewById(R.id.neutralViews);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMoodRemoteView(R.drawable.stat_neutral, R.string.status_bar_notifications_ok_message);            }        });        button = (Button) findViewById(R.id.sadViews);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                setMoodRemoteView(R.drawable.stat_sad, R.string.status_bar_notifications_sad_message);            }        });                button = (Button) findViewById(R.id.clear);        button.setOnClickListener(new Button.OnClickListener() {            public void onClick(View v) {                mNotificationManager.cancel(MOOD_NOTIFICATIONS);            }        });    }    private void setMood(int moodId, int textId, boolean showTicker) {        String str = getResources().getString(textId);        Notification notification = new Notification(moodId, str, null, showTicker ? str : null,                null);        mNotificationManager.notify(MOOD_NOTIFICATIONS, notification);    }    private void setMoodRemoteView(int moodId, int textId) {        String str = getResources().getString(textId);        RemoteViews remoteViews = new RemoteViews(this.getPackageName(),                R.layout.status_bar_balloon);        remoteViews.setImageViewResource(R.id.icon, moodId);        remoteViews.setTextViewText(R.id.text, str);        Notification notification = new Notification(moodId, str, null, null, remoteViews);        mNotificationManager.notify(MOOD_NOTIFICATIONS, notification);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -