blob: 199fbb827fa6d3e02c8eb5492ea46ac58e069d7b [file] [log] [blame]
Anthony Leee9468532014-11-15 15:21:00 -08001/*
2 * Copyright (C) 2009 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
17package com.android.phone;
18
19import android.app.AlertDialog;
20import android.content.Context;
21import android.os.SystemProperties;
22import android.util.Log;
23import android.view.WindowManager;
24
25/**
26 * Helper class for displaying the a string triggered by a lower level Phone request
27 */
28public class PhoneDisplayMessage {
29 private static final String LOG_TAG = "PhoneDisplayMessage";
30 private static final boolean DBG = (SystemProperties.getInt("ro.debuggable", 0) == 1);
31
32 /** Display message dialog */
33 private static AlertDialog sDisplayMessageDialog = null;
34
35 /**
36 * Display the alert dialog with the network message.
37 *
38 * @param context context to get strings.
39 * @param infoMsg Text message from Network.
40 */
41 public static void displayNetworkMessage(Context context, String infoMsg) {
42 if (DBG) log("displayInfoRecord: infoMsg=" + infoMsg);
43
44 String title = (String)context.getText(R.string.network_info_message);
45 displayMessage(context, title, infoMsg);
46 }
47
48 /**
49 * Display the alert dialog with the error message.
50 *
51 * @param context context to get strings.
52 * @param errorMsg Error message describing the network triggered error
53 */
54 public static void displayErrorMessage(Context context, String errorMsg) {
55 if (DBG) log("displayErrorMessage: errorMsg=" + errorMsg);
56
57 String title = (String)context.getText(R.string.network_error_message);
58 displayMessage(context, title, errorMsg);
59 }
60
61 public static void displayMessage(Context context, String title, String msg) {
62 if (DBG) log("displayMessage: msg=" + msg);
63
64 if (sDisplayMessageDialog != null) {
65 sDisplayMessageDialog.dismiss();
66 }
67
68 // displaying system alert dialog on the screen instead of
69 // using another activity to display the message. This
70 // places the message at the forefront of the UI.
71 sDisplayMessageDialog = new AlertDialog.Builder(context)
72 .setIcon(android.R.drawable.ic_dialog_info)
73 .setTitle(title)
74 .setMessage(msg)
75 .setCancelable(true)
76 .create();
77
78 sDisplayMessageDialog.getWindow().setType(
79 WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
80 sDisplayMessageDialog.getWindow().addFlags(
Meng Wanga2a26182019-10-02 14:27:09 -070081 WindowManager.LayoutParams.FLAG_DIM_BEHIND
82 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
83 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Anthony Leee9468532014-11-15 15:21:00 -080084
85 sDisplayMessageDialog.show();
Anthony Leee9468532014-11-15 15:21:00 -080086 }
87
88 /**
89 * Dismiss the DisplayInfo record
90 */
91 public static void dismissMessage() {
92 if (DBG) log("Dissmissing Display Info Record...");
93
94 if (sDisplayMessageDialog != null) {
Meng Wanga2a26182019-10-02 14:27:09 -070095 sDisplayMessageDialog.getWindow().clearFlags(
96 WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
97 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Anthony Leee9468532014-11-15 15:21:00 -080098 sDisplayMessageDialog.dismiss();
99 sDisplayMessageDialog = null;
100 }
101 }
102
103 private static void log(String msg) {
104 Log.d(LOG_TAG, "[PhoneDisplayMessage] " + msg);
105 }
106}