OSDN Git Service

Merge tag 'android-6.0.1_r74' into HEAD
[android-x86/packages-apps-Settings.git] / src / com / android / settings / RegulatoryInfoDisplayActivity.java
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.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;
34
35 /**
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).
44  */
45 public class RegulatoryInfoDisplayActivity extends Activity implements
46         DialogInterface.OnDismissListener {
47     private final String REGULATORY_INFO_RESOURCE = "regulatory_info";
48
49     /**
50      * Display the regulatory info graphic in a dialog window.
51      */
52     @Override
53     protected void onCreate(Bundle savedInstanceState) {
54         super.onCreate(savedInstanceState);
55         Resources resources = getResources();
56
57         if (!resources.getBoolean(R.bool.config_show_regulatory_info)) {
58             finish();   // no regulatory info to display for this device
59         }
60
61         AlertDialog.Builder builder = new AlertDialog.Builder(this)
62                 .setTitle(R.string.regulatory_information_dialog_title)
63                 .setOnDismissListener(this);
64
65         View view = getLayoutInflater().inflate(R.layout.regulatory_info, null);
66
67         boolean regulatoryInfoDrawableExists = false;
68         int resId = getResourceId();
69         if (resId != 0) {
70             try {
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;
78             }
79         }
80
81         if (regulatoryInfoDrawableExists) {
82             ImageView image = (ImageView) view.findViewById(R.id.regulatoryInfo);
83             image.setVisibility(View.VISIBLE);
84             image.setImageResource(resId);
85         }
86
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);
93         }
94
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);
101         }
102         builder.setView(view);
103         builder.show();
104     }
105
106     private int getResourceId() {
107         // Use regulatory_info by default.
108         int resId = getResources().getIdentifier(
109                 REGULATORY_INFO_RESOURCE, "drawable", getPackageName());
110
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());
117             if (id != 0) {
118                 resId = id;
119             }
120         }
121         return resId;
122     }
123
124     @Override
125     public void onDismiss(DialogInterface dialog) {
126         finish();   // close the activity
127     }
128 }