SystemUIDialog.java revision 1bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4
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 com.android.systemui.R;
205005244f10442e75c1f48973fdddce5facf3f360Adrian Roos
215005244f10442e75c1f48973fdddce5facf3f360Adrian Roosimport android.app.AlertDialog;
225005244f10442e75c1f48973fdddce5facf3f360Adrian Roosimport android.content.Context;
235005244f10442e75c1f48973fdddce5facf3f360Adrian Roosimport android.view.WindowManager;
245005244f10442e75c1f48973fdddce5facf3f360Adrian Roos
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) {
335005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        super(context, R.style.Theme_SystemUI_Dialog);
341bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        mContext = context;
351bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
365005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        getWindow().setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL);
375005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
385005244f10442e75c1f48973fdddce5facf3f360Adrian Roos                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
395005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        WindowManager.LayoutParams attrs = getWindow().getAttributes();
40351346092acdfbfcc1d9ebf98d539d2a1196c5e8John Spurlock        attrs.setTitle(getClass().getSimpleName());
415005244f10442e75c1f48973fdddce5facf3f360Adrian Roos        getWindow().setAttributes(attrs);
425005244f10442e75c1f48973fdddce5facf3f360Adrian Roos    }
431bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
441bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setShowForAllUsers(boolean show) {
451bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        if (show) {
461bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock            getWindow().getAttributes().privateFlags |=
471bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock                    WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
481bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        } else {
491bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock            getWindow().getAttributes().privateFlags &=
501bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock                    ~WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
511bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        }
521bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
531bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
541bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setMessage(int resId) {
551bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        setMessage(mContext.getString(resId));
561bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
571bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
581bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setPositiveButton(int resId, OnClickListener onClick) {
591bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        setButton(BUTTON_POSITIVE, mContext.getString(resId), onClick);
601bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
611bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock
621bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    public void setNegativeButton(int resId, OnClickListener onClick) {
631bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock        setButton(BUTTON_NEGATIVE, mContext.getString(resId), onClick);
641bb480a3a4ce2ce63c5d09fa7f5cc38ec160ebf4John Spurlock    }
655005244f10442e75c1f48973fdddce5facf3f360Adrian Roos}
66