SystemUIDialog.java revision c0d7058b14c24cd07912f5629c26b39b7b4673d5
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
405005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        getWindow().setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL);
415005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
425005244f10442e75c1f48973fdddce5facf3f360Adrian Roos                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
435005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        WindowManager.LayoutParams attrs = getWindow().getAttributes();
44351346092acdfbfcc1d9ebf98d539d2a1196c5e8John Spurlock        attrs.setTitle(getClass().getSimpleName());
455005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        getWindow().setAttributes(attrs);
465005244f10442e75c1f48973fdddce5facf3f360Adrian Roos    }
471bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
481bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setShowForAllUsers(boolean show) {
491bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        if (show) {
501bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock            getWindow().getAttributes().privateFlags |=
511bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock                    WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
521bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        } else {
531bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock            getWindow().getAttributes().privateFlags &=
541bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock                    ~WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
551bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        }
561bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
571bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
581bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setMessage(int resId) {
591bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        setMessage(mContext.getString(resId));
601bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
611bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
621bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setPositiveButton(int resId, OnClickListener onClick) {
631bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        setButton(BUTTON_POSITIVE, mContext.getString(resId), onClick);
641bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
651bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
661bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setNegativeButton(int resId, OnClickListener onClick) {
671bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        setButton(BUTTON_NEGATIVE, mContext.getString(resId), onClick);
681bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
695005244f10442e75c1f48973fdddce5facf3f360Adrian Roos}
70