1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.example.notificationshowcase; 18 19 import android.app.Activity; 20 import android.app.NotificationManager; 21 import android.app.PendingIntent; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.os.Bundle; 25 import android.os.Handler; 26 import android.os.Looper; 27 import android.os.Message; 28 import android.os.PowerManager; 29 import android.view.View; 30 import android.view.WindowManager; 31 32 public class FullScreenActivity extends Activity { 33 private static final String TAG = "NotificationShowcase"; 34 35 public static final String EXTRA_ID = "id"; 36 private Handler mHandler = new Handler(Looper.getMainLooper()); 37 private PowerManager.WakeLock mWakeLock; 38 39 @Override onCreate(Bundle savedInstanceState)40 public void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 43 setContentView(R.layout.full_screen); 44 45 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 46 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Incoming Call"); 47 mWakeLock.acquire(15 * 1000); 48 49 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | 50 WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | 51 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 52 WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 53 54 final Intent intent = getIntent(); 55 if (intent != null && intent.hasExtra(EXTRA_ID)) { 56 final int id = intent.getIntExtra(EXTRA_ID, -1); 57 if (id >= 0) { 58 NotificationManager noMa = 59 (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 60 noMa.cancel(NotificationService.NOTIFICATION_ID + id); 61 } 62 } 63 64 mHandler.postDelayed(new Runnable() { 65 @Override 66 public void run() { 67 dismiss(null); 68 } 69 }, 30 * 1000); 70 } 71 dismiss(View v)72 public void dismiss(View v) { 73 if (mWakeLock.isHeld()) { 74 mWakeLock.release(); 75 } 76 finish(); 77 } 78 getPendingIntent(Context context, int id)79 public static PendingIntent getPendingIntent(Context context, int id) { 80 Intent fullScreenIntent = new Intent(context, FullScreenActivity.class); 81 fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 82 83 fullScreenIntent.putExtra(EXTRA_ID, id); 84 PendingIntent pi = PendingIntent.getActivity( 85 context, 22, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT); 86 return pi; 87 } 88 } 89