15005244f10442e75c1f48973fdddce5facf3f360Adrian Roos/* 25005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * Copyright (C) 2014 The Android Open Source Project 35005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * 45005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * Licensed under the Apache License, Version 2.0 (the "License"); 55005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * you may not use this file except in compliance with the License. 65005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * You may obtain a copy of the License at 75005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * 85005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * http://www.apache.org/licenses/LICENSE-2.0 95005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * 105005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * Unless required by applicable law or agreed to in writing, software 115005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * distributed under the License is distributed on an "AS IS" BASIS, 125005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * See the License for the specific language governing permissions and 145005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * limitations under the License 155005244f10442e75c1f48973fdddce5facf3f360Adrian Roos */ 165005244f10442e75c1f48973fdddce5facf3f360Adrian Roos 175005244f10442e75c1f48973fdddce5facf3f360Adrian Roospackage com.android.systemui.statusbar.phone; 185005244f10442e75c1f48973fdddce5facf3f360Adrian Roos 195005244f10442e75c1f48973fdddce5facf3f360Adrian Roosimport android.app.AlertDialog; 205005244f10442e75c1f48973fdddce5facf3f360Adrian Roosimport android.content.Context; 215005244f10442e75c1f48973fdddce5facf3f360Adrian Roosimport android.view.WindowManager; 225005244f10442e75c1f48973fdddce5facf3f360Adrian Roos 23c0d7058b14c24cd07912f5629c26b39b7b4673d5Winsonimport com.android.systemui.R; 24c0d7058b14c24cd07912f5629c26b39b7b4673d5Winson 255005244f10442e75c1f48973fdddce5facf3f360Adrian Roos/** 265005244f10442e75c1f48973fdddce5facf3f360Adrian Roos * Base class for dialogs that should appear over panels and keyguard. 275005244f10442e75c1f48973fdddce5facf3f360Adrian Roos */ 285005244f10442e75c1f48973fdddce5facf3f360Adrian Roospublic class SystemUIDialog extends AlertDialog { 295005244f10442e75c1f48973fdddce5facf3f360Adrian Roos 301bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock private final Context mContext; 311bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock 325005244f10442e75c1f48973fdddce5facf3f360Adrian Roos public SystemUIDialog(Context context) { 335db8a4142e35d62073d81806ff7317e840e30ebcJason Monk this(context, R.style.Theme_SystemUI_Dialog); 345db8a4142e35d62073d81806ff7317e840e30ebcJason Monk } 355db8a4142e35d62073d81806ff7317e840e30ebcJason Monk 365db8a4142e35d62073d81806ff7317e840e30ebcJason Monk public SystemUIDialog(Context context, int theme) { 375db8a4142e35d62073d81806ff7317e840e30ebcJason Monk super(context, theme); 381bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock mContext = context; 391bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock 4039c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk applyFlags(this); 415005244f10442e75c1f48973fdddce5facf3f360Adrian Roos WindowManager.LayoutParams attrs = getWindow().getAttributes(); 42351346092acdfbfcc1d9ebf98d539d2a1196c5e8John Spurlock attrs.setTitle(getClass().getSimpleName()); 435005244f10442e75c1f48973fdddce5facf3f360Adrian Roos getWindow().setAttributes(attrs); 445005244f10442e75c1f48973fdddce5facf3f360Adrian Roos } 451bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock 461bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock public void setShowForAllUsers(boolean show) { 4739c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk setShowForAllUsers(this, show); 481bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock } 491bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock 501bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock public void setMessage(int resId) { 511bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock setMessage(mContext.getString(resId)); 521bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock } 531bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock 541bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock public void setPositiveButton(int resId, OnClickListener onClick) { 551bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock setButton(BUTTON_POSITIVE, mContext.getString(resId), onClick); 561bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock } 571bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock 581bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock public void setNegativeButton(int resId, OnClickListener onClick) { 591bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock setButton(BUTTON_NEGATIVE, mContext.getString(resId), onClick); 601bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock } 6139c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk 6239c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk public static void setShowForAllUsers(AlertDialog dialog, boolean show) { 6339c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk if (show) { 6439c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk dialog.getWindow().getAttributes().privateFlags |= 6539c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; 6639c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk } else { 6739c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk dialog.getWindow().getAttributes().privateFlags &= 6839c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk ~WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; 6939c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk } 7039c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk } 7139c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk 7239c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk public static void applyFlags(AlertDialog dialog) { 7339c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL); 7439c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM 7539c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 7639c98e652fd3e0e3ea3a334d60ba6ee979985978Jason Monk } 775005244f10442e75c1f48973fdddce5facf3f360Adrian Roos} 78