2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
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.os.SystemProperties;
26 import android.text.TextUtils;
27 import android.view.Gravity;
28 import android.view.LayoutInflater;
29 import android.view.View;
30 import android.view.ViewGroup;
31 import android.widget.ImageView;
32 import android.widget.TextView;
33 import com.android.settings.deviceinfo.Status;
36 * {@link Activity} that displays regulatory information for the "Regulatory information"
37 * preference item, and when "*#07#" is dialed on the Phone keypad. To enable this feature,
38 * set the "config_show_regulatory_info" boolean to true in a device overlay resource, and in the
39 * same overlay, either add a drawable named "regulatory_info.png" containing a graphical version
40 * of the required regulatory info (If ro.bootloader.hardware.sku property is set use
41 * "regulatory_info_<sku>.png where sku is ro.bootloader.hardware.sku property value in lowercase"),
42 * or add a string resource named "regulatory_info_text" with an HTML version of the required
43 * information (text will be centered in the dialog).
45 public class RegulatoryInfoDisplayActivity extends Activity implements
46 DialogInterface.OnDismissListener {
47 private final String REGULATORY_INFO_RESOURCE = "regulatory_info";
50 * Display the regulatory info graphic in a dialog window.
53 protected void onCreate(Bundle savedInstanceState) {
54 super.onCreate(savedInstanceState);
55 Resources resources = getResources();
57 if (!resources.getBoolean(R.bool.config_show_regulatory_info)) {
58 finish(); // no regulatory info to display for this device
61 AlertDialog.Builder builder = new AlertDialog.Builder(this)
62 .setTitle(R.string.regulatory_information_dialog_title)
63 .setOnDismissListener(this);
65 View view = getLayoutInflater().inflate(R.layout.regulatory_info, null);
67 boolean regulatoryInfoDrawableExists = false;
68 int resId = getResourceId();
71 Drawable d = getDrawable(resId);
72 // set to false if the width or height is <= 32
73 // (default PNG is a 1x1 pixel image scaled to the display density)
74 regulatoryInfoDrawableExists = (d.getIntrinsicWidth() > 32
75 && d.getIntrinsicHeight() > 32);
76 } catch (Resources.NotFoundException ignored) {
77 regulatoryInfoDrawableExists = false;
81 if (regulatoryInfoDrawableExists) {
82 ImageView image = (ImageView) view.findViewById(R.id.regulatoryInfo);
83 image.setVisibility(View.VISIBLE);
84 image.setImageResource(resId);
87 String sarValues = Status.getSarValues(getResources());
88 TextView sarText = (TextView) view.findViewById(R.id.sarValues);
89 if (!TextUtils.isEmpty(sarValues)) {
90 sarText.setVisibility(resources.getBoolean(R.bool.config_show_sar_enable)
91 ? View.VISIBLE : View.GONE);
92 sarText.setText(sarValues);
95 String icCodes = Status.getIcCodes(getResources());
96 TextView icCode = (TextView) view.findViewById(R.id.icCodes);
97 if (!TextUtils.isEmpty(icCodes)) {
98 icCode.setVisibility(resources.getBoolean(R.bool.config_show_ic_enable)
99 ? View.VISIBLE : View.GONE);
100 icCode.setText(icCodes);
102 builder.setView(view);
106 private int getResourceId() {
107 // Use regulatory_info by default.
108 int resId = getResources().getIdentifier(
109 REGULATORY_INFO_RESOURCE, "drawable", getPackageName());
111 // When hardware sku property exists, use regulatory_info_<sku> resource if valid.
112 String sku = SystemProperties.get("ro.boot.hardware.sku", "");
113 if (!TextUtils.isEmpty(sku)) {
114 String regulatory_info_res = REGULATORY_INFO_RESOURCE + "_" + sku.toLowerCase();
115 int id = getResources().getIdentifier(
116 regulatory_info_res, "drawable", getPackageName());
125 public void onDismiss(DialogInterface dialog) {
126 finish(); // close the activity