2 * Copyright (C) 2009 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.AlertDialog;
20 import android.content.Context;
21 import android.content.res.Configuration;
22 import android.os.Build;
23 import android.os.Bundle;
24 import android.os.SystemProperties;
25 import android.telephony.TelephonyManager;
26 import android.text.TextUtils;
27 import android.view.KeyEvent;
28 import android.webkit.WebView;
29 import android.webkit.WebViewClient;
30 import com.android.internal.app.AlertActivity;
31 import com.android.internal.app.AlertController;
32 import android.content.DialogInterface;
35 * The "dialog" that shows from "Safety information" in the Settings app.
37 public class SettingsSafetyLegalActivity extends AlertActivity
38 implements DialogInterface.OnCancelListener, DialogInterface.OnClickListener {
39 private static final String PROPERTY_LSAFETYLEGAL_URL = "ro.url.safetylegal";
41 private WebView mWebView;
43 private AlertDialog mErrorDialog = null;
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
49 String userSafetylegalUrl = SystemProperties.get(PROPERTY_LSAFETYLEGAL_URL);
51 final Configuration configuration = getResources().getConfiguration();
52 final String language = configuration.locale.getLanguage();
53 final String country = configuration.locale.getCountry();
55 String loc = String.format("locale=%s-%s", language, country);
57 userSafetylegalUrl = String.format("%s&%s", userSafetylegalUrl, loc);
59 mWebView = new WebView(this);
62 mWebView.getSettings().setJavaScriptEnabled(true);
63 if (savedInstanceState == null) {
64 mWebView.loadUrl(userSafetylegalUrl);
66 mWebView.restoreState(savedInstanceState);
68 mWebView.setWebViewClient(new WebViewClient() {
70 public void onPageFinished(WebView view, String url) {
71 // Change from 'Loading...' to the real title
72 mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title));
76 public void onReceivedError(WebView view, int errorCode,
77 String description, String failingUrl) {
78 showErrorAndFinish(failingUrl);
82 final AlertController.AlertParams p = mAlertParams;
83 p.mTitle = getString(R.string.settings_safetylegal_activity_loading);
85 p.mForceInverseBackground = true;
89 private void showErrorAndFinish(String url) {
90 if (mErrorDialog == null) {
91 mErrorDialog = new AlertDialog.Builder(this)
92 .setTitle(R.string.settings_safetylegal_activity_title)
93 .setPositiveButton(android.R.string.ok, this)
94 .setOnCancelListener(this)
98 if (mErrorDialog.isShowing()) {
99 mErrorDialog.dismiss();
102 mErrorDialog.setMessage(getResources()
103 .getString(R.string.settings_safetylegal_activity_unreachable, url));
108 protected void onDestroy() {
111 if (mErrorDialog != null) {
112 mErrorDialog.dismiss();
118 public boolean dispatchKeyEvent(KeyEvent event) {
119 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
120 && event.getAction() == KeyEvent.ACTION_DOWN) {
121 if (mWebView.canGoBack()) {
126 return super.dispatchKeyEvent(event);
129 public void onClick(DialogInterface dialog, int whichButton) {
133 public void onCancel(DialogInterface dialog) {
138 public void onSaveInstanceState(Bundle icicle) {
139 mWebView.saveState(icicle);
140 super.onSaveInstanceState(icicle);