/src/com/android/phone/PhoneDisplayMessage.java

https://gitlab.com/Atomic-ROM/packages_services_Telephony · Java · 102 lines · 49 code · 16 blank · 37 comment · 9 complexity · b34075edff19ab9f8cac6872b278dda4 MD5 · raw file

  1. /*
  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. package com.android.phone;
  17. import android.app.AlertDialog;
  18. import android.content.Context;
  19. import android.os.SystemProperties;
  20. import android.util.Log;
  21. import android.view.WindowManager;
  22. /**
  23. * Helper class for displaying the a string triggered by a lower level Phone request
  24. */
  25. public class PhoneDisplayMessage {
  26. private static final String LOG_TAG = "PhoneDisplayMessage";
  27. private static final boolean DBG = (SystemProperties.getInt("ro.debuggable", 0) == 1);
  28. /** Display message dialog */
  29. private static AlertDialog sDisplayMessageDialog = null;
  30. /**
  31. * Display the alert dialog with the network message.
  32. *
  33. * @param context context to get strings.
  34. * @param infoMsg Text message from Network.
  35. */
  36. public static void displayNetworkMessage(Context context, String infoMsg) {
  37. if (DBG) log("displayInfoRecord: infoMsg=" + infoMsg);
  38. String title = (String)context.getText(R.string.network_info_message);
  39. displayMessage(context, title, infoMsg);
  40. }
  41. /**
  42. * Display the alert dialog with the error message.
  43. *
  44. * @param context context to get strings.
  45. * @param errorMsg Error message describing the network triggered error
  46. */
  47. public static void displayErrorMessage(Context context, String errorMsg) {
  48. if (DBG) log("displayErrorMessage: errorMsg=" + errorMsg);
  49. String title = (String)context.getText(R.string.network_error_message);
  50. displayMessage(context, title, errorMsg);
  51. }
  52. public static void displayMessage(Context context, String title, String msg) {
  53. if (DBG) log("displayMessage: msg=" + msg);
  54. if (sDisplayMessageDialog != null) {
  55. sDisplayMessageDialog.dismiss();
  56. }
  57. // displaying system alert dialog on the screen instead of
  58. // using another activity to display the message. This
  59. // places the message at the forefront of the UI.
  60. sDisplayMessageDialog = new AlertDialog.Builder(context)
  61. .setIcon(android.R.drawable.ic_dialog_info)
  62. .setTitle(title)
  63. .setMessage(msg)
  64. .setCancelable(true)
  65. .create();
  66. sDisplayMessageDialog.getWindow().setType(
  67. WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
  68. sDisplayMessageDialog.getWindow().addFlags(
  69. WindowManager.LayoutParams.FLAG_DIM_BEHIND);
  70. sDisplayMessageDialog.show();
  71. PhoneGlobals.getInstance().wakeUpScreen();
  72. }
  73. /**
  74. * Dismiss the DisplayInfo record
  75. */
  76. public static void dismissMessage() {
  77. if (DBG) log("Dissmissing Display Info Record...");
  78. if (sDisplayMessageDialog != null) {
  79. sDisplayMessageDialog.dismiss();
  80. sDisplayMessageDialog = null;
  81. }
  82. }
  83. private static void log(String msg) {
  84. Log.d(LOG_TAG, "[PhoneDisplayMessage] " + msg);
  85. }
  86. }