1 /* 2 * Copyright (C) 2013 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 17 package com.android.settings; 18 19 import android.app.Activity; 20 import android.app.AlertDialog; 21 import android.content.DialogInterface; 22 import android.content.res.Resources; 23 import android.graphics.drawable.Drawable; 24 import android.os.Bundle; 25 import android.view.Gravity; 26 import android.widget.TextView; 27 28 /** 29 * {@link Activity} that displays regulatory information for the "Regulatory information" 30 * preference item, and when "*#07#" is dialed on the Phone keypad. To enable this feature, 31 * set the "config_show_regulatory_info" boolean to true in a device overlay resource, and in the 32 * same overlay, either add a drawable named "regulatory_info.png" containing a graphical version 33 * of the required regulatory info, or add a string resource named "regulatory_info_text" with 34 * an HTML version of the required information (text will be centered in the dialog). 35 */ 36 public class RegulatoryInfoDisplayActivity extends Activity implements 37 DialogInterface.OnDismissListener { 38 39 /** 40 * Display the regulatory info graphic in a dialog window. 41 */ 42 @Override 43 protected void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 Resources resources = getResources(); 46 47 if (!resources.getBoolean(R.bool.config_show_regulatory_info)) { 48 finish(); // no regulatory info to display for this device 49 } 50 51 AlertDialog.Builder builder = new AlertDialog.Builder(this) 52 .setTitle(R.string.regulatory_information) 53 .setOnDismissListener(this); 54 55 boolean regulatoryInfoDrawableExists; 56 try { 57 Drawable d = resources.getDrawable(R.drawable.regulatory_info); 58 // set to false if the width or height is <= 2 59 // (missing PNG can return an empty 2x2 pixel Drawable) 60 regulatoryInfoDrawableExists = (d.getIntrinsicWidth() > 2 61 && d.getIntrinsicHeight() > 2); 62 } catch (Resources.NotFoundException ignored) { 63 regulatoryInfoDrawableExists = false; 64 } 65 66 CharSequence regulatoryText = resources.getText(R.string.regulatory_info_text); 67 68 if (regulatoryInfoDrawableExists) { 69 builder.setView(getLayoutInflater().inflate(R.layout.regulatory_info, null)); 70 builder.show(); 71 } else if (regulatoryText.length() > 0) { 72 builder.setMessage(regulatoryText); 73 AlertDialog dialog = builder.show(); 74 // we have to show the dialog first, or the setGravity() call will throw a NPE 75 TextView messageText = (TextView) dialog.findViewById(android.R.id.message); 76 messageText.setGravity(Gravity.CENTER); 77 } else { 78 // neither drawable nor text resource exists, finish activity 79 finish(); 80 } 81 } 82 83 @Override 84 public void onDismiss(DialogInterface dialog) { 85 finish(); // close the activity 86 } 87 } 88